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