Commit | Line | Data |
406a97c2 |
1 | use DBIx::Class::Schema::Loader::Optional::Dependencies |
2 | -skip_all_without => 'test_backcompat'; |
3 | |
9a95164d |
4 | use strict; |
f8c2ca5e |
5 | use warnings; |
9a95164d |
6 | use Test::More; |
1c94fb11 |
7 | use lib qw(t/backcompat/0.04006/lib); |
9a95164d |
8 | use make_dbictest_db; |
818c6a0c |
9 | |
8b7749d6 |
10 | local $SIG{__WARN__} = sub { |
11 | warn @_ unless $_[0] =~ /Dynamic schema|really_erase_my_files/; |
12 | }; |
13 | |
9a95164d |
14 | # Takes a $schema as input, runs 4 basic tests |
15 | sub test_schema { |
16 | my ($testname, $schema) = @_; |
17 | |
18 | $schema = $schema->clone if !ref $schema; |
19 | isa_ok($schema, 'DBIx::Class::Schema', $testname); |
20 | |
21 | my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref'); |
22 | isa_ok($foo_rs, 'DBIx::Class::ResultSet', $testname); |
23 | |
24 | my $foo_first = $foo_rs->first; |
25 | like(ref $foo_first, qr/DBICTest::Schema::\d+::Foo/, $testname); |
26 | |
27 | my $foo_first_text = $foo_first->footext; |
28 | is($foo_first_text, 'Foo record associated with the Bar with barid 3'); |
29 | } |
30 | |
31 | my @invocations = ( |
32 | 'hardcode' => sub { |
33 | package DBICTest::Schema::5; |
34 | use base qw/ DBIx::Class::Schema::Loader /; |
35 | __PACKAGE__->connection($make_dbictest_db::dsn); |
36 | __PACKAGE__; |
37 | }, |
38 | 'normal' => sub { |
39 | package DBICTest::Schema::6; |
40 | use base qw/ DBIx::Class::Schema::Loader /; |
41 | __PACKAGE__->loader_options(); |
42 | __PACKAGE__->connect($make_dbictest_db::dsn); |
43 | }, |
44 | 'make_schema_at' => sub { |
45 | use DBIx::Class::Schema::Loader qw/ make_schema_at /; |
46 | make_schema_at( |
47 | 'DBICTest::Schema::7', |
48 | { really_erase_my_files => 1 }, |
49 | [ $make_dbictest_db::dsn ], |
50 | ); |
51 | DBICTest::Schema::7->clone; |
52 | }, |
53 | 'embedded_options' => sub { |
54 | package DBICTest::Schema::8; |
55 | use base qw/ DBIx::Class::Schema::Loader /; |
56 | __PACKAGE__->connect( |
57 | $make_dbictest_db::dsn, |
58 | { loader_options => { really_erase_my_files => 1 } } |
59 | ); |
60 | }, |
61 | 'embedded_options_in_attrs' => sub { |
62 | package DBICTest::Schema::9; |
63 | use base qw/ DBIx::Class::Schema::Loader /; |
64 | __PACKAGE__->connect( |
65 | $make_dbictest_db::dsn, |
66 | undef, |
67 | undef, |
68 | { AutoCommit => 1, loader_options => { really_erase_my_files => 1 } } |
69 | ); |
70 | }, |
71 | 'embedded_options_make_schema_at' => sub { |
72 | use DBIx::Class::Schema::Loader qw/ make_schema_at /; |
73 | make_schema_at( |
74 | 'DBICTest::Schema::10', |
75 | { }, |
76 | [ |
77 | $make_dbictest_db::dsn, |
78 | { loader_options => { really_erase_my_files => 1 } }, |
79 | ], |
80 | ); |
81 | "DBICTest::Schema::10"; |
82 | }, |
83 | 'almost_embedded' => sub { |
84 | package DBICTest::Schema::11; |
85 | use base qw/ DBIx::Class::Schema::Loader /; |
86 | __PACKAGE__->loader_options( really_erase_my_files => 1 ); |
87 | __PACKAGE__->connect( |
88 | $make_dbictest_db::dsn, |
89 | undef, undef, { AutoCommit => 1 } |
90 | ); |
91 | }, |
92 | 'make_schema_at_explicit' => sub { |
93 | use DBIx::Class::Schema::Loader; |
94 | DBIx::Class::Schema::Loader::make_schema_at( |
95 | 'DBICTest::Schema::12', |
96 | { really_erase_my_files => 1 }, |
97 | [ $make_dbictest_db::dsn ], |
98 | ); |
99 | DBICTest::Schema::12->clone; |
100 | } |
101 | ); |
102 | |
103 | # 4 tests per k/v pair |
104 | plan tests => 2 * @invocations; |
105 | |
106 | while(@invocations >= 2) { |
107 | my $style = shift @invocations; |
108 | my $subref = shift @invocations; |
109 | test_schema($style, &$subref); |
110 | } |