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