From: Matt S Trout Date: Sat, 14 Jan 2006 07:36:56 +0000 (+0000) Subject: Some test hackage X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1edaf6fef6739e4d809ae6adfbeaa6b660ca29b3;p=dbsrgits%2FDBIx-Class-Historic.git Some test hackage --- diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 8385e1d..f948be3 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -243,8 +243,10 @@ sub compose_namespace { no strict 'refs'; *{"${target}::schema"} = sub { $schema }; - *{"${target}::class"} = - sub { shift->schema->class(@_) }; + foreach my $meth (qw/class source resultset/) { + *{"${target}::${meth}"} = + sub { shift->schema->$meth(@_) }; + } } $base->class_resolver($target); return $schema; diff --git a/t/basicrels/01core.t b/t/basicrels/01core.t index e0e4fda..e3167db 100644 --- a/t/basicrels/01core.t +++ b/t/basicrels/01core.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/01core.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/04db.t b/t/basicrels/04db.t index 345facb..9683b47 100644 --- a/t/basicrels/04db.t +++ b/t/basicrels/04db.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/04db.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/05multipk.t b/t/basicrels/05multipk.t index d709d21..902896c 100644 --- a/t/basicrels/05multipk.t +++ b/t/basicrels/05multipk.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/05multipk.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/06relationship.t b/t/basicrels/06relationship.t index 9526667..f159034 100644 --- a/t/basicrels/06relationship.t +++ b/t/basicrels/06relationship.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/06relationship.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/07pager.t b/t/basicrels/07pager.t index ed81a2f..fb3a466 100644 --- a/t/basicrels/07pager.t +++ b/t/basicrels/07pager.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/07pager.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/08inflate.t b/t/basicrels/08inflate.t index 65adcae..523cc77 100644 --- a/t/basicrels/08inflate.t +++ b/t/basicrels/08inflate.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/08inflate.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/08inflate_has_a.t b/t/basicrels/08inflate_has_a.t index 8a4495c..afb7f32 100644 --- a/t/basicrels/08inflate_has_a.t +++ b/t/basicrels/08inflate_has_a.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/08inflate_has_a.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/09update.t b/t/basicrels/09update.t index 8e81173..31f53f1 100644 --- a/t/basicrels/09update.t +++ b/t/basicrels/09update.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/09update.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/10auto.t b/t/basicrels/10auto.t index a108be5..4537d85 100644 --- a/t/basicrels/10auto.t +++ b/t/basicrels/10auto.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/10auto.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/11mysql.t b/t/basicrels/11mysql.t index 04d2e44..9913f99 100644 --- a/t/basicrels/11mysql.t +++ b/t/basicrels/11mysql.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/11mysql.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/12pg.t b/t/basicrels/12pg.t index d6f818d..c7b9d3b 100644 --- a/t/basicrels/12pg.t +++ b/t/basicrels/12pg.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/12pg.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/13oracle.t b/t/basicrels/13oracle.t index c9ad119..cf4588c 100644 --- a/t/basicrels/13oracle.t +++ b/t/basicrels/13oracle.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/13oracle.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/14mssql.t b/t/basicrels/14mssql.t index e8c1172..59f6a84 100644 --- a/t/basicrels/14mssql.t +++ b/t/basicrels/14mssql.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/14mssql.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/15limit.t b/t/basicrels/15limit.t index 61f72a3..fb17373 100644 --- a/t/basicrels/15limit.t +++ b/t/basicrels/15limit.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/15limit.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/16joins.t b/t/basicrels/16joins.t index 9957a59..e50db25 100644 --- a/t/basicrels/16joins.t +++ b/t/basicrels/16joins.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/16joins.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/17join_count.t b/t/basicrels/17join_count.t index d701e2e..c1ce46b 100644 --- a/t/basicrels/17join_count.t +++ b/t/basicrels/17join_count.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/17join_count.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/basicrels/18self_referencial.t b/t/basicrels/18self_referencial.t index 51ed0fe..33efc0d 100644 --- a/t/basicrels/18self_referencial.t +++ b/t/basicrels/18self_referencial.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::BasicRels; require "t/run/18self_referencial.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/01core.t b/t/helperrels/01core.t index d902a9d..a6d39f0 100644 --- a/t/helperrels/01core.t +++ b/t/helperrels/01core.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/01core.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/04db.t b/t/helperrels/04db.t index 9b2e882..c7071d2 100644 --- a/t/helperrels/04db.t +++ b/t/helperrels/04db.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/04db.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/05multipk.t b/t/helperrels/05multipk.t index f014d52..a85d475 100644 --- a/t/helperrels/05multipk.t +++ b/t/helperrels/05multipk.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/05multipk.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/06relationship.t b/t/helperrels/06relationship.t index 17cd6c0..48a842e 100644 --- a/t/helperrels/06relationship.t +++ b/t/helperrels/06relationship.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/06relationship.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/07pager.t b/t/helperrels/07pager.t index ecdc78a..b49a233 100644 --- a/t/helperrels/07pager.t +++ b/t/helperrels/07pager.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/07pager.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/08inflate.t b/t/helperrels/08inflate.t index ba84489..34c789b 100644 --- a/t/helperrels/08inflate.t +++ b/t/helperrels/08inflate.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/08inflate.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/08inflate_has_a.t b/t/helperrels/08inflate_has_a.t index fa71c69..078b1c6 100644 --- a/t/helperrels/08inflate_has_a.t +++ b/t/helperrels/08inflate_has_a.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/08inflate_has_a.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/09update.t b/t/helperrels/09update.t index 30f40ca..dd35b32 100644 --- a/t/helperrels/09update.t +++ b/t/helperrels/09update.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/09update.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/10auto.t b/t/helperrels/10auto.t index 538e843..d91b177 100644 --- a/t/helperrels/10auto.t +++ b/t/helperrels/10auto.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/10auto.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/11mysql.t b/t/helperrels/11mysql.t index f794bfe..f3d3663 100644 --- a/t/helperrels/11mysql.t +++ b/t/helperrels/11mysql.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/11mysql.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/12pg.t b/t/helperrels/12pg.t index 3e3a2b2..b5dd9a6 100644 --- a/t/helperrels/12pg.t +++ b/t/helperrels/12pg.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/12pg.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/13oracle.t b/t/helperrels/13oracle.t index 138c969..41a860b 100644 --- a/t/helperrels/13oracle.t +++ b/t/helperrels/13oracle.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/13oracle.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/14mssql.t b/t/helperrels/14mssql.t index 14267e9..def9e24 100644 --- a/t/helperrels/14mssql.t +++ b/t/helperrels/14mssql.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/14mssql.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/15limit.t b/t/helperrels/15limit.t index aec8fa2..b165930 100644 --- a/t/helperrels/15limit.t +++ b/t/helperrels/15limit.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/15limit.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/16joins.t b/t/helperrels/16joins.t index b2e556e..61b79d7 100644 --- a/t/helperrels/16joins.t +++ b/t/helperrels/16joins.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/16joins.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/17join_count.t b/t/helperrels/17join_count.t index a8e3c61..d617f21 100644 --- a/t/helperrels/17join_count.t +++ b/t/helperrels/17join_count.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/17join_count.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/18self_referencial.t b/t/helperrels/18self_referencial.t index 0eabe30..3d9971c 100644 --- a/t/helperrels/18self_referencial.t +++ b/t/helperrels/18self_referencial.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/18self_referencial.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/helperrels/19uuid.t b/t/helperrels/19uuid.t index b718916..040bcb3 100644 --- a/t/helperrels/19uuid.t +++ b/t/helperrels/19uuid.t @@ -4,4 +4,4 @@ use DBICTest; use DBICTest::HelperRels; require "t/run/19uuid.tl"; -run_tests(); +run_tests("DBICTest"); diff --git a/t/run/01core.tl b/t/run/01core.tl index 4337556..5b2ef11 100644 --- a/t/run/01core.tl +++ b/t/run/01core.tl @@ -1,8 +1,9 @@ sub run_tests { +my $schema = shift; plan tests => 34; -my @art = DBICTest->class("Artist")->search({ }, { order_by => 'name DESC'}); +my @art = $schema->class("Artist")->search({ }, { order_by => 'name DESC'}); cmp_ok(@art, '==', 3, "Three artists returned"); @@ -18,7 +19,7 @@ is($art->get_column("name"), 'We Are In Rehab', 'And via get_column'); ok($art->update, 'Update run'); -@art = DBICTest->class("Artist")->search({ name => 'We Are In Rehab' }); +@art = $schema->class("Artist")->search({ name => 'We Are In Rehab' }); cmp_ok(@art, '==', 1, "Changed artist returned by search"); @@ -26,7 +27,7 @@ cmp_ok($art[0]->artistid, '==', 3,'Correct artist too'); $art->delete; -@art = DBICTest->class("Artist")->search({ }); +@art = $schema->class("Artist")->search({ }); cmp_ok(@art, '==', 2, 'And then there were two'); @@ -42,15 +43,15 @@ $art->insert; ok($art->in_storage, "Re-created"); -@art = DBICTest->class("Artist")->search({ }); +@art = $schema->class("Artist")->search({ }); cmp_ok(@art, '==', 3, 'And now there are three again'); -my $new = DBICTest->class("Artist")->create({ artistid => 4 }); +my $new = $schema->class("Artist")->create({ artistid => 4 }); cmp_ok($new->artistid, '==', 4, 'Create produced record ok'); -@art = DBICTest->class("Artist")->search({ }); +@art = $schema->class("Artist")->search({ }); cmp_ok(@art, '==', 4, "Oh my god! There's four of them!"); @@ -66,15 +67,15 @@ $new->name('Man With A Spoon'); $new->update; -$new_again = DBICTest->class("Artist")->find(4); +$new_again = $schema->class("Artist")->find(4); is($new_again->name, 'Man With A Spoon', 'Retrieved correctly'); is($new_again->ID, 'DBICTest::Artist|artistid=4', 'unique object id generated correctly'); -is(DBICTest->class("Artist")->count, 4, 'count ok'); +is($schema->class("Artist")->count, 4, 'count ok'); -my $cd = DBICTest->class("CD")->find(1); +my $cd = $schema->class("CD")->find(1); my %cols = $cd->get_columns; cmp_ok(keys %cols, '==', 4, 'get_columns number of columns ok'); @@ -91,15 +92,15 @@ is($cd->year, 2005, 'set_columns ok'); $cd->discard_changes; # check whether ResultSource->ordered_columns returns columns in order originally supplied -my @cd = DBICTest->class("CD")->find(1)->result_source->ordered_columns; +my @cd = $schema->source("CD")->ordered_columns; is_deeply( \@cd, [qw/cdid artist title year/], 'ordered_columns'); -$cd = DBICTest->class("CD")->search({ title => 'Spoonful of bees' }, { cols => ['title'] })->next; +$cd = $schema->class("CD")->search({ title => 'Spoonful of bees' }, { cols => ['title'] })->next; is($cd->title, 'Spoonful of bees', 'subset of columns returned correctly'); # insert_or_update -$new = DBICTest->class("Track")->new( { +$new = $schema->class("Track")->new( { trackid => 100, cd => 1, position => 1, @@ -111,26 +112,26 @@ ok($new->in_storage, 'insert_or_update insert ok'); # test in update mode $new->position(5); $new->insert_or_update; -is( DBICTest->class("Track")->find(100)->position, 5, 'insert_or_update update ok'); +is( $schema->class("Track")->find(100)->position, 5, 'insert_or_update update ok'); -eval { DBICTest->class("Track")->load_components('DoesNotExist'); }; +eval { $schema->class("Track")->load_components('DoesNotExist'); }; ok $@, $@; -is(DBICTest->class("Artist")->field_name_for->{name}, 'artist name', 'mk_classdata usage ok'); +is($schema->class("Artist")->field_name_for->{name}, 'artist name', 'mk_classdata usage ok'); my $search = [ { 'tags.tag' => 'Cheesy' }, { 'tags.tag' => 'Blue' } ]; -my $or_rs = DBICTest->class("CD")->search($search, { join => 'tags', +my $or_rs = $schema->class("CD")->search($search, { join => 'tags', order_by => 'cdid' }); cmp_ok($or_rs->count, '==', 5, 'Search with OR ok'); -my $distinct_rs = DBICTest->class("CD")->search($search, { join => 'tags', distinct => 1 }); +my $distinct_rs = $schema->class("CD")->search($search, { join => 'tags', distinct => 1 }); cmp_ok($distinct_rs->all, '==', 4, 'DISTINCT search with OR ok'); -my $tag_rs = DBICTest->class('Tag')->search( +my $tag_rs = $schema->class('Tag')->search( [ { 'me.tag' => 'Cheesy' }, { 'me.tag' => 'Blue' } ]); my $rel_rs = $tag_rs->search_related('cd'); diff --git a/t/run/04db.tl b/t/run/04db.tl index 1b4089d..e1da6b4 100644 --- a/t/run/04db.tl +++ b/t/run/04db.tl @@ -1,30 +1,31 @@ sub run_tests { +my $schema = shift; plan tests => 2; # add some rows inside a transaction and commit it # XXX: Is storage->dbh the only way to get a dbh? -DBICTest->class("Artist")->txn_begin; +$schema->class("Artist")->txn_begin; for (10..15) { - DBICTest->class("Artist")->create( { + $schema->class("Artist")->create( { artistid => $_, name => "artist number $_", } ); } -DBICTest->class("Artist")->txn_commit; -my ($artist) = DBICTest->class("Artist")->find(15); +$schema->class("Artist")->txn_commit; +my ($artist) = $schema->class("Artist")->find(15); is($artist->name, 'artist number 15', "Commit ok"); # add some rows inside a transaction and roll it back -DBICTest->class("Artist")->txn_begin; +$schema->class("Artist")->txn_begin; for (21..30) { - DBICTest->class("Artist")->create( { + $schema->class("Artist")->create( { artistid => $_, name => "artist number $_", } ); } -DBICTest->class("Artist")->txn_rollback; -($artist) = DBICTest->class("Artist")->search( artistid => 25 ); +$schema->class("Artist")->txn_rollback; +($artist) = $schema->class("Artist")->search( artistid => 25 ); is($artist, undef, "Rollback ok"); } diff --git a/t/run/05multipk.tl b/t/run/05multipk.tl index 783207f..25ded39 100644 --- a/t/run/05multipk.tl +++ b/t/run/05multipk.tl @@ -1,11 +1,12 @@ sub run_tests { +my $schema = shift; plan tests => 4; $artist = DBICTest::Artist->find(1); ok($artist->find_related('twokeys', {cd => 1}), "find multiple pks using relationships + args"); -ok(DBICTest->class("FourKeys")->find(1,2,3,4), "find multiple pks without hash"); -ok(DBICTest->class("FourKeys")->find(5,4,3,6), "find multiple pks without hash"); -is(DBICTest->class("FourKeys")->find(1,2,3,4)->ID, 'DBICTest::FourKeys|bar=2|foo=1|goodbye=4|hello=3', 'unique object id ok for multiple pks'); +ok($schema->class("FourKeys")->find(1,2,3,4), "find multiple pks without hash"); +ok($schema->class("FourKeys")->find(5,4,3,6), "find multiple pks without hash"); +is($schema->class("FourKeys")->find(1,2,3,4)->ID, 'DBICTest::FourKeys|bar=2|foo=1|goodbye=4|hello=3', 'unique object id ok for multiple pks'); } diff --git a/t/run/06relationship.tl b/t/run/06relationship.tl index 57ff1f6..a954c1b 100644 --- a/t/run/06relationship.tl +++ b/t/run/06relationship.tl @@ -1,18 +1,19 @@ sub run_tests { +my $schema = shift; use strict; use warnings; plan tests => 17; # has_a test -my $cd = DBICTest->class("CD")->find(4); +my $cd = $schema->class("CD")->find(4); my ($artist) = ($INC{'DBICTest/HelperRels'} ? $cd->artist : $cd->search_related('artist')); is($artist->name, 'Random Boy Band', 'has_a search_related ok'); # has_many test with an order_by clause defined -$artist = DBICTest->class("Artist")->find(1); +$artist = $schema->class("Artist")->find(1); my @cds = ($INC{'DBICTest/HelperRels'} ? $artist->cds : $artist->search_related('cds')); @@ -41,7 +42,7 @@ is( ($artist->search_related('cds'))[3]->title, 'Big Flop', 'create_related ok' is( $artist->count_related('cds'), 4, 'count_related ok' ); # set_from_related -my $track = DBICTest->class("Track")->create( { +my $track = $schema->class("Track")->create( { trackid => 1, cd => 3, position => 98, @@ -56,7 +57,7 @@ if ($INC{'DBICTest/HelperRels.pm'}) { # except inflated object } # update_from_related, the same as set_from_related, but it calls update afterwards -$track = DBICTest->class("Track")->create( { +$track = $schema->class("Track")->create( { trackid => 2, cd => 3, position => 99, @@ -64,7 +65,7 @@ $track = DBICTest->class("Track")->create( { } ); $track->update_from_related( cd => $cd ); -my $t_cd = (DBICTest->class("Track")->search( cd => 4, position => 99 ))[0]->cd; +my $t_cd = ($schema->class("Track")->search( cd => 4, position => 99 ))[0]->cd; if ($INC{'DBICTest/HelperRels.pm'}) { # except inflated object is( $t_cd->cdid, 4, 'update_from_related ok' ); @@ -86,7 +87,7 @@ is( $cd->title, 'Greatest Hits', 'find_or_create_related new record ok' ); is( ($artist->search_related('cds'))[4]->title, 'Greatest Hits', 'find_or_create_related new record search ok' ); $artist->delete_related( cds => { title => 'Greatest Hits' }); -cmp_ok( DBICTest->class("CD")->search( title => 'Greatest Hits' ), '==', 0, 'delete_related ok' ); +cmp_ok( $schema->class("CD")->search( title => 'Greatest Hits' ), '==', 0, 'delete_related ok' ); SKIP: { skip "relationship checking needs fixing", 1; @@ -107,15 +108,15 @@ eval { like($@, qr/join condition/, 'failed when creating a rel without join condition, ok'); # many_to_many helper test -$cd = DBICTest->class("CD")->find(1); +$cd = $schema->class("CD")->find(1); my @producers = $cd->producers(); is( $producers[0]->name, 'Matt S Trout', 'many_to_many ok' ); # test undirected many-to-many relationship (e.g. "related artists") -my $undir_maps = DBICTest->class("Artist")->find(1)->artist_undirected_maps; +my $undir_maps = $schema->class("Artist")->find(1)->artist_undirected_maps; is($undir_maps->count, 1, 'found 1 undirected map for artist 1'); -$undir_maps = DBICTest->class("Artist")->find(2)->artist_undirected_maps; +$undir_maps = $schema->class("Artist")->find(2)->artist_undirected_maps; is($undir_maps->count, 1, 'found 1 undirected map for artist 2'); my @art = $undir_maps->search_related('mapped_artists')->all; diff --git a/t/run/07pager.tl b/t/run/07pager.tl index 3132af6..9406d71 100644 --- a/t/run/07pager.tl +++ b/t/run/07pager.tl @@ -1,9 +1,10 @@ sub run_tests { +my $schema = shift; plan tests => 12; # first page -my $it = DBICTest->class("CD")->search( +my $it = $schema->class("CD")->search( {}, { order_by => 'title', rows => 3, @@ -24,7 +25,7 @@ $it->next; is( $it->next, undef, "next past end of page ok" ); # second page, testing with array -my @page2 = DBICTest->class("CD")->search( +my @page2 = $schema->class("CD")->search( {}, { order_by => 'title', rows => 3, @@ -34,7 +35,7 @@ my @page2 = DBICTest->class("CD")->search( is( $page2[0]->title, "Generic Manufactured Singles", "second page first title ok" ); # page a standard resultset -$it = DBICTest->class("CD")->search( +$it = $schema->class("CD")->search( {}, { order_by => 'title', rows => 3 } @@ -46,7 +47,7 @@ is( $page->count, 2, "standard resultset paged rs count ok" ); is( $page->next->title, "Generic Manufactured Singles", "second page of standard resultset ok" ); # test software-based limit paging -$it = DBICTest->class("CD")->search( +$it = $schema->class("CD")->search( {}, { order_by => 'title', rows => 3, diff --git a/t/run/08inflate.tl b/t/run/08inflate.tl index d9cf9d1..9072fd5 100644 --- a/t/run/08inflate.tl +++ b/t/run/08inflate.tl @@ -1,4 +1,5 @@ sub run_tests { +my $schema = shift; eval { require DateTime }; plan skip_all => "Need DateTime for inflation tests" if $@; @@ -12,7 +13,7 @@ DBICTest::Schema::CD->inflate_column( 'year', Class::C3->reinitialize; # inflation test -my $cd = DBICTest->class("CD")->find(3); +my $cd = $schema->class("CD")->find(3); is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); @@ -23,7 +24,7 @@ my $now = DateTime->now; $cd->year( $now ); $cd->update; -($cd) = DBICTest->class("CD")->search( year => $now->year ); +($cd) = $schema->class("CD")->search( year => $now->year ); is( $cd->year->year, $now->year, 'deflate ok' ); } diff --git a/t/run/08inflate_has_a.tl b/t/run/08inflate_has_a.tl index aa2b2e2..8763741 100644 --- a/t/run/08inflate_has_a.tl +++ b/t/run/08inflate_has_a.tl @@ -1,4 +1,5 @@ sub run_tests { +my $schema = shift; eval { require DateTime }; plan skip_all => "Need DateTime for inflation tests" if $@; @@ -14,7 +15,7 @@ DBICTest::Schema::CD->has_a( 'year', 'DateTime', Class::C3->reinitialize; # inflation test -my $cd = DBICTest->class("CD")->find(3); +my $cd = $schema->class("CD")->find(3); is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); @@ -25,17 +26,17 @@ my $now = DateTime->now; $cd->year( $now ); $cd->update; -($cd) = DBICTest->class("CD")->search( year => $now->year ); +($cd) = $schema->class("CD")->search( year => $now->year ); is( $cd->year->year, $now->year, 'deflate ok' ); # re-test using alternate deflate syntax -DBICTest->class("CD")->has_a( 'year', 'DateTime', +$schema->class("CD")->has_a( 'year', 'DateTime', inflate => sub { DateTime->new( year => shift ) }, deflate => 'year' ); # inflation test -$cd = DBICTest->class("CD")->find(3); +$cd = $schema->class("CD")->find(3); is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); @@ -46,7 +47,7 @@ $now = DateTime->now; $cd->year( $now ); $cd->update; -($cd) = DBICTest->class("CD")->search( year => $now->year ); +($cd) = $schema->class("CD")->search( year => $now->year ); is( $cd->year->year, $now->year, 'deflate ok' ); } diff --git a/t/run/09update.tl b/t/run/09update.tl index f831bc1..64b89c0 100644 --- a/t/run/09update.tl +++ b/t/run/09update.tl @@ -1,11 +1,12 @@ sub run_tests { +my $schema = shift; BEGIN { eval "use DBD::SQLite"; plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 3); } -my $art = DBICTest->class("Artist")->find(1); +my $art = $schema->class("Artist")->find(1); isa_ok $art => 'DBICTest::Artist'; diff --git a/t/run/10auto.tl b/t/run/10auto.tl index 1d6b569..2294d6d 100644 --- a/t/run/10auto.tl +++ b/t/run/10auto.tl @@ -1,11 +1,12 @@ sub run_tests { +my $schema = shift; plan tests => 2; -DBICTest->class("Artist")->load_components(qw/PK::Auto::SQLite/); +$schema->class("Artist")->load_components(qw/PK::Auto::SQLite/); # add an artist without primary key to test Auto -my $artist = DBICTest->class("Artist")->create( { name => 'Auto' } ); +my $artist = $schema->class("Artist")->create( { name => 'Auto' } ); $artist->name( 'Auto Change' ); ok($artist->update, 'update on object created without PK ok'); diff --git a/t/run/11mysql.tl b/t/run/11mysql.tl index 791fc8c..da08ea0 100644 --- a/t/run/11mysql.tl +++ b/t/run/11mysql.tl @@ -1,4 +1,5 @@ sub run_tests { +my $schema = shift; my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}; diff --git a/t/run/12pg.tl b/t/run/12pg.tl index 9f8ce94..f83eb46 100644 --- a/t/run/12pg.tl +++ b/t/run/12pg.tl @@ -1,4 +1,5 @@ sub run_tests { +my $schema = shift; my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/}; diff --git a/t/run/13oracle.tl b/t/run/13oracle.tl index d524b96..5c7b3ee 100644 --- a/t/run/13oracle.tl +++ b/t/run/13oracle.tl @@ -1,4 +1,5 @@ sub run_tests { +my $schema = shift; my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/}; diff --git a/t/run/14mssql.tl b/t/run/14mssql.tl index 375bcb2..feb007d 100644 --- a/t/run/14mssql.tl +++ b/t/run/14mssql.tl @@ -1,4 +1,5 @@ -sub run_tests { +sub run_tests { +my $schema = shift; my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/}; @@ -9,7 +10,7 @@ plan skip_all, 'Set $ENV{DBICTEST_MSSQL_DSN}, _USER and _PASS to run this test' plan tests => 4; -DBICTest->class("Schema")->compose_connection( 'MSSQLTest' => $dsn, $user, $pass ); +$schema->class("Schema")->compose_connection( 'MSSQLTest' => $dsn, $user, $pass ); my $dbh = MSSQLTest::Artist->storage->dbh; diff --git a/t/run/15limit.tl b/t/run/15limit.tl index 4137377..8949158 100644 --- a/t/run/15limit.tl +++ b/t/run/15limit.tl @@ -1,4 +1,5 @@ sub run_tests { +my $schema = shift; BEGIN { eval "use DBD::SQLite"; @@ -6,7 +7,7 @@ BEGIN { } # test LIMIT -my $it = DBICTest->class("CD")->search( {}, +my $it = $schema->class("CD")->search( {}, { rows => 3, order_by => 'title' } ); @@ -17,7 +18,7 @@ $it->next; is( $it->next, undef, "next past end of resultset ok" ); # test OFFSET -my @cds = DBICTest->class("CD")->search( {}, +my @cds = $schema->class("CD")->search( {}, { rows => 2, offset => 2, order_by => 'year' } @@ -25,7 +26,7 @@ my @cds = DBICTest->class("CD")->search( {}, is( $cds[0]->title, "Spoonful of bees", "offset ok" ); # test software-based limiting -$it = DBICTest->class("CD")->search( {}, +$it = $schema->class("CD")->search( {}, { rows => 3, software_limit => 1, order_by => 'title' } @@ -36,7 +37,7 @@ $it->next; $it->next; is( $it->next, undef, "software next past end of resultset ok" ); -@cds = DBICTest->class("CD")->search( {}, +@cds = $schema->class("CD")->search( {}, { rows => 2, offset => 2, software_limit => 1, @@ -46,7 +47,7 @@ is( $cds[0]->title, "Spoonful of bees", "software offset ok" ); # based on a failing criteria submitted by waswas # requires SQL::Abstract >= 1.20 -$it = DBICTest->class("CD")->search( +$it = $schema->class("CD")->search( { title => [ -and => { diff --git a/t/run/16joins.tl b/t/run/16joins.tl index cab0a93..3f90fce 100644 --- a/t/run/16joins.tl +++ b/t/run/16joins.tl @@ -1,4 +1,5 @@ sub run_tests { +my $schema = shift; use IO::File; @@ -51,7 +52,7 @@ $match = 'person child INNER JOIN person father ON ( father.person_id = ' is( $sa->_recurse_from(@j3), $match, 'join 3 (inner join) ok'); -my $rs = DBICTest->class("CD")->search( +my $rs = $schema->class("CD")->search( { 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, { from => [ { 'me' => 'cd' }, [ @@ -64,7 +65,7 @@ cmp_ok( $rs->count, '==', 1, "Single record in resultset"); is($rs->first->title, 'Forkful of bees', 'Correct record returned'); -$rs = DBICTest->class("CD")->search( +$rs = $schema->class("CD")->search( { 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, { join => 'artist' }); @@ -72,7 +73,7 @@ cmp_ok( $rs->count, '==', 1, "Single record in resultset"); is($rs->first->title, 'Forkful of bees', 'Correct record returned'); -$rs = DBICTest->class("CD")->search( +$rs = $schema->class("CD")->search( { 'artist.name' => 'We Are Goth', 'liner_notes.notes' => 'Kill Yourself!' }, { join => [ qw/artist liner_notes/ ] }); @@ -82,13 +83,13 @@ cmp_ok( $rs->count, '==', 1, "Single record in resultset"); is($rs->first->title, 'Come Be Depressed With Us', 'Correct record returned'); # when using join attribute, make sure slice()ing all objects has same count as all() -$rs = DBICTest->class("CD")->search( +$rs = $schema->class("CD")->search( { 'artist' => 1 }, { join => [qw/artist/], order_by => 'artist.name' } ); cmp_ok( scalar $rs->all, '==', scalar $rs->slice(0, $rs->count - 1), 'slice() with join has same count as all()' ); -$rs = DBICTest->class("Artist")->search( +$rs = $schema->class("Artist")->search( { 'liner_notes.notes' => 'Kill Yourself!' }, { join => { 'cds' => 'liner_notes' } }); @@ -96,7 +97,7 @@ cmp_ok( $rs->count, '==', 1, "Single record in resultset"); is($rs->first->name, 'We Are Goth', 'Correct record returned'); -$rs = DBICTest->class("CD")->search( +$rs = $schema->class("CD")->search( { 'artist.name' => 'Caterwauler McCrae' }, { prefetch => [ qw/artist liner_notes/ ], order_by => 'me.cdid' }); @@ -131,19 +132,19 @@ $trace->close; unlink 't/var/dbic.trace'; is($selects, 1, 'prefetch ran only 1 select statement'); -my ($artist) = DBICTest->class("Artist")->search({ 'cds.year' => 2001 }, +my ($artist) = $schema->class("Artist")->search({ 'cds.year' => 2001 }, { order_by => 'artistid DESC', join => 'cds' }); is($artist->name, 'Random Boy Band', "Join search by object ok"); -my @cds = DBICTest->class("CD")->search({ 'liner_notes.notes' => 'Buy Merch!' }, +my @cds = $schema->class("CD")->search({ 'liner_notes.notes' => 'Buy Merch!' }, { join => 'liner_notes' }); cmp_ok(scalar @cds, '==', 1, "Single CD retrieved via might_have"); is($cds[0]->title, "Generic Manufactured Singles", "Correct CD retrieved"); -my @artists = DBICTest->class("Artist")->search({ 'tags.tag' => 'Shiny' }, +my @artists = $schema->class("Artist")->search({ 'tags.tag' => 'Shiny' }, { join => { 'cds' => 'tags' } }); cmp_ok( @artists, '==', 2, "two-join search ok" ); diff --git a/t/run/17join_count.tl b/t/run/17join_count.tl index be2c07a..302eefe 100644 --- a/t/run/17join_count.tl +++ b/t/run/17join_count.tl @@ -1,22 +1,23 @@ sub run_tests { +my $schema = shift; eval "use DBD::SQLite"; plan skip_all => 'needs DBD::SQLite for testing' if $@; plan tests => 4; -cmp_ok(DBICTest->class("CD")->count({ 'artist.name' => 'Caterwauler McCrae' }, +cmp_ok($schema->class("CD")->count({ 'artist.name' => 'Caterwauler McCrae' }, { join => 'artist' }), '==', 3, 'Count by has_a ok'); -cmp_ok(DBICTest->class("CD")->count({ 'tags.tag' => 'Blue' }, { join => 'tags' }), +cmp_ok($schema->class("CD")->count({ 'tags.tag' => 'Blue' }, { join => 'tags' }), '==', 4, 'Count by has_many ok'); -cmp_ok(DBICTest->class("CD")->count( +cmp_ok($schema->class("CD")->count( { 'liner_notes.notes' => { '!=' => undef } }, { join => 'liner_notes' }), '==', 3, 'Count by might_have ok'); -cmp_ok(DBICTest->class("CD")->count( +cmp_ok($schema->class("CD")->count( { 'year' => { '>', 1998 }, 'tags.tag' => 'Cheesy', 'liner_notes.notes' => { 'like' => 'Buy%' } }, { join => [ qw/tags liner_notes/ ] } ), diff --git a/t/run/18self_referencial.tl b/t/run/18self_referencial.tl index 0029436..5b3861b 100644 --- a/t/run/18self_referencial.tl +++ b/t/run/18self_referencial.tl @@ -1,4 +1,5 @@ -sub run_tests { +sub run_tests { +my $schema = shift; # this test will check to see if you can have 2 columns # in the same class pointing at the same other class @@ -20,7 +21,7 @@ sub run_tests { plan tests => 4; -my $item = DBICTest->class("SelfRef")->find( 1 ); +my $item = $schema->class("SelfRef")->find( 1 ); is( $item->name, 'First', 'proper start item' ); my @aliases = $item->aliases; diff --git a/t/run/19uuid.tl b/t/run/19uuid.tl index 5648ec3..a877600 100644 --- a/t/run/19uuid.tl +++ b/t/run/19uuid.tl @@ -1,4 +1,5 @@ sub run_tests { +my $schema = shift; eval 'use Data::UUID ; 1' or plan skip_all, 'Install Data::UUID run this test'; @@ -8,7 +9,7 @@ DBICTest::Schema::Artist->load_components('UUIDColumns'); DBICTest::Schema::Artist->uuid_columns('name'); Class::C3->reinitialize(); -my $artist = DBICTest->class("Artist")->create( { artistid => 100 } ); +my $artist = $schema->class("Artist")->create( { artistid => 100 } ); like $artist->name, qr/[\w-]{36}/, 'got something like uuid'; }