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

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Sun Nov 23 12:51:20 GMT 2008


Author: ribasushi
Date: 2008-11-23 12:51:20 +0000 (Sun, 23 Nov 2008)
New Revision: 5184

Modified:
   DBIx-Class/0.08/branches/multicreate/t/96multi_create.t
Log:
The final (for now) part of the saga - castaway's real failing test

Modified: DBIx-Class/0.08/branches/multicreate/t/96multi_create.t
===================================================================
--- DBIx-Class/0.08/branches/multicreate/t/96multi_create.t	2008-11-23 12:50:46 UTC (rev 5183)
+++ DBIx-Class/0.08/branches/multicreate/t/96multi_create.t	2008-11-23 12:51:20 UTC (rev 5184)
@@ -6,7 +6,7 @@
 use lib qw(t/lib);
 use DBICTest;
 
-plan tests => 97;
+plan tests => 104;
 
 my $schema = DBICTest->init_schema();
 
@@ -277,7 +277,6 @@
     'Images named correctly in objects',
   );
 
-
   my $artwork = $schema->resultset('Artwork')->search (
     { 'cd.title' => 'Music to code by at twilight' },
     { join => 'cd' },
@@ -339,6 +338,55 @@
 };
 diag $@ if $@;
 
+# test a multilevel might-have with a PK == FK in the might_have/has_many table
+#
+# CD -> might have -> Artwork
+#                        \
+#                         \-> has_many \
+#                                       --> Artwork_to_Artist
+#                         /-> has_many /
+#                        /
+#                     Artist
+eval {
+  my $someartist = $schema->resultset('Artist')->first;
+  my $cd = $schema->resultset('CD')->create ({
+    artist => $someartist,
+    title => 'Music to code by until the cows come home',
+    year => 2008,
+    artwork => {
+      artwork_to_artist => [
+        { artist => { name => 'cowboy joe' } },
+        { artist => { name => 'billy the kid' } },
+      ],
+    },
+  });
+
+  isa_ok ($cd, 'DBICTest::CD', 'Main CD object created');
+  is ($cd->title, 'Music to code by until the cows come home', 'Correct CD title');
+
+  my $art_obj = $cd->artwork;
+  ok ($art_obj->has_column_loaded ('cd_id'), 'PK/FK present on artwork object');
+  is ($art_obj->artists->count, 2, 'Correct artwork creator count via the new object');
+  is_deeply (
+    [ sort $art_obj->artists->get_column ('name')->all ],
+    [ 'billy the kid', 'cowboy joe' ],
+    'Artists named correctly when queried via object',
+  );
+
+  my $artwork = $schema->resultset('Artwork')->search (
+    { 'cd.title' => 'Music to code by until the cows come home' },
+    { join => 'cd' },
+  )->single;
+  is ($artwork->artists->count, 2, 'Correct artwork creator count via a new search');
+  is_deeply (
+    [ sort $artwork->artists->get_column ('name')->all ],
+    [ 'billy the kid', 'cowboy joe' ],
+    'Artists named correctly queried via a new search',
+  );
+};
+diag $@ if $@;
+
+
 # nested find_or_create
 eval {
   my $newartist2 = $schema->resultset('Artist')->find_or_create({ 




More information about the Bast-commits mailing list