Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pattern matching for parameters #51260

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions actionpack/lib/action_controller/metal/strong_parameters.rb
Expand Up @@ -398,6 +398,10 @@ def to_unsafe_h
end
alias_method :to_unsafe_hash, :to_unsafe_h

def deconstruct_keys(keys)
to_unsafe_h
end

# Convert all hashes in values into parameters, then yield each pair in the same
# way as `Hash#each_pair`.
def each_pair(&block)
Expand Down
16 changes: 16 additions & 0 deletions actionpack/test/controller/parameters/parameters_permit_test.rb
Expand Up @@ -529,6 +529,22 @@ def walk_permitted(params)
assert_not_predicate params[:f], :permitted?
end

test "deconstruct_keys matches string parameters" do
params = ActionController::Parameters.new("f" => { "language_facet" => ["Tibetan"] })
case params
in {"f": {"language_facet": }}
assert_equal ["Tibetan"], language_facet
end
end

test "deconstruct_keys matches symbol parameters" do
params = ActionController::Parameters.new("f" => { "language_facet" => ["Tibetan"] })
case params
in {f: {language_facet: }}
assert_equal ["Tibetan"], language_facet
end
end

test "to_h only deep dups Ruby collections" do
company = Class.new do
attr_reader :dupped
Expand Down