This is how the txnguard should really work
[dbsrgits/DBIx-Class.git] / t / 81transactions.t
index e539119..2c399b0 100644 (file)
@@ -276,7 +276,7 @@ $schema->storage->disconnect;
       # 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 an error/, 'Out of scope warning detected');
+    }, qr/A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error/, 'Out of scope warning detected');
     ok(!$artist_rs->find({name => 'Death Cab for Cutie'}), "Artist not created");
   }, 'rollback successful withot exception');
 
@@ -329,4 +329,21 @@ $schema->storage->disconnect;
   }, qr/Deliberate exception.+Rollback failed/s);
 }
 
+# make sure it simply warns on failed rollbacks
+{
+  my $schema = DBICTest->init_schema();
+  warnings_exist (sub {
+    my $guard = $schema->txn_scope_guard;
+    $schema->resultset ('Artist')->create ({ name => 'bohhoo'});
+
+    $schema->storage->disconnect;  # this should freak out the guard rollback
+
+  },
+  [
+     qr/A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error/,
+     qr/Rollback failed/,
+  ],
+  'out-of-scope with failed rollback properly warned');
+}
+
 done_testing;