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

Deprecate AC::Parameters#== with a Hash

This commit is contained in:
Benjamin Quorning 2016-02-17 14:48:35 +01:00
parent 08fd9f4f11
commit 30440363c0
2 changed files with 18 additions and 11 deletions

View file

@ -144,16 +144,21 @@ module ActionController
end
# Returns true if another +Parameters+ object contains the same content and
# permitted flag, or other Hash-like object contains the same content.
def ==(other_hash)
if other_hash.respond_to?(:permitted?)
self.permitted? == other_hash.permitted? && self.parameters == other_hash.parameters
# permitted flag.
def ==(other)
if other.respond_to?(:permitted?)
self.permitted? == other.permitted? && self.parameters == other.parameters
elsif other.is_a?(Hash)
ActiveSupport::Deprecation.warn <<-WARNING.squish
Comparing equality between `ActionController::Parameters` and a
`Hash` is deprecated and will be removed in Rails 5.1. Please only do
comparisons between instances of `ActionController::Parameters`. If
you need to compare to a hash, first convert it using
`ActionController::Parameters#new`.
WARNING
@parameters == other.with_indifferent_access
else
if other_hash.is_a?(Hash)
@parameters == other_hash.with_indifferent_access
else
@parameters == other_hash
end
@parameters == other
end
end

View file

@ -129,10 +129,12 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
assert_not @params[:person].values_at(:name).first.permitted?
end
test "equality with another hash works" do
test "equality with a hash is deprecated" do
hash1 = { foo: :bar }
params1 = ActionController::Parameters.new(hash1)
assert(params1 == hash1)
assert_deprecated("will be removed in Rails 5.1") do
assert(params1 == hash1)
end
end
test "is equal to Parameters instance with same params" do