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