Add test for custom_column_info callback
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 14ora_common.t
CommitLineData
e7262300 1use strict;
2use lib qw(t/lib);
3use dbixcsl_common_tests;
6b0e47fc 4use Test::More;
5use Test::Exception;
e7262300 6
7my $dsn = $ENV{DBICTEST_ORA_DSN} || '';
8my $user = $ENV{DBICTEST_ORA_USER} || '';
9my $password = $ENV{DBICTEST_ORA_PASS} || '';
10
457e71af 11sub _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
e7262300 20my $tester = dbixcsl_common_tests->new(
21 vendor => 'Oracle',
457e71af 22 custom_column_info => \&_custom_column_info,
c1ac681d 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 },
e7262300 42 dsn => $dsn,
43 user => $user,
44 password => $password,
457e71af 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
e7262300 72);
73
74if( !$dsn || !$user ) {
75 $tester->skip_tests('You need to set the DBICTEST_ORA_DSN, _USER, and _PASS environment variables');
76}
77else {
78 $tester->run_tests();
79}