X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F81transactions.t;h=a13c651f383a2cae282af9b01fb8036cacee237c;hb=dd67b167d4582b5a547f190c276670ad6de5122e;hp=0e3719ea6c4cb34ae53d7fcd421e71c74765941e;hpb=dd7d4b437321e95655a7b9b4de14a7b357e95807;p=dbsrgits%2FDBIx-Class.git diff --git a/t/81transactions.t b/t/81transactions.t index 0e3719e..a13c651 100644 --- a/t/81transactions.t +++ b/t/81transactions.t @@ -150,10 +150,9 @@ my $fail_code = sub { no warnings 'redefine'; no strict 'refs'; - # die in rollback, but maintain sanity for further tests ... + # die in rollback local *{"DBIx::Class::Storage::DBI::SQLite::txn_rollback"} = sub{ my $storage = shift; - $storage->{transaction_depth}--; die 'FAILED'; }; @@ -180,6 +179,9 @@ my $fail_code = sub { $schema->storage->_dbh->rollback; } +# reset schema object (the txn_rollback meddling screws it up) +$schema = DBICTest->init_schema(); + # Test nested failed txn_do() { is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0'); @@ -254,7 +256,7 @@ $schema->storage->disconnect; lives_ok (sub { warnings_exist ( sub { - # The 0 arg says don't die, just let the scope guard go out of scope + # The 0 arg says don't die, just let the scope guard go out of scope # forcing a txn_rollback to happen outer($schema, 0); }, qr/A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error. Rolling back./, 'Out of scope warning detected'); @@ -280,9 +282,9 @@ $schema->storage->disconnect; my $artist = $artist_rs->find({ name => 'Death Cab for Cutie' }); eval { - $artist->cds->create({ + $artist->cds->create({ title => 'Plans', - year => 2005, + year => 2005, $fatal ? ( foo => 'bar' ) : () }); }; @@ -355,4 +357,40 @@ $schema->storage->disconnect; is (@w, 2, 'Both expected warnings found'); } +# make sure AutoCommit => 0 on external handles behaves correctly with scope_guard +{ + my $factory = DBICTest->init_schema (AutoCommit => 0); + cmp_ok ($factory->resultset('CD')->count, '>', 0, 'Something to delete'); + my $dbh = $factory->storage->dbh; + + ok (!$dbh->{AutoCommit}, 'AutoCommit is off on $dbh'); + my $schema = DBICTest::Schema->connect (sub { $dbh }); + + + lives_ok ( sub { + my $guard = $schema->txn_scope_guard; + $schema->resultset('CD')->delete; + $guard->commit; + }, 'No attempt to start a transaction with scope guard'); + + is ($schema->resultset('CD')->count, 0, 'Deletion successful'); +} + +# make sure AutoCommit => 0 on external handles behaves correctly with txn_do +{ + my $factory = DBICTest->init_schema (AutoCommit => 0); + cmp_ok ($factory->resultset('CD')->count, '>', 0, 'Something to delete'); + my $dbh = $factory->storage->dbh; + + ok (!$dbh->{AutoCommit}, 'AutoCommit is off on $dbh'); + my $schema = DBICTest::Schema->connect (sub { $dbh }); + + + lives_ok ( sub { + $schema->txn_do (sub { $schema->resultset ('CD')->delete }); + }, 'No attempt to start a atransaction with txn_do'); + + is ($schema->resultset('CD')->count, 0, 'Deletion successful'); +} + done_testing;