Commit | Line | Data |
a4b2f17b |
1 | use strict; |
a4b2f17b |
2 | use warnings; |
3 | |
56166f36 |
4 | use Test::More; |
5 | use Test::Warn; |
6 | use Test::Exception; |
a4b2f17b |
7 | |
8 | use lib qw(t/lib); |
a4b2f17b |
9 | use_ok( 'DBICTest' ); |
a4b2f17b |
10 | use_ok( 'DBICTest::Schema' ); |
56166f36 |
11 | |
e60dc79f |
12 | my $schema = DBICTest->init_schema; |
a4b2f17b |
13 | |
b720efd1 |
14 | my $e_start = quotemeta('DBIx::Class::'); |
15 | |
56166f36 |
16 | warnings_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 |
25 | my $dbh = $schema->storage->dbh; |
26 | |
27 | throws_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 | |
35 | # destruction of everything except the $dbh should use the proper |
36 | # exception fallback: |
37 | |
38 | # FIXME |
39 | # These explicit disconnections on loss of $storage don't seem |
40 | # right... disable it here for the test anyway |
41 | { |
42 | local $dbh->{Callbacks}{disconnect} = sub { 1 }; |
43 | |
44 | undef ($schema); |
45 | throws_ok ( |
46 | sub { |
47 | $dbh->do ('INSERT INTO nonexistent_table VALUES (1)') |
48 | }, |
49 | qr/DBI Exception.+unhandled by DBIC.+no such table/, |
50 | 'callback works after $schema is gone' |
51 | ); |
52 | } |
53 | |
56166f36 |
54 | done_testing; |