X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fmulti_create%2Fin_memory.t;h=9533af506c2b0208ac7b53a316500aba5027a1c1;hb=fcdd56ca536a7751e2cf5a2c9ba62424c7f18122;hp=cbd5309cac13caf10c4b2a976596f4060a3a68a9;hpb=5b71a733e3a566267b423c030d705c43e19dc43d;p=dbsrgits%2FDBIx-Class.git diff --git a/t/multi_create/in_memory.t b/t/multi_create/in_memory.t index cbd5309..9533af5 100644 --- a/t/multi_create/in_memory.t +++ b/t/multi_create/in_memory.t @@ -8,7 +8,7 @@ use DBICTest; my $schema = DBICTest->init_schema(); -# Test various new() invocations - this is all about backcompat, making +# Test various new() invocations - this is all about backcompat, making # sure that insert() still works as expected by legacy code. # # What we essentially do is multi-instantiate objects, making sure nothing @@ -23,22 +23,20 @@ my $schema = DBICTest->init_schema(); { my $new_artist = $schema->resultset("Artist")->new_result({ 'name' => 'Depeche Mode' }); my $new_related_cd = $new_artist->new_related('cds', { 'title' => 'Leave in Silence', 'year' => 1982}); - eval { + lives_ok { $new_artist->insert; $new_related_cd->insert; - }; - is ($@, '', 'Staged insertion successful'); + } 'Staged insertion successful'; ok($new_artist->in_storage, 'artist inserted'); ok($new_related_cd->in_storage, 'new_related_cd inserted'); } { - my $new_artist = $schema->resultset("Artist")->new_result({ 'name' => 'Depeche Mode' }); + my $new_artist = $schema->resultset("Artist")->new_result({ 'name' => 'Mode Depeche' }); my $new_related_cd = $new_artist->new_related('cds', { 'title' => 'Leave Slightly Noisily', 'year' => 1982}); - eval { + lives_ok { $new_related_cd->insert; - }; - is ($@, '', 'CD insertion survives by finding artist'); + } 'CD insertion survives by finding artist'; ok($new_artist->in_storage, 'artist inserted'); ok($new_related_cd->in_storage, 'new_related_cd inserted'); } @@ -48,10 +46,9 @@ my $schema = DBICTest->init_schema(); my $new_artist = $schema->resultset("Artist")->new ({ 'name' => 'Depeche Mode 2: Insertion Boogaloo' }); $new_cd->artist ($new_artist); - eval { + lives_ok { $new_cd->insert; - }; - is ($@, '', 'CD insertion survives by inserting artist'); + } 'CD insertion survives by inserting artist'; ok($new_cd->in_storage, 'new_related_cd inserted'); ok($new_artist->in_storage, 'artist inserted'); @@ -60,10 +57,25 @@ my $schema = DBICTest->init_schema(); is ($retrieved_cd->artist->name, 'Depeche Mode 2: Insertion Boogaloo', 'Correct artist attached to cd'); } +{ + my $new_cd = $schema->resultset('CD')->new ({ 'title' => 'Leave screaming Off Key in the nude', 'year' => 1982}); + my $new_related_artist = $new_cd->new_related( artist => { 'name' => 'Depeche Mode 3: Insertion Boogaloo' }); + lives_ok { + $new_related_artist->insert; + $new_cd->insert; + } 'CD insertion survives after inserting artist'; + ok($new_cd->in_storage, 'cd inserted'); + ok($new_related_artist->in_storage, 'artist inserted'); + + my $retrieved_cd = $schema->resultset('CD')->find ({ 'title' => 'Leave screaming Off Key in the nude'}); + ok ($retrieved_cd, 'CD found in db'); + is ($retrieved_cd->artist->name, 'Depeche Mode 3: Insertion Boogaloo', 'Correct artist attached to cd'); +} + # test both sides of a 1:(1|0) { for my $reldir ('might_have', 'belongs_to') { - my $artist = $schema->resultset('Artist')->next; + my $artist = $schema->resultset('Artist')->find(1); my $new_track = $schema->resultset('Track')->new ({ title => "$reldir: First track of latest cd", @@ -102,17 +114,16 @@ my $schema = DBICTest->init_schema(); [ { artist => 1, - cdid => 9, + cdid => 10, genreid => undef, single_track => undef, title => "$reldir: Latest cd", tracks => [ { - cd => 9, + cd => 10, last_updated_at => undef, last_updated_on => undef, position => 1, - small_dt => undef, title => "$reldir: First track of latest cd", trackid => 19 } @@ -121,7 +132,7 @@ my $schema = DBICTest->init_schema(); }, { artist => 1, - cdid => 10, + cdid => 11, genreid => undef, single_track => 19, title => "$reldir: Awesome first single",