All tests successful, 15 subtests skipped. Files=8, Tests=189
Matt S Trout [Thu, 21 Jul 2005 14:04:11 +0000 (14:04 +0000)]
t/cdbi-t/19-set_sql.t
t/cdbi-t/98-failure.t [new file with mode: 0644]

index bab8f51..2278cd4 100644 (file)
@@ -62,6 +62,8 @@ Film->set_sql(
        is $pgs[1]->id, $f4->id, "and F4";
 };
 
+SKIP: {
+  skip "DBIx::Class doesn't have has_a yet", 6;
 {
        Actor->has_a(film => "Film");
        Film->set_sql(
@@ -104,3 +106,4 @@ Film->set_sql(
        is $apg[1]->title, "B", "and B";
 }
 
+} # end SKIP block
diff --git a/t/cdbi-t/98-failure.t b/t/cdbi-t/98-failure.t
new file mode 100644 (file)
index 0000000..fe41b05
--- /dev/null
@@ -0,0 +1,57 @@
+use strict;
+use Test::More;
+
+#----------------------------------------------------------------------
+# Test database failures
+#----------------------------------------------------------------------
+
+BEGIN {
+       eval "use DBD::SQLite";
+       plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 7);
+}
+
+use lib 't/testlib';
+use Film;
+
+Film->create_test_film;
+
+{
+       my $btaste = Film->retrieve('Bad Taste');
+       isa_ok $btaste, 'Film', "We have Bad Taste";
+       {
+               no warnings 'redefine';
+               local *DBIx::ContextualFetch::st::execute = sub { die "Database died" };
+               eval { $btaste->delete };
+               ::like $@, qr/Database died/s, "We failed";
+       }
+       my $still = Film->retrieve('Bad Taste');
+       isa_ok $btaste, 'Film', "We still have Bad Taste";
+}
+
+{
+       my $btaste = Film->retrieve('Bad Taste');
+       isa_ok $btaste, 'Film', "We have Bad Taste";
+       $btaste->numexplodingsheep(10);
+       {
+               no warnings 'redefine';
+               local *DBIx::ContextualFetch::st::execute = sub { die "Database died" };
+               eval { $btaste->update };
+               ::like $@, qr/Database died/s, "We failed";
+       }
+       $btaste->discard_changes;
+       my $still = Film->retrieve('Bad Taste');
+       isa_ok $btaste, 'Film', "We still have Bad Taste";
+       is $btaste->numexplodingsheep, 1, "with 1 sheep";
+}
+
+if (0) {
+       my $sheep = Film->maximum_value_of('numexplodingsheep');
+       is $sheep, 1, "1 exploding sheep";
+       {
+               local *DBIx::ContextualFetch::st::execute = sub { die "Database died" };
+               my $sheep = eval { Film->maximum_value_of('numexplodingsheep') };
+               ::like $@, qr/select.*Database died/s,
+                       "Handle database death in single value select";
+       }
+}
+