Commit | Line | Data |
70350518 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
e60dc79f |
7 | use Storable qw(dclone freeze thaw); |
69ac22ee |
8 | |
a47e1233 |
9 | my $schema = DBICTest->init_schema(); |
69ac22ee |
10 | |
e60dc79f |
11 | my %stores = ( |
7244b45f |
12 | dclone_method => sub { return $schema->dclone($_[0]) }, |
13 | "freeze/thaw_method" => sub { |
14 | my $ice = $schema->freeze($_[0]); |
15 | return $schema->thaw($ice); |
16 | }, |
e60dc79f |
17 | ); |
69ac22ee |
18 | |
c65da661 |
19 | plan tests => (7 * keys %stores); |
69ac22ee |
20 | |
e60dc79f |
21 | for my $name (keys %stores) { |
22 | my $store = $stores{$name}; |
23 | |
24 | my $artist = $schema->resultset('Artist')->find(1); |
25 | my $copy = eval { $store->($artist) }; |
26 | is_deeply($copy, $artist, "serialize row object works: $name"); |
27 | |
28 | # Test that an object with a related_resultset can be serialized. |
29 | my @cds = $artist->related_resultset("cds"); |
30 | ok $artist->{related_resultsets}, 'has key: related_resultsets'; |
31 | |
32 | $copy = eval { $store->($artist) }; |
33 | for my $key (keys %$artist) { |
34 | next if $key eq 'related_resultsets'; |
35 | next if $key eq '_inflated_column'; |
36 | is_deeply($copy->{$key}, $artist->{$key}, |
37 | qq[serialize with related_resultset "$key"]); |
38 | } |
c65da661 |
39 | |
7244b45f |
40 | ok eval { $copy->discard_changes; 1 } or diag $@; |
c65da661 |
41 | is($copy->id, $artist->id, "IDs still match "); |
e60dc79f |
42 | } |