major method renames for public api
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / 03_explict_versions.t
1 #!perl
2
3 use Test::More;
4 use Test::Exception;
5
6 use lib 't/lib';
7 use DBICTest;
8 use DBIx::Class::DeploymentHandler;
9 use DBIx::Class::DeploymentHandler::ExplicitVersions;
10 my $db = 'dbi:SQLite:db.db';
11 my @connection = ($db, '', '', { ignore_version => 1 });
12 my $sql_dir = 't/sql';
13
14 unlink 'db.db' if -e 'db.db';
15 if (-d 't/sql') {
16   unlink $_ for glob('t/sql/*');
17 } else {
18   mkdir 't/sql';
19 }
20
21 use DBICVersion_v1;
22 my $s = DBICVersion::Schema->connect(@connection);
23
24 my $handler = DBIx::Class::DeploymentHandler->new({
25    upgrade_directory => $sql_dir,
26    schema => $s,
27    databases => 'SQLite',
28  sqltargs => { add_drop_table => 0 },
29 });
30
31 my $version = $s->schema_version();
32 $handler->prepare_install();
33
34 $handler->install;
35
36 my $versions = [map "$_.0", 0..100];
37
38 {
39   my $vh = DBIx::Class::DeploymentHandler::ExplicitVersions->new({
40     schema => $s,
41     ordered_versions => $versions,
42     to_version => '1.0',
43   });
44
45   ok $vh, 'VersionHandler gets instantiated';
46
47   ok( !$vh->next_version_set, 'next version set returns undef if we are at the version requested' );
48 }
49
50 {
51   my $vh = DBIx::Class::DeploymentHandler::ExplicitVersions->new({
52     schema => $s,
53     ordered_versions => $versions,
54     to_version => '5.0',
55   });
56
57   ok $vh, 'VersionHandler gets instantiated';
58   ok( eq_array($vh->next_version_set, [qw( 1.0 2.0 )]), 'first version pair works' );
59   ok( eq_array($vh->next_version_set, [qw( 2.0 3.0 )]), 'second version pair works' );
60   ok( eq_array($vh->next_version_set, [qw( 3.0 4.0 )]), 'third version pair works' );
61   ok( eq_array($vh->next_version_set, [qw( 4.0 5.0 )]), 'fourth version pair works' );
62   ok( !$vh->next_version_set, 'no more versions after final pair' );
63   ok( !$vh->next_version_set, 'still no more versions after final pair' );
64 }
65
66 dies_ok {
67   my $vh = DBIx::Class::DeploymentHandler::ExplicitVersions->new({
68     schema => $s,
69     ordered_versions => $versions,
70     to_version => '0.0',
71   });
72 } 'cannot request a version before the current version';
73
74 done_testing;
75 __END__
76
77 vim: ts=2 sw=2 expandtab