Don't delegate ActionController::Parameters#values to hash

Instead, cast any nested hashes into ActionController::Parameters.
This commit is contained in:
Gannon McGibbon 2022-03-31 18:10:23 -04:00
parent 68d07c31e6
commit aba6008850
3 changed files with 13 additions and 12 deletions

View File

@ -1,3 +1,7 @@
* Make ActionController::Parameters#values cast nested hashes into parameters.
*Gannon McGibbon*
* Introduce `html:` and `screenshot:` kwargs for system test screenshot helper
Use these as an alternative to the already-available environment variables.

View File

@ -222,15 +222,7 @@ module ActionController
# value?(value)
#
# Returns true if the given value is present for some key in the parameters.
##
# :method: values
#
# :call-seq:
# values()
#
# Returns a new array of the values of the parameters.
delegate :keys, :key?, :has_key?, :member?, :values, :has_value?, :value?, :empty?, :include?,
delegate :keys, :key?, :has_key?, :member?, :has_value?, :value?, :empty?, :include?,
:as_json, :to_s, :each_key, to: :@parameters
# By default, never raise an UnpermittedParameters exception if these
@ -403,6 +395,11 @@ module ActionController
self
end
# Returns a new array of the values of the parameters.
def values
to_enum(:each_value).to_a
end
# Attribute that keeps track of converted arrays, if any, to avoid double
# looping in the common use case permit + mass-assignment. Defined in a
# method to instantiate it only if needed.

View File

@ -312,8 +312,8 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
end
test "values returns an array of the values of the params" do
params = ActionController::Parameters.new(city: "Chicago", state: "Illinois")
assert_equal ["Chicago", "Illinois"], params.values
params = ActionController::Parameters.new(city: "Chicago", state: "Illinois", person: ActionController::Parameters.new(first_name: "David"))
assert_equal ["Chicago", "Illinois", ActionController::Parameters.new(first_name: "David")], params.values
end
test "values_at retains permitted status" do