Add a unique constraint to artist.name in the test schema
[dbsrgits/DBIx-Class.git] / t / 100populate.t
index 2e30a17..8bb0fdc 100644 (file)
@@ -115,47 +115,46 @@ is($link7->id, 7, 'Link 7 id');
 is($link7->url, undef, 'Link 7 url');
 is($link7->title, 'gtitle', 'Link 7 title');
 
-my $rs = $schema->resultset('Artist');
-$rs->delete;
+# populate with literals
+{
+  my $rs = $schema->resultset('Link');
+  $rs->delete;
 
-# test _execute_array_empty (insert_bulk with all literal sql)
+  # test _execute_array_empty (insert_bulk with all literal sql)
 
-$rs->populate([
+  $rs->populate([
     (+{
-        name => \"'DT'",
-        rank => \500,
-        charfield => \"'mtfnpy'",
+        url => \"'cpan.org'",
+        title => \"'The ''best of'' cpan'",
     }) x 5
-]);
+  ]);
 
-is((grep {
-  $_->name eq 'DT' &&
-  $_->rank == 500  &&
-  $_->charfield eq 'mtfnpy'
-} $rs->all), 5, 'populate with all literal SQL');
+  is((grep {
+    $_->url eq 'cpan.org' &&
+    $_->title eq "The 'best of' cpan",
+  } $rs->all), 5, 'populate with all literal SQL');
 
-$rs->delete;
+  $rs->delete;
 
-# test mixed binds with literal sql
+  # test mixed binds with literal sql
 
-$rs->populate([
+  $rs->populate([
     (+{
-        name => \"'DT'",
-        rank => 500,
-        charfield => \"'mtfnpy'",
+        url => \"'cpan.org'",
+        title => "The 'best of' cpan",
     }) x 5
-]);
-
-is((grep {
-  $_->name eq 'DT' &&
-  $_->rank == 500  &&
-  $_->charfield eq 'mtfnpy'
-} $rs->all), 5, 'populate with all literal SQL');
+  ]);
 
-$rs->delete;
+  is((grep {
+    $_->url eq 'cpan.org' &&
+    $_->title eq "The 'best of' cpan",
+  } $rs->all), 5, 'populate with all literal SQL');
 
-###
+  $rs->delete;
+}
 
+my $rs = $schema->resultset('Artist');
+$rs->delete;
 throws_ok {
     $rs->populate([
         {
@@ -296,4 +295,24 @@ for (
   ok ($row, "Stringification test row '$_' properly inserted");
 }
 
+lives_ok {
+   $schema->resultset('TwoKeys')->populate([{
+      artist => 1,
+      cd     => 5,
+      fourkeys_to_twokeys => [{
+            f_foo => 1,
+            f_bar => 1,
+            f_hello => 1,
+            f_goodbye => 1,
+            autopilot => 'a',
+      },{
+            f_foo => 2,
+            f_bar => 2,
+            f_hello => 2,
+            f_goodbye => 2,
+            autopilot => 'b',
+      }]
+   }])
+} 'multicol-PK has_many populate works';
+
 done_testing;