[Bast-commits] r5186 - DBIx-Class/0.08/branches/multicreate/t

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Sun Nov 23 14:45:01 GMT 2008


Author: ribasushi
Date: 2008-11-23 14:45:01 +0000 (Sun, 23 Nov 2008)
New Revision: 5186

Added:
   DBIx-Class/0.08/branches/multicreate/t/96multi_create_new.t
Modified:
   DBIx-Class/0.08/branches/multicreate/t/66relationship.t
Log:
Add a new testfile to check deferred multicreate

Modified: DBIx-Class/0.08/branches/multicreate/t/66relationship.t
===================================================================
--- DBIx-Class/0.08/branches/multicreate/t/66relationship.t	2008-11-23 14:44:00 UTC (rev 5185)
+++ DBIx-Class/0.08/branches/multicreate/t/66relationship.t	2008-11-23 14:45:01 UTC (rev 5186)
@@ -2,13 +2,12 @@
 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 @@
 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');

Added: DBIx-Class/0.08/branches/multicreate/t/96multi_create_new.t
===================================================================
--- DBIx-Class/0.08/branches/multicreate/t/96multi_create_new.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/multicreate/t/96multi_create_new.t	2008-11-23 14:45:01 UTC (rev 5186)
@@ -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');




More information about the Bast-commits mailing list