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 => 6; |
7 | |
2d679367 |
8 | DBICTest::Schema::CD->load_components(qw/CDBICompat::HasA/); |
0567538f |
9 | |
2d679367 |
10 | DBICTest::Schema::CD->has_a( 'year', 'DateTime', |
0567538f |
11 | inflate => sub { DateTime->new( year => shift ) }, |
12 | deflate => sub { shift->year } |
13 | ); |
2d679367 |
14 | Class::C3->reinitialize; |
0567538f |
15 | |
16 | # inflation test |
3712e4f4 |
17 | my $cd = DBICTest->class("CD")->find(3); |
0567538f |
18 | |
19 | is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); |
20 | |
21 | is( $cd->year->month, 1, 'inflated month ok' ); |
22 | |
23 | # deflate test |
24 | my $now = DateTime->now; |
25 | $cd->year( $now ); |
26 | $cd->update; |
27 | |
3712e4f4 |
28 | ($cd) = DBICTest->class("CD")->search( year => $now->year ); |
0567538f |
29 | is( $cd->year->year, $now->year, 'deflate ok' ); |
30 | |
31 | # re-test using alternate deflate syntax |
3712e4f4 |
32 | DBICTest->class("CD")->has_a( 'year', 'DateTime', |
0567538f |
33 | inflate => sub { DateTime->new( year => shift ) }, |
34 | deflate => 'year' |
35 | ); |
36 | |
37 | # inflation test |
3712e4f4 |
38 | $cd = DBICTest->class("CD")->find(3); |
0567538f |
39 | |
40 | is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); |
41 | |
42 | is( $cd->year->month, 1, 'inflated month ok' ); |
43 | |
44 | # deflate test |
45 | $now = DateTime->now; |
46 | $cd->year( $now ); |
47 | $cd->update; |
48 | |
3712e4f4 |
49 | ($cd) = DBICTest->class("CD")->search( year => $now->year ); |
0567538f |
50 | is( $cd->year->year, $now->year, 'deflate ok' ); |
51 | |
52 | } |
53 | |
54 | 1; |