Fix silent failures on autoinc PK without an is_auto_increment attribute
[dbsrgits/DBIx-Class.git] / t / 746mssql.t
index d1b8773..5fc3d30 100644 (file)
@@ -9,7 +9,6 @@ use Test::Exception;
 use Test::Warn;
 use Try::Tiny;
 
-
 use DBICTest;
 
 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PASS/};
@@ -519,6 +518,38 @@ SQL
           'updated money value to NULL round-trip';
       }
     }
+
+# Test leakage of PK on implicit retrieval
+    {
+
+      my $next_owner = $schema->resultset('Owners')->get_column('id')->max + 1;
+      my $next_book = $schema->resultset('BooksInLibrary')->get_column('id')->max + 1;
+
+      cmp_ok(
+        $next_owner,
+        '!=',
+        $next_book,
+        'Preexisting auto-inc PKs staggered'
+      );
+
+      my $yet_another_owner = $schema->resultset('Owners')->create({ name => 'YAO' });
+      my $yet_another_book;
+      warnings_exist {
+        $yet_another_book = $yet_another_owner->create_related( books => { title => 'YAB' })
+      } qr/Missing value for primary key column 'id' on BooksInLibrary - perhaps you forgot to set its 'is_auto_increment'/;
+
+      is(
+        $yet_another_owner->id,
+        $next_owner,
+        'Expected Owner id'
+      );
+
+      is(
+        $yet_another_book->id,
+        $next_book,
+        'Expected Book id'
+      );
+    }
   }
 }