FIX: do not show tags with 0 count on /tags page
This commit is contained in:
parent
dc77cce8d9
commit
aac7796124
|
@ -37,14 +37,14 @@ class TagsController < ::ApplicationController
|
||||||
{ id: tag_group.id, name: tag_group.name, tags: self.class.tag_counts_json(tag_group.tags) }
|
{ id: tag_group.id, name: tag_group.name, tags: self.class.tag_counts_json(tag_group.tags) }
|
||||||
end
|
end
|
||||||
|
|
||||||
ungrouped_tags = Tag.where("tags.id NOT IN (select tag_id from tag_group_memberships)")
|
ungrouped_tags = Tag.where("tags.id NOT IN (select tag_id from tag_group_memberships) AND tags.topic_count > 0")
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
tags: self.class.tag_counts_json(ungrouped_tags), # tags that don't belong to a group
|
tags: self.class.tag_counts_json(ungrouped_tags), # tags that don't belong to a group
|
||||||
extras: { tag_groups: grouped_tag_counts }
|
extras: { tag_groups: grouped_tag_counts }
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
unrestricted_tags = Tag.where("tags.id NOT IN (select tag_id from category_tags)")
|
unrestricted_tags = Tag.where("tags.id NOT IN (select tag_id from category_tags) AND tags.topic_count > 0")
|
||||||
|
|
||||||
categories = Category.where("id in (select category_id from category_tags)")
|
categories = Category.where("id in (select category_id from category_tags)")
|
||||||
.where("id in (?)", guardian.allowed_category_ids)
|
.where("id in (?)", guardian.allowed_category_ids)
|
||||||
|
|
|
@ -5,6 +5,42 @@ describe TagsController do
|
||||||
SiteSetting.tagging_enabled = true
|
SiteSetting.tagging_enabled = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#index' do
|
||||||
|
|
||||||
|
before do
|
||||||
|
tag = Fabricate(:tag, name: 'test')
|
||||||
|
topic_tag = Fabricate(:tag, name: 'topic-test', topic_count: 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples "successfully retrieve tags with topic_count > 0" do
|
||||||
|
it "should return the right response" do
|
||||||
|
get "/tags.json"
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
|
||||||
|
tags = JSON.parse(response.body)["tags"]
|
||||||
|
expect(tags.length).to eq(1)
|
||||||
|
expect(tags[0]['text']).to eq("topic-test")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with tags_listed_by_group enabled" do
|
||||||
|
before do
|
||||||
|
SiteSetting.tags_listed_by_group = true
|
||||||
|
end
|
||||||
|
|
||||||
|
include_examples "successfully retrieve tags with topic_count > 0"
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with tags_listed_by_group disabled" do
|
||||||
|
before do
|
||||||
|
SiteSetting.tags_listed_by_group = false
|
||||||
|
end
|
||||||
|
|
||||||
|
include_examples "successfully retrieve tags with topic_count > 0"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#check_hashtag' do
|
describe '#check_hashtag' do
|
||||||
let(:tag) { Fabricate(:tag, name: 'test') }
|
let(:tag) { Fabricate(:tag, name: 'test') }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue