FIX: Failed to delete post belonging to non-existent topic
This commit is contained in:
parent
bf27aecce2
commit
2ef16e9f4e
|
@ -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
|
||||
|
||||
|
|
|
@ -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) }
|
||||
|
|
Loading…
Reference in New Issue