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