Commit | Line | Data |
70350518 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | |
8 | my $schema = DBICTest::init_schema(); |
0567538f |
9 | |
10 | eval { require DateTime }; |
11 | plan skip_all => "Need DateTime for inflation tests" if $@; |
12 | |
e9100ff7 |
13 | plan tests => 3; |
0567538f |
14 | |
2d679367 |
15 | DBICTest::Schema::CD->inflate_column( 'year', |
0567538f |
16 | { inflate => sub { DateTime->new( year => shift ) }, |
17 | deflate => sub { shift->year } } |
18 | ); |
2d679367 |
19 | Class::C3->reinitialize; |
0567538f |
20 | |
21 | # inflation test |
f9db5527 |
22 | my $cd = $schema->resultset("CD")->find(3); |
0567538f |
23 | |
24 | is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); |
25 | |
26 | is( $cd->year->month, 1, 'inflated month ok' ); |
27 | |
28 | # deflate test |
29 | my $now = DateTime->now; |
30 | $cd->year( $now ); |
31 | $cd->update; |
32 | |
f9db5527 |
33 | ($cd) = $schema->resultset("CD")->search( year => $now->year ); |
0567538f |
34 | is( $cd->year->year, $now->year, 'deflate ok' ); |
35 | |