6 use Test::More tests => 16;
8 use DBICx::TestDatabase;
10 my $schema = DBICx::TestDatabase->new( 'MySchema' );
12 my $rs = $schema->resultset( 'Foo' );
15 my $now = DateTime->now;
16 my $epoch = $now->epoch;
18 $schema->populate( 'Foo', [ [ qw( id bar baz creation_time modification_time ) ], [ 1, ( $epoch ) x 4 ] ] );
21 my $row = $rs->find( 1 );
23 isa_ok( $row->bar, 'DateTime' );
24 isa_ok( $row->baz, 'DateTime' );
25 ok( $row->bar == $now, 'inflate: epoch as int' );
26 ok( $row->baz == $now, 'inflate: epoch as varchar' );
30 $rs->create( { bar => $now, baz => $now } );
31 my $row = $rs->find( 2 );
33 isa_ok( $row->bar, 'DateTime' );
34 isa_ok( $row->baz, 'DateTime' );
35 is( $row->get_column( 'bar' ), $epoch, 'deflate: epoch as int' );
36 is( $row->get_column( 'baz' ), $epoch, 'deflate: epoch as varchar' );
38 # courtesy of TimeStamp
39 isa_ok( $row->creation_time, 'DateTime' ); # courtesy of TimeStamp
40 isa_ok( $row->modification_time, 'DateTime' );
41 like( $row->get_column( 'creation_time' ), qr/^\d+$/, 'TimeStamp as epoch' );
42 like( $row->get_column( 'modification_time' ), qr/^\d+$/, 'TimeStamp as epoch' );
43 like( $row->get_column( 'update_time' ), qr/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}$/, 'TimeStamp still Timestamp' );
45 my $mtime = $row->modification_time;
47 $row->update( { name => 'test' } );
49 $row = $rs->find( 2 );
50 isa_ok( $row->modification_time, 'DateTime' );
51 like( $row->get_column( 'modification_time' ), qr/^\d+$/, 'TimeStamp as epoch' );
52 ok( $row->modification_time > $mtime, 'mtime column was updated' );