未验证 提交 140ec68c 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #33979 from lzap/master

Added ActionController::Parameters.each_value methods
......@@ -348,6 +348,14 @@ def each_pair(&block)
end
alias_method :each, :each_pair
# Convert all hashes in values into parameters, then yield each value in
# the same way as <tt>Hash#each_value</tt>.
def each_value(&block)
@parameters.each_pair do |key, value|
yield [convert_hashes_to_parameters(key, value)]
end
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.
......
......@@ -75,6 +75,24 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
end
end
test "each_value carries permitted status" do
@params.permit!
@params["person"].each_value { |value| assert(value.permitted?) if value == 32 }
end
test "each_value carries unpermitted status" do
@params["person"].each_value { |value| assert_not(value.permitted?) if value == 32 }
end
test "each_key converts to hash for permitted" do
@params.permit!
@params.each_key { |key| assert_kind_of(String, key) if key == "person" }
end
test "each_key converts to hash for unpermitted" do
@params.each_key { |key| assert_kind_of(String, key) if key == "person" }
end
test "empty? returns true when params contains no key/value pairs" do
params = ActionController::Parameters.new
assert_empty params
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册