stub tests for all classes
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / version_handlers / explict_versions.t
1 #!perl
2
3 use Test::More;
4 use Test::Exception;
5
6 use lib 't/lib';
7 use DBICDHTest;
8 use DBICTest;
9 use DBIx::Class::DeploymentHandler;
10 use DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions;
11 my $db = 'dbi:SQLite:db.db';
12 my @connection = ($db, '', '', { ignore_version => 1 });
13 my $sql_dir = 't/sql';
14
15 DBICDHTest::ready;
16
17 use DBICVersion_v1;
18 my $s = DBICVersion::Schema->connect(@connection);
19
20 my $handler = DBIx::Class::DeploymentHandler->new({
21    upgrade_directory => $sql_dir,
22    schema => $s,
23    databases => 'SQLite',
24    sqltargs => { add_drop_table => 0 },
25 });
26
27 my $v_storage = $handler->version_storage;
28
29 my $version = $s->schema_version();
30 $handler->prepare_install();
31
32 $handler->install;
33
34 my $versions = [map "$_.0", 0..100];
35
36 {
37   my $vh = DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions->new({
38     schema => $s,
39     ordered_versions => $versions,
40     to_version => '1.0',
41     version_storage => $v_storage,
42   });
43
44   ok $vh, 'VersionHandler gets instantiated';
45
46   ok( !$vh->next_version_set, 'next version set returns undef if we are at the version requested' );
47 }
48
49 {
50   my $vh = DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions->new({
51     schema => $s,
52     ordered_versions => $versions,
53     to_version => '5.0',
54     version_storage => $v_storage,
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::VersionHandler::ExplicitVersions->new({
68     schema => $s,
69     ordered_versions => $versions,
70     to_version => '0.0',
71     version_storage => $v_storage,
72   });
73 } 'cannot request a version before the current version';
74
75 done_testing;
76 __END__
77
78 vim: ts=2 sw=2 expandtab