Factored common cdbi rel features out into Relationship:: packages
[dbsrgits/DBIx-Class.git] / t / 08inflate_has_a.t
1 use Test::More;
2 use DateTime;
3
4 plan tests => 4;
5
6 use lib qw(t/lib);
7
8 use_ok('DBICTest');
9
10 use DBIx::Class::CDBICompat::HasA;
11
12 unshift(@DBICTest::ISA, 'DBIx::Class::CDBICompat::HasA');
13
14 DBICTest::CD->has_a( 'year', 'DateTime',
15       inflate => sub { DateTime->new( year => shift ) },
16       deflate => sub { shift->year }
17 );
18
19 # inflation test
20 my $cd = DBICTest::CD->retrieve(3);
21
22 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
23
24 is( $cd->year->month, 1, 'inflated month ok' );
25
26 # deflate test
27 my $now = DateTime->now;
28 $cd->year( $now );
29 $cd->update;
30
31 ($cd) = DBICTest::CD->search( year => $now->year );
32 is( $cd->year->year, $now->year, 'deflate ok' );