Skip to content

Commit df4c526

Browse files
committed
Create a test that shows bug ruby-grape#1403
I have created an example that shows that even if it is setted `format :json`, if I send a post request with content_type: application/x-www-form-urlencoded it does return `201`
1 parent dc39328 commit df4c526

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

spec/grape/endpoint_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,18 @@ def app
652652
expect(last_response.body).to eq('{"error":"The requested content-type \'application/xml\' is not supported."}')
653653
end
654654

655+
it 'responds with a 406 for an unsupported content-type for a post request' do
656+
subject.format :json
657+
# subject.content_type :json, "application/json"
658+
subject.post '/request_body' do
659+
params[:user]
660+
end
661+
post '/request_body', 'user=ciao', 'CONTENT_TYPE' => 'application/x-www-form-urlencoded'
662+
expect(last_request.content_type).to eq('application/x-www-form-urlencoded')
663+
expect(last_response.status).to eq(406)
664+
expect(last_response.body).to eq('{"error":"The requested content-type \'application/xml\' is not supported."}')
665+
end
666+
655667
context 'content type with params' do
656668
before do
657669
subject.format :json

0 commit comments

Comments
 (0)