diff options
author | David Chelimsky <dchelimsky@gmail.com> | 2011-05-22 02:47:54 -0400 |
---|---|---|
committer | David Chelimsky <dchelimsky@gmail.com> | 2011-05-22 02:47:54 -0400 |
commit | 9277e72a3ca1009f135b1eb194ff6f3c96a55c1b (patch) | |
tree | 91bbab1fccb733422f420f333ab38daf6e98bddc /actionpack/lib/action_controller | |
parent | 82857adc56efd16d22821971fff4c5e24a3c5b55 (diff) | |
download | rails-9277e72a3ca1009f135b1eb194ff6f3c96a55c1b.tar.gz rails-9277e72a3ca1009f135b1eb194ff6f3c96a55c1b.tar.bz2 rails-9277e72a3ca1009f135b1eb194ff6f3c96a55c1b.zip |
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
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 19 |
1 files changed, 19 insertions, 0 deletions
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| |