Skip to content

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

FIX: Disambiguate tag hashtags in topic tag change posts

Régis Hanola832a324c2a8
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index 6efaeb01a7e..2a896df9e5d 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -244,7 +244,10 @@ class PostRevisor
end
def self.tag_list_to_raw(tag_list)
- tag_list.sort.map { |tag_name| "##{tag_name}" }.join(", ")
+ HashtagAutocompleteService
+ .new(Discourse.system_user.guardian)
+ .hashtags_for("tag", tag_list.sort)
+ .join(", ")
end
def self.tag_change_noop?(topic, incoming)
diff --git a/spec/lib/post_revisor_spec.rb b/spec/lib/post_revisor_spec.rb
index d80aa019bb9..f589f6d3616 100644
--- a/spec/lib/post_revisor_spec.rb
+++ b/spec/lib/post_revisor_spec.rb
@@ -298,8 +298,8 @@ describe PostRevisor do
end
describe "when `create_post_for_category_and_tag_changes` site setting is enabled" do
- fab!(:tag1) { Fabricate(:tag, name: "First tag") }
- fab!(:tag2) { Fabricate(:tag, name: "Second tag") }
+ fab!(:tag1) { Fabricate(:tag, name: "first-tag") }
+ fab!(:tag2) { Fabricate(:tag, name: "second-tag") }
before do
SiteSetting.create_post_for_category_and_tag_changes = true
@@ -346,6 +346,17 @@ describe PostRevisor do
)
end
+ it "suffixes a tag hashtag that collides with a category slug" do
+ Fabricate(:category, slug: tag1.name)
+ post.topic.update!(tags: [])
+
+ post_revisor.revise!(admin, tags: [tag1.name])
+
+ expect(post.topic.ordered_posts.last.raw).to eq(
+ I18n.t("topic_tag_changed.added", added: "##{tag1.name}::tag"),
+ )
+ end
+
it "Creates a small_action post when category is changed" do
current_category = post.topic.category
category = Fabricate(:category)