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