lib/pact_broker/api/resources/pact.rb in pact_broker-1.9.3 vs lib/pact_broker/api/resources/pact.rb in pact_broker-1.10.0

- old
+ new

@@ -4,10 +4,18 @@ require 'pact_broker/api/decorators/pact_decorator' require 'pact_broker/json' require 'pact_broker/pacts/pact_params' require 'pact_broker/api/contracts/put_pact_params_contract' +module Webmachine + class Request + def patch? + method == "PATCH" + end + end +end + module PactBroker module Api module Resources @@ -22,33 +30,43 @@ def content_types_accepted [["application/json", :from_json]] end def allowed_methods - ["GET", "PUT", "DELETE"] + ["GET", "PUT", "DELETE", "PATCH"] end + def known_methods + super + ['PATCH'] + end + def is_conflict? potential_duplicate_pacticipants?(pact_params.pacticipant_names) end def malformed_request? - if request.put? - return invalid_json? || + if request.patch? || request.put? + invalid_json? || contract_validation_errors?(Contracts::PutPactParamsContract.new(pact_params)) else false end end def resource_exists? - pact + !!pact end def from_json response_code = pact ? 200 : 201 - @pact = pact_service.create_or_update_pact(pact_params) + + if request.patch? && resource_exists? + @pact = pact_service.merge_pact(pact_params) + else + @pact = pact_service.create_or_update_pact(pact_params) + end + response.body = to_json response_code end def to_json @@ -71,6 +89,6 @@ end end end end -end \ No newline at end of file +end