File: 03-compat.t

package info (click to toggle)
libdbix-class-datetime-epoch-perl 0.10-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 184 kB
  • sloc: perl: 1,402; makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,683 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use strict;
use warnings;

use lib 't/lib';

use Test::More tests => 15;

use DBICx::TestDatabase;
use DateTime;
my $schema = DBICx::TestDatabase->new( 'MySchema' );

my $rs = $schema->resultset( 'FooCompat' );

{
    my $now = DateTime->now;
    my $epoch = $now->epoch;

    $schema->populate( 'FooCompat', [ [ qw( id bar baz creation_time modification_time ) ], [ 1, ( $epoch ) x 4 ] ] );

    {
        my $row = $rs->find( 1 );

        isa_ok( $row->bar, 'DateTime' );
        isa_ok( $row->baz, 'DateTime' );
        ok( $row->bar == $now, 'inflate: epoch as int' ); 
        ok( $row->baz == $now, 'inflate: epoch as varchar' ); 
    }

    {
        $rs->create( { bar => $now, baz => $now } );
        my $row = $rs->find( 2 );

        isa_ok( $row->bar, 'DateTime' );
        isa_ok( $row->baz, 'DateTime' );
        is( $row->get_column( 'bar' ), $epoch, 'deflate: epoch as int' );
        is( $row->get_column( 'baz' ), $epoch, 'deflate: epoch as varchar' );

        # courtesy of TimeStamp
        isa_ok( $row->creation_time, 'DateTime' ); # courtesy of TimeStamp
        isa_ok( $row->modification_time, 'DateTime' );
        like( $row->get_column( 'creation_time' ), qr/^\d+$/, 'TimeStamp as epoch' );
        like( $row->get_column( 'modification_time' ), qr/^\d+$/, 'TimeStamp as epoch' );

        my $mtime = $row->modification_time;
        sleep( 1 );
        $row->update( { name => 'test' } );

        $row = $rs->find( 2 );
        isa_ok( $row->modification_time, 'DateTime' );
        like( $row->get_column( 'modification_time' ), qr/^\d+$/, 'TimeStamp as epoch' );
        ok( $row->modification_time > $mtime, 'mtime column was updated' );
    }
}