FIX: Topics not always properly shown (#11)

There was a bug with the logic in how we were checking for matching tags
and categories in KE settings. If only tags were set, topics would not
show.
This commit is contained in:
Justin DiRose 2020-10-13 10:32:22 -05:00 committed by GitHub
parent 500ccf9656
commit 22c2387b76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -55,6 +55,7 @@ module KnowledgeExplorer
def topic_in_explorer(category, tags)
category_match = KnowledgeExplorer::Query.categories.include?(category.to_s)
tags = tags.pluck(:name)
tag_match = KnowledgeExplorer::Query.tags.any? { |tag| tags.include?(tag) }
category_match || tag_match

View File

@ -154,6 +154,22 @@ describe KnowledgeExplorer::KnowledgeExplorerController do
expect(response.parsed_body['topic']).to be_blank
end
it 'should return a KE topic when only tags are added to settings' do
SiteSetting.knowledge_explorer_categories = nil
get "/docs.json?topic=#{topic.id}"
expect(response.parsed_body['topic']['id']).to eq(topic.id)
end
it 'should return a KE topic when only categories are added to settings' do
SiteSetting.knowledge_explorer_tags = nil
get "/docs.json?topic=#{topic.id}"
expect(response.parsed_body['topic']['id']).to eq(topic.id)
end
end
end
end