Added quote char test, supported quoting in S::A subclass for joins
[dbsrgits/DBIx-Class.git] / t / 08inflate_has_a.t
CommitLineData
4a07648a 1use Test::More;
8bc482e9 2
3eval { require DateTime };
4plan skip_all => "Need DateTime for inflation tests" if $@;
4a07648a 5
759cfa82 6plan tests => 7;
4a07648a 7
8use lib qw(t/lib);
9
10use_ok('DBICTest');
11
11b78bd6 12DBICTest::CD->load_components(qw/CDBICompat::HasA/);
4a07648a 13
14DBICTest::CD->has_a( 'year', 'DateTime',
15 inflate => sub { DateTime->new( year => shift ) },
16 deflate => sub { shift->year }
17);
18
19# inflation test
656796f2 20my $cd = DBICTest::CD->find(3);
4a07648a 21
22is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
23
24is( $cd->year->month, 1, 'inflated month ok' );
25
26# deflate test
27my $now = DateTime->now;
28$cd->year( $now );
29$cd->update;
30
31($cd) = DBICTest::CD->search( year => $now->year );
32is( $cd->year->year, $now->year, 'deflate ok' );
759cfa82 33
34# re-test using alternate deflate syntax
35DBICTest::CD->has_a( 'year', 'DateTime',
36 inflate => sub { DateTime->new( year => shift ) },
37 deflate => 'year'
38);
39
40# inflation test
656796f2 41$cd = DBICTest::CD->find(3);
759cfa82 42
43is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
44
45is( $cd->year->month, 1, 'inflated month ok' );
46
47# deflate test
48$now = DateTime->now;
49$cd->year( $now );
50$cd->update;
51
52($cd) = DBICTest::CD->search( year => $now->year );
53is( $cd->year->year, $now->year, 'deflate ok' );
54