aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG.md5
-rw-r--r--actionpack/lib/action_controller/metal/strong_parameters.rb12
-rw-r--r--actionpack/test/controller/parameters/accessors_test.rb16
3 files changed, 24 insertions, 9 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index d9046f1431..32721ac233 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Calling `ActionController::Parameters#transform_keys/!` without a block now returns
+ an enumerator for the parameters instead of the underlying hash.
+
+ *Eugene Kenny*
+
* Fix strong parameters blocks all attributes even when only some keys are invalid (non-numerical). It should only block invalid key's values instead.
*Stan Lo*
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb
index 8bde82ccca..016a633f71 100644
--- a/actionpack/lib/action_controller/metal/strong_parameters.rb
+++ b/actionpack/lib/action_controller/metal/strong_parameters.rb
@@ -679,18 +679,16 @@ module ActionController
# 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
diff --git a/actionpack/test/controller/parameters/accessors_test.rb b/actionpack/test/controller/parameters/accessors_test.rb
index 7789e654d5..7b9b716a42 100644
--- a/actionpack/test/controller/parameters/accessors_test.rb
+++ b/actionpack/test/controller/parameters/accessors_test.rb
@@ -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