1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

ActionController::Parameters#permit! is recursive

This commit is contained in:
Brendan Loudermilk 2012-10-04 11:51:08 -07:00
parent b0a7068564
commit 1aa522dc4e
3 changed files with 15 additions and 0 deletions

View file

@ -1,5 +1,8 @@
## Rails 4.0.0 (unreleased) ## ## Rails 4.0.0 (unreleased) ##
* `ActionController::Parameters#permit!` is now recursive. *Brendan
Loudermilk*
* `ActionController::Base.page_cache_extension` option is deprecated * `ActionController::Base.page_cache_extension` option is deprecated
in favour of `ActionController::Base.default_static_extension`. in favour of `ActionController::Base.default_static_extension`.

View file

@ -112,6 +112,11 @@ module ActionController
# params.permitted? # => true # params.permitted? # => true
# Person.new(params) # => #<Person id: nil, name: "Francesco"> # Person.new(params) # => #<Person id: nil, name: "Francesco">
def permit! 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 @permitted = true
self self
end end

View file

@ -57,6 +57,13 @@ class ParametersPermitTest < ActiveSupport::TestCase
assert_equal @params.permitted?, @params.dup.permitted? assert_equal @params.permitted?, @params.dup.permitted?
end 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 test "permitted takes a default value when Parameters.permit_all_parameters is set" do
begin begin
ActionController::Parameters.permit_all_parameters = true ActionController::Parameters.permit_all_parameters = true