Merge 'trunk' into 'cdbicompat_integration'
[dbsrgits/DBIx-Class.git] / t / 84serialize.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7 use Storable qw(dclone freeze thaw);
8
9 my $schema = DBICTest->init_schema();
10
11 my %stores = (
12     dclone          => sub { return dclone($_[0]) },
13     "freeze/thaw"   => sub { return thaw(freeze($_[0])) },
14 );
15
16 plan tests => (7 * keys %stores);
17
18 for 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   
37     ok eval { $copy->discard_changes; 1 };
38     is($copy->id, $artist->id, "IDs still match ");
39 }