From: Peter Rabbitson Date: Mon, 21 Jul 2014 21:45:50 +0000 (+0200) Subject: Rebase Oracle datetime inflation test on top of DBICTest::Schema::Event X-Git-Tag: v0.082800~124 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=12b348d9;p=dbsrgits%2FDBIx-Class.git 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 --- diff --git a/t/inflate/datetime_oracle.t b/t/inflate/datetime_oracle.t index 26a5357..9182f23 100644 --- a/t/inflate/datetime_oracle.t +++ b/t/inflate/datetime_oracle.t @@ -14,7 +14,7 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/}; if (not ($dsn && $user && $pass)) { plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' . - 'Warning: This test drops and creates a table called \'track\''; + 'Warning: This test drops and creates a table called \'event\''; } # DateTime::Format::Oracle needs this set @@ -32,21 +32,25 @@ my $timestamp_datatype = ($schema->storage->_server_info->{normalized_dbms_versi : 'TIMESTAMP' ; -# Need to redefine the last_updated_on column -my $col_metadata = $schema->class('Track')->column_info('last_updated_on'); -$schema->class('Track')->add_column( 'last_updated_on' => { - data_type => 'date' }); -$schema->class('Track')->add_column( 'last_updated_at' => { - data_type => $timestamp_datatype }); - my $dbh = $schema->storage->dbh; #$dbh->do("alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SSXFF'"); eval { - $dbh->do("DROP TABLE track"); + $dbh->do("DROP TABLE event"); }; -$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)"); +$dbh->do(<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' }); -is($new->trackid, 1, "insert sucessful"); +my $new = $schema->resultset('Event')->create({ id => 1, starts_at => '06-MAY-07', created_on => '2009-05-03 21:17:18.5' }); +is($new->id, 1, "insert sucessful"); -my $track = $schema->resultset('Track')->find( 1 ); +my $event = $schema->resultset('Event')->find( 1 ); -is( ref($track->last_updated_on), 'DateTime', "last_updated_on inflated ok"); +is( ref($event->starts_at), 'DateTime', "starts_at inflated ok"); -is( $track->last_updated_on->month, 5, "DateTime methods work on inflated column"); +is( $event->starts_at->month, 5, "DateTime methods work on inflated column"); -#note '$track->last_updated_at => ', $track->last_updated_at; -is( ref($track->last_updated_at), 'DateTime', "last_updated_at inflated ok"); +is( ref($event->created_on), 'DateTime', "created_on inflated ok"); -is( $track->last_updated_at->nanosecond, 500_000_000, "DateTime methods work with nanosecond precision"); +is( $event->created_on->nanosecond, 500_000_000, "DateTime methods work with nanosecond precision"); my $dt = DateTime->now(); -$track->last_updated_on($dt); -$track->last_updated_at($dt); -$track->update; +$event->starts_at($dt); +$event->created_on($dt); +$event->update; -is( $track->last_updated_on->month, $dt->month, "deflate ok"); -is( int $track->last_updated_at->nanosecond, int $dt->nanosecond, "deflate ok with nanosecond precision"); +is( $event->starts_at->month, $dt->month, "deflate ok"); +is( int $event->created_on->nanosecond, int $dt->nanosecond, "deflate ok with nanosecond precision"); # test datetime_setup @@ -93,15 +96,15 @@ $dt = DateTime->now(); my $timestamp = $dt->clone; $timestamp->set_nanosecond( int 500_000_000 ); -$track = $schema->resultset('Track')->find( 1 ); -$track->update({ last_updated_on => $dt, last_updated_at => $timestamp }); +$event = $schema->resultset('Event')->find( 1 ); +$event->update({ starts_at => $dt, created_on => $timestamp }); -$track = $schema->resultset('Track')->find(1); +$event = $schema->resultset('Event')->find(1); -is( $track->last_updated_on, $dt, 'DateTime round-trip as DATE' ); -is( $track->last_updated_at, $timestamp, 'DateTime round-trip as TIMESTAMP' ); +is( $event->starts_at, $dt, 'DateTime round-trip as DATE' ); +is( $event->created_on, $timestamp, 'DateTime round-trip as TIMESTAMP' ); -is( int $track->last_updated_at->nanosecond, int 500_000_000, +is( int $event->created_on->nanosecond, int 500_000_000, 'TIMESTAMP nanoseconds survived' ); } 'dateteime operations executed correctly'; @@ -111,7 +114,7 @@ done_testing; # clean up our mess END { if($schema && (my $dbh = $schema->storage->dbh)) { - $dbh->do("DROP TABLE track"); + $dbh->do("DROP TABLE event"); } undef $schema; }