Ensure errors are always returned in JSON in API

This commit is contained in:
Thibault Jouan 2015-05-01 22:07:55 +00:00
parent 5b9d36cb39
commit 57ea6ca0df
2 changed files with 4 additions and 1 deletions

View File

@ -37,7 +37,9 @@ module API
end
def json_filter!
head :not_acceptable if request.format != :json
if request.format != :json
head :not_acceptable, content_type: 'application/json'
end
end
end
end

View File

@ -15,6 +15,7 @@ describe 'API application' do
it 'responds with a 406 when request format is not JSON' do
get api_ping_path, format: :xml
expect(response.status).to be 406
expect(response.content_type).to eq :json
expect(response.body).to be_empty
end
end