Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clear filtered request attributes between requests in tests

The request attributes filtered_parameters, filtered_env and filtered_path
are memoized for performance reasons. However this can cause unusual
behavior in tests where there are multiple calls to get, post, etc.

Fixes #13803.

(cherry picked from commit 3161606)
  • Loading branch information...
commit b5a6b6a995c0984e01c29f630fc3915ae667f68b 1 parent b942b2e
@pixeltrix pixeltrix authored
View
7 actionpack/CHANGELOG.md
@@ -1,3 +1,10 @@
+* Ensure that `request.filtered_parameters` is reset between calls to `process`
+ in `ActionController::TestCase`.
+
+ Fixes #13803.
+
+ *Andrew White*
+
* Fix `rake routes` error when `Rails::Engine` with empty routes is mounted.
Fixes #13810.
View
3  actionpack/lib/action_controller/test_case.rb
@@ -213,6 +213,9 @@ def assign_parameters(routes, controller_path, action, parameters = {})
# Clear the combined params hash in case it was already referenced.
@env.delete("action_dispatch.request.parameters")
+ # Clear the filter cache variables so they're not stale
+ @filtered_parameters = @filtered_env = @filtered_path = nil
+
params = self.request_parameters.dup
%w(controller action only_path).each do |k|
params.delete(k)
View
11 actionpack/test/controller/log_subscriber_test.rb
@@ -137,6 +137,17 @@ def test_process_action_with_parameters
assert_equal 'Parameters: {"id"=>"10"}', logs[1]
end
+ def test_multiple_process_with_parameters
+ get :show, :id => '10'
+ get :show, :id => '20'
+
+ wait
+
+ assert_equal 6, logs.size
+ assert_equal 'Parameters: {"id"=>"10"}', logs[1]
+ assert_equal 'Parameters: {"id"=>"20"}', logs[4]
+ end
+
def test_process_action_with_wrapped_parameters
@request.env['CONTENT_TYPE'] = 'application/json'
post :show, :id => '10', :name => 'jose'
View
8 actionpack/test/controller/test_case_test.rb
@@ -712,6 +712,14 @@ def test_params_reset_after_post_request
assert @request.params[:foo].blank?
end
+ def test_filtered_parameters_reset_between_requests
+ get :no_op, :foo => "bar"
+ assert_equal "bar", @request.filtered_parameters[:foo]
+
+ get :no_op, :foo => "baz"
+ assert_equal "baz", @request.filtered_parameters[:foo]
+ end
+
def test_symbolized_path_params_reset_after_request
get :test_params, :id => "foo"
assert_equal "foo", @request.symbolized_path_parameters[:id]
Please sign in to comment.
Something went wrong with that request. Please try again.