Merge pull request #27790 from domcleal/ac-params-each-yields
Yield array from AC::Parameters#each for block with one arg
This commit is contained in:
commit
5d337fe386
@ -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?
|
||||
|
Loading…
Reference in New Issue
Block a user