Skip to content

A platform for community discussion. Free, open, simple.

DEV: Exclude synonyms from tag chooser choices in Form Templates and order them alphabetically (#32974)

Juan David Martínez Cubillos921835dfbe4b
diff --git a/app/controllers/form_templates_controller.rb b/app/controllers/form_templates_controller.rb
index de3fc0912e2..fbe6e8538d5 100644
--- a/app/controllers/form_templates_controller.rb
+++ b/app/controllers/form_templates_controller.rb
@@ -43,7 +43,8 @@ class FormTemplatesController < ApplicationController
next form_field unless form_field["tag_group"]
tag_group_name = form_field["tag_group"]
- tags = tag_groups[tag_group_name].tags
+ tags = tag_groups[tag_group_name].tags.reject { |tag| tag.target_tag_id.present? }
+
ordered_field = {}
form_field.each do |key, value|
diff --git a/spec/requests/form_templates_controller_spec.rb b/spec/requests/form_templates_controller_spec.rb
index 55e7601bf0f..87c433e81ea 100644
--- a/spec/requests/form_templates_controller_spec.rb
+++ b/spec/requests/form_templates_controller_spec.rb
@@ -64,10 +64,12 @@ RSpec.describe FormTemplatesController do
end
context "when using tag groups in a form template" do
+ fab!(:admin)
fab!(:tag1) { Fabricate(:tag, description: "Tag 1 custom Translation") }
fab!(:tag2) { Fabricate(:tag, description: "Tag 2 custom Translation") }
fab!(:tag3) { Fabricate(:tag) }
fab!(:tag4) { Fabricate(:tag) }
+ fab!(:tag_synonym) { Fabricate(:tag, name: "discourse") }
fab!(:tag_group1) { Fabricate(:tag_group, name: "tag_group1", tags: [tag1, tag3]) }
fab!(:tag_group2) { Fabricate(:tag_group, name: "tag_group2", tags: [tag2, tag4]) }
@@ -100,6 +102,13 @@ RSpec.describe FormTemplatesController do
)
end
+ before do
+ sign_in(admin)
+ #Creates the synonym
+ post "/tag/#{tag1.name}/synonyms.json", params: { synonyms: [tag_synonym.name] }
+ sign_in(user)
+ end
+
it "should return a single template with the correct data" do
get "/form-templates/#{tag_groups_form_template.id}.json"
expect(response.status).to eq(200)
@@ -121,6 +130,10 @@ RSpec.describe FormTemplatesController do
expect(parsed_template[1]["attributes"]["tag_choices"]).to eq(
{ tag2.name => tag2.description },
)
+
+ # It excludes synonyms
+ expect(parsed_template[0]["choices"].count).to eq(2)
+
expect(parsed_template[0]["choices"]).to eq([tag1.name, tag3.name])
expect(parsed_template[1]["choices"]).to eq([tag2.name, tag4.name])
end