make use_moose detection more robust
[catagits/Catalyst-Model-DBIC-Schema.git] / t / 07connect_info.t
index 0e0ed70..519a5ca 100644 (file)
@@ -11,6 +11,8 @@ use ASchemaClass;
 
 # execise the connect_info coercion
 
+my $coderef = sub {};
+
 my @tests = (
     ['dbi:SQLite:foo.db', '', ''],
     { dsn => 'dbi:SQLite:foo.db', user => '', password => '' },
@@ -38,6 +40,9 @@ my @tests = (
         pg_enable_utf8 => 1, auto_savepoint => 1 } ],
     { dsn => 'dbi:Pg:dbname=foo', user => 'user', password => 'pass',
         pg_enable_utf8 => 1, auto_savepoint => 1 },
+
+    [$coderef, { pg_enable_utf8 => 1, auto_savepoint => 1 }],
+    { dbh_maker => $coderef, pg_enable_utf8 => 1, auto_savepoint => 1 },
 );
 
 my @invalid = (
@@ -47,8 +52,6 @@ my @invalid = (
         { pg_enable_utf8 => 1 }, { AutoCommit => 1 }, { auto_savepoint => 1 }],
 );
 
-plan tests => @tests / 2 + @invalid + 1;
-
 # ignore redefined warnings, and uninitialized warnings from old
 # ::Storage::DBI::Replicated
 local $SIG{__WARN__} = sub {
@@ -84,10 +87,25 @@ my $m = TryConnectInfos->new(
     replicants   => \@replicants
 );
 
+lives_and {
+    is_deeply(TryConnectInfos->new(replicants => $tests[1])->replicants,
+        [ $tests[1] ])
+} 'single replicant hashref coerces correctly';
+
 is_deeply $m->replicants, [
     map $tests[$_], grep $_ % 2, 0 .. $#tests
 ], 'replicant connect_infos coerced correctly';
 
+{
+    ASchemaClass->connection( @{$tests[0]} );
+    my $m = instance();
+
+    is_deeply $m->connect_info, $tests[1],
+        'connect_info coerced correctly when defining connection in the schema class';
+}
+
+done_testing;
+
 sub instance {
     Catalyst::Model::DBIC::Schema->new({
         schema_class => 'ASchemaClass',