Commit | Line | Data |
fa994d3c |
1 | use strict; |
2 | use Test::More; |
0c344f4e |
3 | use Test::Warn; |
ef8e9c69 |
4 | use DBIx::Class::Schema::Loader::Optional::Dependencies; |
fa994d3c |
5 | use lib qw(t/lib); |
6 | use make_dbictest_db; |
7 | |
8 | # Takes a $schema as input, runs 4 basic tests |
9 | sub test_schema { |
0c344f4e |
10 | my ($testname, $schema) = @_; |
fa994d3c |
11 | |
0c344f4e |
12 | warnings_are ( sub { |
fa994d3c |
13 | $schema = $schema->clone if !ref $schema; |
14 | isa_ok($schema, 'DBIx::Class::Schema', $testname); |
15 | |
0c344f4e |
16 | my $rel_foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref'); |
17 | isa_ok($rel_foo_rs, 'DBIx::Class::ResultSet', $testname); |
18 | |
19 | my $rel_foo = $rel_foo_rs->next; |
20 | isa_ok($rel_foo, "DBICTest::Schema::_${testname}::Foo", $testname); |
fa994d3c |
21 | |
0c344f4e |
22 | is($rel_foo->footext, 'Foo record associated with the Bar with barid 3', "$testname correct object"); |
fa994d3c |
23 | |
0c344f4e |
24 | my $foo_rs = $schema->resultset('Foo'); |
25 | my $foo_new = $foo_rs->create({footext => "${testname}_foo"}); |
26 | is ($foo_rs->search({footext => "${testname}_foo"})->count, 1, "$testname object created") || die; |
27 | }, [], "No warnings during $testname invocations"); |
fa994d3c |
28 | } |
29 | |
30 | my @invocations = ( |
fa994d3c |
31 | 'hardcode' => sub { |
0c344f4e |
32 | package DBICTest::Schema::_hardcode; |
fa994d3c |
33 | use base qw/ DBIx::Class::Schema::Loader /; |
8b7749d6 |
34 | __PACKAGE__->naming('current'); |
42ea7b88 |
35 | __PACKAGE__->use_namespaces(0); |
fa994d3c |
36 | __PACKAGE__->connection($make_dbictest_db::dsn); |
37 | __PACKAGE__; |
38 | }, |
39 | 'normal' => sub { |
0c344f4e |
40 | package DBICTest::Schema::_normal; |
fa994d3c |
41 | use base qw/ DBIx::Class::Schema::Loader /; |
59cfa251 |
42 | __PACKAGE__->loader_options(); |
8b7749d6 |
43 | __PACKAGE__->naming('current'); |
42ea7b88 |
44 | __PACKAGE__->use_namespaces(0); |
fa994d3c |
45 | __PACKAGE__->connect($make_dbictest_db::dsn); |
46 | }, |
47 | 'make_schema_at' => sub { |
48 | use DBIx::Class::Schema::Loader qw/ make_schema_at /; |
49 | make_schema_at( |
0c344f4e |
50 | 'DBICTest::Schema::_make_schema_at', |
42ea7b88 |
51 | { |
52 | really_erase_my_files => 1, |
53 | naming => 'current', |
54 | use_namespaces => 0 |
55 | }, |
fa994d3c |
56 | [ $make_dbictest_db::dsn ], |
57 | ); |
0c344f4e |
58 | DBICTest::Schema::_make_schema_at->clone; |
fa994d3c |
59 | }, |
60 | 'embedded_options' => sub { |
0c344f4e |
61 | package DBICTest::Schema::_embedded_options; |
fa994d3c |
62 | use base qw/ DBIx::Class::Schema::Loader /; |
8b7749d6 |
63 | __PACKAGE__->naming('current'); |
42ea7b88 |
64 | __PACKAGE__->use_namespaces(0); |
fa994d3c |
65 | __PACKAGE__->connect( |
66 | $make_dbictest_db::dsn, |
28b4691d |
67 | { loader_options => { really_erase_my_files => 1 } } |
fa994d3c |
68 | ); |
69 | }, |
70 | 'embedded_options_in_attrs' => sub { |
0c344f4e |
71 | package DBICTest::Schema::_embedded_options_in_attrs; |
fa994d3c |
72 | use base qw/ DBIx::Class::Schema::Loader /; |
8b7749d6 |
73 | __PACKAGE__->naming('current'); |
42ea7b88 |
74 | __PACKAGE__->use_namespaces(0); |
fa994d3c |
75 | __PACKAGE__->connect( |
76 | $make_dbictest_db::dsn, |
77 | undef, |
78 | undef, |
28b4691d |
79 | { AutoCommit => 1, loader_options => { really_erase_my_files => 1 } } |
fa994d3c |
80 | ); |
81 | }, |
82 | 'embedded_options_make_schema_at' => sub { |
83 | use DBIx::Class::Schema::Loader qw/ make_schema_at /; |
84 | make_schema_at( |
0c344f4e |
85 | 'DBICTest::Schema::_embedded_options_make_schema_at', |
fa994d3c |
86 | { }, |
87 | [ |
88 | $make_dbictest_db::dsn, |
8b7749d6 |
89 | { loader_options => { |
90 | really_erase_my_files => 1, |
42ea7b88 |
91 | naming => 'current', |
92 | use_namespaces => 0, |
8b7749d6 |
93 | } }, |
fa994d3c |
94 | ], |
95 | ); |
0c344f4e |
96 | "DBICTest::Schema::_embedded_options_make_schema_at"; |
fa994d3c |
97 | }, |
98 | 'almost_embedded' => sub { |
0c344f4e |
99 | package DBICTest::Schema::_almost_embedded; |
fa994d3c |
100 | use base qw/ DBIx::Class::Schema::Loader /; |
8b7749d6 |
101 | __PACKAGE__->loader_options( |
102 | really_erase_my_files => 1, |
42ea7b88 |
103 | naming => 'current', |
104 | use_namespaces => 0, |
8b7749d6 |
105 | ); |
fa994d3c |
106 | __PACKAGE__->connect( |
107 | $make_dbictest_db::dsn, |
108 | undef, undef, { AutoCommit => 1 } |
109 | ); |
110 | }, |
111 | 'make_schema_at_explicit' => sub { |
112 | use DBIx::Class::Schema::Loader; |
113 | DBIx::Class::Schema::Loader::make_schema_at( |
0c344f4e |
114 | 'DBICTest::Schema::_make_schema_at_explicit', |
42ea7b88 |
115 | { |
116 | really_erase_my_files => 1, |
117 | naming => 'current', |
118 | use_namespaces => 0, |
119 | }, |
fa994d3c |
120 | [ $make_dbictest_db::dsn ], |
121 | ); |
0c344f4e |
122 | DBICTest::Schema::_make_schema_at_explicit->clone; |
0ca61324 |
123 | }, |
73099af4 |
124 | 'no_skip_load_external' => sub { |
c213fd3d |
125 | # By default we should pull in t/lib/DBICTest/Schema/_no_skip_load_external/Foo.pm $skip_me since t/lib is in @INC |
0ca61324 |
126 | use DBIx::Class::Schema::Loader; |
127 | DBIx::Class::Schema::Loader::make_schema_at( |
0c344f4e |
128 | 'DBICTest::Schema::_no_skip_load_external', |
42ea7b88 |
129 | { |
130 | really_erase_my_files => 1, |
131 | naming => 'current', |
132 | use_namespaces => 0, |
133 | }, |
0ca61324 |
134 | [ $make_dbictest_db::dsn ], |
135 | ); |
0c344f4e |
136 | DBICTest::Schema::_no_skip_load_external->clone; |
0ca61324 |
137 | }, |
73099af4 |
138 | 'skip_load_external' => sub { |
c213fd3d |
139 | # When we explicitly skip_load_external t/lib/DBICTest/Schema/_skip_load_external/Foo.pm should be ignored |
0ca61324 |
140 | use DBIx::Class::Schema::Loader; |
141 | DBIx::Class::Schema::Loader::make_schema_at( |
0c344f4e |
142 | 'DBICTest::Schema::_skip_load_external', |
42ea7b88 |
143 | { |
144 | really_erase_my_files => 1, |
145 | naming => 'current', |
146 | use_namespaces => 0, |
147 | skip_load_external => 1, |
148 | }, |
0ca61324 |
149 | [ $make_dbictest_db::dsn ], |
150 | ); |
0c344f4e |
151 | DBICTest::Schema::_skip_load_external->clone; |
0ca61324 |
152 | }, |
ef8e9c69 |
153 | (DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('use_moose') ? |
0c344f4e |
154 | ('use_moose' => sub { |
155 | package DBICTest::Schema::_use_moose; |
ef8e9c69 |
156 | use base qw/ DBIx::Class::Schema::Loader /; |
157 | __PACKAGE__->naming('current'); |
42ea7b88 |
158 | __PACKAGE__->use_namespaces(0); |
ef8e9c69 |
159 | __PACKAGE__->connect( |
160 | $make_dbictest_db::dsn, |
161 | { loader_options => { use_moose => 1 } } |
162 | ); |
163 | }) |
164 | : () |
165 | ), |
fa994d3c |
166 | ); |
167 | |
0c344f4e |
168 | # 6 tests per k/v pair |
169 | plan tests => 6 * (@invocations/2) + 2; # + 2 more manual ones below. |
fa994d3c |
170 | |
0c344f4e |
171 | while(@invocations) { |
fa994d3c |
172 | my $style = shift @invocations; |
0c344f4e |
173 | my $cref = shift @invocations; |
174 | |
175 | my $schema = do { |
176 | local $SIG{__WARN__} = sub { |
c38ec663 |
177 | warn $_[0] unless $_[0] =~ /Deleting existing file .+ due to 'really_erase_my_files' setting/ |
0c344f4e |
178 | }; |
179 | $cref->(); |
180 | }; |
181 | |
182 | test_schema($style, $schema); |
fa994d3c |
183 | } |
0ca61324 |
184 | |
b7219351 |
185 | { |
186 | no warnings 'once'; |
0ca61324 |
187 | |
0c344f4e |
188 | is($DBICTest::Schema::_no_skip_load_external::Foo::skip_me, "bad mojo", |
b7219351 |
189 | "external content loaded"); |
0c344f4e |
190 | is($DBICTest::Schema::_skip_load_external::Foo::skip_me, undef, |
b7219351 |
191 | "external content not loaded with skip_load_external => 1"); |
192 | } |