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