Test for earlier column_info overwriting (r1890)
[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 DBICTest::Schema::CD->add_column('year');
9 my $schema = DBICTest->init_schema();
10
11 eval { require DateTime };
12 plan skip_all => "Need DateTime for inflation tests" if $@;
13
14 plan tests => 3;
15
16 DBICTest::Schema::CD->inflate_column( 'year',
17     { inflate => sub { DateTime->new( year => shift ) },
18       deflate => sub { shift->year } }
19 );
20 Class::C3->reinitialize;
21
22 # inflation test
23 my $cd = $schema->resultset("CD")->find(3);
24
25 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
26
27 is( $cd->year->month, 1, 'inflated month ok' );
28
29 # deflate test
30 my $now = DateTime->now;
31 $cd->year( $now );
32 $cd->update;
33
34 ($cd) = $schema->resultset("CD")->search( year => $now->year );
35 is( $cd->year->year, $now->year, 'deflate ok' );
36