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