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 | |
ec9c93f1 |
8 | DBICTest::Schema::CD->add_column('year'); |
a47e1233 |
9 | my $schema = DBICTest->init_schema(); |
0567538f |
10 | |
11 | eval { require DateTime }; |
12 | plan skip_all => "Need DateTime for inflation tests" if $@; |
13 | |
e9100ff7 |
14 | plan tests => 3; |
0567538f |
15 | |
2d679367 |
16 | DBICTest::Schema::CD->inflate_column( 'year', |
0567538f |
17 | { inflate => sub { DateTime->new( year => shift ) }, |
18 | deflate => sub { shift->year } } |
19 | ); |
2d679367 |
20 | Class::C3->reinitialize; |
0567538f |
21 | |
22 | # inflation test |
f9db5527 |
23 | my $cd = $schema->resultset("CD")->find(3); |
0567538f |
24 | |
25 | is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); |
26 | |
27 | is( $cd->year->month, 1, 'inflated month ok' ); |
28 | |
29 | # deflate test |
30 | my $now = DateTime->now; |
31 | $cd->year( $now ); |
32 | $cd->update; |
33 | |
f9db5527 |
34 | ($cd) = $schema->resultset("CD")->search( year => $now->year ); |
0567538f |
35 | is( $cd->year->year, $now->year, 'deflate ok' ); |
36 | |