Updated S::A and S::A::L version reqs
[dbsrgits/DBIx-Class.git] / t / 08inflate_has_a.t
1 use Test::More;
2
3 eval { require DateTime };
4 plan skip_all => "Need DateTime for inflation tests" if $@;
5
6 plan tests => 7;
7
8 use lib qw(t/lib);
9
10 use_ok('DBICTest');
11
12 DBICTest::CD->load_components(qw/CDBICompat::HasA/);
13
14 DBICTest::CD->has_a( 'year', 'DateTime',
15       inflate => sub { DateTime->new( year => shift ) },
16       deflate => sub { shift->year }
17 );
18
19 # inflation test
20 my $cd = DBICTest::CD->find(3);
21
22 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
23
24 is( $cd->year->month, 1, 'inflated month ok' );
25
26 # deflate test
27 my $now = DateTime->now;
28 $cd->year( $now );
29 $cd->update;
30
31 ($cd) = DBICTest::CD->search( year => $now->year );
32 is( $cd->year->year, $now->year, 'deflate ok' );
33
34 # re-test using alternate deflate syntax
35 DBICTest::CD->has_a( 'year', 'DateTime',
36       inflate => sub { DateTime->new( year => shift ) },
37       deflate => 'year'
38 );
39
40 # inflation test
41 $cd = DBICTest::CD->find(3);
42
43 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
44
45 is( $cd->year->month, 1, 'inflated month ok' );
46
47 # deflate test
48 $now = DateTime->now;
49 $cd->year( $now );
50 $cd->update;
51
52 ($cd) = DBICTest::CD->search( year => $now->year );
53 is( $cd->year->year, $now->year, 'deflate ok' );
54