fix POD coverage and t/backcompat/0.04006/23dumpmore.t
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / backcompat / 0.04006 / 20invocations.t
1 use strict;
2 use Test::More;
3 use lib qw(t/backcompat/0.04006/lib);
4 use make_dbictest_db;
5
6 plan skip_all => 'set SCHEMA_LOADER_TESTS_BACKCOMPAT to enable these tests'
7     unless $ENV{SCHEMA_LOADER_TESTS_BACKCOMPAT};
8
9 # Takes a $schema as input, runs 4 basic tests
10 sub test_schema {
11     my ($testname, $schema) = @_;
12
13     $schema = $schema->clone if !ref $schema;
14     isa_ok($schema, 'DBIx::Class::Schema', $testname);
15
16     my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
17     isa_ok($foo_rs, 'DBIx::Class::ResultSet', $testname);
18
19     my $foo_first = $foo_rs->first;
20     like(ref $foo_first, qr/DBICTest::Schema::\d+::Foo/, $testname);
21
22     my $foo_first_text = $foo_first->footext;
23     is($foo_first_text, 'Foo record associated with the Bar with barid 3');
24 }
25
26 my @invocations = (
27     'hardcode' => sub {
28         package DBICTest::Schema::5;
29         use base qw/ DBIx::Class::Schema::Loader /;
30         __PACKAGE__->connection($make_dbictest_db::dsn);
31         __PACKAGE__;
32     },
33     'normal' => sub {
34         package DBICTest::Schema::6;
35         use base qw/ DBIx::Class::Schema::Loader /;
36         __PACKAGE__->loader_options();
37         __PACKAGE__->connect($make_dbictest_db::dsn);
38     },
39     'make_schema_at' => sub {
40         use DBIx::Class::Schema::Loader qw/ make_schema_at /;
41         make_schema_at(
42             'DBICTest::Schema::7',
43             { really_erase_my_files => 1 },
44             [ $make_dbictest_db::dsn ],
45         );
46         DBICTest::Schema::7->clone;
47     },
48     'embedded_options' => sub {
49         package DBICTest::Schema::8;
50         use base qw/ DBIx::Class::Schema::Loader /;
51         __PACKAGE__->connect(
52             $make_dbictest_db::dsn,
53             { loader_options => { really_erase_my_files => 1 } }
54         );
55     },
56     'embedded_options_in_attrs' => sub {
57         package DBICTest::Schema::9;
58         use base qw/ DBIx::Class::Schema::Loader /;
59         __PACKAGE__->connect(
60             $make_dbictest_db::dsn,
61             undef,
62             undef,
63             { AutoCommit => 1, loader_options => { really_erase_my_files => 1 } }
64         );
65     },
66     'embedded_options_make_schema_at' => sub {
67         use DBIx::Class::Schema::Loader qw/ make_schema_at /;
68         make_schema_at(
69             'DBICTest::Schema::10',
70             { },
71             [
72                 $make_dbictest_db::dsn,
73                 { loader_options => { really_erase_my_files => 1 } },
74             ],
75         );
76         "DBICTest::Schema::10";
77     },
78     'almost_embedded' => sub {
79         package DBICTest::Schema::11;
80         use base qw/ DBIx::Class::Schema::Loader /;
81         __PACKAGE__->loader_options( really_erase_my_files => 1 );
82         __PACKAGE__->connect(
83             $make_dbictest_db::dsn,
84             undef, undef, { AutoCommit => 1 }
85         );
86     },
87     'make_schema_at_explicit' => sub {
88         use DBIx::Class::Schema::Loader;
89         DBIx::Class::Schema::Loader::make_schema_at(
90             'DBICTest::Schema::12',
91             { really_erase_my_files => 1 },
92             [ $make_dbictest_db::dsn ],
93         );
94         DBICTest::Schema::12->clone;
95     }
96 );
97
98 # 4 tests per k/v pair
99 plan tests => 2 * @invocations;
100
101 while(@invocations >= 2) {
102     my $style = shift @invocations;
103     my $subref = shift @invocations;
104     test_schema($style, &$subref);
105 }