Prevent Schema::Loader from overwriting unchanged schema files
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 20invocations.t
CommitLineData
fa994d3c 1use strict;
2use Test::More;
3use lib qw(t/lib);
4use make_dbictest_db;
5
6# Takes a $schema as input, runs 4 basic tests
7sub 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
23my @invocations = (
fa994d3c 24 'hardcode' => sub {
25 package DBICTest::Schema::5;
26 use base qw/ DBIx::Class::Schema::Loader /;
fa994d3c 27 __PACKAGE__->connection($make_dbictest_db::dsn);
28 __PACKAGE__;
29 },
30 'normal' => sub {
31 package DBICTest::Schema::6;
32 use base qw/ DBIx::Class::Schema::Loader /;
59cfa251 33 __PACKAGE__->loader_options();
fa994d3c 34 __PACKAGE__->connect($make_dbictest_db::dsn);
35 },
36 'make_schema_at' => sub {
37 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
38 make_schema_at(
39 'DBICTest::Schema::7',
28b4691d 40 { really_erase_my_files => 1 },
fa994d3c 41 [ $make_dbictest_db::dsn ],
42 );
43 DBICTest::Schema::7->clone;
44 },
45 'embedded_options' => sub {
46 package DBICTest::Schema::8;
47 use base qw/ DBIx::Class::Schema::Loader /;
48 __PACKAGE__->connect(
49 $make_dbictest_db::dsn,
28b4691d 50 { loader_options => { really_erase_my_files => 1 } }
fa994d3c 51 );
52 },
53 'embedded_options_in_attrs' => sub {
54 package DBICTest::Schema::9;
55 use base qw/ DBIx::Class::Schema::Loader /;
56 __PACKAGE__->connect(
57 $make_dbictest_db::dsn,
58 undef,
59 undef,
28b4691d 60 { AutoCommit => 1, loader_options => { really_erase_my_files => 1 } }
fa994d3c 61 );
62 },
63 'embedded_options_make_schema_at' => sub {
64 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
65 make_schema_at(
66 'DBICTest::Schema::10',
67 { },
68 [
69 $make_dbictest_db::dsn,
28b4691d 70 { loader_options => { really_erase_my_files => 1 } },
fa994d3c 71 ],
72 );
73 "DBICTest::Schema::10";
74 },
75 'almost_embedded' => sub {
76 package DBICTest::Schema::11;
77 use base qw/ DBIx::Class::Schema::Loader /;
28b4691d 78 __PACKAGE__->loader_options( really_erase_my_files => 1 );
fa994d3c 79 __PACKAGE__->connect(
80 $make_dbictest_db::dsn,
81 undef, undef, { AutoCommit => 1 }
82 );
83 },
84 'make_schema_at_explicit' => sub {
85 use DBIx::Class::Schema::Loader;
86 DBIx::Class::Schema::Loader::make_schema_at(
87 'DBICTest::Schema::12',
28b4691d 88 { really_erase_my_files => 1 },
fa994d3c 89 [ $make_dbictest_db::dsn ],
90 );
91 DBICTest::Schema::12->clone;
92 }
93);
94
95# 4 tests per k/v pair
96plan tests => 2 * @invocations;
97
98while(@invocations >= 2) {
99 my $style = shift @invocations;
100 my $subref = shift @invocations;
101 test_schema($style, &$subref);
102}