Skip to content

Commit

Permalink
Don't modify params in place - fixes rails#2624
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltrix authored and spastorino committed Aug 25, 2011
1 parent 5978fae commit 283f597
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 3 additions & 5 deletions actionpack/lib/action_controller/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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?
Expand Down
6 changes: 6 additions & 0 deletions actionpack/test/controller/test_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,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']
Expand Down

0 comments on commit 283f597

Please sign in to comment.