diff --git a/lib/pact_broker/api/resources/pacticipant.rb b/lib/pact_broker/api/resources/pacticipant.rb index 35db96806..89c9e8abe 100644 --- a/lib/pact_broker/api/resources/pacticipant.rb +++ b/lib/pact_broker/api/resources/pacticipant.rb @@ -11,7 +11,10 @@ def content_types_provided end def content_types_accepted - [["application/json", :from_json]] + [ + ["application/json", :from_json], + ["application/merge-patch+json", :from_merge_patch_json] + ] end def allowed_methods @@ -44,6 +47,14 @@ def from_json response.body = to_json end + def from_merge_patch_json + if request.patch? + from_json + else + 415 + end + end + def resource_exists? !!pacticipant end diff --git a/spec/features/update_pacticipant_spec.rb b/spec/features/update_pacticipant_spec.rb index 3a0be53ea..8eb2a37f1 100644 --- a/spec/features/update_pacticipant_spec.rb +++ b/spec/features/update_pacticipant_spec.rb @@ -43,6 +43,13 @@ context "when the pacticipant does not exist" do it { is_expected.to be_a_404_response } end + + context "with application/merge-patch+json" do + subject { put(path, request_body.to_json, {'CONTENT_TYPE' => 'application/merge-patch+json' }) } + + its(:status) { is_expected.to eq 415 } + end + end context "with a PATCH" do @@ -66,5 +73,26 @@ expect(subject.headers['Content-Type']).to eq "application/hal+json;charset=utf-8" end end + + context "with application/merge-patch+json" do + before do + td.create_pacticipant("Some Consumer", repository_name: "existing") + end + + subject { patch(path, request_body.to_json, {'CONTENT_TYPE' => 'application/merge-patch+json' }) } + + it "returns a 200 OK" do + puts subject.body unless subject.status == 200 + expect(subject.status).to be 200 + end + + it "leaves any existing properties that were not defined" do + expect(response_body_hash[:repositoryName]).to eq "existing" + end + + it "returns a json body with the updated pacticipant" do + expect(subject.headers['Content-Type']).to eq "application/hal+json;charset=utf-8" + end + end end end