提交 945dd254 编写于 作者: G Godfrey Chan

Ensure we are returning either `true` or `false` for `#==`

460eb83d cused `ActiveRecord::Base#==` to sometimes return `nil` in some cases,
this ensures we always return a boolean value. Also fixed a similar problem in
AR reflections.
上级 86c53d51
......@@ -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? :==
......
......@@ -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
......
......@@ -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")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册