test/requests/error_json_test.rb in rambulance-1.1.0 vs test/requests/error_json_test.rb in rambulance-1.1.1

- old
+ new

@@ -53,10 +53,29 @@ elsif Rails::VERSION::STRING >= '4.2.0' assert_equal 201, response.status end end + test 'returns an appropriate status based on the rails version when the HTTP Content-type header is malformed' do + if Rails::VERSION::STRING >= '5.1.0' + post '/users', headers: { "CONTENT_TYPE" => "charset=gbk" } + else + post '/users', nil, "CONTENT_TYPE" => "charset=gbk" + end + + if Rails::VERSION::STRING >= '6.0.0' + assert_equal 406, response.status + assert_equal "The requested content type is not acceptable.\n", response.body + elsif Rails::VERSION::STRING >= '5.2.0' + assert_equal 422, response.status + elsif Rails::VERSION::STRING >= '5.1.0' + assert_equal 500, response.status + elsif Rails::VERSION::STRING >= '4.2.0' + assert_equal 201, response.status + end + end + private def without_layouts `mv test/fake_app/app/views/layouts/application.html.erb .` `mv test/fake_app/app/views/layouts/error.html.erb .` @@ -65,15 +84,15 @@ ensure `mv application.html.erb test/fake_app/app/views/layouts/` `mv error.html.erb test/fake_app/app/views/layouts/` end - def get(path) + def get(path, params: {}, headers: {}) without_layouts do if Rails::VERSION::STRING >= '5.1.0' - super path, headers: { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" } + super path, params: params, headers: { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" }.merge(headers) else - super path, nil, "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" + super path, params, { "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" }.merge(headers) end end end def json_response