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:
parent
4046c9fb40
commit
7e85101b89
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue