Test with more perl versions
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10_05ora_common.t
index 463c968..2cb7480 100644 (file)
@@ -2,6 +2,7 @@ use strict;
 use warnings;
 use Test::More;
 use Test::Exception;
+use DBIx::Class::Optional::Dependencies;
 use DBIx::Class::Schema::Loader 'make_schema_at';
 use DBIx::Class::Schema::Loader::Utils qw/slurp_file split_name/;
 use Try::Tiny;
@@ -25,7 +26,7 @@ my $auto_inc_cb = sub {
     my ($table, $col) = @_;
     return (
         qq{ CREATE SEQUENCE ${table}_${col}_seq START WITH 1 INCREMENT BY 1},
-        qq{ 
+        qq{
             CREATE OR REPLACE TRIGGER ${table}_${col}_trigger
             BEFORE INSERT ON ${table}
             FOR EACH ROW
@@ -45,9 +46,12 @@ my $tester = dbixcsl_common_tests->new(
     vendor      => 'Oracle',
     auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY',
     auto_inc_cb => $auto_inc_cb,
-    auto_inc_drop_cb => $auto_inc_drop_cb, 
+    auto_inc_drop_cb => $auto_inc_drop_cb,
     preserve_case_mode_is_exclusive => 1,
     quote_char                      => '"',
+    default_is_deferrable => 0,
+    default_on_delete_clause => 'NO ACTION',
+    default_on_update_clause => 'NO ACTION',
     dsn         => $dsn,
     user        => $user,
     password    => $password,
@@ -81,6 +85,12 @@ my $tester = dbixcsl_common_tests->new(
         'int'          => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
         'smallint'     => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
 
+        # very long DEFAULT throws an ORA-24345
+        "number(15) DEFAULT to_number(decode(substrb(userenv('CLIENT_INFO'),1,1),' ',null,substrb(userenv('CLIENT_INFO'),1,10)))" => {
+            data_type => 'numeric', size => [15,0], original => { data_type => 'number' },
+            default_value => \"to_number(decode(substrb(userenv('CLIENT_INFO'),1,1),' ',null,substrb(userenv('CLIENT_INFO'),1,10)))"
+        },
+
         'decimal'      => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
         'dec'          => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
         'numeric'      => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
@@ -149,7 +159,7 @@ my $tester = dbixcsl_common_tests->new(
     },
     extra => {
         create => [
-            q{ 
+            q{
                 CREATE TABLE oracle_loader_test1 (
                     id NUMBER(11),
                     value VARCHAR2(100)
@@ -157,9 +167,23 @@ my $tester = dbixcsl_common_tests->new(
             },
             q{ COMMENT ON TABLE oracle_loader_test1 IS 'oracle_loader_test1 table comment' },
             q{ COMMENT ON COLUMN oracle_loader_test1.value IS 'oracle_loader_test1.value column comment' },
+            # 4 through 8 are used for the multi-schema tests
+            q{
+                create table oracle_loader_test9 (
+                    id int primary key
+                )
+            },
+            q{
+                create table oracle_loader_test10 (
+                    id int primary key,
+                    nine_id int,
+                    foreign key (nine_id) references oracle_loader_test9(id)
+                        on delete set null deferrable
+                )
+            },
         ],
-        drop  => [qw/oracle_loader_test1/],
-        count => 3 + 30 * 2,
+        drop  => [qw/oracle_loader_test1 oracle_loader_test9 oracle_loader_test10/],
+        count => 7 + 31 * 2,
         run   => sub {
             my ($monikers, $classes);
             ($schema, $monikers, $classes) = @_;
@@ -186,8 +210,21 @@ my $tester = dbixcsl_common_tests->new(
             like $code, qr/^=head2 value\n\n(.+:.+\n)+\noracle_loader_test1\.value column comment\n\n/m,
                 'column comment and attrs';
 
+            # test on delete/update fk clause introspection
+            ok ((my $rel_info = $schema->source('OracleLoaderTest10')->relationship_info('nine')),
+                'got rel info');
+
+            is $rel_info->{attrs}{on_delete}, 'SET NULL',
+                'ON DELETE clause introspected correctly';
+
+            is $rel_info->{attrs}{on_update}, 'NO ACTION',
+                'ON UPDATE clause set to NO ACTION by default';
+
+            is $rel_info->{attrs}{is_deferrable}, 1,
+                'DEFERRABLE clause introspected correctly';
+
             SKIP: {
-                skip 'Set the DBICTEST_ORA_EXTRAUSER_DSN, _USER and _PASS environment variables to run the cross-schema relationship tests', 6 * 2
+                skip 'Set the DBICTEST_ORA_EXTRAUSER_DSN, _USER and _PASS environment variables to run the cross-schema relationship tests', 31 * 2
                     unless $ENV{DBICTEST_ORA_EXTRAUSER_DSN};
 
                 $extra_schema = $schema->clone;
@@ -208,7 +245,7 @@ my $tester = dbixcsl_common_tests->new(
                     )
 EOF
 
-                $dbh1->do($_) for $auto_inc_cb->('oracle_loader_test4', 'id');
+                $dbh1->do($_) for $auto_inc_cb->(lc "${schema1}.oracle_loader_test4", 'id');
 
                 $dbh1->do("GRANT ALL ON oracle_loader_test4 TO $schema2");
                 $dbh1->do("GRANT ALL ON oracle_loader_test4_id_seq TO $schema2");
@@ -276,12 +313,8 @@ EOF
                 my $schema2_moniker = join '', map ucfirst lc, split_name to_identifier $schema2;
 
                 my %monikers;
-                $monikers{'1.4'} = $schema1_moniker . 'OracleLoaderTest4';
                 $monikers{'1.5'} = $schema1_moniker . 'OracleLoaderTest5';
                 $monikers{'2.5'} = $schema2_moniker . 'OracleLoaderTest5';
-                $monikers{'2.6'} = $schema2_moniker . 'OracleLoaderTest6';
-                $monikers{'2.7'} = $schema2_moniker . 'OracleLoaderTest7';
-                $monikers{'1.8'} = $schema1_moniker . 'OracleLoaderTest8';
 
                 foreach my $db_schema ([$schema1, $schema2], '%') {
                     lives_and {
@@ -297,7 +330,6 @@ EOF
                             {
                                 naming => 'current',
                                 db_schema => $db_schema,
-                                moniker_parts => [qw/schema name/],
                                 dump_directory => EXTRA_DUMP_DIR,
                                 quiet => 1,
                             },
@@ -316,12 +348,15 @@ EOF
                     } 'connected test schema';
 
                     lives_and {
-                        ok $rsrc = $test_schema->source($monikers{'1.4'});
+                        ok $rsrc = $test_schema->source('OracleLoaderTest4');
                     } 'got source for table in schema1';
 
                     is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
                         'column in schema1';
 
+                    is try { $rsrc->column_info('id')->{sequence} }, lc "${schema1}.oracle_loader_test4_id_seq",
+                        'sequence in schema1';
+
                     is try { $rsrc->column_info('value')->{data_type} }, 'varchar2',
                         'column in schema1';
 
@@ -329,7 +364,7 @@ EOF
                         'column in schema1';
 
                     lives_and {
-                        ok $rs = $test_schema->resultset($monikers{'1.4'});
+                        ok $rs = $test_schema->resultset('OracleLoaderTest4');
                     } 'got resultset for table in schema1';
 
                     lives_and {
@@ -367,7 +402,7 @@ EOF
                         'correct unique constraint in schema1');
 
                     lives_and {
-                        ok $rsrc = $test_schema->source($monikers{'2.6'});
+                        ok $rsrc = $test_schema->source('OracleLoaderTest6');
                     } 'got source for table in schema2';
 
                     is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
@@ -380,7 +415,7 @@ EOF
                         'column in schema2 introspected correctly';
 
                     lives_and {
-                        ok $rs = $test_schema->resultset($monikers{'2.6'});
+                        ok $rs = $test_schema->resultset('OracleLoaderTest6');
                     } 'got resultset for table in schema2';
 
                     lives_and {
@@ -400,7 +435,7 @@ EOF
                         'relationship in schema2';
 
                     lives_and {
-                        ok $rsrc = $test_schema->source($monikers{'2.7'});
+                        ok $rsrc = $test_schema->source('OracleLoaderTest7');
                     } 'got source for table in schema2';
 
                     %uniqs = try { $rsrc->unique_constraints };
@@ -414,22 +449,22 @@ EOF
                         'correct unique constraint in schema2');
 
                     lives_and {
-                        ok $test_schema->source($monikers{'2.6'})
+                        ok $test_schema->source('OracleLoaderTest6')
                             ->has_relationship('oracle_loader_test4');
                     } 'cross-schema relationship in multi-db_schema';
 
                     lives_and {
-                        ok $test_schema->source($monikers{'1.4'})
+                        ok $test_schema->source('OracleLoaderTest4')
                             ->has_relationship('oracle_loader_test6s');
                     } 'cross-schema relationship in multi-db_schema';
 
                     lives_and {
-                        ok $test_schema->source($monikers{'1.8'})
+                        ok $test_schema->source('OracleLoaderTest8')
                             ->has_relationship('oracle_loader_test7');
                     } 'cross-schema relationship in multi-db_schema';
 
                     lives_and {
-                        ok $test_schema->source($monikers{'2.7'})
+                        ok $test_schema->source('OracleLoaderTest7')
                             ->has_relationship('oracle_loader_test8s');
                     } 'cross-schema relationship in multi-db_schema';
                 }
@@ -441,6 +476,9 @@ EOF
 if( !$dsn || !$user ) {
     $tester->skip_tests('You need to set the DBICTEST_ORA_DSN, _USER, and _PASS environment variables');
 }
+elsif (!DBIx::Class::Optional::Dependencies->req_ok_for ('rdbms_oracle')) {
+    $tester->skip_tests('You need to install ' . DBIx::Class::Optional::Dependencies->req_missing_for ('rdbms_oracle'));
+}
 else {
     $tester->run_tests();
 }