Commit | Line | Data |
8e52f1da |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use lib 't/lib'; |
5 | |
7ec868bf |
6 | use Test::More tests => 16; |
8e52f1da |
7 | |
8 | use DBICx::TestDatabase; |
9 | use DateTime; |
10 | my $schema = DBICx::TestDatabase->new( 'MySchema' ); |
11 | |
12 | my $rs = $schema->resultset( 'Foo' ); |
13 | |
14 | { |
15 | my $now = DateTime->now; |
16 | my $epoch = $now->epoch; |
17 | |
18 | $schema->populate( 'Foo', [ [ 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' ); |
8857ad73 |
43 | like( $row->get_column( 'update_time' ), qr/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}$/, 'TimeStamp still Timestamp' ); |
8e52f1da |
44 | |
45 | my $mtime = $row->modification_time; |
46 | sleep( 1 ); |
47 | $row->update( { name => 'test' } ); |
48 | |
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' ); |
53 | } |
54 | } |