Commit | Line | Data |
51516b1c |
1 | use Test::More; |
8bc482e9 |
2 | |
3 | eval { require DateTime }; |
4 | plan skip_all => "Need DateTime for inflation tests" if $@; |
51516b1c |
5 | |
6 | plan tests => 4; |
7 | |
8 | use lib qw(t/lib); |
9 | |
10 | use_ok('DBICTest'); |
11 | |
0e5c2582 |
12 | DBICTest::CD->inflate_column( 'year', |
13 | { inflate => sub { DateTime->new( year => shift ) }, |
14 | deflate => sub { shift->year } } |
15 | ); |
16 | |
51516b1c |
17 | # inflation test |
656796f2 |
18 | my $cd = DBICTest::CD->find(3); |
0e5c2582 |
19 | |
51516b1c |
20 | is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); |
21 | |
22 | is( $cd->year->month, 1, 'inflated month ok' ); |
23 | |
24 | # deflate test |
cabca325 |
25 | my $now = DateTime->now; |
26 | $cd->year( $now ); |
51516b1c |
27 | $cd->update; |
28 | |
cabca325 |
29 | ($cd) = DBICTest::CD->search( year => $now->year ); |
0e5c2582 |
30 | is( $cd->year->year, $now->year, 'deflate ok' ); |