From: Gerda Shank Date: Wed, 10 Feb 2010 00:46:43 +0000 (+0000) Subject: start adding tests for multi update X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Ftopic%2Fmulti_update;p=dbsrgits%2FDBIx-Class.git start adding tests for multi update --- diff --git a/t/multi_update/cd_single.t b/t/multi_update/cd_single.t new file mode 100644 index 0000000..63e2975 --- /dev/null +++ b/t/multi_update/cd_single.t @@ -0,0 +1,36 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); + +my $cd = $schema->resultset('CD')->first; +my $track_hash = { + cd => $cd, + title => 'Multicreate rocks', + cd_single => { + artist => $cd->artist, + year => 2008, + title => 'Disemboweling MultiCreate', + }, +}; + +my $track = $schema->resultset('Track')->new_result($track_hash); + +isa_ok( $track, 'DBICTest::Track', 'Main Track object created' ); +$track->insert; +ok( 1, 'created track' ); + +is( $track->title, 'Multicreate rocks', 'Correct Track title' ); +is( $track->cd_single->title, 'Disemboweling MultiCreate' ); + +$track_hash->{trackid} = $track->trackid; +$track_hash->{cd_single}->{title} = 'Disemboweling MultiUpdate'; +$schema->resultset('Track')->update_or_create($track_hash); +is( $track->cd_single->title, 'Disemboweling MultiUpdate', 'correct cd_single title' ); + +done_testing; diff --git a/t/multi_update/has_many.t b/t/multi_update/has_many.t new file mode 100644 index 0000000..1cddf83 --- /dev/null +++ b/t/multi_update/has_many.t @@ -0,0 +1,39 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); + +my $track_no_lyrics = $schema->resultset ('Track') + ->search ({ 'lyrics.lyric_id' => undef }, { join => 'lyrics' }) + ->first; + +my $lyric = $track_no_lyrics->create_related ('lyrics', { + lyric_versions => [ + { text => 'english doubled' }, + { text => 'english doubled' }, + ], +}); +is ($lyric->lyric_versions->count, 2, "Two identical has_many's created"); + +# should the lyric_versions have pks? just replace them all? +# this tries to do a create +$track_no_lyrics = $schema->resultset('Track')->update_or_create( { + trackid => $track_no_lyrics->trackid, + title => 'Titled Updated by Multi Update', + lyrics => { + lyric_versions => [ + { text => 'Some new text' }, + { text => 'Other text' }, + ], + }, +}); +is( $track_no_lyrics->title, 'Title Updated by Multi Update', 'title updated' ); +is( $track_no_lyrics->lyrics->search_related('lyric_versions', { text => 'Other text' } )->count, 1, 'related record updated' ); + + +done_testing;