FIX: reply_count and post_replies for a restored post (#37232)

When deleting and then undeleting/restoring a post, we need to update
`post_replies` and `reply_count` for the posts that point to the
restored one.
This commit is contained in:
Renato Atilio
2026-01-22 14:42:28 -03:00
committed by GitHub
parent 8fe4b255e0
commit 882e79dcb3
2 changed files with 44 additions and 0 deletions
+2
View File
@@ -263,6 +263,8 @@ class Post < ActiveRecord::Base
recover_public_post_actions
TopicLink.extract_from(self)
QuotedPost.extract_from(self)
extract_quoted_post_numbers
save_reply_relationships
topic.category.update_latest if topic && topic.category_id && topic.category
end
+42
View File
@@ -374,6 +374,48 @@ RSpec.describe PostDestroyer do
expect(post.like_count).to eq(2)
expect(post.custom_fields["deleted_public_actions"]).to be_nil
end
it "restores PostReply when the reply is recovered" do
reply =
create_post(topic: post.topic, user: codinghorror, reply_to_post_number: post.post_number)
expect(post.post_replies.count).to eq(1)
PostDestroyer.new(moderator, reply).destroy
expect(post.post_replies.count).to eq(0)
PostDestroyer.new(moderator, reply.reload).recover
expect(post.post_replies.reload.count).to eq(1)
end
it "restores reply_count when the reply is recovered" do
reply =
create_post(topic: post.topic, user: codinghorror, reply_to_post_number: post.post_number)
expect(post.reload.reply_count).to eq(1)
PostDestroyer.new(moderator, reply).destroy
expect(post.reload.reply_count).to eq(0)
PostDestroyer.new(moderator, reply.reload).recover
expect(post.reload.reply_count).to eq(1)
end
it "restores PostReply for quoted posts when recovered" do
reply =
create_post(
topic: post.topic,
user: codinghorror,
raw:
"[quote=\"#{post.user.username}, post:#{post.post_number}, topic:#{post.topic_id}\"]\nquoted\n[/quote]\nmy reply",
)
expect(post.post_replies.count).to eq(1)
expect(reply.reply_to_post_number).to be_nil
PostDestroyer.new(moderator, reply).destroy
expect(post.post_replies.count).to eq(0)
PostDestroyer.new(moderator, reply.reload).recover
expect(post.post_replies.reload.count).to eq(1)
end
end
describe "basic destroying" do