aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations_test.rb
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-01-26 06:23:03 +0000
committerMichael Koziarski <michael@koziarski.com>2008-01-26 06:23:03 +0000
commitc48f744400844e4c73eb91c83d86c3e915a9d78b (patch)
tree4ab9aab31349aebaeff17181d1170fdbcc486ebe /activerecord/test/cases/associations_test.rb
parent02625c9c962a868ee7d1a0903d5aaead290ec0ef (diff)
downloadrails-c48f744400844e4c73eb91c83d86c3e915a9d78b.tar.gz
rails-c48f744400844e4c73eb91c83d86c3e915a9d78b.tar.bz2
rails-c48f744400844e4c73eb91c83d86c3e915a9d78b.zip
Make sure that belongs_to counter decrements when assigning nil Closes #10804 [jeanmartin]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8735 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/cases/associations_test.rb')
-rwxr-xr-xactiverecord/test/cases/associations_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb
index a15abf90a6..0df508d01d 100755
--- a/activerecord/test/cases/associations_test.rb
+++ b/activerecord/test/cases/associations_test.rb
@@ -1308,6 +1308,18 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal 0, Topic.find(debate.id).send(:read_attribute, "replies_count"), "First reply deleted"
end
+ def test_belongs_to_counter_with_assigning_nil
+ p = Post.find(1)
+ c = Comment.find(1)
+
+ assert_equal p.id, c.post_id
+ assert_equal 2, Post.find(p.id).comments.size
+
+ c.post = nil
+
+ assert_equal 1, Post.find(p.id).comments.size
+ end
+
def test_belongs_to_counter_with_reassigning
t1 = Topic.create("title" => "t1")
t2 = Topic.create("title" => "t2")