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

Fix equality comparison raising error bug

This commit is contained in:
lulalala 2019-01-12 21:03:22 +08:00
parent 90815b12c5
commit e7834214a6
2 changed files with 8 additions and 1 deletions

View file

@ -64,7 +64,7 @@ module ActiveModel
end
def ==(other)
attributes_for_hash == other.attributes_for_hash
other.is_a?(self.class) && attributes_for_hash == other.attributes_for_hash
end
alias eql? ==

View file

@ -190,4 +190,11 @@ class ErrorTest < ActiveModel::TestCase
assert error != ActiveModel::Error.new(person, :title, foo: :bar)
assert error != ActiveModel::Error.new(Person.new, :name, foo: :bar)
end
test "comparing against different class would not raise error" do
person = Person.new
error = ActiveModel::Error.new(person, :name, foo: :bar)
assert error != person
end
end