Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle missing parent when deleting comment #8056

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/comment.rb
Expand Up @@ -47,8 +47,8 @@ class Comment < ApplicationRecord
end

after_destroy do
self.parent.update_comments_counter
participation = author.participations.find_by(target_id: post.id)
parent&.update_comments_counter
participation = author.participations.find_by(target_id: commentable_id)
participation.unparticipate! if participation.present?
end

Expand Down
8 changes: 8 additions & 0 deletions spec/models/comment_spec.rb
Expand Up @@ -24,6 +24,14 @@
participations = Participation.where(target_id: comment_alice.commentable_id, author_id: comment_alice.author_id)
expect(participations.first.count).to eq(1)
end

it "should work if parent is gone" do
comment_alice.parent.delete
comment_alice.reload
expect {
comment_alice.destroy
}.to_not raise_error
end
end

describe "#subscribers" do
Expand Down