From: Tara L Andrews Date: Wed, 7 Mar 2012 12:47:12 +0000 (+0100) Subject: don't error on relationship deletion no-op X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=681893aaf3a08910a7baf865bdbe3b4d17433abc;p=scpubgit%2Fstemmatology.git don't error on relationship deletion no-op --- diff --git a/lib/Text/Tradition/Collation/RelationshipStore.pm b/lib/Text/Tradition/Collation/RelationshipStore.pm index 21faa93..0098563 100644 --- a/lib/Text/Tradition/Collation/RelationshipStore.pm +++ b/lib/Text/Tradition/Collation/RelationshipStore.pm @@ -48,12 +48,8 @@ is( scalar @v2, 2, "Added a global relationship with two instances" ); is( scalar @v1, 1, "Deleted first relationship" ); @v2 = $c->del_relationship( 'n8', 'n13' ); is( scalar @v2, 2, "Deleted second global relationship" ); -try { - my @v3 = $c->del_relationship( 'n1', 'n2' ); - ok( 0, "Should have errored on non-existent relationship" ); -} catch( Text::Tradition::Error $e ) { - like( $e->message, qr/No relationship defined/, "Attempt to delete non-existent relationship errored" ); -} +my @v3 = $c->del_relationship( 'n1', 'n2' ); +is( scalar @v3, 0, "Nothing deleted on non-existent relationship" ); =end testing @@ -327,7 +323,7 @@ non-local, removes the relationship everywhere in the graph. sub del_relationship { my( $self, $source, $target ) = @_; my $rel = $self->get_relationship( $source, $target ); - throw( "No relationship defined between $source and $target" ) unless $rel; + return () unless $rel; # Nothing to delete; return an empty set. my @vectors = ( [ $source, $target ] ); $self->_remove_relationship( $source, $target ); if( $rel->nonlocal ) { diff --git a/t/text_tradition_collation_relationshipstore.t b/t/text_tradition_collation_relationshipstore.t index 717c878..9f9ed65 100644 --- a/t/text_tradition_collation_relationshipstore.t +++ b/t/text_tradition_collation_relationshipstore.t @@ -34,12 +34,8 @@ is( scalar @v2, 2, "Added a global relationship with two instances" ); is( scalar @v1, 1, "Deleted first relationship" ); @v2 = $c->del_relationship( 'n8', 'n13' ); is( scalar @v2, 2, "Deleted second global relationship" ); -try { - my @v3 = $c->del_relationship( 'n1', 'n2' ); - ok( 0, "Should have errored on non-existent relationship" ); -} catch( Text::Tradition::Error $e ) { - like( $e->message, qr/No relationship defined/, "Attempt to delete non-existent relationship errored" ); -} +my @v3 = $c->del_relationship( 'n1', 'n2' ); +is( scalar @v3, 0, "Nothing deleted on non-existent relationship" ); }