FIX: if mandatory parent tag is missing, add it

Previous behaviour was to silently remove tags that
belonged to a group with a parent tag that was missing.

The "required parent tag" feature is meant to guide people
to use the correct tags and show scoped results in the tag
input field, and to help create topic lists of related
tags. It isn't meant to be a strict requirement in the
composer that should trigger errors or restrictions.
This commit is contained in:
Neil Lalonde
2019-04-26 14:39:39 -04:00
parent 1486328756
commit c2a8a2bc97
3 changed files with 87 additions and 16 deletions

View File

@@ -196,7 +196,7 @@ describe "category tag restrictions" do
end
context "tag groups with parent tag" do
it "filter_allowed_tags returns results based on whether parent tag is present or not" do
it "for input field, filter_allowed_tags returns results based on whether parent tag is present or not" do
tag_group = Fabricate(:tag_group, parent_tag_id: tag1.id)
tag_group.tags = [tag3, tag4]
expect(filter_allowed_tags(for_input: true)).to contain_exactly(tag1, tag2)
@@ -204,6 +204,14 @@ describe "category tag restrictions" do
expect(filter_allowed_tags(for_input: true, selected_tags: [tag1.name, tag3.name])).to contain_exactly(tag2, tag4)
end
it "for tagging a topic, filter_allowed_tags allows tags without parent tag" do
tag_group = Fabricate(:tag_group, parent_tag_id: tag1.id)
tag_group.tags = [tag3, tag4]
expect(filter_allowed_tags(for_topic: true)).to contain_exactly(tag1, tag2, tag3, tag4)
expect(filter_allowed_tags(for_topic: true, selected_tags: [tag1.name])).to contain_exactly(tag1, tag2, tag3, tag4)
expect(filter_allowed_tags(for_topic: true, selected_tags: [tag1.name, tag3.name])).to contain_exactly(tag1, tag2, tag3, tag4)
end
context "and category restrictions" do
let(:car_category) { Fabricate(:category) }
let(:other_category) { Fabricate(:category) }