No longer explicitly disconnect on ::Storage DESTROY
[dbsrgits/DBIx-Class.git] / t / storage / error.t
CommitLineData
a4b2f17b 1use strict;
a4b2f17b 2use warnings;
3
56166f36 4use Test::More;
5use Test::Warn;
6use Test::Exception;
a4b2f17b 7
8use lib qw(t/lib);
a4b2f17b 9use_ok( 'DBICTest' );
a4b2f17b 10use_ok( 'DBICTest::Schema' );
56166f36 11
e60dc79f 12my $schema = DBICTest->init_schema;
a4b2f17b 13
b720efd1 14my $e_start = quotemeta('DBIx::Class::');
15
56166f36 16warnings_are ( sub {
b720efd1 17 throws_ok (
18 sub {
19 $schema->resultset('CD')->create({ title => 'vacation in antarctica' })
20 },
21 qr/$e_start.+constraint failed.+NULL/s
22 ); # as opposed to some other error
56166f36 23}, [], 'No warnings besides exception' );
a4b2f17b 24
b720efd1 25my $dbh = $schema->storage->dbh;
26
27throws_ok (
28 sub {
29 $dbh->do ('INSERT INTO nonexistent_table VALUES (1)')
30 },
31 qr/$e_start.+DBI Exception.+no such table/,
32 'DBI exceptions properly handled by dbic-installed callback'
33);
34
68fe9141 35# This usage is a bit unusual but it was actually seen in the wild
b720efd1 36# destruction of everything except the $dbh should use the proper
37# exception fallback:
38
b720efd1 39{
b720efd1 40 undef ($schema);
41 throws_ok (
42 sub {
43 $dbh->do ('INSERT INTO nonexistent_table VALUES (1)')
44 },
45 qr/DBI Exception.+unhandled by DBIC.+no such table/,
46 'callback works after $schema is gone'
47 );
48}
49
56166f36 50done_testing;