FIX: Missing template error when rendering `topics#show` error message.

This commit is contained in:
Guo Xiang Tan 2017-09-28 11:04:17 +08:00
parent 3e6bf38394
commit 4319d8a142
2 changed files with 16 additions and 1 deletions

View File

@ -162,7 +162,7 @@ class ApplicationController < ActionController::Base
if show_json_errors
# HACK: do not use render_json_error for topics#show
if request.params[:controller] == 'topics' && request.params[:action] == 'show'
return render status: status_code, layout: false, text: (status_code == 404 || status_code == 410) ? build_not_found_page(status_code) : I18n.t(type)
return render status: status_code, layout: false, plain: (status_code == 404 || status_code == 410) ? build_not_found_page(status_code) : I18n.t(type)
end
render_json_error I18n.t(opts[:custom_message] || type), type: type, status: status_code

View File

@ -4,6 +4,21 @@ RSpec.describe TopicsController do
let(:topic) { Fabricate(:topic) }
let(:user) { Fabricate(:user) }
describe '#show' do
let(:private_topic) { Fabricate(:private_message_topic) }
describe 'when topic is not allowed' do
it 'should return the right response' do
sign_in(user)
get "/t/#{private_topic.id}.json"
expect(response.status).to eq(403)
expect(response.body).to eq(I18n.t('invalid_access'))
end
end
end
describe '#timings' do
let(:post_1) { Fabricate(:post, topic: topic) }