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) commentable_type.constantize.reset_counters(commentable_id, :comments)
end end
def after_restore
commentable_type.constantize.reset_counters(commentable_id, :comments)
end
def reply? def reply?
!root? !root?
end end

View File

@@ -8,13 +8,15 @@ describe Comment do
expect(comment).to be_valid expect(comment).to be_valid
end 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) debate = create(:debate)
comment = create(:comment, commentable: debate) comment = create(:comment, commentable: debate)
expect(debate.reload.comments_count).to eq(1) expect(debate.reload.comments_count).to eq(1)
comment.hide comment.hide
expect(debate.reload.comments_count).to eq(0) expect(debate.reload.comments_count).to eq(0)
comment.restore
expect(debate.reload.comments_count).to eq(1)
end end
describe "#as_administrator?" do describe "#as_administrator?" do