From 793bc52d00af46ec528f2f094208c4e8b0c6ebb6 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 18 Sep 2015 10:27:25 +0200 Subject: [PATCH] recalculates comments_count when restoring in addition to when hiding a comment --- app/models/comment.rb | 4 ++++ spec/models/comment_spec.rb | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 52192cc7f..237eb329e 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index a89a939c1..fdb632986 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -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