FIX: Failed to delete post belonging to non-existent topic

This commit is contained in:
Gerhard Schlager 2018-11-22 15:08:37 +01:00
parent bf27aecce2
commit 2ef16e9f4e
2 changed files with 11 additions and 1 deletions

View File

@ -394,7 +394,7 @@ class PostSerializer < BasicPostSerializer
def topic
@topic = object.topic
@topic ||= Topic.with_deleted.find(object.topic_id) if scope.is_staff?
@topic ||= Topic.with_deleted.find_by(id: object.topic_id) if scope.is_staff?
@topic
end

View File

@ -566,6 +566,16 @@ describe PostDestroyer do
end
end
it "deletes a post belonging to a non-existent topic" do
DB.exec("DELETE FROM topics WHERE id = ?", post.topic_id)
post.reload
PostDestroyer.new(admin, post).destroy
expect(post.deleted_at).to be_present
expect(post.deleted_by).to eq(admin)
end
describe 'after delete' do
let!(:coding_horror) { Fabricate(:coding_horror) }