Resolve $rsrc instance duality on metadata traversal
[dbsrgits/DBIx-Class.git] / t / 82cascade_copy.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 use DBICTest;
9
10 my $schema = DBICTest->init_schema();
11
12 my $artist = $schema->resultset('Artist')->find(1);
13 my $artist_cds = $artist->search_related('cds');
14
15 my $cover_band = $artist->copy ({name => $artist->name . '_cover' });
16
17 my $cover_cds = $cover_band->search_related('cds');
18 cmp_ok($cover_band->id, '!=', $artist->id, 'ok got new column id...');
19 is($cover_cds->count, $artist_cds->count, 'duplicated rows count ok');
20
21 #check multi-keyed
22 is(
23   $cover_band->search_related('twokeys')->count,
24   $artist->search_related('twokeys')->count,
25   'duplicated multiPK ok'
26 );
27
28 #and check copying a few relations away
29 cmp_ok($cover_cds->search_related('tags')->count, '==',
30    $artist_cds->search_related('tags')->count , 'duplicated count ok');
31
32
33 # check from the other side
34 my $cd = $schema->resultset('CD')->find(1);
35 my $dup_cd = $cd->copy ({ title => 'ha!' });
36 is(
37   $dup_cd->search_related('twokeys')->count,
38   $cd->search_related('twokeys')->count,
39   'duplicated multiPK ok'
40 );
41
42 done_testing;