Release shipped, Changes update and version bumped
[dbsrgits/DBIx-Class.git] / t / run / 08inflate_has_a.tl
CommitLineData
0567538f 1sub run_tests {
2
3eval { require DateTime };
4plan skip_all => "Need DateTime for inflation tests" if $@;
5
6plan tests => 6;
7
2d679367 8DBICTest::Schema::CD->load_components(qw/CDBICompat::HasA/);
0567538f 9
2d679367 10DBICTest::Schema::CD->has_a( 'year', 'DateTime',
0567538f 11 inflate => sub { DateTime->new( year => shift ) },
12 deflate => sub { shift->year }
13);
2d679367 14Class::C3->reinitialize;
0567538f 15
16# inflation test
3712e4f4 17my $cd = DBICTest->class("CD")->find(3);
0567538f 18
19is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
20
21is( $cd->year->month, 1, 'inflated month ok' );
22
23# deflate test
24my $now = DateTime->now;
25$cd->year( $now );
26$cd->update;
27
3712e4f4 28($cd) = DBICTest->class("CD")->search( year => $now->year );
0567538f 29is( $cd->year->year, $now->year, 'deflate ok' );
30
31# re-test using alternate deflate syntax
3712e4f4 32DBICTest->class("CD")->has_a( 'year', 'DateTime',
0567538f 33 inflate => sub { DateTime->new( year => shift ) },
34 deflate => 'year'
35);
36
37# inflation test
3712e4f4 38$cd = DBICTest->class("CD")->find(3);
0567538f 39
40is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
41
42is( $cd->year->month, 1, 'inflated month ok' );
43
44# deflate test
45$now = DateTime->now;
46$cd->year( $now );
47$cd->update;
48
3712e4f4 49($cd) = DBICTest->class("CD")->search( year => $now->year );
0567538f 50is( $cd->year->year, $now->year, 'deflate ok' );
51
52}
53
541;