made cdbi-t optional
[dbsrgits/DBIx-Class-Historic.git] / t / cdbi-t / 98-failure.t
CommitLineData
5a66aa65 1use strict;
2use Test::More;
3
289ba852 4BEGIN {
5 eval "use DBIx::Class::CDBICompat;";
6 plan $@ ? (skip_all => 'Class::Trigger and DBIx::ContextualFetch required') : (tests=> 24);
7}
8
5a66aa65 9#----------------------------------------------------------------------
10# Test database failures
11#----------------------------------------------------------------------
12
13BEGIN {
14 eval "use DBD::SQLite";
15 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 7);
16}
17
18use lib 't/testlib';
19use Film;
20
21Film->create_test_film;
22
23{
24 my $btaste = Film->retrieve('Bad Taste');
25 isa_ok $btaste, 'Film', "We have Bad Taste";
26 {
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";
31 }
32 my $still = Film->retrieve('Bad Taste');
33 isa_ok $btaste, 'Film', "We still have Bad Taste";
34}
35
36{
37 my $btaste = Film->retrieve('Bad Taste');
38 isa_ok $btaste, 'Film', "We have Bad Taste";
39 $btaste->numexplodingsheep(10);
40 {
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";
45 }
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";
50}
51
52if (0) {
53 my $sheep = Film->maximum_value_of('numexplodingsheep');
54 is $sheep, 1, "1 exploding sheep";
55 {
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";
60 }
61}
62