aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/metal/strong_parameters.rb7
-rw-r--r--actionpack/test/controller/parameters/dup_test.rb22
2 files changed, 29 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb
index 4db30e64b4..b64617d084 100644
--- a/actionpack/lib/action_controller/metal/strong_parameters.rb
+++ b/actionpack/lib/action_controller/metal/strong_parameters.rb
@@ -613,6 +613,13 @@ module ActionController
undef_method :to_param
+ # Returns duplicate of object including all parameters
+ def deep_dup
+ self.class.new(@parameters.deep_dup).tap do |duplicate|
+ duplicate.permitted = @permitted
+ end
+ end
+
protected
attr_reader :parameters
diff --git a/actionpack/test/controller/parameters/dup_test.rb b/actionpack/test/controller/parameters/dup_test.rb
index d88891ca30..fb707a1354 100644
--- a/actionpack/test/controller/parameters/dup_test.rb
+++ b/actionpack/test/controller/parameters/dup_test.rb
@@ -1,5 +1,6 @@
require "abstract_unit"
require "action_controller/metal/strong_parameters"
+require "active_support/core_ext/object/deep_dup"
class ParametersDupTest < ActiveSupport::TestCase
setup do
@@ -40,4 +41,25 @@ class ParametersDupTest < ActiveSupport::TestCase
dupped_params.permit!
assert_not_equal @params, dupped_params
end
+
+ test "deep_dup content" do
+ dupped_params = @params.deep_dup
+ dupped_params[:person][:age] = "45"
+ dupped_params[:person][:addresses].clear
+
+ assert_not_equal @params[:person][:age], dupped_params[:person][:age]
+ assert_not_equal @params[:person][:addresses], dupped_params[:person][:addresses]
+ end
+
+ test "deep_dup @permitted" do
+ dupped_params = @params.deep_dup
+ dupped_params.permit!
+
+ assert_not @params.permitted?
+ end
+
+ test "deep_dup @permitted is being copied" do
+ @params.permit!
+ assert @params.deep_dup.permitted?
+ end
end