recalculates comments_count when restoring in addition to when hiding a comment

This commit is contained in:
kikito
2015-09-18 10:27:25 +02:00
parent 1e8605fa28
commit 793bc52d00
2 changed files with 7 additions and 1 deletions

View File

@@ -75,6 +75,10 @@ class Comment < ActiveRecord::Base
commentable_type.constantize.reset_counters(commentable_id, :comments)
end
def after_restore
commentable_type.constantize.reset_counters(commentable_id, :comments)
end
def reply?
!root?
end

View File

@@ -8,13 +8,15 @@ describe Comment do
expect(comment).to be_valid
end
it "should update cache_counter in debate after hide" do
it "updates cache_counter in debate after hide and restore" do
debate = create(:debate)
comment = create(:comment, commentable: debate)
expect(debate.reload.comments_count).to eq(1)
comment.hide
expect(debate.reload.comments_count).to eq(0)
comment.restore
expect(debate.reload.comments_count).to eq(1)
end
describe "#as_administrator?" do