diff options
Diffstat (limited to 'activerecord/test/associations_test.rb')
-rwxr-xr-x | activerecord/test/associations_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 59951d47fb..85df401fb1 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -1175,6 +1175,24 @@ class BelongsToAssociationsTest < Test::Unit::TestCase topic.update_attributes(:title => "37signals") assert_equal 1, Topic.find(topic.id)[:replies_count] end + + def test_belongs_to_counter_after_save + topic = Topic.create("title" => "monday night") + topic.replies.create("title" => "re: monday night", "content" => "football") + assert_equal 1, Topic.find(topic.id).send(:read_attribute, "replies_count") + + topic.save + assert_equal 1, Topic.find(topic.id).send(:read_attribute, "replies_count") + end + + def test_belongs_to_counter_after_update_attributes + topic = Topic.create("title" => "37s") + topic.replies.create("title" => "re: 37s", "content" => "rails") + assert_equal 1, Topic.find(topic.id).send(:read_attribute, "replies_count") + + topic.update_attributes("title" => "37signals") + assert_equal 1, Topic.find(topic.id).send(:read_attribute, "replies_count") + end def test_assignment_before_parent_saved client = Client.find(:first) |