X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fdelete%2Frelated.t;h=d4dc26b5e92b9bd17a3e91cc197e6ccbf76eff51;hb=67cd640337ddda2ee20e5ec81a638ff611cd24df;hp=f3fb78b84a4288b4e48d459466a0d97651c19166;hpb=ecef7b5e63ab290cb2e8b120a65f178cb871397f;p=dbsrgits%2FDBIx-Class.git diff --git a/t/delete/related.t b/t/delete/related.t index f3fb78b..d4dc26b 100644 --- a/t/delete/related.t +++ b/t/delete/related.t @@ -1,15 +1,15 @@ -use Test::More; use strict; use warnings; +use Test::More; + use lib qw(t/lib); use DBICTest; -plan tests => 3; - my $schema = DBICTest->init_schema(); my $ars = $schema->resultset('Artist'); my $cdrs = $schema->resultset('CD'); +my $cd2pr_rs = $schema->resultset('CD_to_Producer'); # create some custom entries $ars->populate ([ @@ -18,6 +18,7 @@ $ars->populate ([ [qw/72 a2/], [qw/73 a3/], ]); + $cdrs->populate ([ [qw/cdid artist title year/], [qw/70 71 delete0 2005/], @@ -28,6 +29,13 @@ $cdrs->populate ([ [qw/75 73 delete5 2008/], ]); +my $prod = $schema->resultset('Producer')->create ({ name => 'deleter' }); +my $prod_cd = $cdrs->find (70); +my $cd2pr = $cd2pr_rs->create ({ + producer => $prod, + cd => $prod_cd, +}); + my $total_cds = $cdrs->count; # test that delete_related w/o conditions deletes all related records only @@ -43,3 +51,17 @@ is ($cdrs->count, $total_cds -= 2, 'related + condition delete ok'); # test that related deletion with limit condition works $a2_cds->search ({}, { rows => 1})->delete; is ($cdrs->count, $total_cds -= 1, 'related + limit delete ok'); + +{ + local $TODO = 'delete_related is based on search_related which is based on search which does not understand object arguments'; + local $SIG{__WARN__} = sub {}; # trap the non-numeric warning, remove when the TODO is removed + + my $cd2pr_count = $cd2pr_rs->count; + $prod_cd->delete_related('cd_to_producer', { producer => $prod } ); + is ($cd2pr_rs->count, $cd2pr_count -= 1, 'm2m link deleted succesfully'); + + # see 187ec69a for why this is neccessary + $prod->result_source(undef); +} + +done_testing;