Add an 'on_disconnect_do' argument to
[dbsrgits/DBIx-Class.git] / t / 92storage_on_connect_do.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 5;
5
6 use lib qw(t/lib);
7 use base 'DBICTest';
8
9
10 my $schema = DBICTest->init_schema(
11     no_connect  => 1,
12     no_deploy   => 1,
13 );
14 ok $schema->connection(
15     DBICTest->_database,
16     {
17         on_connect_do       => ['CREATE TABLE TEST_empty (id INTEGER)'],
18         on_disconnect_do    =>
19             [\&check_exists, 'DROP TABLE TEST_empty', \&check_dropped],
20     },
21 ), 'connection()';
22
23 ok $schema->storage->dbh->do('SELECT 1 FROM TEST_empty'), 'on_connect_do() worked';
24 eval { $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent'); };
25 ok $@, 'Searching for nonexistent table dies';
26
27 $schema->storage->disconnect();
28
29 sub check_exists {
30     my $storage = shift;
31     ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';
32 }
33
34 sub check_dropped {
35     my $storage = shift;
36     eval { $storage->dbh->do('SELECT 1 FROM TEST_empty'); };
37     ok $@, 'Reading from dropped table fails';
38 }