1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Delete PATH_INFO after each controller test request

Prevents PATH_INFO from being used to infer the request format in later
test requests when no explicit format is given.

As the request PATH_INFO may be set before a request, it can't be
deleted during pre-request scrubbing.

Fixes #27774
This commit is contained in:
Dominic Cleal 2017-01-20 14:33:52 +00:00
parent c309073c74
commit 13c7f2b537
No known key found for this signature in database
GPG key ID: 7C7D326F2C2B72CC
2 changed files with 15 additions and 0 deletions

View file

@ -534,6 +534,7 @@ module ActionController
@request.delete_header "HTTP_ACCEPT"
end
@request.query_string = ""
@request.env.delete "PATH_INFO"
@response.sent!
end

View file

@ -728,6 +728,20 @@ XML
assert_equal "text/html", @response.body
end
def test_request_path_info_and_format_reset
get :test_format, format: "json"
assert_equal "application/json", @response.body
get :test_uri, format: "json"
assert_equal "/test_case_test/test/test_uri.json", @response.body
get :test_format
assert_equal "text/html", @response.body
get :test_uri
assert_equal "/test_case_test/test/test_uri", @response.body
end
def test_request_format_kwarg_overrides_params
get :test_format, format: "json", params: { format: "html" }
assert_equal "application/json", @response.body