Commit | Line | Data |
0567538f |
1 | sub run_tests { |
2 | |
3 | eval { require DateTime }; |
4 | plan skip_all => "Need DateTime for inflation tests" if $@; |
5 | |
6 | plan tests => 3; |
7 | |
2d679367 |
8 | DBICTest::Schema::CD->inflate_column( 'year', |
0567538f |
9 | { inflate => sub { DateTime->new( year => shift ) }, |
10 | deflate => sub { shift->year } } |
11 | ); |
2d679367 |
12 | Class::C3->reinitialize; |
0567538f |
13 | |
14 | # inflation test |
3712e4f4 |
15 | my $cd = DBICTest->class("CD")->find(3); |
0567538f |
16 | |
17 | is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); |
18 | |
19 | is( $cd->year->month, 1, 'inflated month ok' ); |
20 | |
21 | # deflate test |
22 | my $now = DateTime->now; |
23 | $cd->year( $now ); |
24 | $cd->update; |
25 | |
3712e4f4 |
26 | ($cd) = DBICTest->class("CD")->search( year => $now->year ); |
0567538f |
27 | is( $cd->year->year, $now->year, 'deflate ok' ); |
28 | |
29 | } |
30 | |
31 | 1; |