From 9277e72a3ca1009f135b1eb194ff6f3c96a55c1b Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sun, 22 May 2011 02:47:54 -0400 Subject: Stringify param values in controller tests. This reduces false positives that come from using ints in params in tests, which do not get converted to strings in the tests. In implementations going through rack, they do get converted to strings. - David Chelimsky and Sam Umbach --- actionpack/lib/action_controller/test_case.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'actionpack/lib/action_controller/test_case.rb') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 89ff5ba174..9c1f77ec91 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -395,7 +395,26 @@ module ActionController end alias xhr :xml_http_request + def stringify_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] = stringify_values(value) + end + when Array + hash_or_array_or_value.map {|i| stringify_values(i)} + when Numeric, Symbol + hash_or_array_or_value.to_s + else + hash_or_array_or_value + end + end + def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') + # Ensure that numbers and symbols passed as params are converted to + # strings, as is the case when engaging rack. + stringify_values(parameters) + # Sanity check for required instance variables so we can give an # understandable error message. %w(@routes @controller @request @response).each do |iv_name| -- cgit v1.2.3 From 3f0c71c8524856c32bc056bdb38136b3d18f2aaf Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sun, 22 May 2011 08:11:54 -0400 Subject: use to_param (and change method to name accordingly) - exclude Rack::Test::UploadedFile to pass existing tests. Are there any other types we're missing? --- actionpack/lib/action_controller/test_case.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_controller/test_case.rb') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 9c1f77ec91..639e24c995 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -395,25 +395,25 @@ module ActionController end alias xhr :xml_http_request - def stringify_values(hash_or_array_or_value) + 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] = stringify_values(value) + hash_or_array_or_value[key] = paramify_values(value) end when Array - hash_or_array_or_value.map {|i| stringify_values(i)} - when Numeric, Symbol - hash_or_array_or_value.to_s - else + hash_or_array_or_value.map {|i| paramify_values(i)} + when Rack::Test::UploadedFile hash_or_array_or_value + else + hash_or_array_or_value.to_param end end def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') # Ensure that numbers and symbols passed as params are converted to - # strings, as is the case when engaging rack. - stringify_values(parameters) + # proper params, as is the case when engaging rack. + paramify_values(parameters) # Sanity check for required instance variables so we can give an # understandable error message. -- cgit v1.2.3