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