Added small create test that passes and existing DateTime object
[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
e9100ff7 14plan tests => 3;
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
27is( $cd->year->month, 1, 'inflated month ok' );
28
29# deflate test
30my $now = DateTime->now;
31$cd->year( $now );
32$cd->update;
33
f9db5527 34($cd) = $schema->resultset("CD")->search( year => $now->year );
0567538f 35is( $cd->year->year, $now->year, 'deflate ok' );
36