Test suite now is fully parallelizable
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / 02-instantiation.t
CommitLineData
b974984a 1#!perl
2
4a65f60b 3use strict;
4use warnings;
5
b974984a 6use lib 't/lib';
02d58ac0 7use DBICDHTest;
b974984a 8use DBIx::Class::DeploymentHandler;
4a65f60b 9use aliased 'DBIx::Class::DeploymentHandler', 'DH';
10
11use File::Path 'remove_tree';
fe3b6dff 12use Test::More;
7b3d00f9 13use File::Temp 'tempdir';
4a65f60b 14use Test::Exception;
15
f3b5161e 16my $dbh = DBICDHTest::dbh();
624e3018 17my @connection = (sub { $dbh }, { ignore_version => 1 });
7b3d00f9 18my $sql_dir = tempdir( CLEANUP => 1 );
4a65f60b 19
20VERSION1: {
21 use_ok 'DBICVersion_v1';
22 my $s = DBICVersion::Schema->connect(@connection);
23 $DBICVersion::Schema::VERSION = 1;
24 ok($s, 'DBICVersion::Schema 1 instantiates correctly');
25 my $handler = DH->new({
91adde75 26 script_directory => $sql_dir,
4a65f60b 27 schema => $s,
28 databases => 'SQLite',
02a7b8ac 29 sql_translator_args => { add_drop_table => 0 },
4a65f60b 30 });
31
32 ok($handler, 'DBIx::Class::DeploymentHandler w/1 instantiates correctly');
33
34 my $version = $s->schema_version;
5761fe02 35 $handler->prepare_install;
4a65f60b 36
37 dies_ok {
38 $s->resultset('Foo')->create({
39 bar => 'frew',
40 })
41 } 'schema not deployed';
42 $handler->install;
43 dies_ok {
44 $handler->install;
45 } 'cannot install twice';
46 lives_ok {
47 $s->resultset('Foo')->create({
48 bar => 'frew',
49 })
50 } 'schema is deployed';
51}
52
53VERSION2: {
54 use_ok 'DBICVersion_v2';
55 my $s = DBICVersion::Schema->connect(@connection);
56 $DBICVersion::Schema::VERSION = 2;
57 ok($s, 'DBICVersion::Schema 2 instantiates correctly');
58 my $handler = DH->new({
91adde75 59 script_directory => $sql_dir,
4a65f60b 60 schema => $s,
61 databases => 'SQLite',
62 });
63
64 ok($handler, 'DBIx::Class::DeploymentHandler w/2 instantiates correctly');
65
66 my $version = $s->schema_version();
5761fe02 67 $handler->prepare_install;
be140a5f 68 $handler->prepare_upgrade({ from_version => 1, to_version => $version} );
4a65f60b 69 dies_ok {
70 $s->resultset('Foo')->create({
71 bar => 'frew',
72 baz => 'frew',
73 })
74 } 'schema not deployed';
75 dies_ok {
76 $s->resultset('Foo')->create({
77 bar => 'frew',
78 baz => 'frew',
79 })
80 } 'schema not uppgrayyed';
81 $handler->upgrade;
82 lives_ok {
83 $s->resultset('Foo')->create({
84 bar => 'frew',
85 baz => 'frew',
86 })
87 } 'schema is deployed';
88}
89
90VERSION3: {
91 use_ok 'DBICVersion_v3';
92 my $s = DBICVersion::Schema->connect(@connection);
93 $DBICVersion::Schema::VERSION = 3;
94 ok($s, 'DBICVersion::Schema 3 instantiates correctly');
95 my $handler = DH->new({
91adde75 96 script_directory => $sql_dir,
4a65f60b 97 schema => $s,
98 databases => 'SQLite',
99 });
100
101 ok($handler, 'DBIx::Class::DeploymentHandler w/3 instantiates correctly');
102
103 my $version = $s->schema_version();
5761fe02 104 $handler->prepare_install;
be140a5f 105 $handler->prepare_upgrade({ from_version => 2, to_version => $version });
4a65f60b 106 dies_ok {
107 $s->resultset('Foo')->create({
108 bar => 'frew',
109 baz => 'frew',
110 biff => 'frew',
111 })
112 } 'schema not deployed';
113 $handler->upgrade;
114 lives_ok {
115 $s->resultset('Foo')->create({
116 bar => 'frew',
117 baz => 'frew',
118 biff => 'frew',
119 })
120 } 'schema is deployed';
121}
122
123DOWN2: {
124 use_ok 'DBICVersion_v4';
125 my $s = DBICVersion::Schema->connect(@connection);
126 $DBICVersion::Schema::VERSION = 2;
127 ok($s, 'DBICVersion::Schema 2 instantiates correctly');
128 my $handler = DH->new({
91adde75 129 script_directory => $sql_dir,
4a65f60b 130 schema => $s,
131 databases => 'SQLite',
132 });
133
134 ok($handler, 'DBIx::Class::DeploymentHandler w/2 instantiates correctly');
e0743c25 135
4a65f60b 136 my $version = $s->schema_version();
be140a5f 137 $handler->prepare_downgrade({ from_version => 3, to_version => $version });
4a65f60b 138 lives_ok {
139 $s->resultset('Foo')->create({
140 bar => 'frew',
141 baz => 'frew',
142 biff => 'frew',
143 })
144 } 'schema at version 3';
145 $handler->downgrade;
146 dies_ok {
147 $s->resultset('Foo')->create({
148 bar => 'frew',
149 baz => 'frew',
150 biff => 'frew',
151 })
152 } 'schema not at version 3';
153 lives_ok {
154 $s->resultset('Foo')->create({
155 bar => 'frew',
156 baz => 'frew',
157 })
158 } 'schema is at version 2';
159}
b974984a 160
161done_testing;