added test for find or create related functionality in nested inserts
[dbsrgits/DBIx-Class.git] / t / 96multi_create.t
index d898563..0cbc9bf 100644 (file)
@@ -194,3 +194,27 @@ is($cd->artist->id, 1, 'rel okay');
 
 my $new_cd = $schema->resultset("CD")->create($new_cd_hashref);
 is($new_cd->artist->id, 17, 'new id retained okay');
+
+
+# Test find or create related functionality
+my $new_artist = $schema->resultset("Artist")->create({ artistid => 18, name => 'larry' });
+my $new_cd_hashref2 = { 
+              cdid => 28, 
+               title => 'Boogie Wiggle', 
+              year => '2007', 
+              artist => { artistid => 18, name => 'larry' }
+             };
+
+eval {
+       $schema->resultset("CD")->create($new_cd_hashref2);
+};
+is($@, '', 'new artist created without clash');
+
+# Make sure exceptions from errors in created rels propogate
+eval {
+    my $t = $schema->resultset("Track")->new({});
+    $t->cd($t->new_related('cd', { artist => undef } ) );
+    $t->{_rel_in_storage} = 0;
+    $t->insert;
+};
+like($@, qr/cd.artist may not be NULL/, "Exception propogated properly");