diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index fa778fda331..33885ab8f07 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -840,6 +840,8 @@ class TopicsController < ApplicationController end def feed + raise Discourse::NotFound if !Post.exists?(topic_id: params[:topic_id]) + @topic_view = TopicView.new(params[:topic_id]) discourse_expires_in 1.minute render 'topics/show', formats: [:rss] diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index ac18ce3550b..5419e2fb049 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -2519,6 +2519,12 @@ RSpec.describe TopicsController do expect(response.body).to_not include("/forum/forum") expect(response.body).to include("http://test.localhost/forum/t/#{topic.slug}") end + + it 'returns 404 when posts are deleted' do + topic.posts.each(&:trash!) + get "/t/foo/#{topic.id}.rss" + expect(response.status).to eq(404) + end end describe '#invite_group' do