Made source_name read-only on source instances, r/w on classes
[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 DBICTest::Schema::CD->add_column('year2');
11 $DB::single = 1;
12 eval { require DateTime };
13 plan skip_all => "Need DateTime for inflation tests" if $@;
14
15 plan tests => 4;
16
17 $DB::single = 1;
18
19 $schema->class('CD')
20 #DBICTest::Schema::CD
21 ->inflate_column( 'year',
22     { inflate => sub { DateTime->new( year => shift ) },
23       deflate => sub { shift->year } }
24 );
25 Class::C3->reinitialize;
26
27 # inflation test
28 my $cd = $schema->resultset("CD")->find(3);
29
30 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
31
32 is( $cd->year->year, 1997, 'inflated year ok' );
33
34 is( $cd->year->month, 1, 'inflated month ok' );
35
36 # deflate test
37 my $now = DateTime->now;
38 $cd->year( $now );
39 $cd->update;
40
41 ($cd) = $schema->resultset("CD")->search( year => $now->year );
42 is( $cd->year->year, $now->year, 'deflate ok' );
43