Relax overly aggressive exception-well-formedness checks from 84e4e006
[dbsrgits/DBIx-Class.git] / t / multi_create / standard.t
index 7aca7a4..54cf04e 100644 (file)
@@ -3,17 +3,16 @@ use warnings;
 
 use Test::More;
 use Test::Exception;
+use Test::Warn;
 use lib qw(t/lib);
 use DBICTest;
 
-plan tests => 91;
-
 my $schema = DBICTest->init_schema();
 
 lives_ok ( sub {
   my $cd = $schema->resultset('CD')->create({
-    artist => { 
-      name => 'Fred Bloggs' 
+    artist => {
+      name => 'Fred Bloggs'
     },
     title => 'Some CD',
     year => 1996
@@ -112,7 +111,7 @@ lives_ok ( sub {
 #                                               /
 #                                          Producer
 lives_ok ( sub {
-  my $artist = $schema->resultset('Artist')->first;
+  my $artist = $schema->resultset('Artist')->find(1);
   my $cd = $schema->resultset('CD')->create ({
     artist => $artist,
     title => 'Music to code by at night',
@@ -152,7 +151,7 @@ lives_ok ( sub {
   is ($cd->title, 'Music to code by at night', 'Correct CD title');
   is ($cd->tracks->count, 2, 'Two tracks on main CD');
 
-  my ($t1, $t2) = $cd->tracks->all;
+  my ($t1, $t2) = sort { $a->id <=> $b->id } $cd->tracks->all;
   is ($t1->title, 'Off by one again', 'Correct 1st track name');
   is ($t1->cd_single, undef, 'No single for 1st track');
   is ($t2->title, 'The dereferencer', 'Correct 2nd track name');
@@ -316,10 +315,10 @@ lives_ok ( sub {
 }, 'Test might_have again but with just a PK and FK (neither specified) in the mid-table');
 
 lives_ok ( sub {
-  my $newartist2 = $schema->resultset('Artist')->find_or_create({ 
+  my $newartist2 = $schema->resultset('Artist')->find_or_create({
     name => 'Fred 3',
     cds => [
-      { 
+      {
         title => 'Noah Act',
         year => 2007,
       },
@@ -330,9 +329,9 @@ lives_ok ( sub {
 
 lives_ok ( sub {
   my $artist = $schema->resultset('Artist')->first;
-  
+
   my $cd_result = $artist->create_related('cds', {
-  
+
     title => 'TestOneCD1',
     year => 2007,
     tracks => [
@@ -341,14 +340,14 @@ lives_ok ( sub {
     ],
 
   });
-  
+
   isa_ok( $cd_result, 'DBICTest::CD', "Got Good CD Class");
   ok( $cd_result->title eq "TestOneCD1", "Got Expected Title");
-  
+
   my $tracks = $cd_result->tracks;
-  
+
   isa_ok( $tracks, 'DBIx::Class::ResultSet', 'Got Expected Tracks ResultSet');
-  
+
   foreach my $track ($tracks->all)
   {
     isa_ok( $track, 'DBICTest::Track', 'Got Expected Track Class');
@@ -357,9 +356,9 @@ lives_ok ( sub {
 
 lives_ok ( sub {
   my $artist = $schema->resultset('Artist')->first;
-  
+
   my $cd_result = $artist->create_related('cds', {
-  
+
     title => 'TestOneCD2',
     year => 2007,
     tracks => [
@@ -370,15 +369,15 @@ lives_ok ( sub {
     liner_notes => { notes => 'I can haz liner notes?' },
 
   });
-  
+
   isa_ok( $cd_result, 'DBICTest::CD', "Got Good CD Class");
   ok( $cd_result->title eq "TestOneCD2", "Got Expected Title");
   ok( $cd_result->notes eq 'I can haz liner notes?', 'Liner notes');
-  
+
   my $tracks = $cd_result->tracks;
-  
+
   isa_ok( $tracks, 'DBIx::Class::ResultSet', "Got Expected Tracks ResultSet");
-  
+
   foreach my $track ($tracks->all)
   {
     isa_ok( $track, 'DBICTest::Track', 'Got Expected Track Class');
@@ -403,22 +402,25 @@ lives_ok ( sub {
 
   $kurt_cobain->{cds} = [ $in_utero ];
 
+  warnings_exist {
+    $schema->resultset('Artist')->populate([ $kurt_cobain ]);
+  }  qr/\QFast-path populate() with supplied related objects is not possible/;
+
 
-  $schema->resultset('Artist')->populate([ $kurt_cobain ]); # %)
-  $a = $schema->resultset('Artist')->find({name => 'Kurt Cobain'});
+  my $artist = $schema->resultset('Artist')->find({name => 'Kurt Cobain'});
 
-  is($a->name, 'Kurt Cobain', 'Artist insertion ok');
-  is($a->cds && $a->cds->first && $a->cds->first->title, 
+  is($artist->name, 'Kurt Cobain', 'Artist insertion ok');
+  is($artist->cds && $artist->cds->first && $artist->cds->first->title,
       'In Utero', 'CD insertion ok');
 }, 'populate');
 
 ## Create foreign key col obj including PK
 ## See test 20 in 66relationships.t
 lives_ok ( sub {
-  my $new_cd_hashref = { 
-    cdid => 27, 
-    title => 'Boogie Woogie', 
-    year => '2007', 
+  my $new_cd_hashref = {
+    cdid => 27,
+    title => 'Boogie Woogie',
+    year => '2007',
     artist => { artistid => 17, name => 'king luke' }
   };
 
@@ -431,10 +433,10 @@ lives_ok ( sub {
 }, 'Create foreign key col obj including PK');
 
 lives_ok ( sub {
-  $schema->resultset("CD")->create({ 
-              cdid => 28, 
-              title => 'Boogie Wiggle', 
-              year => '2007', 
+  $schema->resultset("CD")->create({
+              cdid => 28,
+              title => 'Boogie Wiggle',
+              year => '2007',
               artist => { artistid => 18, name => 'larry' }
              });
 }, 'new cd created without clash on related artist');
@@ -444,7 +446,11 @@ throws_ok ( sub {
     #$t->cd($t->new_related('cd', { artist => undef } ) );
     #$t->{_rel_in_storage} = 0;
     $t->insert;
-}, qr/cd.artist may not be NULL/, "Exception propogated properly");
+}, qr/DBI Exception.+(?x:
+    \QNOT NULL constraint failed: cd.artist\E
+      |
+    \Qcd.artist may not be NULL\E
+)/s, "Exception propogated properly");
 
 lives_ok ( sub {
   $schema->resultset('CD')->create ({
@@ -464,4 +470,4 @@ lives_ok ( sub {
   is ($m2m_cd->first->producers->first->name, 'Cowboy Neal', 'Correct producer row created');
 }, 'Test multi create over many_to_many');
 
-1;
+done_testing;