Merge 'trunk' into 'cdbicompat_integration'
[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 = (
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 19plan tests => (7 * keys %stores);
69ac22ee 20
e60dc79f 21for 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}