aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Claghorn <george.claghorn@gmail.com>2018-04-21 18:56:11 -0400
committerGitHub <noreply@github.com>2018-04-21 18:56:11 -0400
commit7452351815f0c49164c02368d12d28a83df5134d (patch)
tree77a50e6dd2032f4e7cfb6111320813eb468bbc63
parentf2151c3b3cc969ab95faccaae181ce10c4373cf7 (diff)
parent7a8d9649cdefe5706003e1e377e22722962dff22 (diff)
downloadrails-7452351815f0c49164c02368d12d28a83df5134d.tar.gz
rails-7452351815f0c49164c02368d12d28a83df5134d.tar.bz2
rails-7452351815f0c49164c02368d12d28a83df5134d.zip
Merge pull request #32673 from eugeneius/raw_post_multiple_requests
Reset RAW_POST_DATA between test requests
-rw-r--r--actionpack/lib/action_controller/test_case.rb9
-rw-r--r--actionpack/test/controller/test_case_test.rb8
2 files changed, 13 insertions, 4 deletions
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 798d142755..8f2a7e2b5f 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -460,10 +460,6 @@ module ActionController
def process(action, method: "GET", params: {}, session: nil, body: nil, flash: {}, format: nil, xhr: false, as: nil)
check_required_ivars
- if body
- @request.set_header "RAW_POST_DATA", body
- end
-
http_method = method.to_s.upcase
@html_document = nil
@@ -478,6 +474,10 @@ module ActionController
@response.request = @request
@controller.recycle!
+ if body
+ @request.set_header "RAW_POST_DATA", body
+ end
+
@request.set_header "REQUEST_METHOD", http_method
if as
@@ -604,6 +604,7 @@ module ActionController
env.delete "action_dispatch.request.query_parameters"
env.delete "action_dispatch.request.request_parameters"
env["rack.input"] = StringIO.new
+ env.delete "RAW_POST_DATA"
env
end
diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb
index d1122abba6..e66c409786 100644
--- a/actionpack/test/controller/test_case_test.rb
+++ b/actionpack/test/controller/test_case_test.rb
@@ -681,6 +681,14 @@ XML
assert_equal "baz", @request.filtered_parameters[:foo]
end
+ def test_raw_post_reset_between_post_requests
+ post :no_op, params: { foo: "bar" }
+ assert_equal "foo=bar", @request.raw_post
+
+ post :no_op, params: { foo: "baz" }
+ assert_equal "foo=baz", @request.raw_post
+ end
+
def test_path_is_kept_after_the_request
get :test_params, params: { id: "foo" }
assert_equal "/test_case_test/test/test_params/foo", @request.path