Commit | Line | Data |
3cf3fa9f |
1 | use Test::More; |
2 | use strict; |
3 | use warnings; |
4 | use lib qw(t/lib); |
5 | use DBICTest; |
6 | |
7 | plan tests => 9; |
8 | |
9 | # This set of tests attempts to do a delete on a chained resultset, which |
10 | # would lead to SQL DELETE with a JOIN, which is not supported by the |
11 | # SQL generator right now. |
12 | # So it currently checks that these operations fail with a warning. |
13 | # When the SQL generator is fixed this test will need fixing up appropriately. |
14 | |
15 | my $schema = DBICTest->init_schema(); |
16 | my $total_tracks = $schema->resultset('Track')->count; |
17 | cmp_ok($total_tracks, '>', 0, 'need track records'); |
18 | |
19 | # test that delete_related w/o conditions deletes all related records only |
20 | { |
21 | my $w; |
22 | local $SIG{__WARN__} = sub { $w = shift }; |
23 | |
24 | my $artist = $schema->resultset("Artist")->find(3); |
25 | my $artist_tracks = $artist->cds->search_related('tracks')->count; |
26 | cmp_ok($artist_tracks, '<', $total_tracks, 'need more tracks than just related tracks'); |
27 | |
28 | ok(!eval{$artist->cds->search_related('tracks')->delete}); |
29 | cmp_ok($schema->resultset('Track')->count, '==', $total_tracks, 'No tracks should be deleted'); |
30 | like ($w, qr/Currently \$rs->delete\(\) does not generate proper SQL/, 'Delete join warning'); |
31 | } |
32 | |
33 | # test that delete_related w/conditions deletes just the matched related records only |
34 | { |
35 | my $w; |
36 | local $SIG{__WARN__} = sub { $w = shift }; |
37 | |
38 | my $artist2 = $schema->resultset("Artist")->find(2); |
39 | my $artist2_tracks = $artist2->search_related('cds')->search_related('tracks')->count; |
40 | cmp_ok($artist2_tracks, '<', $total_tracks, 'need more tracks than related tracks'); |
41 | |
42 | ok(!eval{$artist2->search_related('cds')->search_related('tracks')->delete}); |
43 | cmp_ok($schema->resultset('Track')->count, '==', $total_tracks, 'No tracks should be deleted'); |
44 | like ($w, qr/Currently \$rs->delete\(\) does not generate proper SQL/, 'Delete join warning'); |
45 | } |