Skip to content

A platform for community discussion. Free, open, simple.

DEV: Make `find_post_using` raise only `Discourse::NotFound` (#16133)

Jarek Radosz768c80c2a44b
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb
index e31b08fbe9e..7954e3b86a4 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb
@@ -869,7 +869,7 @@ class PostsController < ApplicationController
post = finder.with_deleted.first
raise Discourse::NotFound unless post
- post.topic = Topic.with_deleted.find(post.topic_id)
+ post.topic = Topic.with_deleted.find_by(id: post.topic_id)
if !post.topic ||
(
diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rb
index f0cc6654bb7..96a6ceb78ac 100644
--- a/spec/requests/posts_controller_spec.rb
+++ b/spec/requests/posts_controller_spec.rb
@@ -16,6 +16,12 @@ shared_examples 'finding and showing post' do
expect(response.status).to eq(200)
end
+ it "returns 404 when post's topic is deleted" do
+ post.topic.destroy!
+ get url
+ expect(response.status).to eq(404)
+ end
+
context "deleted post" do
before do
post.trash!(user)