未验证 提交 57c9932e 编写于 作者: C Carlos Antonio da Silva 提交者: GitHub

Merge pull request #37753 from yoones/add_has_member_to_strong_parameters

Add params.member? to mimic Hash behavior
* Add `params.member?` to mimic Hash behavior
*Younes Serraj*
* `process_action.action_controller` notifications now include the following in their payloads:
* `:request` - the `ActionDispatch::Request`
......
......@@ -180,6 +180,14 @@ class Parameters
#
# Returns true if the given key is present in the parameters.
##
# :method: member?
#
# :call-seq:
# member?(key)
#
# Returns true if the given key is present in the parameters.
##
# :method: keys
#
......@@ -211,7 +219,7 @@ class Parameters
# values()
#
# Returns a new array of the values of the parameters.
delegate :keys, :key?, :has_key?, :values, :has_value?, :value?, :empty?, :include?,
delegate :keys, :key?, :has_key?, :member?, :values, :has_value?, :value?, :empty?, :include?,
:as_json, :to_s, :each_key, to: :@parameters
# By default, never raise an UnpermittedParameters exception if these
......
......@@ -162,6 +162,14 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
assert_not @params.key?(:address)
end
test "member? returns true if the given key is present in the params" do
assert @params.member?(:person)
end
test "member? returns false if the given key is not present in the params" do
assert_not @params.member?(:address)
end
test "keys returns an array of the keys of the params" do
assert_equal ["person"], @params.keys
assert_equal ["age", "name", "addresses"], @params[:person].keys
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册