v0.001006
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / version_handlers / explict_versions.t
index c6d0d98..07ad3dd 100644 (file)
@@ -1,5 +1,8 @@
 #!perl
 
+use strict;
+use warnings;
+
 use Test::More;
 use Test::Exception;
 
@@ -73,13 +76,42 @@ my $versions = [map "$_.0", 0..100];
   ok( !$vh->next_version_set, 'still no more versions after final pair' );
 }
 
+{
+  my $vh = ExplicitVersions->new({
+    ordered_versions => $versions,
+    to_version => '1.0',
+    schema_version => '5.0',
+    database_version => '5.0',
+  });
+
+  ok $vh, 'VersionHandler gets instantiated';
+  ok(
+    eq_array($vh->previous_version_set, [qw( 5.0 4.0 )]),
+    'first version pair works'
+  );
+  ok(
+    eq_array($vh->previous_version_set, [qw( 4.0 3.0 )]),
+    'second version pair works'
+  );
+  ok(
+    eq_array($vh->previous_version_set, [qw( 3.0 2.0 )]),
+    'third version pair works'
+  );
+  ok(
+    eq_array($vh->previous_version_set, [qw( 2.0 1.0 )]),
+    'fourth version pair works'
+  );
+  ok( !$vh->previous_version_set, 'no more versions after final pair' );
+  ok( !$vh->previous_version_set, 'still no more versions after final pair' );
+}
+
 dies_ok {
   my $vh = ExplicitVersions->new({
     ordered_versions => $versions,
-    schema_version => '1.0',
+    schema_version => '2.0',
     database_version => '1.1',
   });
-  $vh->next_vesion_set
+  $vh->next_version_set
 } 'dies if database version not found in ordered_versions';
 
 dies_ok {
@@ -89,7 +121,18 @@ dies_ok {
     schema_version => '1.0',
     database_version => '1.0',
   });
-} 'cannot request a version before the current version';
+  $vh->next_version_set;
+} 'cannot request an upgrade before the current version';
+
+dies_ok {
+  my $vh = ExplicitVersions->new({
+    ordered_versions => $versions,
+    to_version => '2.0',
+    schema_version => '1.0',
+    database_version => '1.0',
+  });
+  $vh->previous_version_set;
+} 'cannot request a downgrade after the current version';
 
 done_testing;
 #vim: ts=2 sw=2 expandtab