Removed BasicRels and reorganized where the various init/setup code resides.
[dbsrgits/DBIx-Class.git] / t / run / 08inflate_serialize.tl
CommitLineData
e9100ff7 1sub run_tests {
2my $schema = shift;
3
4use Data::Dumper;
5
6my @serializers = (
7 { module => 'YAML.pm',
8 inflater => sub { YAML::Load (shift) },
9 deflater => sub { die "Expecting a reference" unless (ref $_[0]); YAML::Dump (shift) },
10 },
11 { module => 'Storable.pm',
12 inflater => sub { Storable::thaw (shift) },
13 deflater => sub { die "Expecting a reference" unless (ref $_[0]); Storable::nfreeze (shift) },
14 },
15);
16
17
18my $selected;
19foreach my $serializer (@serializers) {
20 eval { require $serializer->{module} };
21 unless ($@) {
22 $selected = $serializer;
23 last;
24 }
25}
26
27plan (skip_all => "No suitable serializer found") unless $selected;
28
29plan (tests => 6);
30DBICTest::Schema::Serialized->inflate_column( 'serialized',
31 { inflate => $selected->{inflater},
32 deflate => $selected->{deflater},
33 },
34);
35Class::C3->reinitialize;
36
37my $complex1 = {
38 id => 1,
39 serialized => {
40 a => 1,
41 b => [
42 { c => 2 },
43 ],
44 d => 3,
45 },
46};
47
48my $complex2 = {
49 id => 1,
50 serialized => [
51 'a',
52 { b => 1, c => 2},
53 'd',
54 ],
55};
56
57my $rs = $schema->resultset('Serialized');
58my $entry = $rs->create({ id => 1, serialized => ''});
59
60my $inflated;
61
62ok($entry->update ({ %{$complex1} }), 'hashref deflation ok');
63ok($inflated = $entry->serialized, 'hashref inflation ok');
64is_deeply($inflated, $complex1->{serialized}, 'inflated hash matches original');
65
66ok($entry->update ({ %{$complex2} }), 'arrayref deflation ok');
67ok($inflated = $entry->serialized, 'arrayref inflation ok');
68is_deeply($inflated, $complex2->{serialized}, 'inflated array matches original');
69
70}
71
721;