A platform for community discussion. Free, open, simple.
FIX: Failed to delete post belonging to non-existent topic
Gerhard Schlager2ef16e9f4e5d
diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rbindex f778c80ba64..42686fae37a 100644--- a/app/serializers/post_serializer.rb+++ b/app/serializers/post_serializer.rb@@ -394,7 +394,7 @@ class PostSerializer < BasicPostSerializerdef 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?@topicenddiff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rbindex 5702bf61ce3..7a91c3bef3f 100644--- a/spec/components/post_destroyer_spec.rb+++ b/spec/components/post_destroyer_spec.rb@@ -566,6 +566,16 @@ describe PostDestroyer doendend+ 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' dolet!(:coding_horror) { Fabricate(:coding_horror) }