$dbh->{HandleError} does throw_exception, "unsafe" connect_info option to suppress...
[dbsrgits/DBIx-Class.git] / t / 92storage.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 {
9     package DBICTest::ExplodingStorage::Sth;
10     use strict;
11     use warnings;
12
13     sub execute { die "Kablammo!" }
14
15     sub bind_param {}
16
17     package DBICTest::ExplodingStorage;
18     use strict;
19     use warnings;
20     use base 'DBIx::Class::Storage::DBI::SQLite';
21
22     my $count = 0;
23     sub sth {
24       my ($self, $sql) = @_;
25       return bless {},  "DBICTest::ExplodingStorage::Sth" unless $count++;
26       return $self->next::method($sql);
27     }
28
29     sub connected {
30       return 0 if $count == 1;
31       return shift->next::method(@_);
32     }
33 }
34
35 plan tests => 3;
36
37 my $schema = DBICTest->init_schema();
38
39 is( ref($schema->storage), 'DBIx::Class::Storage::DBI::SQLite',
40     'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite' );
41
42
43 my $storage = $schema->storage;
44 $storage->ensure_connected;
45
46 bless $storage, "DBICTest::ExplodingStorage";
47 $schema->storage($storage);
48
49 eval { 
50     $schema->resultset('Artist')->create({ name => "Exploding Sheep" }) 
51 };
52
53 is($@, "", "Exploding \$sth->execute was caught");
54
55 is(1, $schema->resultset('Artist')->search({name => "Exploding Sheep" })->count,
56   "And the STH was retired");
57
58
59 1;