From: Christopher H. Laco Date: Sat, 20 May 2006 20:40:55 +0000 (+0000) Subject: Added delete_related tests to verify it only deletes related records X-Git-Tag: v0.07002~75^2~180 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c6ce6ec6a7ffb98065ccf6e71fc0420e3a71d982;p=dbsrgits%2FDBIx-Class.git Added delete_related tests to verify it only deletes related records --- diff --git a/t/53delete_related.t b/t/53delete_related.t new file mode 100644 index 0000000..f193566 --- /dev/null +++ b/t/53delete_related.t @@ -0,0 +1,30 @@ +use Test::More; +use strict; +use warnings; +use lib qw(t/lib); +use DBICTest; +use DBICTest::BasicRels; + +plan tests => 7; + +my $schema = DBICTest->schema; +my $total_cds = $schema->resultset('CD')->count; +cmp_ok($total_cds, '>', 0, 'need cd records'); + +# test that delete_related w/o conditions deletes all related records only +my $artist = $schema->resultset("Artist")->find(3); +my $artist_cds = $artist->cds->count; +cmp_ok($artist_cds, '<', $total_cds, 'need more cds than just related cds'); + +ok($artist->delete_related('cds')); +cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist_cds), 'too many cds were deleted'); + +$total_cds -= $artist_cds; + +# test that delete_related w/conditions deletes just the matched related records only +my $artist2 = $schema->resultset("Artist")->find(2); +my $artist2_cds = $artist2->search_related('cds')->count; +cmp_ok($artist2_cds, '<', $total_cds, 'need more cds than related cds'); + +ok($artist2->delete_related('cds', {title => {like => '%'}})); +cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist2_cds), 'too many cds were deleted');