From 700c55831f993d52dcc1eb301346fbcfd54b82d9 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 7 Sep 2016 16:16:39 +0900 Subject: call `.to_h` to avoid using deprecated method `ActionController::Parameters#merge` call `HashWithIndifferentAccess#merge`. In addition, it calls `HashWithIndifferentAccess#update` from `HashWithIndifferentAccess#merge`, where it is called the `#to_hash` of argument. But `ActionController::Parameters#to_hash` is deprecated, warning message is displayed. To avoid this, modify to convert object to `Hash`. Fixes #26415 --- actionpack/lib/action_controller/metal/strong_parameters.rb | 2 +- actionpack/test/controller/parameters/parameters_permit_test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index dea4657988..387c2aa0b9 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -578,7 +578,7 @@ module ActionController # +other_hash+ merges into current hash. def merge(other_hash) new_instance_with_inherited_permitted_status( - @parameters.merge(other_hash) + @parameters.merge(other_hash.to_h) ) end diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb index 164efd936c..728d8e1279 100644 --- a/actionpack/test/controller/parameters/parameters_permit_test.rb +++ b/actionpack/test/controller/parameters/parameters_permit_test.rb @@ -237,6 +237,13 @@ class ParametersPermitTest < ActiveSupport::TestCase assert @params.merge(a: "b").permitted? end + test "merge with parameters" do + other_params = ActionController::Parameters.new(id: "1234").permit! + merged_params = @params.merge(other_params) + + assert merged_params[:id] + end + test "modifying the parameters" do @params[:person][:hometown] = "Chicago" @params[:person][:family] = { brother: "Jonas" } -- cgit v1.2.3