test for ->install
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / 02-instantiation.t
CommitLineData
b974984a 1#!perl
2
3use Test::More;
239acef9 4use Test::Exception;
b974984a 5
6use lib 't/lib';
7use DBICTest;
8use DBIx::Class::DeploymentHandler;
9
e0743c25 10my $sql_dir = 't/sql';
b974984a 11
e0743c25 12VERSION1: {
13 use_ok 'DBICVersion_v1';
14 my $s = DBICVersion::Schema->connect('dbi:SQLite::memory:');
15 ok($s, 'DBICVersion::Schema 1.0 instantiates correctly');
16 my $handler = DBIx::Class::DeploymentHandler->new({
17 schema => $s,
18 });
19
20 ok($handler, 'DBIx::Class::DeploymentHandler w/1.0 instantiates correctly');
21
22 my $version = $s->schema_version();
23 $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, 0);
24 ok(-e 't/sql/DBICVersion-Schema-1.0-SQLite.sql', 'DDL for 1.0 got created successfully');
239acef9 25
26 dies_ok {
27 $s->resultset('Foo')->create({
28 bar => 'frew',
29 })
30 } 'schema not deployed';
31 $handler->install;
32 lives_ok {
33 $s->resultset('Foo')->create({
34 bar => 'frew',
35 })
36 } 'schema is deployed';
e0743c25 37}
38
39VERSION2: {
40 use_ok 'DBICVersion_v2';
41 my $s = DBICVersion::Schema->connect('dbi:SQLite::memory:');
42 ok($s, 'DBICVersion::Schema 2.0 instantiates correctly');
43 my $handler = DBIx::Class::DeploymentHandler->new({
44 schema => $s,
45 });
46
47 ok($handler, 'DBIx::Class::DeploymentHandler w/2.0 instantiates correctly');
48
49 $version = $s->schema_version();
50 $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, 0);
51 $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, '1.0');
52 ok(-e 't/sql/DBICVersion-Schema-2.0-SQLite.sql', 'DDL for 2.0 got created successfully');
53 ok(-e 't/sql/DBICVersion-Schema-1.0-2.0-SQLite.sql', 'DDL for migration from 1.0 to 2.0 got created successfully');
239acef9 54 dies_ok {
55 $s->resultset('Foo')->create({
56 bar => 'frew',
57 baz => 'frew',
58 })
59 } 'schema not deployed';
60 $handler->install;
61 lives_ok {
62 $s->resultset('Foo')->create({
63 bar => 'frew',
64 baz => 'frew',
65 })
66 } 'schema is deployed';
e0743c25 67}
68
69VERSION3: {
70 use_ok 'DBICVersion_v3';
71 my $s = DBICVersion::Schema->connect('dbi:SQLite::memory:');
72 ok($s, 'DBICVersion::Schema 3.0 instantiates correctly');
73 my $handler = DBIx::Class::DeploymentHandler->new({
74 schema => $s,
75 });
76
77 ok($handler, 'DBIx::Class::DeploymentHandler w/3.0 instantiates correctly');
78
79 $version = $s->schema_version();
80 $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, 0);
81 $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, '1.0');
82 $handler->create_ddl_dir( 'SQLite', $version, $sql_dir, '2.0');
83 ok(-e 't/sql/DBICVersion-Schema-3.0-SQLite.sql', 'DDL for 3.0 got created successfully');
84 ok(-e 't/sql/DBICVersion-Schema-1.0-3.0-SQLite.sql', 'DDL for migration from 1.0 to 3.0 got created successfully');
85 ok(-e 't/sql/DBICVersion-Schema-2.0-3.0-SQLite.sql', 'DDL for migration from 2.0 to 3.0 got created successfully');
239acef9 86 dies_ok {
87 $s->resultset('Foo')->create({
88 bar => 'frew',
89 baz => 'frew',
90 biff => 'frew',
91 })
92 } 'schema not deployed';
93 $handler->install;
94 lives_ok {
95 $s->resultset('Foo')->create({
96 bar => 'frew',
97 baz => 'frew',
98 biff => 'frew',
99 })
100 } 'schema is deployed';
e0743c25 101}
b974984a 102
103done_testing;