Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #14526 from chancancode/fix_ar_equality

Ensure we are returning either `true` or `false` for `#==`
  • Loading branch information...
commit 66b42a67af60025ce5f393e13589dfcdf9409334 2 parents 3ae3396 + 945dd25
@fxn fxn authored
View
2  activerecord/lib/active_record/core.rb
@@ -299,7 +299,7 @@ def encode_with(coder)
def ==(comparison_object)
super ||
comparison_object.instance_of?(self.class) &&
- id &&
+ !id.nil? &&
comparison_object.id == id
end
alias :eql? :==
View
2  activerecord/lib/active_record/reflection.rb
@@ -151,7 +151,7 @@ def ==(other_aggregation)
super ||
other_aggregation.kind_of?(self.class) &&
name == other_aggregation.name &&
- other_aggregation.options &&
+ !other_aggregation.options.nil? &&
active_record == other_aggregation.active_record
end
View
13 activerecord/test/cases/base_test.rb
@@ -533,6 +533,7 @@ def test_find_by_slug
def test_equality_of_new_records
assert_not_equal Topic.new, Topic.new
+ assert_equal false, Topic.new == Topic.new
end
def test_equality_of_destroyed_records
@@ -544,6 +545,12 @@ def test_equality_of_destroyed_records
assert_equal topic_2, topic_1
end
+ def test_equality_with_blank_ids
+ one = Subscriber.new(:id => '')
+ two = Subscriber.new(:id => '')
+ assert_equal one, two
+ end
+
def test_hashing
assert_equal [ Topic.find(1) ], [ Topic.find(2).topic ] & [ Topic.find(1) ]
end
@@ -578,12 +585,6 @@ def test_destroy_without_prepared_statement
assert_equal nil, Topic.find_by_id(topic.id)
end
- def test_blank_ids
- one = Subscriber.new(:id => '')
- two = Subscriber.new(:id => '')
- assert_equal one, two
- end
-
def test_comparison_with_different_objects
topic = Topic.create
category = Category.create(:name => "comparison")
Please sign in to comment.
Something went wrong with that request. Please try again.