Restore code that I removed in revision 3640 that tests still need
[dbsrgits/DBIx-Class.git] / t / 92storage_on_connect_do.t
CommitLineData
579ca3f7 1use strict;
2use warnings;
3
4use Test::More tests => 5;
5
6use lib qw(t/lib);
7use base 'DBICTest';
8
9
10my $schema = DBICTest->init_schema(
11 no_connect => 1,
12 no_deploy => 1,
13);
14ok $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
23ok $schema->storage->dbh->do('SELECT 1 FROM TEST_empty'), 'on_connect_do() worked';
24eval { $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent'); };
25ok $@, 'Searching for nonexistent table dies';
26
27$schema->storage->disconnect();
28
29sub check_exists {
30 my $storage = shift;
31 ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';
32}
33
34sub check_dropped {
35 my $storage = shift;
36 eval { $storage->dbh->do('SELECT 1 FROM TEST_empty'); };
37 ok $@, 'Reading from dropped table fails';
38}