diff options
author | Dominic Cleal <dominic@cleal.org> | 2017-01-24 10:55:43 +0000 |
---|---|---|
committer | Dominic Cleal <dominic@cleal.org> | 2017-12-06 14:50:35 +0000 |
commit | d7a121a0d624dd8180556521f0611d4c8e2c648f (patch) | |
tree | 4743d2db9cf6ee807b1e8e7560a369d0002d6fc4 | |
parent | ce37e1643a62436a7c0ce059def4c5d9c72f7367 (diff) | |
download | rails-d7a121a0d624dd8180556521f0611d4c8e2c648f.tar.gz rails-d7a121a0d624dd8180556521f0611d4c8e2c648f.tar.bz2 rails-d7a121a0d624dd8180556521f0611d4c8e2c648f.zip |
Yield array from AC::Parameters#each for block with one arg
Matches Hash#each behaviour as used in Rails 4.
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/parameters/accessors_test.rb | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index ef7c4c4c16..a56ac749f8 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -335,7 +335,7 @@ module ActionController # 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 diff --git a/actionpack/test/controller/parameters/accessors_test.rb b/actionpack/test/controller/parameters/accessors_test.rb index 43cabae7d2..154430d4b0 100644 --- a/actionpack/test/controller/parameters/accessors_test.rb +++ b/actionpack/test/controller/parameters/accessors_test.rb @@ -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? |