Skip to content

Commit

Permalink
Add params.member? to mimic Hash behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
yoones committed Nov 19, 2019
1 parent f2df777 commit 34b6e8c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,3 +1,7 @@
* 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`
Expand Down
10 changes: 9 additions & 1 deletion actionpack/lib/action_controller/metal/strong_parameters.rb
Expand Up @@ -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
#
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/controller/parameters/accessors_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 34b6e8c

Please sign in to comment.