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:
parent
90815b12c5
commit
e7834214a6
2 changed files with 8 additions and 1 deletions
|
@ -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? ==
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue