add_relationship, relationship_info, relationships moved to ResultSource
[dbsrgits/DBIx-Class.git] / t / run / 08inflate_has_a.tl
1 sub run_tests {
2
3 eval { require DateTime };
4 plan skip_all => "Need DateTime for inflation tests" if $@;
5
6 plan tests => 6;
7
8 DBICTest::Schema::CD->load_components(qw/CDBICompat::HasA/);
9
10 DBICTest::Schema::CD->has_a( 'year', 'DateTime',
11       inflate => sub { DateTime->new( year => shift ) },
12       deflate => sub { shift->year }
13 );
14 Class::C3->reinitialize;
15
16 # inflation test
17 my $cd = DBICTest->class("CD")->find(3);
18
19 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
20
21 is( $cd->year->month, 1, 'inflated month ok' );
22
23 # deflate test
24 my $now = DateTime->now;
25 $cd->year( $now );
26 $cd->update;
27
28 ($cd) = DBICTest->class("CD")->search( year => $now->year );
29 is( $cd->year->year, $now->year, 'deflate ok' );
30
31 # re-test using alternate deflate syntax
32 DBICTest->class("CD")->has_a( 'year', 'DateTime',
33       inflate => sub { DateTime->new( year => shift ) },
34       deflate => 'year'
35 );
36
37 # inflation test
38 $cd = DBICTest->class("CD")->find(3);
39
40 is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
41
42 is( $cd->year->month, 1, 'inflated month ok' );
43
44 # deflate test
45 $now = DateTime->now;
46 $cd->year( $now );
47 $cd->update;
48
49 ($cd) = DBICTest->class("CD")->search( year => $now->year );
50 is( $cd->year->year, $now->year, 'deflate ok' );
51
52 }
53
54 1;