Standardising and improving Row's docs. Added cross linking etc.
[dbsrgits/DBIx-Class.git] / t / 92storage.t
CommitLineData
efe6365b 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
baa31d2f 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
9a0891be 35plan tests => 6;
efe6365b 36
fcf741b1 37my $schema = DBICTest->init_schema( sqlite_use_file => 1 );
efe6365b 38
39is( ref($schema->storage), 'DBIx::Class::Storage::DBI::SQLite',
40 'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite' );
41
baa31d2f 42my $storage = $schema->storage;
43$storage->ensure_connected;
44
19fb8520 45eval {
46 $schema->storage->throw_exception('test_exception_42');
47};
48like($@, qr/\btest_exception_42\b/, 'basic exception');
49
50eval {
51 $schema->resultset('CD')->search_literal('broken +%$#$1')->all;
52};
53like($@, qr/prepare_cached failed/, 'exception via DBI->HandleError, etc');
54
baa31d2f 55bless $storage, "DBICTest::ExplodingStorage";
56$schema->storage($storage);
57
58eval {
19fb8520 59 $schema->resultset('Artist')->create({ name => "Exploding Sheep" });
baa31d2f 60};
61
62is($@, "", "Exploding \$sth->execute was caught");
63
64is(1, $schema->resultset('Artist')->search({name => "Exploding Sheep" })->count,
65 "And the STH was retired");
66
9a0891be 67my $info = { on_connect_do => [] };
68
69$storage->connect_info(['foo','bar','baz',$info]);
70
71ok(exists($info->{on_connect_do}), q{Didn't kill key passed to storage});
baa31d2f 72
efe6365b 731;