Commit | Line | Data |
54a9a088 |
1 | use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt cdbicompat ); |
83eef562 |
2 | |
70350518 |
3 | use strict; |
f4086911 |
4 | use warnings; |
70350518 |
5 | |
83eef562 |
6 | use Test::More; |
7 | use lib 't/lib'; |
8 | use DBICTest; |
ae0419e2 |
9 | |
f4086911 |
10 | my $schema = DBICTest->init_schema(); |
11 | |
658b87f6 |
12 | DBICTest::Schema::CD->load_components(qw/CDBICompat::Relationships/); |
0567538f |
13 | |
2d679367 |
14 | DBICTest::Schema::CD->has_a( 'year', 'DateTime', |
0567538f |
15 | inflate => sub { DateTime->new( year => shift ) }, |
16 | deflate => sub { shift->year } |
17 | ); |
cc8ffd7b |
18 | Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO; |
0567538f |
19 | |
20 | # inflation test |
f9db5527 |
21 | my $cd = $schema->resultset("CD")->find(3); |
0567538f |
22 | |
23 | is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); |
24 | |
25 | is( $cd->year->month, 1, 'inflated month ok' ); |
26 | |
27 | # deflate test |
28 | my $now = DateTime->now; |
29 | $cd->year( $now ); |
30 | $cd->update; |
31 | |
ede573ac |
32 | ($cd) = $schema->resultset("CD")->search({ year => $now->year }); |
0567538f |
33 | is( $cd->year->year, $now->year, 'deflate ok' ); |
34 | |
35 | # re-test using alternate deflate syntax |
1edaf6fe |
36 | $schema->class("CD")->has_a( 'year', 'DateTime', |
0567538f |
37 | inflate => sub { DateTime->new( year => shift ) }, |
38 | deflate => 'year' |
39 | ); |
40 | |
41 | # inflation test |
f9db5527 |
42 | $cd = $schema->resultset("CD")->find(3); |
0567538f |
43 | |
44 | is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); |
45 | |
46 | is( $cd->year->month, 1, 'inflated month ok' ); |
47 | |
48 | # deflate test |
49 | $now = DateTime->now; |
50 | $cd->year( $now ); |
51 | $cd->update; |
52 | |
ede573ac |
53 | ($cd) = $schema->resultset("CD")->search({ year => $now->year }); |
0567538f |
54 | is( $cd->year->year, $now->year, 'deflate ok' ); |
55 | |
d9bd5195 |
56 | done_testing; |