Removed CDBI subclassing bugs. constrain_columns to work out now
[dbsrgits/DBIx-Class.git] / t / 68inflate.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 my $schema = DBICTest->init_schema();
9
10 eval { require DateTime };
11 plan skip_all => "Need DateTime for inflation tests" if $@;
12
13 plan tests => 4;
14
15 $schema->class('CD')
16 #DBICTest::Schema::CD
17 ->inflate_column( 'year',
18     { inflate => sub { DateTime->new( year => shift ) },
19       deflate => sub { shift->year } }
20 );
21 Class::C3->reinitialize;
22
23 # inflation test
24 my $cd = $schema->resultset("CD")->find(3);
25
26 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
27
28 is( $cd->year->year, 1997, 'inflated year ok' );
29
30 is( $cd->year->month, 1, 'inflated month ok' );
31
32 # deflate test
33 my $now = DateTime->now;
34 $cd->year( $now );
35 $cd->update;
36
37 ($cd) = $schema->resultset("CD")->search( year => $now->year );
38 is( $cd->year->year, $now->year, 'deflate ok' );
39