diff options
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 5 | ||||
-rwxr-xr-x | activerecord/test/base_test.rb | 4 |
3 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 677cb46f50..d3690eb92f 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed comparison of Active Record objects so two new objects are not equal #2099 [deberg] + * Fixed that the SQL Server adapter would sometimes return DBI::Timestamp objects instead of Time #2127 [Tom Ward] * Added the instance methods #root and #ancestors on acts_as_tree and fixed siblings to not include the current node #2142, #2140 [coffee2code] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index f11fca69f4..e0bce194b2 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1169,7 +1169,10 @@ module ActiveRecord #:nodoc: # Returns true if the +comparison_object+ is the same object, or is of the same type and has the same id. def ==(comparison_object) - comparison_object.equal?(self) or (comparison_object.instance_of?(self.class) and comparison_object.id == id) + comparison_object.equal?(self) || + (comparison_object.instance_of?(self.class) && + comparison_object.id == id && + !comparison_object.new_record?) end # Delegates to == diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index b12d0c941d..108955f5a3 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -468,6 +468,10 @@ class BasicsTest < Test::Unit::TestCase assert_equal Topic.find(1), Topic.find(2).parent end + def test_equality_of_new_records + assert_not_equal Topic.new, Topic.new + end + def test_hashing assert_equal [ Topic.find(1) ], [ Topic.find(2).parent ] & [ Topic.find(1) ] end |