From f31e8df25908b818fba3d9e09ef984058669776f Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 15 Apr 2019 12:09:56 +1000 Subject: [PATCH] fix: handle deleting integration when consumer and provider are the same pacticipant --- lib/pact_broker/integrations/service.rb | 2 +- spec/lib/pact_broker/integrations/service_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/pact_broker/integrations/service.rb b/lib/pact_broker/integrations/service.rb index 0289ae1dc..4d4dbc1b7 100644 --- a/lib/pact_broker/integrations/service.rb +++ b/lib/pact_broker/integrations/service.rb @@ -20,7 +20,7 @@ def self.delete(consumer_name, provider_name) version_repository.delete_orphan_versions(consumer, provider) pacticipant_service.delete_if_orphan(consumer) - pacticipant_service.delete_if_orphan(provider) + pacticipant_service.delete_if_orphan(provider) unless consumer == provider end end end diff --git a/spec/lib/pact_broker/integrations/service_spec.rb b/spec/lib/pact_broker/integrations/service_spec.rb index 33d93a6eb..0ab33ec1c 100644 --- a/spec/lib/pact_broker/integrations/service_spec.rb +++ b/spec/lib/pact_broker/integrations/service_spec.rb @@ -208,6 +208,19 @@ module Integrations expect { subject }.to change { PactBroker::Domain::Version.count } end end + + context "when a pacticipant has a pact with itself... I wouldn't have believed it unless I'd seen it..." do + before do + td.create_consumer("Foo") + .use_provider("Foo") + .create_consumer_version("1") + .create_pact + end + + it "doesn't blow up" do + Service.delete("Foo", "Foo") + end + end end end end