Commit | Line | Data |
fa994d3c |
1 | use strict; |
2 | use Test::More; |
3 | use lib qw(t/lib); |
4 | use make_dbictest_db; |
5 | |
6 | # Takes a $schema as input, runs 4 basic tests |
7 | sub test_schema { |
8 | my ($testname, $schema) = @_; |
9 | |
10 | $schema = $schema->clone if !ref $schema; |
11 | isa_ok($schema, 'DBIx::Class::Schema', $testname); |
12 | |
13 | my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref'); |
14 | isa_ok($foo_rs, 'DBIx::Class::ResultSet', $testname); |
15 | |
16 | my $foo_first = $foo_rs->first; |
17 | like(ref $foo_first, qr/DBICTest::Schema::\d+::Foo/, $testname); |
18 | |
19 | my $foo_first_text = $foo_first->footext; |
20 | is($foo_first_text, 'Foo record associated with the Bar with barid 3'); |
21 | } |
22 | |
23 | my @invocations = ( |
24 | 'deprecated_one' => sub { |
25 | package DBICTest::Schema::1; |
26 | use base qw/ DBIx::Class::Schema::Loader /; |
27 | __PACKAGE__->connection($make_dbictest_db::dsn); |
28 | __PACKAGE__->load_from_connection( relationships => 1 ); |
29 | __PACKAGE__; |
30 | }, |
31 | 'deprecated_two' => sub { |
32 | package DBICTest::Schema::2; |
33 | use base qw/ DBIx::Class::Schema::Loader /; |
34 | __PACKAGE__->load_from_connection( |
35 | relationships => 1, |
36 | connect_info => [ $make_dbictest_db::dsn ], |
37 | ); |
38 | __PACKAGE__; |
39 | }, |
40 | 'deprecated_three' => sub { |
41 | package DBICTest::Schema::3; |
42 | use base qw/ DBIx::Class::Schema::Loader /; |
43 | __PACKAGE__->load_from_connection( |
44 | relationships => 1, |
45 | dsn => $make_dbictest_db::dsn, |
46 | ); |
47 | __PACKAGE__; |
48 | }, |
49 | 'deprecated_four' => sub { |
50 | package DBICTest::Schema::4; |
51 | use base qw/ DBIx::Class::Schema::Loader /; |
52 | __PACKAGE__->connection($make_dbictest_db::dsn); |
53 | __PACKAGE__->loader_options( relationships => 1 ); |
54 | __PACKAGE__; |
55 | }, |
56 | 'hardcode' => sub { |
57 | package DBICTest::Schema::5; |
58 | use base qw/ DBIx::Class::Schema::Loader /; |
59 | __PACKAGE__->loader_options( relationships => 1 ); |
60 | __PACKAGE__->connection($make_dbictest_db::dsn); |
61 | __PACKAGE__; |
62 | }, |
63 | 'normal' => sub { |
64 | package DBICTest::Schema::6; |
65 | use base qw/ DBIx::Class::Schema::Loader /; |
66 | __PACKAGE__->loader_options( relationships => 1 ); |
67 | __PACKAGE__->connect($make_dbictest_db::dsn); |
68 | }, |
69 | 'make_schema_at' => sub { |
70 | use DBIx::Class::Schema::Loader qw/ make_schema_at /; |
71 | make_schema_at( |
72 | 'DBICTest::Schema::7', |
73 | { relationships => 1 }, |
74 | [ $make_dbictest_db::dsn ], |
75 | ); |
76 | DBICTest::Schema::7->clone; |
77 | }, |
78 | 'embedded_options' => sub { |
79 | package DBICTest::Schema::8; |
80 | use base qw/ DBIx::Class::Schema::Loader /; |
81 | __PACKAGE__->connect( |
82 | $make_dbictest_db::dsn, |
83 | { loader_options => { relationships => 1 } } |
84 | ); |
85 | }, |
86 | 'embedded_options_in_attrs' => sub { |
87 | package DBICTest::Schema::9; |
88 | use base qw/ DBIx::Class::Schema::Loader /; |
89 | __PACKAGE__->connect( |
90 | $make_dbictest_db::dsn, |
91 | undef, |
92 | undef, |
93 | { AutoCommit => 1, loader_options => { relationships => 1 } } |
94 | ); |
95 | }, |
96 | 'embedded_options_make_schema_at' => sub { |
97 | use DBIx::Class::Schema::Loader qw/ make_schema_at /; |
98 | make_schema_at( |
99 | 'DBICTest::Schema::10', |
100 | { }, |
101 | [ |
102 | $make_dbictest_db::dsn, |
103 | { loader_options => { relationships => 1 } }, |
104 | ], |
105 | ); |
106 | "DBICTest::Schema::10"; |
107 | }, |
108 | 'almost_embedded' => sub { |
109 | package DBICTest::Schema::11; |
110 | use base qw/ DBIx::Class::Schema::Loader /; |
111 | __PACKAGE__->loader_options( relationships => 1 ); |
112 | __PACKAGE__->connect( |
113 | $make_dbictest_db::dsn, |
114 | undef, undef, { AutoCommit => 1 } |
115 | ); |
116 | }, |
117 | 'make_schema_at_explicit' => sub { |
118 | use DBIx::Class::Schema::Loader; |
119 | DBIx::Class::Schema::Loader::make_schema_at( |
120 | 'DBICTest::Schema::12', |
121 | { relationships => 1 }, |
122 | [ $make_dbictest_db::dsn ], |
123 | ); |
124 | DBICTest::Schema::12->clone; |
125 | } |
126 | ); |
127 | |
128 | # 4 tests per k/v pair |
129 | plan tests => 2 * @invocations; |
130 | |
131 | while(@invocations >= 2) { |
132 | my $style = shift @invocations; |
133 | my $subref = shift @invocations; |
134 | test_schema($style, &$subref); |
135 | } |