From 1712d90050bd4b32a9ee93548b5eef05a69491f7 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 12 Jul 2011 00:04:01 +0100 Subject: Fix exception if old and new targets are both nil. Fixes #1471. --- .../test/cases/associations/belongs_to_associations_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 4190f6d76d..818902beb5 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -681,4 +681,13 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase firm = client.create_firm! :name => "baa" assert_equal firm.id, client.client_of end + + def test_self_referential_belongs_to_with_counter_cache_assigning_nil + comment = Comment.create! :post => posts(:thinking), :body => "fuu" + comment.parent = nil + comment.save! + + assert_equal nil, comment.reload.parent + assert_equal 0, comments(:greetings).reload.children_count + end end -- cgit v1.2.3