aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/parameters
diff options
context:
space:
mode:
authorRoque Pinel <repinel@gmail.com>2015-07-18 18:40:47 -0400
committerRoque Pinel <repinel@gmail.com>2015-07-18 18:48:41 -0400
commit780af27bf9135be8cc4ae1a9c1ce4c9b4d15fd4b (patch)
tree1f49133cf02551eae7cff44260c92d03d0db10e5 /actionpack/test/controller/parameters
parent3f1c5d39c01e13bcf9e34865f00ded56a3a321fc (diff)
downloadrails-780af27bf9135be8cc4ae1a9c1ce4c9b4d15fd4b.tar.gz
rails-780af27bf9135be8cc4ae1a9c1ce4c9b4d15fd4b.tar.bz2
rails-780af27bf9135be8cc4ae1a9c1ce4c9b4d15fd4b.zip
Fix exception overwritten for parameters fetch method
When executing an `ActionController::Parameters#fetch` with a block that raises a `KeyError` the raised `KeyError` will be rescued and converted to an `ActionController::ParameterMissing` exception, covering up the original exception. [Jonas Schubert Erlandsson & Roque Pinel]
Diffstat (limited to 'actionpack/test/controller/parameters')
-rw-r--r--actionpack/test/controller/parameters/parameters_permit_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb
index 05532ec21b..2dd2826196 100644
--- a/actionpack/test/controller/parameters/parameters_permit_test.rb
+++ b/actionpack/test/controller/parameters/parameters_permit_test.rb
@@ -194,6 +194,19 @@ class ParametersPermitTest < ActiveSupport::TestCase
assert_equal "monkey", @params.fetch(:foo) { "monkey" }
end
+ test "fetch doesnt raise ParameterMissing exception if there is a default that is nil" do
+ assert_equal nil, @params.fetch(:foo, nil)
+ assert_equal nil, @params.fetch(:foo) { nil }
+ end
+
+ test 'KeyError in fetch block should not be coverd up' do
+ params = ActionController::Parameters.new
+ e = assert_raises(KeyError) do
+ params.fetch(:missing_key) { {}.fetch(:also_missing) }
+ end
+ assert_match(/:also_missing$/, e.message)
+ end
+
test "not permitted is sticky beyond merges" do
assert !@params.merge(a: "b").permitted?
end