0ce901cfcc2f381d5f8bd9a1a8f7ffc1301e6130
[dbsrgits/DBIx-Class.git] / t / 68inflate.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 DBICTest::Schema::CD->add_column('year');
9 my $schema = DBICTest->init_schema();
10
11 eval { require DateTime };
12 plan skip_all => "Need DateTime for inflation tests" if $@;
13
14 plan tests => 4;
15
16 DBICTest::Schema::CD->inflate_column( 'year',
17     { inflate => sub { DateTime->new( year => shift ) },
18       deflate => sub { shift->year } }
19 );
20 Class::C3->reinitialize;
21
22 # inflation test
23 my $cd = $schema->resultset("CD")->find(3);
24
25 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
26
27 is( $cd->year->year, 1997, 'inflated year ok' );
28
29 is( $cd->year->month, 1, 'inflated month ok' );
30
31 # deflate test
32 my $now = DateTime->now;
33 $cd->year( $now );
34 $cd->update;
35
36 ($cd) = $schema->resultset("CD")->search( year => $now->year );
37 is( $cd->year->year, $now->year, 'deflate ok' );
38