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