Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / t / cdbi / 68-inflate_has_a.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
54a9a088 2use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt cdbicompat );
83eef562 3
70350518 4use strict;
f4086911 5use warnings;
70350518 6
83eef562 7use Test::More;
c0329273 8
83eef562 9use DBICTest;
ae0419e2 10
f4086911 11my $schema = DBICTest->init_schema();
12
658b87f6 13DBICTest::Schema::CD->load_components(qw/CDBICompat::Relationships/);
0567538f 14
2d679367 15DBICTest::Schema::CD->has_a( 'year', 'DateTime',
0567538f 16 inflate => sub { DateTime->new( year => shift ) },
17 deflate => sub { shift->year }
18);
cc8ffd7b 19Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO;
0567538f 20
21# inflation test
f9db5527 22my $cd = $schema->resultset("CD")->find(3);
0567538f 23
24is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
25
26is( $cd->year->month, 1, 'inflated month ok' );
27
28# deflate test
29my $now = DateTime->now;
30$cd->year( $now );
31$cd->update;
32
ede573ac 33($cd) = $schema->resultset("CD")->search({ year => $now->year });
0567538f 34is( $cd->year->year, $now->year, 'deflate ok' );
35
36# re-test using alternate deflate syntax
1edaf6fe 37$schema->class("CD")->has_a( 'year', 'DateTime',
0567538f 38 inflate => sub { DateTime->new( year => shift ) },
39 deflate => 'year'
40);
41
42# inflation test
f9db5527 43$cd = $schema->resultset("CD")->find(3);
0567538f 44
45is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
46
47is( $cd->year->month, 1, 'inflated month ok' );
48
49# deflate test
50$now = DateTime->now;
51$cd->year( $now );
52$cd->update;
53
ede573ac 54($cd) = $schema->resultset("CD")->search({ year => $now->year });
0567538f 55is( $cd->year->year, $now->year, 'deflate ok' );
56
d9bd5195 57done_testing;