6 use Test::More tests => 19;
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 dt ) ], [ 1, ( $epoch ) x 4, $now ] ] );
21 my $row = $rs->find( 1 );
23 isa_ok( $row->bar, 'DateTime' );
24 isa_ok( $row->baz, 'DateTime' );
25 isa_ok( $row->dt, 'DateTime' );
26 ok( $row->bar == $now, 'inflate: epoch as int' );
27 ok( $row->baz == $now, 'inflate: epoch as varchar' );
28 ok( $row->dt == $now, 'inflate: regular datetime column' );
32 $rs->create( { bar => $now, baz => $now, dt => $now } );
33 my $row = $rs->find( 2 );
35 isa_ok( $row->bar, 'DateTime' );
36 isa_ok( $row->baz, 'DateTime' );
37 isa_ok( $row->dt, 'DateTime' );
38 is( $row->get_column( 'bar' ), $epoch, 'deflate: epoch as int' );
39 is( $row->get_column( 'baz' ), $epoch, 'deflate: epoch as varchar' );
40 is( $row->get_column( 'dt' ), join( ' ', $now->ymd, $now->hms ), 'deflate: regular datetime column' );
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' );
48 my $mtime = $row->modification_time;
50 $row->update( { name => 'test' } );
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' );