提交 01f0c3f3 编写于 作者: C Carlos Antonio da Silva

Remove deprecated Hash#diff with no replacement.

If you're using it to compare hashes for the purpose of testing,
please use MiniTest's assert_equal instead.
上级 b296edd2
* Remove deprecated `Hash#diff` with no replacement.
If you're using it to compare hashes for the purpose of testing, please use
MiniTest's `assert_equal` instead.
*Carlos Antonio da Silva*
* Remove deprecated `Date#to_time_in_current_zone` in favour of `Date#in_time_zone`.
*Vipul A M*
......
require 'active_support/core_ext/hash/conversions'
require 'active_support/core_ext/hash/deep_merge'
require 'active_support/core_ext/hash/diff'
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/hash/keys'
......
require 'active_support/deprecation'
class Hash
# Returns a hash that represents the difference between two hashes.
#
# {1 => 2}.diff(1 => 2) # => {}
# {1 => 2}.diff(1 => 3) # => {1 => 2}
# {}.diff(1 => 2) # => {1 => 2}
# {1 => 2, 3 => 4}.diff(1 => 2) # => {3 => 4}
def diff(other)
ActiveSupport::Deprecation.warn "Hash#diff is no longer used inside of Rails, and is being deprecated with no replacement. If you're using it to compare hashes for the purpose of testing, please use MiniTest's assert_equal instead."
dup.
delete_if { |k, v| other[k] == v }.
merge!(other.dup.delete_if { |k, v| has_key?(k) })
end
end
......@@ -701,12 +701,6 @@ def test_reverse_merge
assert_equal expected, merged
end
def test_diff
assert_deprecated do
assert_equal({ :a => 2 }, { :a => 2, :b => 5 }.diff({ :a => 1, :b => 5 }))
end
end
def test_slice
original = { :a => 'x', :b => 'y', :c => 10 }
expected = { :a => 'x', :b => 'y' }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册