Commit | Line | Data |
fa994d3c |
1 | use strict; |
2 | use Test::More; |
ef8e9c69 |
3 | use DBIx::Class::Schema::Loader::Optional::Dependencies; |
fa994d3c |
4 | use lib qw(t/lib); |
5 | use make_dbictest_db; |
6 | |
fdd8ff16 |
7 | local $SIG{__WARN__} = sub { |
8 | warn $_[0] unless $_[0] =~ /really_erase_my_files/ |
9 | }; |
10 | |
fa994d3c |
11 | # Takes a $schema as input, runs 4 basic tests |
12 | sub test_schema { |
13 | my ($testname, $schema) = @_; |
14 | |
15 | $schema = $schema->clone if !ref $schema; |
16 | isa_ok($schema, 'DBIx::Class::Schema', $testname); |
17 | |
18 | my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref'); |
19 | isa_ok($foo_rs, 'DBIx::Class::ResultSet', $testname); |
20 | |
21 | my $foo_first = $foo_rs->first; |
22 | like(ref $foo_first, qr/DBICTest::Schema::\d+::Foo/, $testname); |
23 | |
24 | my $foo_first_text = $foo_first->footext; |
25 | is($foo_first_text, 'Foo record associated with the Bar with barid 3'); |
26 | } |
27 | |
28 | my @invocations = ( |
fa994d3c |
29 | 'hardcode' => sub { |
30 | package DBICTest::Schema::5; |
31 | use base qw/ DBIx::Class::Schema::Loader /; |
8b7749d6 |
32 | __PACKAGE__->naming('current'); |
fa994d3c |
33 | __PACKAGE__->connection($make_dbictest_db::dsn); |
34 | __PACKAGE__; |
35 | }, |
36 | 'normal' => sub { |
37 | package DBICTest::Schema::6; |
38 | use base qw/ DBIx::Class::Schema::Loader /; |
59cfa251 |
39 | __PACKAGE__->loader_options(); |
8b7749d6 |
40 | __PACKAGE__->naming('current'); |
fa994d3c |
41 | __PACKAGE__->connect($make_dbictest_db::dsn); |
42 | }, |
43 | 'make_schema_at' => sub { |
44 | use DBIx::Class::Schema::Loader qw/ make_schema_at /; |
45 | make_schema_at( |
46 | 'DBICTest::Schema::7', |
8b7749d6 |
47 | { really_erase_my_files => 1, naming => 'current' }, |
fa994d3c |
48 | [ $make_dbictest_db::dsn ], |
49 | ); |
50 | DBICTest::Schema::7->clone; |
51 | }, |
52 | 'embedded_options' => sub { |
53 | package DBICTest::Schema::8; |
54 | use base qw/ DBIx::Class::Schema::Loader /; |
8b7749d6 |
55 | __PACKAGE__->naming('current'); |
fa994d3c |
56 | __PACKAGE__->connect( |
57 | $make_dbictest_db::dsn, |
28b4691d |
58 | { loader_options => { really_erase_my_files => 1 } } |
fa994d3c |
59 | ); |
60 | }, |
61 | 'embedded_options_in_attrs' => sub { |
62 | package DBICTest::Schema::9; |
63 | use base qw/ DBIx::Class::Schema::Loader /; |
8b7749d6 |
64 | __PACKAGE__->naming('current'); |
fa994d3c |
65 | __PACKAGE__->connect( |
66 | $make_dbictest_db::dsn, |
67 | undef, |
68 | undef, |
28b4691d |
69 | { AutoCommit => 1, loader_options => { really_erase_my_files => 1 } } |
fa994d3c |
70 | ); |
71 | }, |
72 | 'embedded_options_make_schema_at' => sub { |
73 | use DBIx::Class::Schema::Loader qw/ make_schema_at /; |
74 | make_schema_at( |
75 | 'DBICTest::Schema::10', |
76 | { }, |
77 | [ |
78 | $make_dbictest_db::dsn, |
8b7749d6 |
79 | { loader_options => { |
80 | really_erase_my_files => 1, |
81 | naming => 'current' |
82 | } }, |
fa994d3c |
83 | ], |
84 | ); |
85 | "DBICTest::Schema::10"; |
86 | }, |
87 | 'almost_embedded' => sub { |
88 | package DBICTest::Schema::11; |
89 | use base qw/ DBIx::Class::Schema::Loader /; |
8b7749d6 |
90 | __PACKAGE__->loader_options( |
91 | really_erase_my_files => 1, |
92 | naming => 'current' |
93 | ); |
fa994d3c |
94 | __PACKAGE__->connect( |
95 | $make_dbictest_db::dsn, |
96 | undef, undef, { AutoCommit => 1 } |
97 | ); |
98 | }, |
99 | 'make_schema_at_explicit' => sub { |
100 | use DBIx::Class::Schema::Loader; |
101 | DBIx::Class::Schema::Loader::make_schema_at( |
102 | 'DBICTest::Schema::12', |
8b7749d6 |
103 | { really_erase_my_files => 1, naming => 'current' }, |
fa994d3c |
104 | [ $make_dbictest_db::dsn ], |
105 | ); |
106 | DBICTest::Schema::12->clone; |
0ca61324 |
107 | }, |
73099af4 |
108 | 'no_skip_load_external' => sub { |
0ca61324 |
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 ], |
115 | ); |
116 | DBICTest::Schema::13->clone; |
117 | }, |
73099af4 |
118 | 'skip_load_external' => sub { |
0ca61324 |
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 ], |
125 | ); |
126 | DBICTest::Schema::14->clone; |
127 | }, |
ef8e9c69 |
128 | (DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('use_moose') ? |
129 | ('moose' => sub { |
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 } } |
136 | ); |
137 | }) |
138 | : () |
139 | ), |
fa994d3c |
140 | ); |
141 | |
142 | # 4 tests per k/v pair |
0ca61324 |
143 | plan tests => 2 * @invocations + 2; # + 2 more manual ones below. |
fa994d3c |
144 | |
145 | while(@invocations >= 2) { |
146 | my $style = shift @invocations; |
147 | my $subref = shift @invocations; |
148 | test_schema($style, &$subref); |
149 | } |
0ca61324 |
150 | |
b7219351 |
151 | { |
152 | no warnings 'once'; |
0ca61324 |
153 | |
b7219351 |
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"); |
158 | } |