Commit | Line | Data |
c6ce6ec6 |
1 | use Test::More; |
2 | use strict; |
3 | use warnings; |
4 | use lib qw(t/lib); |
5 | use DBICTest; |
c6ce6ec6 |
6 | |
7 | plan tests => 7; |
8 | |
ae515736 |
9 | my $schema = DBICTest->init_schema(); |
c6ce6ec6 |
10 | my $total_cds = $schema->resultset('CD')->count; |
11 | cmp_ok($total_cds, '>', 0, 'need cd records'); |
12 | |
13 | # test that delete_related w/o conditions deletes all related records only |
14 | my $artist = $schema->resultset("Artist")->find(3); |
15 | my $artist_cds = $artist->cds->count; |
16 | cmp_ok($artist_cds, '<', $total_cds, 'need more cds than just related cds'); |
17 | |
18 | ok($artist->delete_related('cds')); |
19 | cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist_cds), 'too many cds were deleted'); |
20 | |
21 | $total_cds -= $artist_cds; |
22 | |
23 | # test that delete_related w/conditions deletes just the matched related records only |
24 | my $artist2 = $schema->resultset("Artist")->find(2); |
25 | my $artist2_cds = $artist2->search_related('cds')->count; |
26 | cmp_ok($artist2_cds, '<', $total_cds, 'need more cds than related cds'); |
27 | |
28 | ok($artist2->delete_related('cds', {title => {like => '%'}})); |
29 | cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist2_cds), 'too many cds were deleted'); |
a5f761f7 |
30 | |