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__->connection($make_dbictest_db::dsn);
39 package DBICTest::Schema::_normal;
40 use base qw/ DBIx::Class::Schema::Loader /;
41 __PACKAGE__->loader_options();
42 __PACKAGE__->naming('current');
43 __PACKAGE__->connect($make_dbictest_db::dsn);
45 'make_schema_at' => sub {
46 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
48 'DBICTest::Schema::_make_schema_at',
49 { really_erase_my_files => 1, naming => 'current' },
50 [ $make_dbictest_db::dsn ],
52 DBICTest::Schema::_make_schema_at->clone;
54 'embedded_options' => sub {
55 package DBICTest::Schema::_embedded_options;
56 use base qw/ DBIx::Class::Schema::Loader /;
57 __PACKAGE__->naming('current');
59 $make_dbictest_db::dsn,
60 { loader_options => { really_erase_my_files => 1 } }
63 'embedded_options_in_attrs' => sub {
64 package DBICTest::Schema::_embedded_options_in_attrs;
65 use base qw/ DBIx::Class::Schema::Loader /;
66 __PACKAGE__->naming('current');
68 $make_dbictest_db::dsn,
71 { AutoCommit => 1, loader_options => { really_erase_my_files => 1 } }
74 'embedded_options_make_schema_at' => sub {
75 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
77 'DBICTest::Schema::_embedded_options_make_schema_at',
80 $make_dbictest_db::dsn,
82 really_erase_my_files => 1,
87 "DBICTest::Schema::_embedded_options_make_schema_at";
89 'almost_embedded' => sub {
90 package DBICTest::Schema::_almost_embedded;
91 use base qw/ DBIx::Class::Schema::Loader /;
92 __PACKAGE__->loader_options(
93 really_erase_my_files => 1,
97 $make_dbictest_db::dsn,
98 undef, undef, { AutoCommit => 1 }
101 'make_schema_at_explicit' => sub {
102 use DBIx::Class::Schema::Loader;
103 DBIx::Class::Schema::Loader::make_schema_at(
104 'DBICTest::Schema::_make_schema_at_explicit',
105 { really_erase_my_files => 1, naming => 'current' },
106 [ $make_dbictest_db::dsn ],
108 DBICTest::Schema::_make_schema_at_explicit->clone;
110 'no_skip_load_external' => sub {
111 # By default we should pull in t/lib/DBICTest/Schema/_no_skip_load_external/Foo.pm $skip_me since t/lib is in @INC
112 use DBIx::Class::Schema::Loader;
113 DBIx::Class::Schema::Loader::make_schema_at(
114 'DBICTest::Schema::_no_skip_load_external',
115 { really_erase_my_files => 1, naming => 'current' },
116 [ $make_dbictest_db::dsn ],
118 DBICTest::Schema::_no_skip_load_external->clone;
120 'skip_load_external' => sub {
121 # When we explicitly skip_load_external t/lib/DBICTest/Schema/_skip_load_external/Foo.pm should be ignored
122 use DBIx::Class::Schema::Loader;
123 DBIx::Class::Schema::Loader::make_schema_at(
124 'DBICTest::Schema::_skip_load_external',
125 { really_erase_my_files => 1, naming => 'current', skip_load_external => 1 },
126 [ $make_dbictest_db::dsn ],
128 DBICTest::Schema::_skip_load_external->clone;
130 (DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('use_moose') ?
131 ('use_moose' => sub {
132 package DBICTest::Schema::_use_moose;
133 use base qw/ DBIx::Class::Schema::Loader /;
134 __PACKAGE__->naming('current');
135 __PACKAGE__->connect(
136 $make_dbictest_db::dsn,
137 { loader_options => { use_moose => 1 } }
144 # 6 tests per k/v pair
145 plan tests => 6 * (@invocations/2) + 2; # + 2 more manual ones below.
147 while(@invocations) {
148 my $style = shift @invocations;
149 my $cref = shift @invocations;
152 local $SIG{__WARN__} = sub {
153 warn $_[0] unless $_[0] =~ /really_erase_my_files/
158 test_schema($style, $schema);
164 is($DBICTest::Schema::_no_skip_load_external::Foo::skip_me, "bad mojo",
165 "external content loaded");
166 is($DBICTest::Schema::_skip_load_external::Foo::skip_me, undef,
167 "external content not loaded with skip_load_external => 1");