aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/error.rb2
-rw-r--r--activemodel/test/cases/error_test.rb7
2 files changed, 8 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/error.rb b/activemodel/lib/active_model/error.rb
index 9731fa74df..5a1298e27f 100644
--- a/activemodel/lib/active_model/error.rb
+++ b/activemodel/lib/active_model/error.rb
@@ -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? ==
diff --git a/activemodel/test/cases/error_test.rb b/activemodel/test/cases/error_test.rb
index d1193d123f..d74321fee5 100644
--- a/activemodel/test/cases/error_test.rb
+++ b/activemodel/test/cases/error_test.rb
@@ -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