test refactor
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / version_handlers / db_schema_versions.t
CommitLineData
24794769 1#!perl
2
3use Test::More;
4use Test::Exception;
5
6use lib 't/lib';
7use DBICTest;
8use DBIx::Class::DeploymentHandler;
c703d15d 9use DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions;
24794769 10my $db = 'dbi:SQLite:db.db';
11my @connection = ($db, '', '', { ignore_version => 1 });
12my $sql_dir = 't/sql';
13
14unlink 'db.db' if -e 'db.db';
15if (-d 't/sql') {
16 unlink $_ for glob('t/sql/*');
17} else {
18 mkdir 't/sql';
19}
20
21use DBICVersion_v1;
22my $s = DBICVersion::Schema->connect(@connection);
23
24my $handler = DBIx::Class::DeploymentHandler->new({
25 upgrade_directory => $sql_dir,
26 schema => $s,
27 databases => 'SQLite',
28 sqltargs => { add_drop_table => 0 },
29});
fb105cfa 30my $v_storage = $handler->version_storage;
24794769 31my $version = $s->schema_version();
a912450b 32$handler->prepare_install();
24794769 33
34$handler->install;
35{
c703d15d 36 my $vh = DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions->new({
24794769 37 schema => $s,
38 ordered_versions => $versions,
39 to_version => '5.0',
fb105cfa 40 version_storage => $v_storage,
24794769 41 });
42
43 ok( $vh, 'VersionHandler gets instantiated' );
44 ok( eq_array( $vh->next_version_set, [qw( 1.0 5.0 )] ), 'db version and to_version get correctly put into version set');
45 ok( !$vh->next_version_set, 'next_version_set only works once');
46 ok( !$vh->next_version_set, 'seriously.');
47}
48
49{
c703d15d 50 my $vh = DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions->new({
24794769 51 schema => $s,
52 ordered_versions => $versions,
fb105cfa 53 version_storage => $v_storage,
24794769 54 });
55
56 ok( $vh, 'VersionHandler gets instantiated' );
57 ok( !$vh->next_version_set, 'VersionHandler is null when schema_version and db_verison are the same' );
58}
59
60{
c703d15d 61 my $vh = DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions->new({
24794769 62 schema => $s,
63 ordered_versions => $versions,
fb105cfa 64 version_storage => $v_storage,
24794769 65 });
66
67 ok( $vh, 'VersionHandler gets instantiated' );
68 ok( !$vh->next_version_set, 'VersionHandler is null when schema_version and db_verison are the same' );
69}
70
71{
72 $DBICVersion::Schema::VERSION = '10.0';
73
c703d15d 74 my $vh = DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions->new({
24794769 75 schema => $s,
76 ordered_versions => $versions,
fb105cfa 77 version_storage => $v_storage,
24794769 78 });
79
80 ok( $vh, 'VersionHandler gets instantiated' );
81 ok( eq_array( $vh->next_version_set, [qw( 1.0 10.0 )] ), 'db version and schema version get correctly put into version set');
82 ok( !$vh->next_version_set, 'VersionHandler is null on next try' );
83}
84
85done_testing;
86__END__
87
88vim: ts=2 sw=2 expandtab