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); |
0d8817bc |
9 | use DBICTest; |
56166f36 |
10 | |
e60dc79f |
11 | my $schema = DBICTest->init_schema; |
a4b2f17b |
12 | |
56166f36 |
13 | warnings_are ( sub { |
b720efd1 |
14 | throws_ok ( |
15 | sub { |
16 | $schema->resultset('CD')->create({ title => 'vacation in antarctica' }) |
17 | }, |
cfa136aa |
18 | qr/DBI Exception.+cd\.artist.+NULL/s |
b720efd1 |
19 | ); # as opposed to some other error |
56166f36 |
20 | }, [], 'No warnings besides exception' ); |
a4b2f17b |
21 | |
b720efd1 |
22 | my $dbh = $schema->storage->dbh; |
23 | |
24 | throws_ok ( |
25 | sub { |
26 | $dbh->do ('INSERT INTO nonexistent_table VALUES (1)') |
27 | }, |
0007aedf |
28 | qr/DBI Exception.+no such table.+nonexistent_table/s, |
b720efd1 |
29 | 'DBI exceptions properly handled by dbic-installed callback' |
30 | ); |
31 | |
68fe9141 |
32 | # This usage is a bit unusual but it was actually seen in the wild |
b720efd1 |
33 | # destruction of everything except the $dbh should use the proper |
34 | # exception fallback: |
35 | |
cc1924ac |
36 | SKIP: { |
0d8817bc |
37 | if (DBIx::Class::_ENV_::PEEPEENESS) { |
cc1924ac |
38 | skip "Your perl version $] appears to leak like a sieve - skipping garbage collected \$schema test", 1; |
39 | } |
40 | |
b720efd1 |
41 | undef ($schema); |
42 | throws_ok ( |
43 | sub { |
44 | $dbh->do ('INSERT INTO nonexistent_table VALUES (1)') |
45 | }, |
0007aedf |
46 | qr/DBI Exception.+unhandled by DBIC.+no such table.+nonexistent_table/s, |
b720efd1 |
47 | 'callback works after $schema is gone' |
48 | ); |
49 | } |
50 | |
56166f36 |
51 | done_testing; |