From 7a8d9649cdefe5706003e1e377e22722962dff22 Mon Sep 17 00:00:00 2001
From: Eugene Kenny <elkenny@gmail.com>
Date: Fri, 20 Apr 2018 19:56:28 -0400
Subject: Reset RAW_POST_DATA between test requests

`RAW_POST_DATA` is derived from the `rack.input` header, which changes
with each test request. It needs to be cleared in `scrub_env!`, or all
requests within the same test will see the value from the first request.
---
 actionpack/lib/action_controller/test_case.rb | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

(limited to 'actionpack/lib')

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
 
-- 
cgit v1.2.3