FIX: Changing owner of deleted reply didn't work

This commit is contained in:
Gerhard Schlager 2018-05-16 17:02:43 +02:00
parent 4103783821
commit ae6236d090
2 changed files with 11 additions and 3 deletions

View File

@ -781,7 +781,7 @@ class Post < ActiveRecord::Base
end end
def create_reply_relationship_with(post) def create_reply_relationship_with(post)
return if post.nil? return if post.nil? || self.deleted_at.present?
post_reply = post.post_replies.new(reply_id: id) post_reply = post.post_replies.new(reply_id: id)
if post_reply.save if post_reply.save
if Topic.visible_post_types.include?(self.post_type) if Topic.visible_post_types.include?(self.post_type)

View File

@ -5,8 +5,8 @@ describe PostOwnerChanger do
let!(:editor) { Fabricate(:admin) } let!(:editor) { Fabricate(:admin) }
let(:topic) { Fabricate(:topic) } let(:topic) { Fabricate(:topic) }
let(:user_a) { Fabricate(:user) } let(:user_a) { Fabricate(:user) }
let(:p1) { Fabricate(:post, topic_id: topic.id) } let(:p1) { Fabricate(:post, topic_id: topic.id, post_number: 1) }
let(:p2) { Fabricate(:post, topic_id: topic.id) } let(:p2) { Fabricate(:post, topic_id: topic.id, post_number: 2) }
let(:p3) { Fabricate(:post) } let(:p3) { Fabricate(:post) }
it "raises an error with a parameter missing" do it "raises an error with a parameter missing" do
@ -75,6 +75,14 @@ describe PostOwnerChanger do
expect(p1.reload.user).to eq(user_a) expect(p1.reload.user).to eq(user_a)
end end
it "changes the owner when the post is deleted" do
p4 = Fabricate(:post, topic_id: topic.id, reply_to_post_number: p2.post_number)
PostDestroyer.new(editor, p4).destroy
PostOwnerChanger.new(post_ids: [p4.id], topic_id: topic.id, new_owner: user_a, acting_user: editor).change_owner!
expect(p4.reload.user).to eq(user_a)
end
context "sets topic notification level for the new owner" do context "sets topic notification level for the new owner" do
let(:p4) { Fabricate(:post, post_number: 2, topic_id: topic.id) } let(:p4) { Fabricate(:post, post_number: 2, topic_id: topic.id) }