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