preinstall may no longer connect to the database
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / 04-preconnect.t
diff --git a/t/04-preconnect.t b/t/04-preconnect.t
new file mode 100644 (file)
index 0000000..6260194
--- /dev/null
@@ -0,0 +1,40 @@
+#!perl
+
+use strict;
+use warnings;
+
+use lib 't/lib';
+use DBICDHTest;
+use DBIx::Class::DeploymentHandler;
+use aliased 'DBIx::Class::DeploymentHandler', 'DH';
+
+use File::Path qw(remove_tree mkpath);
+use Test::More;
+use Test::Exception;
+
+DBICDHTest::ready;
+
+my $db = 'dbi:SQLite:db.db';
+my @connection = ($db, '', '', { ignore_version => 1, }, { on_connect_do => sub { die }});
+my $sql_dir = 't/sql';
+
+VERSION1: {
+  use_ok 'DBICVersion_v1';
+  my $s = DBICVersion::Schema->connect(@connection);
+  $DBICVersion::Schema::VERSION = 1;
+  ok($s, 'DBICVersion::Schema 1 instantiates correctly');
+  ok !$s->storage->connected, 'creating schema did not connect';
+  my $handler = DH->new({
+    upgrade_directory => $sql_dir,
+    schema => $s,
+    databases => 'SQLite',
+    sql_translator_args => { add_drop_table => 0 },
+  });
+  ok !$s->storage->connected, 'creating handler did not connect';
+  ok($handler, 'DBIx::Class::DeploymentHandler w/1 instantiates correctly');
+
+  mkpath('t/sql/SQLite/preinstall/1');
+  $handler->preinstall({ version => 1, storage_type => 'SQLite' });
+  ok !$s->storage->connected, 'creating schema did not connect';
+}
+done_testing;