4 #----------------------------------------------------------------------
5 # Test database failures
6 #----------------------------------------------------------------------
9 eval "use DBIx::Class::CDBICompat;";
11 plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required');
16 use lib 't/cdbi/testlib';
19 Film->create_test_film;
22 my $btaste = Film->retrieve('Bad Taste');
23 isa_ok $btaste, 'Film', "We have Bad Taste";
25 no warnings 'redefine';
26 local *DBIx::ContextualFetch::st::execute = sub { die "Database died" };
27 eval { $btaste->delete };
28 ::like $@, qr/Database died/s, "We failed";
30 my $still = Film->retrieve('Bad Taste');
31 isa_ok $btaste, 'Film', "We still have Bad Taste";
35 my $btaste = Film->retrieve('Bad Taste');
36 isa_ok $btaste, 'Film', "We have Bad Taste";
37 $btaste->numexplodingsheep(10);
39 no warnings 'redefine';
40 local *DBIx::ContextualFetch::st::execute = sub { die "Database died" };
41 eval { $btaste->update };
42 ::like $@, qr/Database died/s, "We failed";
44 $btaste->discard_changes;
45 my $still = Film->retrieve('Bad Taste');
46 isa_ok $btaste, 'Film', "We still have Bad Taste";
47 is $btaste->numexplodingsheep, 1, "with 1 sheep";
51 my $sheep = Film->maximum_value_of('numexplodingsheep');
52 is $sheep, 1, "1 exploding sheep";
54 local *DBIx::ContextualFetch::st::execute = sub { die "Database died" };
55 my $sheep = eval { Film->maximum_value_of('numexplodingsheep') };
56 ::like $@, qr/select.*Database died/s,
57 "Handle database death in single value select";