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