Let on_connect_do() and on_disconnect_do() take code references.
[dbsrgits/DBIx-Class.git] / t / 92storage_on_connect_do.t
index 038e4d7..a736272 100644 (file)
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 5;
+use Test::More tests => 9;
 
 use lib qw(t/lib);
 use base 'DBICTest';
@@ -26,6 +26,21 @@ ok $@, 'Searching for nonexistent table dies';
 
 $schema->storage->disconnect();
 
+my($connected, $disconnected);
+ok $schema->connection(
+    DBICTest->_database,
+    {
+        on_connect_do       => sub { $connected = 1 },
+        on_disconnect_do    => sub { $disconnected = 1 },
+    },
+), 'second connection()';
+$schema->storage->dbh->do('SELECT 1');
+ok $connected, 'on_connect_do() called after connect()';
+ok ! $disconnected, 'on_disconnect_do() not called after connect()';
+$schema->storage->disconnect();
+ok $disconnected, 'on_disconnect_do() called after disconnect()';
+
+
 sub check_exists {
     my $storage = shift;
     ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';