Fixes #3574 - Use country codes (e.g. DE or ES) for knowledgebase answer selection.

This commit is contained in:
Dominik Klein 2021-09-13 19:21:03 +02:00
parent 6636af8d34
commit 53d68b12ae
2 changed files with 22 additions and 1 deletions

View file

@ -70,7 +70,7 @@ class KnowledgeBase::SearchController < ApplicationController
end
if include_locale && (system_locale = object.kb_locale.system_locale)
output[:title] += " (#{system_locale.name})"
output[:title] += " (#{system_locale.locale.upcase})"
end
output

View file

@ -88,6 +88,27 @@ RSpec.describe 'Knowledge Base search with details', type: :request, searchindex
end
end
context 'when using include_locale parameter' do
context 'when no multiple locales exists' do
it 'no locale added to title' do
post endpoint, params: { query: published_answer.translations.first.title, include_locale: true }
expect(json_response['details'][0]['title']).to not_include('(EN-US)')
end
end
context 'when multiple locales exists' do
before do
# Create a alternative knowledge base locale.
alternative_locale
end
it 'locale added to title' do
post endpoint, params: { query: published_answer.translations.first.title, include_locale: true }
expect(json_response['details'][0]['title']).to include('(EN-US)')
end
end
end
context 'when using paging' do
let(:answers) do
Array.new(20) do |nth|