diff --git a/lib/pact_broker/pacts/service.rb b/lib/pact_broker/pacts/service.rb index 2ab22df45..092ab8b46 100644 --- a/lib/pact_broker/pacts/service.rb +++ b/lib/pact_broker/pacts/service.rb @@ -94,9 +94,10 @@ def find_distinct_pacts_between consumer, options distinct end - def pact_has_changed_since_previous_version? pact + # TODO also take into account overridden revisions + def pact_is_new_or_pact_has_changed_since_previous_version? pact previous_pact = pact_repository.find_previous_pact pact - previous_pact && pact.json_content != previous_pact.json_content + previous_pact.nil? || pact.json_content != previous_pact.json_content end private @@ -108,6 +109,8 @@ def update_pact params, existing_pact if existing_pact.json_content != updated_pact.json_content webhook_service.execute_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED + else + logger.debug "Pact has not changed since previous revision, not triggering webhooks" end updated_pact @@ -122,8 +125,11 @@ def create_pact params, version, provider end def trigger_webhooks pact - if pact_has_changed_since_previous_version? pact + # TODO add tests for this + if pact_is_new_or_pact_has_changed_since_previous_version?(pact) webhook_service.execute_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED + else + logger.debug "Pact has not changed since previous version, not triggering webhooks" end end end diff --git a/spec/lib/pact_broker/pacts/service_spec.rb b/spec/lib/pact_broker/pacts/service_spec.rb index 6d48d2766..5bbf915ad 100644 --- a/spec/lib/pact_broker/pacts/service_spec.rb +++ b/spec/lib/pact_broker/pacts/service_spec.rb @@ -30,7 +30,7 @@ module Pacts end - describe "#pact_has_changed_since_previous_version?" do + describe "#pact_is_new_or_pact_has_changed_since_previous_version?" do let(:json_content) { { 'some' => 'json'}.to_json } let(:pact) { instance_double(PactBroker::Domain::Pact, json_content: json_content)} @@ -38,7 +38,7 @@ module Pacts allow_any_instance_of(Pacts::Repository).to receive(:find_previous_pact).and_return(previous_pact) end - subject { Service.pact_has_changed_since_previous_version? pact } + subject { Service.pact_is_new_or_pact_has_changed_since_previous_version? pact } context "when a previous pact is found" do let(:previous_pact) { instance_double(PactBroker::Domain::Pact, json_content: previous_json_content)} @@ -60,8 +60,9 @@ module Pacts context "when a previous pact is not found" do let(:previous_pact) { nil } - it "returns false" do - expect(subject).to be_falsey + + it "returns true" do + expect(subject).to be_truthy end end end