3 use DBIx::Class::Schema::Loader::Optional::Dependencies;
7 local $SIG{__WARN__} = sub {
8 warn $_[0] unless $_[0] =~ /really_erase_my_files/
11 # Takes a $schema as input, runs 4 basic tests
13 my ($testname, $schema) = @_;
15 $schema = $schema->clone if !ref $schema;
16 isa_ok($schema, 'DBIx::Class::Schema', $testname);
18 my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
19 isa_ok($foo_rs, 'DBIx::Class::ResultSet', $testname);
21 my $foo_first = $foo_rs->first;
22 like(ref $foo_first, qr/DBICTest::Schema::\d+::Foo/, $testname);
24 my $foo_first_text = $foo_first->footext;
25 is($foo_first_text, 'Foo record associated with the Bar with barid 3');
30 package DBICTest::Schema::5;
31 use base qw/ DBIx::Class::Schema::Loader /;
32 __PACKAGE__->naming('current');
33 __PACKAGE__->connection($make_dbictest_db::dsn);
37 package DBICTest::Schema::6;
38 use base qw/ DBIx::Class::Schema::Loader /;
39 __PACKAGE__->loader_options();
40 __PACKAGE__->naming('current');
41 __PACKAGE__->connect($make_dbictest_db::dsn);
43 'make_schema_at' => sub {
44 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
46 'DBICTest::Schema::7',
47 { really_erase_my_files => 1, naming => 'current' },
48 [ $make_dbictest_db::dsn ],
50 DBICTest::Schema::7->clone;
52 'embedded_options' => sub {
53 package DBICTest::Schema::8;
54 use base qw/ DBIx::Class::Schema::Loader /;
55 __PACKAGE__->naming('current');
57 $make_dbictest_db::dsn,
58 { loader_options => { really_erase_my_files => 1 } }
61 'embedded_options_in_attrs' => sub {
62 package DBICTest::Schema::9;
63 use base qw/ DBIx::Class::Schema::Loader /;
64 __PACKAGE__->naming('current');
66 $make_dbictest_db::dsn,
69 { AutoCommit => 1, loader_options => { really_erase_my_files => 1 } }
72 'embedded_options_make_schema_at' => sub {
73 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
75 'DBICTest::Schema::10',
78 $make_dbictest_db::dsn,
80 really_erase_my_files => 1,
85 "DBICTest::Schema::10";
87 'almost_embedded' => sub {
88 package DBICTest::Schema::11;
89 use base qw/ DBIx::Class::Schema::Loader /;
90 __PACKAGE__->loader_options(
91 really_erase_my_files => 1,
95 $make_dbictest_db::dsn,
96 undef, undef, { AutoCommit => 1 }
99 'make_schema_at_explicit' => sub {
100 use DBIx::Class::Schema::Loader;
101 DBIx::Class::Schema::Loader::make_schema_at(
102 'DBICTest::Schema::12',
103 { really_erase_my_files => 1, naming => 'current' },
104 [ $make_dbictest_db::dsn ],
106 DBICTest::Schema::12->clone;
108 'no_skip_load_external' => sub {
109 # By default we should pull in t/lib/DBICTest/Schema/13/Foo.pm $skip_me since t/lib is in @INC
110 use DBIx::Class::Schema::Loader;
111 DBIx::Class::Schema::Loader::make_schema_at(
112 'DBICTest::Schema::13',
113 { really_erase_my_files => 1, naming => 'current' },
114 [ $make_dbictest_db::dsn ],
116 DBICTest::Schema::13->clone;
118 'skip_load_external' => sub {
119 # When we explicitly skip_load_external t/lib/DBICTest/Schema/14/Foo.pm should be ignored
120 use DBIx::Class::Schema::Loader;
121 DBIx::Class::Schema::Loader::make_schema_at(
122 'DBICTest::Schema::14',
123 { really_erase_my_files => 1, naming => 'current', skip_load_external => 1 },
124 [ $make_dbictest_db::dsn ],
126 DBICTest::Schema::14->clone;
128 (DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('use_moose') ?
130 package DBICTest::Schema::8;
131 use base qw/ DBIx::Class::Schema::Loader /;
132 __PACKAGE__->naming('current');
133 __PACKAGE__->connect(
134 $make_dbictest_db::dsn,
135 { loader_options => { use_moose => 1 } }
142 # 4 tests per k/v pair
143 plan tests => 2 * @invocations + 2; # + 2 more manual ones below.
145 while(@invocations >= 2) {
146 my $style = shift @invocations;
147 my $subref = shift @invocations;
148 test_schema($style, &$subref);
154 is($DBICTest::Schema::13::Foo::skip_me, "bad mojo",
155 "external content loaded");
156 is($DBICTest::Schema::14::Foo::skip_me, undef,
157 "external content not loaded with skip_load_external => 1");