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