initial merge of Schwern's CDBICompat work, with many thanks
[dbsrgits/DBIx-Class.git] / t / 84serialize.t
CommitLineData
70350518 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
e60dc79f 7use Storable qw(dclone freeze thaw);
69ac22ee 8
a47e1233 9my $schema = DBICTest->init_schema();
69ac22ee 10
e60dc79f 11my %stores = (
12 dclone => sub { return dclone($_[0]) },
13 "freeze/thaw" => sub { return thaw(freeze($_[0])) },
14);
69ac22ee 15
e60dc79f 16plan tests => (5 * keys %stores);
69ac22ee 17
e60dc79f 18for my $name (keys %stores) {
19 my $store = $stores{$name};
20
21 my $artist = $schema->resultset('Artist')->find(1);
22 my $copy = eval { $store->($artist) };
23 is_deeply($copy, $artist, "serialize row object works: $name");
24
25 # Test that an object with a related_resultset can be serialized.
26 my @cds = $artist->related_resultset("cds");
27 ok $artist->{related_resultsets}, 'has key: related_resultsets';
28
29 $copy = eval { $store->($artist) };
30 for my $key (keys %$artist) {
31 next if $key eq 'related_resultsets';
32 next if $key eq '_inflated_column';
33 is_deeply($copy->{$key}, $artist->{$key},
34 qq[serialize with related_resultset "$key"]);
35 }
36}