From: Matt S Trout Date: Mon, 26 Dec 2005 01:32:42 +0000 (+0000) Subject: Switched tests to use DBICTest->class("...") X-Git-Tag: v0.05005~119^2~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3712e4f41b929456d8fad713ca702e4a48e9a940;p=dbsrgits%2FDBIx-Class.git Switched tests to use DBICTest->class("...") --- diff --git a/lib/DBIx/Class/UUIDColumns.pm b/lib/DBIx/Class/UUIDColumns.pm index 2d951e3..dca0c58 100644 --- a/lib/DBIx/Class/UUIDColumns.pm +++ b/lib/DBIx/Class/UUIDColumns.pm @@ -39,7 +39,6 @@ sub uuid_columns { sub insert { my ($self) = @_; - warn "Got here"; for my $column (@{$self->uuid_auto_columns}) { $self->store_column( $column, $self->get_uuid ) unless defined $self->get_column( $column ); diff --git a/t/run/01core.tl b/t/run/01core.tl index da0a6a3..a6f5b88 100644 --- a/t/run/01core.tl +++ b/t/run/01core.tl @@ -2,7 +2,7 @@ sub run_tests { plan tests => 29; -my @art = DBICTest::Artist->search({ }, { order_by => 'name DESC'}); +my @art = DBICTest->class("Artist")->search({ }, { order_by => 'name DESC'}); cmp_ok(@art, '==', 3, "Three artists returned"); @@ -18,7 +18,7 @@ is($art->get_column("name"), 'We Are In Rehab', 'And via get_column'); ok($art->update, 'Update run'); -@art = DBICTest::Artist->search({ name => 'We Are In Rehab' }); +@art = DBICTest->class("Artist")->search({ name => 'We Are In Rehab' }); cmp_ok(@art, '==', 1, "Changed artist returned by search"); @@ -26,7 +26,7 @@ cmp_ok($art[0]->artistid, '==', 3,'Correct artist too'); $art->delete; -@art = DBICTest::Artist->search({ }); +@art = DBICTest->class("Artist")->search({ }); cmp_ok(@art, '==', 2, 'And then there were two'); @@ -42,15 +42,15 @@ $art->insert; ok($art->in_storage, "Re-created"); -@art = DBICTest::Artist->search({ }); +@art = DBICTest->class("Artist")->search({ }); cmp_ok(@art, '==', 3, 'And now there are three again'); -my $new = DBICTest::Artist->create({ artistid => 4 }); +my $new = DBICTest->class("Artist")->create({ artistid => 4 }); cmp_ok($new->artistid, '==', 4, 'Create produced record ok'); -@art = DBICTest::Artist->search({ }); +@art = DBICTest->class("Artist")->search({ }); cmp_ok(@art, '==', 4, "Oh my god! There's four of them!"); @@ -66,15 +66,15 @@ $new->name('Man With A Spoon'); $new->update; -$new_again = DBICTest::Artist->find(4); +$new_again = DBICTest->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::Artist->count, 4, 'count ok'); +is(DBICTest->class("Artist")->count, 4, 'count ok'); -my $cd = DBICTest::CD->find(1); +my $cd = DBICTest->class("CD")->find(1); my %cols = $cd->get_columns; cmp_ok(keys %cols, '==', 4, 'get_columns number of columns ok'); @@ -90,11 +90,11 @@ is($cd->year, 2005, 'set_columns ok'); $cd->discard_changes; -$cd = DBICTest::CD->search({ title => 'Spoonful of bees' }, { cols => ['title'] })->next; +$cd = DBICTest->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::Track->new( { +$new = DBICTest->class("Track")->new( { trackid => 100, cd => 1, position => 1, @@ -106,13 +106,13 @@ ok($new->in_storage, 'insert_or_update insert ok'); # test in update mode $new->position(5); $new->insert_or_update; -is( DBICTest::Track->find(100)->position, 5, 'insert_or_update update ok'); +is( DBICTest->class("Track")->find(100)->position, 5, 'insert_or_update update ok'); -eval { DBICTest::Track->load_components('DoesNotExist'); }; +eval { DBICTest->class("Track")->load_components('DoesNotExist'); }; ok $@, $@; -is(DBICTest::Artist->field_name_for->{name}, 'artist name', 'mk_classdata usage ok'); +is(DBICTest->class("Artist")->field_name_for->{name}, 'artist name', 'mk_classdata usage ok'); } diff --git a/t/run/04db.tl b/t/run/04db.tl index 1f07da7..1b4089d 100644 --- a/t/run/04db.tl +++ b/t/run/04db.tl @@ -4,27 +4,27 @@ plan tests => 2; # add some rows inside a transaction and commit it # XXX: Is storage->dbh the only way to get a dbh? -DBICTest::Artist->txn_begin; +DBICTest->class("Artist")->txn_begin; for (10..15) { - DBICTest::Artist->create( { + DBICTest->class("Artist")->create( { artistid => $_, name => "artist number $_", } ); } -DBICTest::Artist->txn_commit; -my ($artist) = DBICTest::Artist->find(15); +DBICTest->class("Artist")->txn_commit; +my ($artist) = DBICTest->class("Artist")->find(15); is($artist->name, 'artist number 15', "Commit ok"); # add some rows inside a transaction and roll it back -DBICTest::Artist->txn_begin; +DBICTest->class("Artist")->txn_begin; for (21..30) { - DBICTest::Artist->create( { + DBICTest->class("Artist")->create( { artistid => $_, name => "artist number $_", } ); } -DBICTest::Artist->txn_rollback; -($artist) = DBICTest::Artist->search( artistid => 25 ); +DBICTest->class("Artist")->txn_rollback; +($artist) = DBICTest->class("Artist")->search( artistid => 25 ); is($artist, undef, "Rollback ok"); } diff --git a/t/run/05multipk.tl b/t/run/05multipk.tl index 3a0eb0d..2f49936 100644 --- a/t/run/05multipk.tl +++ b/t/run/05multipk.tl @@ -2,10 +2,10 @@ sub run_tests { plan tests => 3; -ok(DBICTest::FourKeys->find(1,2,3,4), "find multiple pks without hash"); -ok(DBICTest::FourKeys->find(5,4,3,6), "find multiple pks without hash"); +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::FourKeys->find(1,2,3,4)->ID, 'DBICTest::FourKeys|bar=2|foo=1|goodbye=4|hello=3', 'unique object id ok for multiple pks'); +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'); } diff --git a/t/run/06relationship.tl b/t/run/06relationship.tl index 5a5c6e5..7141be8 100644 --- a/t/run/06relationship.tl +++ b/t/run/06relationship.tl @@ -3,14 +3,14 @@ sub run_tests { plan tests => 13; # has_a test -my $cd = DBICTest::CD->find(4); +my $cd = DBICTest->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::Artist->find(1); +$artist = DBICTest->class("Artist")->find(1); my @cds = ($INC{'DBICTest/HelperRels'} ? $artist->cds : $artist->search_related('cds')); @@ -39,7 +39,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::Track->create( { +my $track = DBICTest->class("Track")->create( { trackid => 1, cd => 3, position => 98, @@ -54,7 +54,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::Track->create( { +$track = DBICTest->class("Track")->create( { trackid => 2, cd => 3, position => 99, @@ -62,7 +62,7 @@ $track = DBICTest::Track->create( { } ); $track->update_from_related( cd => $cd ); -my $t_cd = (DBICTest::Track->search( cd => 4, position => 99 ))[0]->cd; +my $t_cd = (DBICTest->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' ); @@ -87,12 +87,12 @@ SKIP: { #skip 'Need to add delete_related', 1; # delete_related $artist->delete_related( cds => { title => 'Greatest Hits' }); - cmp_ok( DBICTest::CD->search( title => 'Greatest Hits' ), '==', 0, 'delete_related ok' ); + cmp_ok( DBICTest->class("CD")->search( title => 'Greatest Hits' ), '==', 0, 'delete_related ok' ); }; # try to add a bogus relationship using the wrong cols eval { - $artist->add_relationship( + DBICTest::Schema::Artist->add_relationship( tracks => 'DBICTest::Track', { 'foreign.cd' => 'self.cdid' } ); @@ -101,7 +101,7 @@ like($@, qr/Unknown column/, 'failed when creating a rel with invalid key, ok'); # another bogus relationship using no join condition eval { - $artist->add_relationship( tracks => 'DBICTest::Track' ); + DBICTest::Schema::Artist->add_relationship( tracks => 'DBICTest::Track' ); }; like($@, qr/join condition/, 'failed when creating a rel without join condition, ok'); diff --git a/t/run/07pager.tl b/t/run/07pager.tl index 86f4035..3132af6 100644 --- a/t/run/07pager.tl +++ b/t/run/07pager.tl @@ -3,7 +3,7 @@ sub run_tests { plan tests => 12; # first page -my $it = DBICTest::CD->search( +my $it = DBICTest->class("CD")->search( {}, { order_by => 'title', rows => 3, @@ -24,7 +24,7 @@ $it->next; is( $it->next, undef, "next past end of page ok" ); # second page, testing with array -my @page2 = DBICTest::CD->search( +my @page2 = DBICTest->class("CD")->search( {}, { order_by => 'title', rows => 3, @@ -34,7 +34,7 @@ my @page2 = DBICTest::CD->search( is( $page2[0]->title, "Generic Manufactured Singles", "second page first title ok" ); # page a standard resultset -$it = DBICTest::CD->search( +$it = DBICTest->class("CD")->search( {}, { order_by => 'title', rows => 3 } @@ -46,7 +46,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::CD->search( +$it = DBICTest->class("CD")->search( {}, { order_by => 'title', rows => 3, diff --git a/t/run/08inflate.tl b/t/run/08inflate.tl index 96d9134..d9cf9d1 100644 --- a/t/run/08inflate.tl +++ b/t/run/08inflate.tl @@ -12,7 +12,7 @@ DBICTest::Schema::CD->inflate_column( 'year', Class::C3->reinitialize; # inflation test -my $cd = DBICTest::CD->find(3); +my $cd = DBICTest->class("CD")->find(3); is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); @@ -23,7 +23,7 @@ my $now = DateTime->now; $cd->year( $now ); $cd->update; -($cd) = DBICTest::CD->search( year => $now->year ); +($cd) = DBICTest->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 fe4833a..aa2b2e2 100644 --- a/t/run/08inflate_has_a.tl +++ b/t/run/08inflate_has_a.tl @@ -14,7 +14,7 @@ DBICTest::Schema::CD->has_a( 'year', 'DateTime', Class::C3->reinitialize; # inflation test -my $cd = DBICTest::CD->find(3); +my $cd = DBICTest->class("CD")->find(3); is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); @@ -25,17 +25,17 @@ my $now = DateTime->now; $cd->year( $now ); $cd->update; -($cd) = DBICTest::CD->search( year => $now->year ); +($cd) = DBICTest->class("CD")->search( year => $now->year ); is( $cd->year->year, $now->year, 'deflate ok' ); # re-test using alternate deflate syntax -DBICTest::CD->has_a( 'year', 'DateTime', +DBICTest->class("CD")->has_a( 'year', 'DateTime', inflate => sub { DateTime->new( year => shift ) }, deflate => 'year' ); # inflation test -$cd = DBICTest::CD->find(3); +$cd = DBICTest->class("CD")->find(3); is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); @@ -46,7 +46,7 @@ $now = DateTime->now; $cd->year( $now ); $cd->update; -($cd) = DBICTest::CD->search( year => $now->year ); +($cd) = DBICTest->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 fbb6593..f831bc1 100644 --- a/t/run/09update.tl +++ b/t/run/09update.tl @@ -5,7 +5,7 @@ BEGIN { plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 3); } -my $art = DBICTest::Artist->find(1); +my $art = DBICTest->class("Artist")->find(1); isa_ok $art => 'DBICTest::Artist'; diff --git a/t/run/10auto.tl b/t/run/10auto.tl index 242cca3..d715304 100644 --- a/t/run/10auto.tl +++ b/t/run/10auto.tl @@ -2,10 +2,10 @@ sub run_tests { plan tests => 1; -DBICTest::Artist->load_components(qw/PK::Auto::SQLite/); +DBICTest->class("Artist")->load_components(qw/PK::Auto::SQLite/); # add an artist without primary key to test Auto -my $artist = DBICTest::Artist->create( { name => 'Auto' } ); +my $artist = DBICTest->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..bbc6503 100644 --- a/t/run/11mysql.tl +++ b/t/run/11mysql.tl @@ -9,7 +9,7 @@ plan skip_all, 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test' plan tests => 4; -DBICTest::Schema->compose_connection('MySQLTest' => $dsn, $user, $pass); +DBICTest->class("Schema")->compose_connection('MySQLTest' => $dsn, $user, $pass); my $dbh = MySQLTest::Artist->storage->dbh; diff --git a/t/run/12pg.tl b/t/run/12pg.tl index 9f8ce94..e79a687 100644 --- a/t/run/12pg.tl +++ b/t/run/12pg.tl @@ -9,7 +9,7 @@ plan skip_all, 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test' plan tests => 2; -DBICTest::Schema->compose_connection('PgTest' => $dsn, $user, $pass); +DBICTest->class("Schema")->compose_connection('PgTest' => $dsn, $user, $pass); my $dbh = PgTest::Artist->storage->dbh; diff --git a/t/run/13oracle.tl b/t/run/13oracle.tl index d524b96..154d916 100644 --- a/t/run/13oracle.tl +++ b/t/run/13oracle.tl @@ -8,7 +8,7 @@ plan skip_all, 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' plan tests => 4; -DBICTest::Schema->compose_connection('OraTest' => $dsn, $user, $pass); +DBICTest->class("Schema")->compose_connection('OraTest' => $dsn, $user, $pass); my $dbh = OraTest::Artist->storage->dbh; diff --git a/t/run/14mssql.tl b/t/run/14mssql.tl index c7b398b..375bcb2 100644 --- a/t/run/14mssql.tl +++ b/t/run/14mssql.tl @@ -9,7 +9,7 @@ plan skip_all, 'Set $ENV{DBICTEST_MSSQL_DSN}, _USER and _PASS to run this test' plan tests => 4; -DBICTest::Schema->compose_connection( 'MSSQLTest' => $dsn, $user, $pass ); +DBICTest->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 33b076d..4137377 100644 --- a/t/run/15limit.tl +++ b/t/run/15limit.tl @@ -6,7 +6,7 @@ BEGIN { } # test LIMIT -my $it = DBICTest::CD->search( {}, +my $it = DBICTest->class("CD")->search( {}, { rows => 3, order_by => 'title' } ); @@ -17,7 +17,7 @@ $it->next; is( $it->next, undef, "next past end of resultset ok" ); # test OFFSET -my @cds = DBICTest::CD->search( {}, +my @cds = DBICTest->class("CD")->search( {}, { rows => 2, offset => 2, order_by => 'year' } @@ -25,7 +25,7 @@ my @cds = DBICTest::CD->search( {}, is( $cds[0]->title, "Spoonful of bees", "offset ok" ); # test software-based limiting -$it = DBICTest::CD->search( {}, +$it = DBICTest->class("CD")->search( {}, { rows => 3, software_limit => 1, order_by => 'title' } @@ -36,7 +36,7 @@ $it->next; $it->next; is( $it->next, undef, "software next past end of resultset ok" ); -@cds = DBICTest::CD->search( {}, +@cds = DBICTest->class("CD")->search( {}, { rows => 2, offset => 2, software_limit => 1, @@ -46,7 +46,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::CD->search( +$it = DBICTest->class("CD")->search( { title => [ -and => { diff --git a/t/run/16joins.tl b/t/run/16joins.tl index 98a8515..e9aabc9 100644 --- a/t/run/16joins.tl +++ b/t/run/16joins.tl @@ -51,7 +51,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::CD->search( +my $rs = DBICTest->class("CD")->search( { 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, { from => [ { 'me' => 'cd' }, [ @@ -64,7 +64,7 @@ cmp_ok( $rs->count, '==', 1, "Single record in resultset"); is($rs->first->title, 'Forkful of bees', 'Correct record returned'); -$rs = DBICTest::CD->search( +$rs = DBICTest->class("CD")->search( { 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, { join => 'artist' }); @@ -72,7 +72,7 @@ cmp_ok( $rs->count, '==', 1, "Single record in resultset"); is($rs->first->title, 'Forkful of bees', 'Correct record returned'); -$rs = DBICTest::CD->search( +$rs = DBICTest->class("CD")->search( { 'artist.name' => 'We Are Goth', 'liner_notes.notes' => 'Kill Yourself!' }, { join => [ qw/artist liner_notes/ ] }); @@ -81,7 +81,7 @@ cmp_ok( $rs->count, '==', 1, "Single record in resultset"); is($rs->first->title, 'Come Be Depressed With Us', 'Correct record returned'); -$rs = DBICTest::Artist->search( +$rs = DBICTest->class("Artist")->search( { 'liner_notes.notes' => 'Kill Yourself!' }, { join => { 'cds' => 'liner_notes' } }); @@ -100,7 +100,7 @@ DBICTest::Schema::CD->add_relationship( { 'foreign.liner_id' => 'self.cdid' }, { join_type => 'LEFT', accessor => 'single' }); -$rs = DBICTest::CD->search( +$rs = DBICTest->class("CD")->search( { 'artist.name' => 'Caterwauler McCrae' }, { prefetch => [ qw/artist liner_notes/ ], order_by => 'me.cdid' }); @@ -135,19 +135,19 @@ $trace->close; unlink 't/var/dbic.trace'; is($selects, 1, 'prefetch ran only 1 select statement'); -my ($artist) = DBICTest::Artist->search({ 'cds.year' => 2001 }, +my ($artist) = DBICTest->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::CD->search({ 'liner_notes.notes' => 'Buy Merch!' }, +my @cds = DBICTest->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::Artist->search({ 'tags.tag' => 'Shiny' }, +my @artists = DBICTest->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 0442215..be2c07a 100644 --- a/t/run/17join_count.tl +++ b/t/run/17join_count.tl @@ -4,19 +4,19 @@ eval "use DBD::SQLite"; plan skip_all => 'needs DBD::SQLite for testing' if $@; plan tests => 4; -cmp_ok(DBICTest::CD->count({ 'artist.name' => 'Caterwauler McCrae' }, +cmp_ok(DBICTest->class("CD")->count({ 'artist.name' => 'Caterwauler McCrae' }, { join => 'artist' }), '==', 3, 'Count by has_a ok'); -cmp_ok(DBICTest::CD->count({ 'tags.tag' => 'Blue' }, { join => 'tags' }), +cmp_ok(DBICTest->class("CD")->count({ 'tags.tag' => 'Blue' }, { join => 'tags' }), '==', 4, 'Count by has_many ok'); -cmp_ok(DBICTest::CD->count( +cmp_ok(DBICTest->class("CD")->count( { 'liner_notes.notes' => { '!=' => undef } }, { join => 'liner_notes' }), '==', 3, 'Count by might_have ok'); -cmp_ok(DBICTest::CD->count( +cmp_ok(DBICTest->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 419968e..0029436 100644 --- a/t/run/18self_referencial.tl +++ b/t/run/18self_referencial.tl @@ -20,7 +20,7 @@ sub run_tests { plan tests => 4; -my $item = DBICTest::SelfRef->find( 1 ); +my $item = DBICTest->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 8c2f464..5648ec3 100644 --- a/t/run/19uuid.tl +++ b/t/run/19uuid.tl @@ -8,7 +8,7 @@ DBICTest::Schema::Artist->load_components('UUIDColumns'); DBICTest::Schema::Artist->uuid_columns('name'); Class::C3->reinitialize(); -my $artist = DBICTest::Artist->create( { artistid => 100 } ); +my $artist = DBICTest->class("Artist")->create( { artistid => 100 } ); like $artist->name, qr/[\w-]{36}/, 'got something like uuid'; }