Commit | Line | Data |
0567538f |
1 | sub run_tests { |
1edaf6fe |
2 | my $schema = shift; |
0567538f |
3 | |
4 | eval { require DateTime }; |
5 | plan skip_all => "Need DateTime for inflation tests" if $@; |
6 | |
9fcda149 |
7 | plan tests => 5; |
0567538f |
8 | |
2d679367 |
9 | DBICTest::Schema::CD->inflate_column( 'year', |
0567538f |
10 | { inflate => sub { DateTime->new( year => shift ) }, |
11 | deflate => sub { shift->year } } |
12 | ); |
2d679367 |
13 | Class::C3->reinitialize; |
0567538f |
14 | |
15 | # inflation test |
f9db5527 |
16 | my $cd = $schema->resultset("CD")->find(3); |
0567538f |
17 | |
18 | is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); |
19 | |
20 | is( $cd->year->month, 1, 'inflated month ok' ); |
21 | |
22 | # deflate test |
23 | my $now = DateTime->now; |
24 | $cd->year( $now ); |
25 | $cd->update; |
26 | |
f9db5527 |
27 | ($cd) = $schema->resultset("CD")->search( year => $now->year ); |
0567538f |
28 | is( $cd->year->year, $now->year, 'deflate ok' ); |
29 | |
9fcda149 |
30 | use YAML; |
31 | DBICTest::Schema::Serialized->inflate_column( 'serialized', |
32 | { inflate => sub { Load (shift) }, |
33 | deflate => sub { die "Expecting a reference" unless (ref $_[0]); Dump (shift) } } |
34 | ); |
35 | Class::C3->reinitialize; |
36 | |
37 | my $complex1 = { |
38 | id => 1, |
39 | serialized => { |
40 | a => 1, |
41 | b => 2, |
42 | }, |
43 | }; |
44 | |
45 | my $complex2 = { |
46 | id => 1, |
47 | serialized => [qw/a b 1 2/], |
48 | }; |
49 | |
50 | my $rs = $schema->resultset('Serialized'); |
51 | |
52 | my $entry = $rs->create($complex2); |
53 | |
54 | ok($entry->update ($complex1), "update with hashref deflating ok"); |
55 | |
56 | ok($entry->update ($complex2), "update with arrayref deflating ok"); |
57 | |
0567538f |
58 | } |
59 | |
60 | 1; |