4 use DBIx::Class::Schema::Loader::Optional::Dependencies;
8 # Takes a $schema as input, runs 4 basic tests
10 my ($testname, $schema) = @_;
13 $schema = $schema->clone if !ref $schema;
14 isa_ok($schema, 'DBIx::Class::Schema', $testname);
16 my $rel_foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
17 isa_ok($rel_foo_rs, 'DBIx::Class::ResultSet', $testname);
19 my $rel_foo = $rel_foo_rs->next;
20 isa_ok($rel_foo, "DBICTest::Schema::_${testname}::Foo", $testname);
22 is($rel_foo->footext, 'Foo record associated with the Bar with barid 3', "$testname correct object");
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");
32 package DBICTest::Schema::_hardcode;
33 use base qw/ DBIx::Class::Schema::Loader /;
34 __PACKAGE__->naming('current');
35 __PACKAGE__->use_namespaces(0);
36 __PACKAGE__->connection($make_dbictest_db::dsn);
40 package DBICTest::Schema::_normal;
41 use base qw/ DBIx::Class::Schema::Loader /;
42 __PACKAGE__->loader_options();
43 __PACKAGE__->naming('current');
44 __PACKAGE__->use_namespaces(0);
45 __PACKAGE__->connect($make_dbictest_db::dsn);
47 'make_schema_at' => sub {
48 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
50 'DBICTest::Schema::_make_schema_at',
52 really_erase_my_files => 1,
56 [ $make_dbictest_db::dsn ],
58 DBICTest::Schema::_make_schema_at->clone;
60 'embedded_options' => sub {
61 package DBICTest::Schema::_embedded_options;
62 use base qw/ DBIx::Class::Schema::Loader /;
63 __PACKAGE__->naming('current');
64 __PACKAGE__->use_namespaces(0);
66 $make_dbictest_db::dsn,
67 { loader_options => { really_erase_my_files => 1 } }
70 'embedded_options_in_attrs' => sub {
71 package DBICTest::Schema::_embedded_options_in_attrs;
72 use base qw/ DBIx::Class::Schema::Loader /;
73 __PACKAGE__->naming('current');
74 __PACKAGE__->use_namespaces(0);
76 $make_dbictest_db::dsn,
79 { AutoCommit => 1, loader_options => { really_erase_my_files => 1 } }
82 'embedded_options_make_schema_at' => sub {
83 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
85 'DBICTest::Schema::_embedded_options_make_schema_at',
88 $make_dbictest_db::dsn,
90 really_erase_my_files => 1,
96 "DBICTest::Schema::_embedded_options_make_schema_at";
98 'almost_embedded' => sub {
99 package DBICTest::Schema::_almost_embedded;
100 use base qw/ DBIx::Class::Schema::Loader /;
101 __PACKAGE__->loader_options(
102 really_erase_my_files => 1,
106 __PACKAGE__->connect(
107 $make_dbictest_db::dsn,
108 undef, undef, { AutoCommit => 1 }
111 'make_schema_at_explicit' => sub {
112 use DBIx::Class::Schema::Loader;
113 DBIx::Class::Schema::Loader::make_schema_at(
114 'DBICTest::Schema::_make_schema_at_explicit',
116 really_erase_my_files => 1,
120 [ $make_dbictest_db::dsn ],
122 DBICTest::Schema::_make_schema_at_explicit->clone;
124 'no_skip_load_external' => sub {
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
126 use DBIx::Class::Schema::Loader;
127 DBIx::Class::Schema::Loader::make_schema_at(
128 'DBICTest::Schema::_no_skip_load_external',
130 really_erase_my_files => 1,
134 [ $make_dbictest_db::dsn ],
136 DBICTest::Schema::_no_skip_load_external->clone;
138 'skip_load_external' => sub {
139 # When we explicitly skip_load_external t/lib/DBICTest/Schema/_skip_load_external/Foo.pm should be ignored
140 use DBIx::Class::Schema::Loader;
141 DBIx::Class::Schema::Loader::make_schema_at(
142 'DBICTest::Schema::_skip_load_external',
144 really_erase_my_files => 1,
147 skip_load_external => 1,
149 [ $make_dbictest_db::dsn ],
151 DBICTest::Schema::_skip_load_external->clone;
153 (DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('use_moose') ?
154 ('use_moose' => sub {
155 package DBICTest::Schema::_use_moose;
156 use base qw/ DBIx::Class::Schema::Loader /;
157 __PACKAGE__->naming('current');
158 __PACKAGE__->use_namespaces(0);
159 __PACKAGE__->connect(
160 $make_dbictest_db::dsn,
161 { loader_options => { use_moose => 1 } }
168 # 6 tests per k/v pair
169 plan tests => 6 * (@invocations/2) + 2; # + 2 more manual ones below.
171 while(@invocations) {
172 my $style = shift @invocations;
173 my $cref = shift @invocations;
176 local $SIG{__WARN__} = sub {
177 warn $_[0] unless $_[0] =~ /Deleting existing file .+ due to 'really_erase_my_files' setting/
182 test_schema($style, $schema);
188 is($DBICTest::Schema::_no_skip_load_external::Foo::skip_me, "bad mojo",
189 "external content loaded");
190 is($DBICTest::Schema::_skip_load_external::Foo::skip_me, undef,
191 "external content not loaded with skip_load_external => 1");