recalculates comments_count when restoring in addition to when hiding a comment
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user