Permalink
Browse files

ActionController::Parameters#permit! is recursive

  • Loading branch information...
1 parent b0a7068 commit 1aa522dc4e00fdd54b1e1e38ad74311483849fcb @bloudermilk bloudermilk committed Oct 4, 2012
View
@@ -1,5 +1,8 @@
## Rails 4.0.0 (unreleased) ##
+* `ActionController::Parameters#permit!` is now recursive. *Brendan
+ Loudermilk*
+
* `ActionController::Base.page_cache_extension` option is deprecated
in favour of `ActionController::Base.default_static_extension`.
@@ -112,6 +112,11 @@ def permitted?
# params.permitted? # => true
# Person.new(params) # => #<Person id: nil, name: "Francesco">
def permit!
+ each_pair do |key, value|
+ convert_hashes_to_parameters(key, value)
+ self[key].permit! if self[key].respond_to? :permit!
+ end
+
@permitted = true
self
end
@@ -57,6 +57,13 @@ class ParametersPermitTest < ActiveSupport::TestCase
assert_equal @params.permitted?, @params.dup.permitted?
end
+ test "permit is recursive" do
+ @params.permit!
+ assert @params.permitted?
+ assert @params[:person].permitted?
+ assert @params[:person][:name].permitted?
+ end
+
test "permitted takes a default value when Parameters.permit_all_parameters is set" do
begin
ActionController::Parameters.permit_all_parameters = true

0 comments on commit 1aa522d

Please sign in to comment.