提交 a0c39ff8 编写于 作者: R Ryuta Kamizono

Merge pull request #36302 from eugeneius/parameters_transform_keys_enumerator

Return parameters enumerator from transform_keys/!
上级 8988b42e
* Calling `ActionController::Parameters#transform_keys/!` without a block now returns
an enumerator for the parameters instead of the underlying hash.
*Eugene Kenny*
* Fix a bug where DebugExceptions throws an error when malformed query parameters are provided
*Yuki Nishijima*, *Stan Lo*
## Rails 6.0.0.rc1 (April 24, 2019) ##
* Make system tests take a failed screenshot in a `before_teardown` hook
......
......@@ -673,18 +673,16 @@ def transform_values!
# Returns a new <tt>ActionController::Parameters</tt> instance with the
# results of running +block+ once for every key. The values are unchanged.
def transform_keys(&block)
if block
new_instance_with_inherited_permitted_status(
@parameters.transform_keys(&block)
)
else
@parameters.transform_keys
end
return to_enum(:transform_keys) unless block_given?
new_instance_with_inherited_permitted_status(
@parameters.transform_keys(&block)
)
end
# Performs keys transformation and returns the altered
# <tt>ActionController::Parameters</tt> instance.
def transform_keys!(&block)
return to_enum(:transform_keys!) unless block_given?
@parameters.transform_keys!(&block)
self
end
......
......@@ -203,6 +203,16 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
assert_not_predicate @params.transform_keys { |k| k }, :permitted?
end
test "transform_keys without a block returns an enumerator" do
assert_kind_of Enumerator, @params.transform_keys
assert_kind_of ActionController::Parameters, @params.transform_keys.each { |k| k }
end
test "transform_keys! without a block returns an enumerator" do
assert_kind_of Enumerator, @params.transform_keys!
assert_kind_of ActionController::Parameters, @params.transform_keys!.each { |k| k }
end
test "transform_values retains permitted status" do
@params.permit!
assert_predicate @params.transform_values { |v| v }, :permitted?
......@@ -219,8 +229,9 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
end
end
test "transform_values without block yieds an enumerator" do
test "transform_values without a block returns an enumerator" do
assert_kind_of Enumerator, @params.transform_values
assert_kind_of ActionController::Parameters, @params.transform_values.each { |v| v }
end
test "transform_values! converts hashes to parameters" do
......@@ -229,8 +240,9 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
end
end
test "transform_values! without block yields an enumerator" do
test "transform_values! without a block returns an enumerator" do
assert_kind_of Enumerator, @params.transform_values!
assert_kind_of ActionController::Parameters, @params.transform_values!.each { |v| v }
end
test "value? returns true if the given value is present in the params" do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册