Commit | Line | Data |
29f37a29 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use lib 't/lib'; |
5 | |
6 | use Test::More tests => 15; |
7 | |
8 | use DBICx::TestDatabase; |
9 | use DateTime; |
10 | my $schema = DBICx::TestDatabase->new( 'MySchema' ); |
11 | |
12 | my $rs = $schema->resultset( 'FooCompat' ); |
13 | |
14 | { |
15 | my $now = DateTime->now; |
16 | my $epoch = $now->epoch; |
17 | |
18 | $schema->populate( 'FooCompat', [ [ qw( id bar baz creation_time modification_time ) ], [ 1, ( $epoch ) x 4 ] ] ); |
19 | |
20 | { |
21 | my $row = $rs->find( 1 ); |
22 | |
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' ); |
27 | } |
28 | |
29 | { |
30 | $rs->create( { bar => $now, baz => $now } ); |
31 | my $row = $rs->find( 2 ); |
32 | |
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' ); |
37 | |
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 | |
44 | my $mtime = $row->modification_time; |
45 | sleep( 1 ); |
46 | $row->update( { name => 'test' } ); |
47 | |
48 | $row = $rs->find( 2 ); |
49 | isa_ok( $row->modification_time, 'DateTime' ); |
50 | like( $row->get_column( 'modification_time' ), qr/^\d+$/, 'TimeStamp as epoch' ); |
51 | ok( $row->modification_time > $mtime, 'mtime column was updated' ); |
52 | } |
53 | } |