make set_from_related handle undef
[dbsrgits/DBIx-Class.git] / t / run / 22cascade_copy.tl
1 use strict;
2 use warnings;
3
4 sub run_tests {
5 my $schema = shift;
6
7 plan tests => 4;
8 my $artist = $schema->resultset('Artist')->find(1);
9 my $artist_cds = $artist->search_related('cds');
10
11 my $cover_band;
12
13 {
14   no warnings 'redefine';
15   local *DBICTest::Artist::result_source_instance = \&DBICTest::Schema::Artist::result_source_instance;
16
17   $cover_band = $artist->copy;
18 }
19
20 my $cover_cds = $cover_band->search_related('cds');
21 cmp_ok($cover_band->id, '!=', $artist->id, 'ok got new column id...');
22 is($cover_cds->count, $artist_cds->count, 'duplicated rows count ok');
23
24 #check multi-keyed
25 cmp_ok($cover_band->search_related('twokeys')->count, '>', 0, 'duplicated multiPK ok');
26
27 #and check copying a few relations away
28 cmp_ok($cover_cds->search_related('tags')->count, '==',
29    $artist_cds->search_related('tags')->count , 'duplicated count ok');
30
31 }
32 1;