Commit | Line | Data |
7adfd53f |
1 | package Reaction::Test::WithDB; |
2 | |
3 | use base qw/Reaction::Test/; |
4 | use Reaction::Class; |
5 | |
6 | has 'schema' => ( |
7 | isa => 'DBIx::Class::Schema', is => 'rw', |
8 | set_or_lazy_build('schema') |
9 | ); |
10 | |
11 | has 'schema_class' => ( |
12 | isa => 'Str', is => 'rw', set_or_lazy_fail('schema_class') |
13 | ); |
14 | |
15 | has 'connect_info' => ( |
16 | isa => 'ArrayRef', is => 'rw', required => 1, lazy => 1, |
17 | default => sub { [ 'dbi:SQLite:t/var/reaction_test_withdb.db' ] }, |
18 | ); |
19 | |
20 | override 'new' => sub { |
21 | my $self = super(); |
22 | $self->BUILDALL; |
23 | return $self; |
24 | }; |
25 | |
26 | sub BUILD { |
27 | my ($self) = @_; |
28 | my $schema = $self->schema_class->connect(@{$self->connect_info}); |
29 | $schema->deploy({ add_drop_table => 1 }); |
30 | $schema->setup_test_data if $schema->can('setup_test_data'); |
31 | $self->schema($schema); |
32 | } |
33 | |
34 | 1; |
35 | |
36 | =head1 NAME |
37 | |
38 | Reaction::Test::WithDB |
39 | |
40 | =head1 DESCRIPTION |
41 | |
42 | =head2 new |
43 | |
44 | =head2 BUILD |
45 | |
46 | Deploys database schema, dropping tables if they already exist. |
47 | |
48 | =head1 ATTRIBUTES |
49 | |
50 | =head2 schema |
51 | |
52 | L<DBIx::Class::Schema> |
53 | |
54 | =head2 schema_class |
55 | |
56 | =head2 connect_info |
57 | |
58 | Uses C<[ dbi:SQLite:t/var/reaction_test_withdb.db ]> by default. |
59 | |
60 | =head1 SEE ALSO |
61 | |
62 | L<Reaction::Test> |
63 | |
64 | =head1 AUTHORS |
65 | |
66 | See L<Reaction::Class> for authors. |
67 | |
68 | =head1 LICENSE |
69 | |
70 | See L<Reaction::Class> for the license. |
71 | |
72 | =cut |