From 4319d8a142ea23bdfc9025d137662aa17ac37bd0 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan <tgx_world@hotmail.com> Date: Thu, 28 Sep 2017 11:04:17 +0800 Subject: [PATCH] FIX: Missing template error when rendering `topics#show` error message. --- app/controllers/application_controller.rb | 2 +- spec/requests/topics_controller_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3f8f51e63ec..2832e704af2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index cb5133a3e03..bdf13e01d91 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -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) }