From: Peter Rabbitson Date: Sun, 23 Nov 2008 14:45:01 +0000 (+0000) Subject: Add a new testfile to check deferred multicreate X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d4d6aae347cce574c7d7520b808fbceb293cf968;p=dbsrgits%2FDBIx-Class-Historic.git Add a new testfile to check deferred multicreate --- diff --git a/t/66relationship.t b/t/66relationship.t index 224403c..ad095ad 100644 --- a/t/66relationship.t +++ b/t/66relationship.t @@ -2,13 +2,12 @@ use strict; use warnings; use Test::More; -use Test::Exception; use lib qw(t/lib); use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 72; +plan tests => 66; # has_a test my $cd = $schema->resultset("CD")->find(4); @@ -252,31 +251,6 @@ $artist->cds->update({artist => $nartist->id}); cmp_ok($artist->cds->count, '==', 0, "Correct new #cds for artist"); cmp_ok($nartist->cds->count, '==', 2, "Correct new #cds for artist"); -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 { - $new_artist->insert; - $new_related_cd->insert; -}; -is ($@, '', 'Staged insertion successful'); -ok($new_artist->in_storage, 'artist inserted'); -ok($new_related_cd->in_storage, 'new_related_cd inserted'); - -my $new_cd = $schema->resultset("CD")->new_result({}); -my $new_related_artist = $new_cd->new_related('artist', { 'name' => 'Marillion',}); -lives_ok ( - sub { - $new_related_artist->insert; - $new_cd->title( 'Misplaced Childhood' ); - $new_cd->year ( 1985 ); -# $new_cd->artist( $new_related_artist ); # For exact backward compatibility # not sure what this means - $new_cd->insert; - }, - 'Reversed staged insertion successful' -); -ok($new_related_artist->in_storage, 'related artist inserted'); -ok($new_cd->in_storage, 'cd inserted'); - # check if is_foreign_key_constraint attr is set my $rs_normal = $schema->source('Track'); my $relinfo = $rs_normal->relationship_info ('cd'); diff --git a/t/96multi_create_new.t b/t/96multi_create_new.t new file mode 100644 index 0000000..00b3c41 --- /dev/null +++ b/t/96multi_create_new.t @@ -0,0 +1,48 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; +use lib qw(t/lib); +use DBICTest; + +plan 'no_plan'; + +my $schema = DBICTest->init_schema(); + +# 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 +# gets inserted. Then we add some more objects to the mix either via +# new_related() or by setting an accessor directly (or both) - again +# expecting no inserts. Then after calling insert() on the starter object +# we expect everything to get inserted _except_ the externally set +# objects - those should be insert()able afterwards + + +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 { + $new_artist->insert; + $new_related_cd->insert; +}; +is ($@, '', 'Staged insertion successful'); +ok($new_artist->in_storage, 'artist inserted'); +ok($new_related_cd->in_storage, 'new_related_cd inserted'); + + +my $new_cd = $schema->resultset("CD")->new_result({}); +my $new_related_artist = $new_cd->new_related('artist', { 'name' => 'Marillion',}); +lives_ok ( + sub { + $new_related_artist->insert; + $new_cd->title( 'Misplaced Childhood' ); + $new_cd->year ( 1985 ); + $new_cd->artist( $new_related_artist ); # For exact backward compatibility + $new_cd->insert; + }, + 'Reversed staged insertion successful' +); +ok($new_related_artist->in_storage, 'related artist inserted'); +ok($new_cd->in_storage, 'cd inserted');