Add test for custom_column_info callback
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 14ora_common.t
1 use strict;
2 use lib qw(t/lib);
3 use dbixcsl_common_tests;
4 use Test::More;
5 use Test::Exception;
6
7 my $dsn      = $ENV{DBICTEST_ORA_DSN} || '';
8 my $user     = $ENV{DBICTEST_ORA_USER} || '';
9 my $password = $ENV{DBICTEST_ORA_PASS} || '';
10
11 sub _custom_column_info {
12     my $info = shift;
13
14     if ( $info->{TYPE_NAME} eq 'DATE' ){
15         return { timezone => "Europe/Berlin" };
16     }
17     return;
18 }
19
20 my $tester = dbixcsl_common_tests->new(
21     vendor      => 'Oracle',
22     custom_column_info => \&_custom_column_info,
23     auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY',
24     auto_inc_cb => sub {
25         my ($table, $col) = @_;
26         return (
27             qq{ CREATE SEQUENCE ${table}_${col}_seq START WITH 1 INCREMENT BY 1},
28             qq{ 
29                 CREATE OR REPLACE TRIGGER ${table}_${col}_trigger
30                 BEFORE INSERT ON ${table}
31                 FOR EACH ROW
32                 BEGIN
33                     SELECT ${table}_${col}_seq.nextval INTO :NEW.${col} FROM dual;
34                 END;
35             }
36         );
37     },
38     auto_inc_drop_cb => sub {
39         my ($table, $col) = @_;
40         return qq{ DROP SEQUENCE ${table}_${col}_seq };
41     },
42     dsn         => $dsn,
43     user        => $user,
44     password    => $password,
45     extra => {
46         create => [qq{
47             CREATE TABLE oracle_loader_test1 (
48                 id number(5) NOT NULL,
49                 name varchar2(100) NOT NULL,
50                 create_date date NOT NULL,
51                 modification_date date,
52                 PRIMARY KEY (id)
53             )
54         },],
55         drop  => [qw/ oracle_loader_test1 /],
56         count => 2,
57         run   => sub {
58             my ( $schema, $monikers, $classes ) = @_;
59             my $rs = $schema->resultset( $monikers->{oracle_loader_test1} );
60
61             is $rs->result_source->column_info('create_date')->{timezone},
62                 'Europe/Berlin',
63                 'create_date hast timezone';
64
65             is $rs->result_source->column_info('modification_date')->{timezone},
66                 'Europe/Berlin',
67                 'modification_date hast timezone';
68
69         },
70       }
71
72 );
73
74 if( !$dsn || !$user ) {
75     $tester->skip_tests('You need to set the DBICTEST_ORA_DSN, _USER, and _PASS environment variables');
76 }
77 else {
78     $tester->run_tests();
79 }