X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F746mssql.t;h=e3ddd6d5c3a25ebf10f3bc7f349036b6f6f44213;hb=d8516e922b021c1aa8b0626694cb472b5407573b;hp=d1b8773f05a2137cf2ddeff25d3e50c19dea4734;hpb=d3a2e424976a449718ad750b72d4bf3acf689caf;p=dbsrgits%2FDBIx-Class.git diff --git a/t/746mssql.t b/t/746mssql.t index d1b8773..e3ddd6d 100644 --- a/t/746mssql.t +++ b/t/746mssql.t @@ -7,10 +7,9 @@ use warnings; use Test::More; use Test::Exception; use Test::Warn; -use Try::Tiny; - use DBICTest; +use DBIx::Class::_Util qw( dbic_internal_try dbic_internal_catch ); my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PASS/}; @@ -63,10 +62,10 @@ for my $opts_name (keys %opts) { my $opts = $opts{$opts_name}{opts}; $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opts); - try { + dbic_internal_try { $schema->storage->ensure_connected } - catch { + dbic_internal_catch { if ($opts{$opts_name}{required}) { die "on_connect_call option '$opts_name' is not functional: $_"; } @@ -501,24 +500,69 @@ SQL $row = $rs->create({ amount => 100 }); } 'inserted a money value'; - cmp_ok ((try { $rs->find($row->id)->amount })||0, '==', 100, - 'money value round-trip'); + cmp_ok ( + ( eval { $rs->find($row->id)->amount } ) || 0, + '==', + 100, + 'money value round-trip' + ); lives_ok { $row->update({ amount => 200 }); } 'updated a money value'; - cmp_ok ((try { $rs->find($row->id)->amount })||0, '==', 200, - 'updated money value round-trip'); + cmp_ok ( + ( eval { $rs->find($row->id)->amount } ) || 0, + '==', + 200, + 'updated money value round-trip' + ); lives_ok { $row->update({ amount => undef }); } 'updated a money value to NULL'; - is try { $rs->find($row->id)->amount }, undef, - 'updated money value to NULL round-trip'; + lives_ok { + is( + $rs->find($row->id)->amount, + undef, + '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' + ); + } } }