提交 6d7f35ec 编写于 作者: Y yuuji.yaginuma

add `ActionController::Parameters#merge!`

This method has the same behavior as `Hash#merge!`, returns current
`ActionController::Parameters`.
上级 8e76f695
* Add `ActionController::Parameters#merge!`, which behaves the same as `Hash#merge!`.
*Yuji Yaginuma*
* Allow keys not found in RACK_KEY_TRANSLATION for setting the environment when rendering
arbitrary templates.
......
......@@ -573,6 +573,13 @@ def merge(other_hash)
)
end
# Returns current <tt>ActionController::Parameters</tt> instance which
# +other_hash+ merges into current hash.
def merge!(other_hash)
@parameters.merge!(other_hash.to_h)
self
end
# This is required by ActiveModel attribute assignment, so that user can
# pass +Parameters+ to a mass assignment methods in a model. It should not
# matter as we are using +HashWithIndifferentAccess+ internally.
......
......@@ -244,6 +244,23 @@ def walk_permitted(params)
assert merged_params[:id]
end
test "not permitted is sticky beyond merge!" do
assert_not @params.merge!(a: "b").permitted?
end
test "permitted is sticky beyond merge!" do
@params.permit!
assert @params.merge!(a: "b").permitted?
end
test "merge! with parameters" do
other_params = ActionController::Parameters.new(id: "1234").permit!
@params.merge!(other_params)
assert_equal "1234", @params[:id]
assert_equal "32", @params[:person][:age]
end
test "modifying the parameters" do
@params[:person][:hometown] = "Chicago"
@params[:person][:family] = { brother: "Jonas" }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册