From 460eb83de0579c36d96410e48a1385987ad0020c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 18 Sep 2013 16:14:41 -0700 Subject: support objects with blank string primary keys --- activerecord/lib/active_record/core.rb | 2 +- activerecord/test/cases/base_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 0bc6933918..5e6fee52f7 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -284,7 +284,7 @@ module ActiveRecord def ==(comparison_object) super || comparison_object.instance_of?(self.class) && - id.present? && + id && comparison_object.id == id end alias :eql? :== diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 87597db7b0..9877e6812d 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -566,6 +566,12 @@ class BasicsTest < ActiveRecord::TestCase assert_equal topic, Topic.find(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") -- cgit v1.2.3