FIX: Error bulk deleting posts when action post is already deleted (#371)

* DEV: Break when action post is already deleted

* FIX: Post needs to be unassigned on deletion

* WIP: Add spec

* DEV: Update spec
This commit is contained in:
Keegan George 2022-08-25 12:48:55 -07:00 committed by GitHub
parent 4046c9fb40
commit 7e85101b89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -835,6 +835,7 @@ after_initialize do
PostCustomField
.where(name: "action_code_post_id", value: post.id)
.find_each do |post_custom_field|
next if post_custom_field.post == nil
if ![Post.types[:small_action], Post.types[:whisper]].include?(
post_custom_field.post.post_type,
)

View File

@ -560,6 +560,8 @@ RSpec.describe Assigner do
context "post" do
let(:post_2) { Fabricate(:post, topic: topic) }
let(:assigner) { described_class.new(post_2, moderator) }
let(:post_3) { Fabricate(:post, topic: topic) }
let(:assigner_2) { described_class.new(post_3, moderator) }
before do
SiteSetting.unassign_on_close = true
@ -596,6 +598,17 @@ RSpec.describe Assigner do
PostDestroyer.new(moderator, post_2).destroy
expect { small_action_post.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
it "deletes post successfully when small action is already deleted" do
assigner_2.assign(moderator)
small_action_post = PostCustomField.where(name: "action_code_post_id").first.post
PostDestroyer.new(moderator, small_action_post).destroy
PostDestroyer.new(moderator, post_3).destroy
expect(small_action_post.reload.deleted_at).to be_present
expect(post_3.reload.deleted_at).to be_present
end
end
end