Skip to content

Commit

Permalink
fix: correct all content types that were application/json to applicat…
Browse files Browse the repository at this point in the history
…ion/hal+json
  • Loading branch information
bethesque committed Jun 4, 2018
1 parent a4ce4c2 commit 690e39b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/pact_broker/api/resources/base_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ def pact_params
end

def set_json_error_message message
response.headers['Content-Type'] = 'application/json;charset=utf-8'
response.headers['Content-Type'] = 'application/hal+json;charset=utf-8'
response.body = {error: message}.to_json
end

def set_json_validation_error_messages errors
response.headers['Content-Type'] = 'application/json;charset=utf-8'
response.headers['Content-Type'] = 'application/hal+json;charset=utf-8'
response.body = {errors: errors}.to_json
end

Expand All @@ -128,7 +128,7 @@ def invalid_json?
rescue StandardError => e
logger.error "Error parsing JSON #{e} - #{request_body}"
set_json_error_message "Error parsing JSON - #{e.message}"
response.headers['Content-Type'] = 'application/json;charset=utf-8'
response.headers['Content-Type'] = 'application/hal+json;charset=utf-8'
true
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/api/resources/pact_webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def validation_errors? webhook
errors = webhook_service.errors(webhook)

unless errors.empty?
response.headers['Content-Type'] = 'application/json;charset=utf-8'
response.headers['Content-Type'] = 'application/hal+json;charset=utf-8'
response.body = { errors: errors.messages }.to_json
end

Expand Down
2 changes: 1 addition & 1 deletion spec/features/create_webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

it "returns a JSON content type" do
subject
expect(last_response.headers['Content-Type']).to eq 'application/json;charset=utf-8'
expect(last_response.headers['Content-Type']).to eq 'application/hal+json;charset=utf-8'
end

it "returns the validation errors" do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact_broker/api/resources/pact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module Resources
end

it "returns a JSON content type" do
expect(response.headers['Content-Type']).to eq "application/json;charset=utf-8"
expect(response.headers['Content-Type']).to eq "application/hal+json;charset=utf-8"
end

it "returns an error message" do
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/pact_broker/api/resources/pact_webhooks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module Resources

it "returns a JSON content type" do
subject
expect(last_response.headers['Content-Type']).to eq 'application/json;charset=utf-8'
expect(last_response.headers['Content-Type']).to eq 'application/hal+json;charset=utf-8'
end

it "returns an error message" do
Expand All @@ -111,7 +111,7 @@ module Resources

it "returns a JSON content type" do
subject
expect(last_response.headers['Content-Type']).to eq 'application/json;charset=utf-8'
expect(last_response.headers['Content-Type']).to eq 'application/hal+json;charset=utf-8'
end

it "returns an error message" do
Expand All @@ -132,7 +132,7 @@ module Resources

it "returns a JSON content type" do
subject
expect(last_response.headers['Content-Type']).to eq 'application/json;charset=utf-8'
expect(last_response.headers['Content-Type']).to eq 'application/hal+json;charset=utf-8'
end

it "returns the validation errors" do
Expand Down
4 changes: 2 additions & 2 deletions spec/support/shared_examples_for_responses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@

RSpec::Matchers.define :be_a_json_response do
match do | actual |
expect(actual.headers['Content-Type']).to eq 'application/json;charset=utf-8'
expect(actual.headers['Content-Type']).to eq 'application/hal+json;charset=utf-8'
end
end

RSpec::Matchers.define :be_a_json_error_response do | message |
match do | actual |
expect(actual.status).to be 400
expect(actual.headers['Content-Type']).to eq 'application/json;charset=utf-8'
expect(actual.headers['Content-Type']).to eq 'application/hal+json;charset=utf-8'
expect(actual.body).to include message
end
end
Expand Down

0 comments on commit 690e39b

Please sign in to comment.