Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

prevent errors when passing a frozen string as a param to ActionContr…

…oller::TestCase#process

since ActionDispatch::Http::Parameters#encode_params will force encoding on all params strings (when using an encoding aware Ruby), dup all strings passed into process.  This prevents modification of params passed in and, more importantly, doesn't barf when a frozen string is passed
thanks and high fives to kinsteronline
  • Loading branch information...
commit 78a4aea83e2fe5b2e544199d1af17bc5cbebcb42 1 parent 813e288
Trent Ogren misfo authored jeremy committed
4 actionpack/lib/action_controller/test_case.rb
View
@@ -146,7 +146,9 @@ def assign_parameters(routes, controller_path, action, parameters = {})
if value.is_a? Fixnum
value = value.to_s
elsif value.is_a? Array
- value = Result.new(value)
+ value = Result.new(value.map { |v| v.is_a?(String) ? v.dup : v })
+ elsif value.is_a? String
+ value = value.dup
end
if extra_keys.include?(key.to_sym)
12 actionpack/test/controller/test_test.rb
View
@@ -480,6 +480,18 @@ def test_params_passing
)
end
+ def test_params_passing_with_frozen_values
+ assert_nothing_raised do
+ get :test_params, :frozen => 'icy'.freeze, :frozens => ['icy'.freeze].freeze
+ end
+ parsed_params = eval(@response.body)
+ assert_equal(
+ {'controller' => 'test_test/test', 'action' => 'test_params',
+ 'frozen' => 'icy', 'frozens' => ['icy']},
+ parsed_params
+ )
+ end
+
def test_id_converted_to_string
get :test_params, :id => 20, :foo => Object.new
assert_kind_of String, @request.path_parameters['id']
Please sign in to comment.
Something went wrong with that request. Please try again.