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