From 4acf9cac678133355ff7a7f4c8bc272ac4fd3c88 Mon Sep 17 00:00:00 2001 From: Mantas Date: Thu, 3 Mar 2022 09:19:14 +0200 Subject: [PATCH] Fixes #3915 - No longer public KB answers do not return http 404 --- .../knowledge_base/public/base_controller.rb | 2 +- .../knowledge_base_public/answers_spec.rb | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 spec/requests/knowledge_base_public/answers_spec.rb diff --git a/app/controllers/knowledge_base/public/base_controller.rb b/app/controllers/knowledge_base/public/base_controller.rb index 7cb9ab15c..1f3df1eb0 100644 --- a/app/controllers/knowledge_base/public/base_controller.rb +++ b/app/controllers/knowledge_base/public/base_controller.rb @@ -105,6 +105,6 @@ class KnowledgeBase::Public::BaseController < ApplicationController end @page_title_error = :not_found - render 'knowledge_base/public/not_found' + render 'knowledge_base/public/not_found', status: :not_found end end diff --git a/spec/requests/knowledge_base_public/answers_spec.rb b/spec/requests/knowledge_base_public/answers_spec.rb new file mode 100644 index 000000000..7026868f0 --- /dev/null +++ b/spec/requests/knowledge_base_public/answers_spec.rb @@ -0,0 +1,38 @@ +# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ + +require 'rails_helper' + +RSpec.describe 'KnowledgeBase public answers', type: :request do + include_context 'basic Knowledge Base' + + describe '#show' do + context 'when visitor is a guest' do + it 'returns OK for published answer' do + get help_answer_path(locale_name, category, published_answer) + expect(response).to have_http_status :ok + end + + it 'returns NOT FOUND for draft answer' do + get help_answer_path(locale_name, category, draft_answer) + expect(response).to have_http_status :not_found + end + end + + context 'when visitor is an editor' do + before do + published_answer && draft_answer + authenticated_as(create(:admin), via: :browser) + end + + it 'returns OK for published answer' do + get help_answer_path(locale_name, category, published_answer) + expect(response).to have_http_status :ok + end + + it 'returns OK for draft answer' do + get help_answer_path(locale_name, category, draft_answer) + expect(response).to have_http_status :ok + end + end + end +end