X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Frun%2F06relationship.tl;h=0d691a01df9207819e3fd667c541f2e12be90b9c;hb=8452e496;hp=04d22498f4e1b2d9b847699502bf8c90230232d3;hpb=07037f89d4d9bf97c59a2c083de74f669521da47;p=dbsrgits%2FDBIx-Class.git diff --git a/t/run/06relationship.tl b/t/run/06relationship.tl index 04d2249..0d691a0 100644 --- a/t/run/06relationship.tl +++ b/t/run/06relationship.tl @@ -1,16 +1,16 @@ sub run_tests { -plan tests => 13; +plan tests => 14; # 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, @@ -48,13 +48,13 @@ my $track = DBICTest::Track->create( { $track->set_from_related( cd => $cd ); if ($INC{'DBICTest/HelperRels.pm'}) { # except inflated object - is($track->cd->cdid, 4, 'set_from_related ok' ); + is($track->disc->cdid, 4, 'set_from_related ok, including alternative accessor' ); } else { is( $track->cd, 4, 'set_from_related ok' ); } # 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,13 +87,13 @@ 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( - tracks => 'DBICTest::Track', + DBICTest::Schema::Artist->add_relationship( + tracks => 'DBICTest::Schema::Track', { 'foreign.cd' => 'self.cdid' } ); }; @@ -101,10 +101,15 @@ 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'); +# many_to_many helper test +$cd = DBICTest->class("CD")->find(1); +my @producers = $cd->producers(); +is( $producers[0]->name, 'Matt S Trout', 'many_to_many ok' ); + } 1;