Removed CDBI subclassing bugs. constrain_columns to work out now
[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
a47e1233 8my $schema = DBICTest->init_schema();
0567538f 9
10eval { require DateTime };
11plan skip_all => "Need DateTime for inflation tests" if $@;
12
89279e9d 13plan tests => 4;
0567538f 14
93405cf0 15$schema->class('CD')
16#DBICTest::Schema::CD
17->inflate_column( 'year',
0567538f 18 { inflate => sub { DateTime->new( year => shift ) },
19 deflate => sub { shift->year } }
20);
2d679367 21Class::C3->reinitialize;
0567538f 22
23# inflation test
f9db5527 24my $cd = $schema->resultset("CD")->find(3);
0567538f 25
26is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
27
89279e9d 28is( $cd->year->year, 1997, 'inflated year ok' );
29
0567538f 30is( $cd->year->month, 1, 'inflated month ok' );
31
32# deflate test
33my $now = DateTime->now;
34$cd->year( $now );
35$cd->update;
36
f9db5527 37($cd) = $schema->resultset("CD")->search( year => $now->year );
0567538f 38is( $cd->year->year, $now->year, 'deflate ok' );
39