Yield array from AC::Parameters#each for block with one arg

Matches Hash#each behaviour as used in Rails 4.
上级 ce37e164
......@@ -335,7 +335,7 @@ def to_unsafe_h
# the same way as <tt>Hash#each_pair</tt>.
def each_pair(&block)
@parameters.each_pair do |key, value|
yield key, convert_hashes_to_parameters(key, value)
yield [key, convert_hashes_to_parameters(key, value)]
end
end
alias_method :each, :each_pair
......
......@@ -51,6 +51,14 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
@params.each { |key, value| assert_not(value.permitted?) if key == "person" }
end
test "each returns key,value array for block with arity 1" do
@params.each do |arg|
assert_kind_of Array, arg
assert_equal "person", arg[0]
assert_kind_of ActionController::Parameters, arg[1]
end
end
test "each_pair carries permitted status" do
@params.permit!
@params.each_pair { |key, value| assert(value.permitted?) if key == "person" }
......@@ -60,6 +68,14 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
@params.each_pair { |key, value| assert_not(value.permitted?) if key == "person" }
end
test "each_pair returns key,value array for block with arity 1" do
@params.each_pair do |arg|
assert_kind_of Array, arg
assert_equal "person", arg[0]
assert_kind_of ActionController::Parameters, arg[1]
end
end
test "empty? returns true when params contains no key/value pairs" do
params = ActionController::Parameters.new
assert params.empty?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册