Skip to content

Commit 12b348d

Browse files
committed
Rebase Oracle datetime inflation test on top of DBICTest::Schema::Event
The butchering of Track made sense in 2007, not so much today The test seems to behave identically, hope I didn't fuck up anything... https://travis-ci.org/dbsrgits/dbix-class/builds/30513847#L398
1 parent 8d73fcd commit 12b348d

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

t/inflate/datetime_oracle.t

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
1414

1515
if (not ($dsn && $user && $pass)) {
1616
plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' .
17-
'Warning: This test drops and creates a table called \'track\'';
17+
'Warning: This test drops and creates a table called \'event\'';
1818
}
1919

2020
# DateTime::Format::Oracle needs this set
@@ -32,21 +32,25 @@ my $timestamp_datatype = ($schema->storage->_server_info->{normalized_dbms_versi
3232
: 'TIMESTAMP'
3333
;
3434

35-
# Need to redefine the last_updated_on column
36-
my $col_metadata = $schema->class('Track')->column_info('last_updated_on');
37-
$schema->class('Track')->add_column( 'last_updated_on' => {
38-
data_type => 'date' });
39-
$schema->class('Track')->add_column( 'last_updated_at' => {
40-
data_type => $timestamp_datatype });
41-
4235
my $dbh = $schema->storage->dbh;
4336

4437
#$dbh->do("alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SSXFF'");
4538

4639
eval {
47-
$dbh->do("DROP TABLE track");
40+
$dbh->do("DROP TABLE event");
4841
};
49-
$dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255), last_updated_on DATE, last_updated_at $timestamp_datatype)");
42+
$dbh->do(<<EOS);
43+
CREATE TABLE event (
44+
id number NOT NULL,
45+
starts_at date NOT NULL,
46+
created_on $timestamp_datatype NOT NULL,
47+
varchar_date varchar(20),
48+
varchar_datetime varchar(20),
49+
skip_inflation date,
50+
ts_without_tz date,
51+
PRIMARY KEY (id)
52+
)
53+
EOS
5054

5155
# TODO is in effect for the rest of the tests
5256
local $TODO = 'FIXME - something odd is going on with Oracle < 9 datetime support'
@@ -55,27 +59,26 @@ local $TODO = 'FIXME - something odd is going on with Oracle < 9 datetime suppor
5559
lives_ok {
5660

5761
# insert a row to play with
58-
my $new = $schema->resultset('Track')->create({ trackid => 1, cd => 1, position => 1, title => 'Track1', last_updated_on => '06-MAY-07', last_updated_at => '2009-05-03 21:17:18.5' });
59-
is($new->trackid, 1, "insert sucessful");
62+
my $new = $schema->resultset('Event')->create({ id => 1, starts_at => '06-MAY-07', created_on => '2009-05-03 21:17:18.5' });
63+
is($new->id, 1, "insert sucessful");
6064

61-
my $track = $schema->resultset('Track')->find( 1 );
65+
my $event = $schema->resultset('Event')->find( 1 );
6266

63-
is( ref($track->last_updated_on), 'DateTime', "last_updated_on inflated ok");
67+
is( ref($event->starts_at), 'DateTime', "starts_at inflated ok");
6468

65-
is( $track->last_updated_on->month, 5, "DateTime methods work on inflated column");
69+
is( $event->starts_at->month, 5, "DateTime methods work on inflated column");
6670

67-
#note '$track->last_updated_at => ', $track->last_updated_at;
68-
is( ref($track->last_updated_at), 'DateTime', "last_updated_at inflated ok");
71+
is( ref($event->created_on), 'DateTime', "created_on inflated ok");
6972

70-
is( $track->last_updated_at->nanosecond, 500_000_000, "DateTime methods work with nanosecond precision");
73+
is( $event->created_on->nanosecond, 500_000_000, "DateTime methods work with nanosecond precision");
7174

7275
my $dt = DateTime->now();
73-
$track->last_updated_on($dt);
74-
$track->last_updated_at($dt);
75-
$track->update;
76+
$event->starts_at($dt);
77+
$event->created_on($dt);
78+
$event->update;
7679

77-
is( $track->last_updated_on->month, $dt->month, "deflate ok");
78-
is( int $track->last_updated_at->nanosecond, int $dt->nanosecond, "deflate ok with nanosecond precision");
80+
is( $event->starts_at->month, $dt->month, "deflate ok");
81+
is( int $event->created_on->nanosecond, int $dt->nanosecond, "deflate ok with nanosecond precision");
7982

8083
# test datetime_setup
8184

@@ -93,15 +96,15 @@ $dt = DateTime->now();
9396
my $timestamp = $dt->clone;
9497
$timestamp->set_nanosecond( int 500_000_000 );
9598

96-
$track = $schema->resultset('Track')->find( 1 );
97-
$track->update({ last_updated_on => $dt, last_updated_at => $timestamp });
99+
$event = $schema->resultset('Event')->find( 1 );
100+
$event->update({ starts_at => $dt, created_on => $timestamp });
98101

99-
$track = $schema->resultset('Track')->find(1);
102+
$event = $schema->resultset('Event')->find(1);
100103

101-
is( $track->last_updated_on, $dt, 'DateTime round-trip as DATE' );
102-
is( $track->last_updated_at, $timestamp, 'DateTime round-trip as TIMESTAMP' );
104+
is( $event->starts_at, $dt, 'DateTime round-trip as DATE' );
105+
is( $event->created_on, $timestamp, 'DateTime round-trip as TIMESTAMP' );
103106

104-
is( int $track->last_updated_at->nanosecond, int 500_000_000,
107+
is( int $event->created_on->nanosecond, int 500_000_000,
105108
'TIMESTAMP nanoseconds survived' );
106109

107110
} 'dateteime operations executed correctly';
@@ -111,7 +114,7 @@ done_testing;
111114
# clean up our mess
112115
END {
113116
if($schema && (my $dbh = $schema->storage->dbh)) {
114-
$dbh->do("DROP TABLE track");
117+
$dbh->do("DROP TABLE event");
115118
}
116119
undef $schema;
117120
}

0 commit comments

Comments
 (0)