Introduce the describe_class_methods() utility function
[dbsrgits/DBIx-Class.git] / t / multi_create / multilev_single_PKeqFK.t
index c1c7c1c..301e80b 100644 (file)
@@ -1,15 +1,15 @@
+BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
+
 use strict;
 use warnings;
 
 use Test::More;
 use Test::Exception;
-use lib qw(t/lib);
+
 use DBICTest;
 
 sub mc_diag { diag (@_) if $ENV{DBIC_MULTICREATE_DEBUG} };
 
-plan tests => 16;
-
 my $schema = DBICTest->init_schema();
 
 mc_diag (<<'DG');
@@ -30,8 +30,30 @@ my $rels = {
   might_have => 'artwork',
 };
 
-my $artist_rs = $schema->resultset('Artist');
+for my $type (qw/has_one might_have/) {
+
+  lives_ok (sub {
+
+    my $rel = $rels->{$type};
+    my $cd_title = "Simple test $type cd";
+
+    my $cd = $schema->resultset('CD')->create ({
+      artist => 1,
+      title => $cd_title,
+      year => 2008,
+      $rel => {},
+    });
+
+    isa_ok ($cd, 'DBICTest::CD', 'Main CD object created');
+    is ($cd->title, $cd_title, 'Correct CD title');
+
+    isa_ok ($cd->$rel, 'DBICTest::Artwork', 'Related artwork present');
+    ok ($cd->$rel->in_storage, 'And in storage');
 
+  }, "Simple $type creation");
+}
+
+my $artist_rs = $schema->resultset('Artist');
 for my $type (qw/has_one might_have/) {
 
   my $rel = $rels->{$type};
@@ -39,7 +61,7 @@ for my $type (qw/has_one might_have/) {
   my $cd_title = "Test $type cd";
   my $artist_names = [ map { "Artist via $type $_" } (1, 2) ];
 
-  my $someartist = $artist_rs->next;
+  my $someartist = $artist_rs->search({}, { rows => 1 })->next;
 
   lives_ok (sub {
     my $cd = $schema->resultset('CD')->create ({
@@ -80,4 +102,4 @@ for my $type (qw/has_one might_have/) {
   }, "multilevel $type with a PK == FK in the $type/has_many table ok");
 }
 
-1;
+done_testing;