slightly different testing strategy
[dbsrgits/DBIx-Class-DateTime-Epoch.git] / t / 02-schema.t
CommitLineData
8e52f1da 1use strict;
2use warnings;
3
4use lib 't/lib';
5
3be80851 6use Test::More tests => 19;
8e52f1da 7
8use DBICx::TestDatabase;
9use DateTime;
10my $schema = DBICx::TestDatabase->new( 'MySchema' );
11
12my $rs = $schema->resultset( 'Foo' );
13
14{
15 my $now = DateTime->now;
16 my $epoch = $now->epoch;
17
3be80851 18 $schema->populate( 'Foo', [ [ qw( id bar baz creation_time modification_time dt ) ], [ 1, ( $epoch ) x 4, $now ] ] );
8e52f1da 19
20 {
21 my $row = $rs->find( 1 );
22
23 isa_ok( $row->bar, 'DateTime' );
24 isa_ok( $row->baz, 'DateTime' );
3be80851 25 isa_ok( $row->dt, 'DateTime' );
8e52f1da 26 ok( $row->bar == $now, 'inflate: epoch as int' );
27 ok( $row->baz == $now, 'inflate: epoch as varchar' );
3be80851 28 ok( $row->dt == $now, 'inflate: regular datetime column' );
8e52f1da 29 }
30
31 {
3be80851 32 $rs->create( { bar => $now, baz => $now, dt => $now } );
8e52f1da 33 my $row = $rs->find( 2 );
34
35 isa_ok( $row->bar, 'DateTime' );
36 isa_ok( $row->baz, 'DateTime' );
3be80851 37 isa_ok( $row->dt, 'DateTime' );
8e52f1da 38 is( $row->get_column( 'bar' ), $epoch, 'deflate: epoch as int' );
39 is( $row->get_column( 'baz' ), $epoch, 'deflate: epoch as varchar' );
3be80851 40 is( $row->get_column( 'dt' ), join( ' ', $now->ymd, $now->hms ), 'deflate: regular datetime column' );
8e52f1da 41
42 # courtesy of TimeStamp
43 isa_ok( $row->creation_time, 'DateTime' ); # courtesy of TimeStamp
44 isa_ok( $row->modification_time, 'DateTime' );
45 like( $row->get_column( 'creation_time' ), qr/^\d+$/, 'TimeStamp as epoch' );
46 like( $row->get_column( 'modification_time' ), qr/^\d+$/, 'TimeStamp as epoch' );
47
48 my $mtime = $row->modification_time;
49 sleep( 1 );
50 $row->update( { name => 'test' } );
51
52 $row = $rs->find( 2 );
53 isa_ok( $row->modification_time, 'DateTime' );
54 like( $row->get_column( 'modification_time' ), qr/^\d+$/, 'TimeStamp as epoch' );
55 ok( $row->modification_time > $mtime, 'mtime column was updated' );
56 }
57}