Renamed DBIx::Class::PK's retrieve() as find()
[dbsrgits/DBIx-Class.git] / t / 08inflate.t
1 use Test::More;
2
3 eval { require DateTime };
4 plan skip_all => "Need DateTime for inflation tests" if $@;
5
6 plan tests => 4;
7
8 use lib qw(t/lib);
9
10 use_ok('DBICTest');
11
12 DBICTest::CD->inflate_column( 'year',
13     { inflate => sub { DateTime->new( year => shift ) },
14       deflate => sub { shift->year } }
15 );
16
17 # inflation test
18 my $cd = DBICTest::CD->find(3);
19
20 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
21
22 is( $cd->year->month, 1, 'inflated month ok' );
23
24 # deflate test
25 my $now = DateTime->now;
26 $cd->year( $now );
27 $cd->update;
28
29 ($cd) = DBICTest::CD->search( year => $now->year );
30 is( $cd->year->year, $now->year, 'deflate ok' );