X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F05restrict.t;fp=t%2F05restrict.t;h=7b2702bb1946d6e2d11d54432dedf84c35748266;hb=d87edac900b7430e435d828aa8deab5a2dd8495e;hp=3682be08d0c7f89b0f9f49b1a323350d92f20cb8;hpb=772c89c170f979890e5f8d7e7522d50e8dc0323e;p=dbsrgits%2FDBIx-Class-Schema-RestrictWithObject.git diff --git a/t/05restrict.t b/t/05restrict.t index 3682be0..7b2702b 100644 --- a/t/05restrict.t +++ b/t/05restrict.t @@ -4,11 +4,18 @@ use Test::More; use Scalar::Util; -plan (tests => 17); +BEGIN { + eval "use DBD::SQLite"; + plan $@ + ? ( skip_all => 'needs DBD::SQLite for testing' ) + : ( tests => 19 ); +} + use lib qw(t/lib); -use RestrictByUserTest; +use_ok('DBIx::Class::Schema::RestrictWithObject'); +use_ok('RestrictByUserTest'); my $schema = RestrictByUserTest->init_schema; ok($schema, "Connected successfully"); @@ -24,21 +31,21 @@ ok($user2->notes->create({name => 'note 2-2'}), "Successfully created 2-2 note") ok($user2->notes->create({name => 'note 2-3'}), "Successfully created 2-3 note"); ok($user2->notes->create({name => 'note 2-4'}), "Successfully created 2-4 note"); -my $u1_schema = $schema->restrict_by_user($user1); -my $u2_schema = $schema->restrict_by_user($user2, "MY"); -my $u3_schema = $schema->restrict_by_user($user2, "BUNK"); +my $u1_schema = $schema->restrict_with_object($user1); +my $u2_schema = $schema->restrict_with_object($user2, "MY"); +my $u3_schema = $schema->restrict_with_object($user2, "BUNK"); -is($u1_schema->user->id, $user1->id, "Correct restriction for user 1"); -is($u2_schema->user->id, $user2->id, "Correct restriction for user 2"); +is($u1_schema->restricting_object->id, $user1->id, "Correct restriction for user 1"); +is($u2_schema->restricting_object->id, $user2->id, "Correct restriction for user 2"); is($u2_schema->restricted_prefix, "MY", "Correct prefix for user 2"); -ok(Scalar::Util::refaddr($u1_schema) ne Scalar::Util::refaddr($u2_schema), +ok(Scalar::Util::refaddr($u1_schema) ne Scalar::Util::refaddr($u2_schema), "Successful clones"); is($schema->resultset('Notes')->count, 6, 'Correct un resticted count'); is($u1_schema->resultset('Notes')->count, 2, 'Correct resticted count'); is($u2_schema->resultset('Notes')->count, 4, 'Correct resticted count using prefix'); -is($u2_schema->resultset('Notes')->count, 4, +is($u2_schema->resultset('Notes')->count, 4, 'Correct resticted count using prefix and fallback'); is($u2_schema->resultset('Users')->count, 2, 'Unrestricted resultsets work');