From: Andy Grundman Date: Tue, 2 Aug 2005 23:44:20 +0000 (+0000) Subject: Added tests for set_from_related, update_from_related, find_or_create_related, delete... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=570efc13c4b1856f1a5f63b09680e25dcb6195cb;p=dbsrgits%2FDBIx-Class-Historic.git Added tests for set_from_related, update_from_related, find_or_create_related, delete_related --- diff --git a/t/06relationship.t b/t/06relationship.t index d89a0ed..b395599 100644 --- a/t/06relationship.t +++ b/t/06relationship.t @@ -1,6 +1,6 @@ use Test::More; -plan tests => 8; +plan tests => 14; use lib qw(t/lib); @@ -29,9 +29,46 @@ is( ($artist->search_related('cds'))[3]->title, 'Big Flop', 'create_related ok' # count_related is( $artist->count_related('cds'), 4, 'count_related ok' ); -SKIP: { +# set_from_related +my $track = DBICTest::Track->create( { + trackid => 1, + cd => 3, + position => 98, + title => 'Hidden Track' +} ); +$track->set_from_related( cd => $cd ); +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( { + trackid => 2, + cd => 3, + position => 99, + title => 'Hidden Track' +} ); +$track->update_from_related( cd => $cd ); +is( (DBICTest::Track->search( cd => 4, position => 99 ))[0]->cd, 4, 'update_from_related ok' ); + +# find_or_create_related with an existing record +$cd = $artist->find_or_create_related( 'cds', { title => 'Big Flop' } ); +is( $cd->year, 2005, 'find_or_create_related on existing record ok' ); - #skip "Relationship with invalid cols not yet checked", 1; +# find_or_create_related creating a new record +$cd = $artist->find_or_create_related( 'cds', { + title => 'Greatest Hits', + year => 2006, +} ); +is( $cd->title, 'Greatest Hits', 'find_or_create_related new record ok' ); +my @cds = $artist->search_related('cds'); +is( ($artist->search_related('cds'))[4]->title, 'Greatest Hits', 'find_or_create_related new record search ok' ); + +SKIP: { + skip 'Need to add delete_related', 1; + # delete_related + ($cd) = DBICTest::CD->search( title => 'Greatest Hits' ); + $artist->delete_related( cds => $cd ); + is( DBICTest::CD->search( title => 'Greatest Hits' ), undef, 'delete_related ok' ); +}; # try to add a bogus relationship using the wrong cols eval { @@ -42,8 +79,6 @@ eval { }; like($@, qr/Unknown column/, 'failed when creating a rel with invalid key, ok'); -} # End SKIP block - # another bogus relationship using no join condition eval { $artist->add_relationship( tracks => 'DBICTest::Track' );