4 #----------------------------------------------------------------------
5 # Test database failures
6 #----------------------------------------------------------------------
9 eval "use DBIx::Class::CDBICompat;";
11 plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required');
14 eval "use DBD::SQLite";
15 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 7);
18 use lib 't/cdbi/testlib';
21 Film->create_test_film;
24 my $btaste = Film->retrieve('Bad Taste');
25 isa_ok $btaste, 'Film', "We have Bad Taste";
27 no warnings 'redefine';
28 local *DBIx::ContextualFetch::st::execute = sub { die "Database died" };
29 eval { $btaste->delete };
30 ::like $@, qr/Database died/s, "We failed";
32 my $still = Film->retrieve('Bad Taste');
33 isa_ok $btaste, 'Film', "We still have Bad Taste";
37 my $btaste = Film->retrieve('Bad Taste');
38 isa_ok $btaste, 'Film', "We have Bad Taste";
39 $btaste->numexplodingsheep(10);
41 no warnings 'redefine';
42 local *DBIx::ContextualFetch::st::execute = sub { die "Database died" };
43 eval { $btaste->update };
44 ::like $@, qr/Database died/s, "We failed";
46 $btaste->discard_changes;
47 my $still = Film->retrieve('Bad Taste');
48 isa_ok $btaste, 'Film', "We still have Bad Taste";
49 is $btaste->numexplodingsheep, 1, "with 1 sheep";
53 my $sheep = Film->maximum_value_of('numexplodingsheep');
54 is $sheep, 1, "1 exploding sheep";
56 local *DBIx::ContextualFetch::st::execute = sub { die "Database died" };
57 my $sheep = eval { Film->maximum_value_of('numexplodingsheep') };
58 ::like $@, qr/select.*Database died/s,
59 "Handle database death in single value select";