Convert the tests with multiple DBDs to new optdeps system
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10_09firebird_common.t
index 23c71e8..358c60a 100644 (file)
@@ -2,32 +2,38 @@ use strict;
 use warnings;
 use Test::More;
 use Scope::Guard ();
-use DBIx::Class::Optional::Dependencies;
+use DBIx::Class::Schema::Loader::Optional::Dependencies;
 use DBIx::Class::Schema::Loader::Utils qw/sigwarn_silencer/;
 use lib qw(t/lib);
 use dbixcsl_common_tests;
 
-my %dsns;
-for (qw(FIREBIRD FIREBIRD_ODBC FIREBIRD_INTERBASE)) {
-    next unless $ENV{"DBICTEST_${_}_DSN"};
+my %env2optdep = map { $_ => lc "test_rdbms_$_" } qw(FIREBIRD FIREBIRD_INTERBASE FIREBIRD_ODBC);
+
+plan skip_all => 'requirements not satisfied:  ' . (join '  OR  ', map
+    { "[ @{[ DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for( $_ ) ]} ]" }
+    values %env2optdep
+) unless scalar grep
+    { DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for( $_ ) }
+    values %env2optdep
+;
 
-    my $dep_group = lc "rdbms_$_";
-    if (!DBIx::Class::Optional::Dependencies->req_ok_for($dep_group)) {
-        diag 'You need to install ' . DBIx::Class::Optional::Dependencies->req_missing_for($dep_group)
-            . " to test with $_";
+my %dsns;
+for my $type (keys %env2optdep) {
+    my %conninfo;
+    @conninfo{qw(dsn user password)} = map { $ENV{"DBICTEST_${type}_$_"} } qw(DSN USER PASS);
+    next unless $conninfo{dsn};
+
+    my $dep_group = $env2optdep{$type};
+    if (!DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for($dep_group)) {
+        diag "Testing with DBICTEST_${type}_DSN needs " . DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for($dep_group);
         next;
     }
 
-    $dsns{$_}{dsn} = $ENV{"DBICTEST_${_}_DSN"};
-    $dsns{$_}{user} = $ENV{"DBICTEST_${_}_USER"};
-    $dsns{$_}{password} = $ENV{"DBICTEST_${_}_PASS"};
-    $dsns{$_}{connect_info_opts} = { on_connect_call => 'use_softcommit' }
-        if /\AFIREBIRD(?:_INTERBASE)\z/;
+    $dsns{$type} = \%conninfo;
+    $dsns{$type}{connect_info_opts} = { on_connect_call => 'use_softcommit' }
+        if $type =~ /\AFIREBIRD(?:_INTERBASE)?\z/;
 };
 
-plan skip_all => 'You need to set the DBICTEST_FIREBIRD_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_ODBC_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_INTERBASE_DSN, _USER and _PASS environment variables'
-    unless %dsns;
-
 my $schema;
 
 my $tester = dbixcsl_common_tests->new(
@@ -58,7 +64,7 @@ my $tester = dbixcsl_common_tests->new(
     null        => '',
     preserve_case_mode_is_exclusive => 1,
     quote_char                      => '"',
-    connect_info => [ values %dsns ],
+    connect_info => [ map { $dsns{$_} } sort keys %dsns ],
     data_types  => {
         # based on the Interbase Data Definition Guide
         # http://www.ibphoenix.com/downloads/60DataDef.zip
@@ -120,39 +126,46 @@ my $tester = dbixcsl_common_tests->new(
                       => { data_type => 'blob sub_type text character set unicode_fss' },
     },
     extra => {
-        count  => 9,
+        count  => 11,
+        create => [
+            q{
+                CREATE TABLE "Firebird_Loader_Test1" (
+                    "Id" INTEGER NOT NULL PRIMARY KEY,
+                    "Foo" INTEGER DEFAULT 42
+                )
+            },
+            q{
+                CREATE GENERATOR "Gen_Firebird_Loader_Test1_Id"
+            },
+            q{
+                CREATE TRIGGER "Firebird_Loader_Test1_BI" for "Firebird_Loader_Test1"
+                ACTIVE BEFORE INSERT POSITION 0
+                AS
+                BEGIN
+                 IF (NEW."Id" IS NULL) THEN
+                  NEW."Id" = GEN_ID("Gen_Firebird_Loader_Test1_Id",1);
+                END
+            },
+            q{
+                CREATE VIEW firebird_loader_test2 AS SELECT * FROM "Firebird_Loader_Test1"
+            },
+        ],
+        pre_drop_ddl => [
+            'DROP VIEW firebird_loader_test2',
+            'DROP TRIGGER "Firebird_Loader_Test1_BI"',
+            'DROP GENERATOR "Gen_Firebird_Loader_Test1_Id"',
+            'DROP TABLE "Firebird_Loader_Test1"',
+        ],
         run    => sub {
             $schema = shift;
             my ($monikers, $classes, $self) = @_;
 
-            cleanup_extra();
-
             my $dbh = $schema->storage->dbh;
 
 # create a mixed case table
             $dbh->do($_) for (
-q{
-    CREATE TABLE "Firebird_Loader_Test1" (
-        "Id" INTEGER NOT NULL PRIMARY KEY,
-        "Foo" INTEGER DEFAULT 42
-    )
-},
-q{
-    CREATE GENERATOR "Gen_Firebird_Loader_Test1_Id"
-},
-q{
-    CREATE TRIGGER "Firebird_Loader_Test1_BI" for "Firebird_Loader_Test1"
-    ACTIVE BEFORE INSERT POSITION 0
-    AS
-    BEGIN
-     IF (NEW."Id" IS NULL) THEN
-      NEW."Id" = GEN_ID("Gen_Firebird_Loader_Test1_Id",1);
-    END
-},
             );
 
-            my $guard = Scope::Guard->new(\&cleanup_extra);
-
             local $schema->loader->{preserve_case} = 1;
             $schema->loader->_setup;
 
@@ -172,6 +185,15 @@ q{
 
             is eval { $rsrc->column_info('Foo')->{default_value} }, 42, 'default_value detected for mixed case column';
 
+            # test that views are marked as such
+            my $view_source = $schema->resultset($monikers->{firebird_loader_test2})->result_source;
+            isa_ok $view_source, 'DBIx::Class::ResultSource::View',
+                'view result source';
+
+            like $view_source->view_definition,
+                qr/\A \s* select\b .* \bfrom \s+ (?-i:"Firebird_Loader_Test1") \s* \z/imsx,
+                'view definition';
+
             # test the fixed up ->_dbh_type_info_type_name for the ODBC driver
             if ($schema->storage->_dbi_connect_info->[0] =~ /:ODBC:/i) {
                 my %truncated_types = (
@@ -207,16 +229,4 @@ q{
     $tester->run_tests();
 }
 
-sub cleanup_extra {
-    $schema->storage->disconnect;
-    my $dbh = $schema->storage->dbh;
-
-    foreach my $stmt (
-        'DROP TRIGGER "Firebird_Loader_Test1_BI"',
-        'DROP GENERATOR "Gen_Firebird_Loader_Test1_Id"',
-        'DROP TABLE "Firebird_Loader_Test1"',
-    ) {
-        eval { $dbh->do($stmt) };
-    }
-}
 # vim:et sts=4 sw=4 tw=0: