Using "is" instead of "cmp_ok"
[dbsrgits/DBIx-Class.git] / t / 53delete_chained.t
CommitLineData
3cf3fa9f 1use Test::More;
2use strict;
3use warnings;
4use lib qw(t/lib);
5use DBICTest;
6
0f6fc705 7plan tests => 7;
3cf3fa9f 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
15my $schema = DBICTest->init_schema();
16my $total_tracks = $schema->resultset('Track')->count;
17cmp_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
0f6fc705 28 my $rs = $artist->cds->search_related('tracks');
29 $total_tracks -= $rs->count;
30 ok($rs->delete);
cb9b5b23 31 is($schema->resultset('Track')->count, $total_tracks, '3 tracks should be deleted');
3cf3fa9f 32}
33
34# test that delete_related w/conditions deletes just the matched related records only
35{
36 my $w;
37 local $SIG{__WARN__} = sub { $w = shift };
38
39 my $artist2 = $schema->resultset("Artist")->find(2);
40 my $artist2_tracks = $artist2->search_related('cds')->search_related('tracks')->count;
41 cmp_ok($artist2_tracks, '<', $total_tracks, 'need more tracks than related tracks');
42
0f6fc705 43 my $rs = $artist2->search_related('cds')->search_related('tracks');
44 $total_tracks -= $rs->count;
45 ok($rs->delete);
cb9b5b23 46 is($schema->resultset('Track')->count, $total_tracks, 'No tracks should be deleted');
3cf3fa9f 47}