Skip to content
Browse files

Don't modify params in place - fixes #2624

(cherry picked from commit 14cf4b2)
  • Loading branch information...
1 parent b938b04 commit 2af37b0fdd531a6efbaf76c636270b2e7f12aba1 @pixeltrix pixeltrix committed Aug 23, 2011
Showing with 9 additions and 5 deletions.
  1. +3 −5 actionpack/lib/action_controller/test_case.rb
  2. +6 −0 actionpack/test/controller/test_test.rb
View
8 actionpack/lib/action_controller/test_case.rb
@@ -398,9 +398,7 @@ def xml_http_request(request_method, action, parameters = nil, session = nil, fl
def paramify_values(hash_or_array_or_value)
case hash_or_array_or_value
when Hash
- hash_or_array_or_value.each do |key, value|
- hash_or_array_or_value[key] = paramify_values(value)
- end
+ Hash[hash_or_array_or_value.map{|key, value| [key, paramify_values(value)] }]
when Array
hash_or_array_or_value.map {|i| paramify_values(i)}
when Rack::Test::UploadedFile
@@ -413,7 +411,7 @@ def paramify_values(hash_or_array_or_value)
def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
# Ensure that numbers and symbols passed as params are converted to
# proper params, as is the case when engaging rack.
- paramify_values(parameters)
+ parameters = paramify_values(parameters)
# Sanity check for required instance variables so we can give an
# understandable error message.
@@ -447,7 +445,7 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =
@controller.params.merge!(parameters)
build_request_uri(action, parameters)
@controller.class.class_eval { include Testing }
- @controller.recycle!
+ @controller.recycle!
@controller.process_with_new_base_test(@request, @response)
@assigns = @controller.respond_to?(:view_assigns) ? @controller.view_assigns : {}
@request.session.delete('flash') if @request.session['flash'].blank?
View
6 actionpack/test/controller/test_test.rb
@@ -515,6 +515,12 @@ def test_params_passing_with_frozen_values
)
end
+ def test_params_passing_doesnt_modify_in_place
+ page = {:name => "Page name", :month => 4, :year => 2004, :day => 6}
+ get :test_params, :page => page
+ assert_equal 2004, page[:year]
+ end
+
def test_id_converted_to_string
get :test_params, :id => 20, :foo => Object.new
assert_kind_of String, @request.path_parameters['id']

0 comments on commit 2af37b0

Please sign in to comment.
Something went wrong with that request. Please try again.