Permalink
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...
misfo authored and jeremy committed Feb 8, 2011
1 parent 813e288 commit 78a4aea83e2fe5b2e544199d1af17bc5cbebcb42
Showing with 15 additions and 1 deletion.
  1. +3 −1 actionpack/lib/action_controller/test_case.rb
  2. +12 −0 actionpack/test/controller/test_test.rb
@@ -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)
@@ -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']

0 comments on commit 78a4aea

Please sign in to comment.