DEV: Add tests for `SiteSerializer#top_tags` (#18498)
This commit is contained in:
parent
f3392a5a81
commit
3629b2de1b
|
@ -135,4 +135,52 @@ RSpec.describe SiteSerializer do
|
|||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
expect(serialized[:anonymous_default_sidebar_tags]).to eq(["dev", "random"])
|
||||
end
|
||||
|
||||
describe '#top_tags' do
|
||||
fab!(:tag) { Fabricate(:tag) }
|
||||
|
||||
describe 'when tagging is not enabled' do
|
||||
before do
|
||||
SiteSetting.tagging_enabled = false
|
||||
end
|
||||
|
||||
it 'is not included in the serialised object' do
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
|
||||
expect(serialized[:top_tags]).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when tagging is enabled' do
|
||||
fab!(:tag2) { Fabricate(:tag) }
|
||||
fab!(:tag3) { Fabricate(:tag) }
|
||||
|
||||
before do
|
||||
SiteSetting.tagging_enabled = true
|
||||
end
|
||||
|
||||
it 'is not included in the serialised object when there are no tags' do
|
||||
tag.destroy!
|
||||
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
|
||||
expect(serialized[:top_tags]).to eq([])
|
||||
end
|
||||
|
||||
it 'is included in the serialised object containing the top tags' do
|
||||
tag2 = Fabricate(:tag)
|
||||
tag2 = Fabricate(:tag)
|
||||
|
||||
SiteSetting.max_tags_in_filter_list = 1
|
||||
|
||||
CategoryTagStat.create!(category_id: SiteSetting.uncategorized_category_id, tag_id: tag2.id, topic_count: 2)
|
||||
CategoryTagStat.create!(category_id: SiteSetting.uncategorized_category_id, tag_id: tag.id, topic_count: 1)
|
||||
CategoryTagStat.create!(category_id: SiteSetting.uncategorized_category_id, tag_id: tag3.id, topic_count: 5)
|
||||
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
|
||||
expect(serialized[:top_tags]).to eq([tag3.name, tag2.name])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue