Skip to content

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

FIX: topic embed blank tags or passed with nil do not blank out existing topic tags (#27699)

Jeff Wong70fc39211b11
diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rb
index 41544bdeb2e..2959a76e933 100644
--- a/app/models/topic_embed.rb
+++ b/app/models/topic_embed.rb
@@ -124,7 +124,7 @@ class TopicEmbed < ActiveRecord::Base
existing_tag_names = post.topic.tags.pluck(:name).sort
incoming_tag_names = Array(tags).map { |tag| tag.respond_to?(:name) ? tag.name : tag }.sort
- tags_changed = existing_tag_names != incoming_tag_names
+ tags_changed = !tags.nil? && existing_tag_names != incoming_tag_names
if (content_sha1 != embed.content_sha1) || (title && title != post&.topic&.title) ||
tags_changed
diff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rb
index 9fcb21efab4..4bef66b264f 100644
--- a/spec/models/topic_embed_spec.rb
+++ b/spec/models/topic_embed_spec.rb
@@ -371,6 +371,18 @@ RSpec.describe TopicEmbed do
imported_page = TopicEmbed.import(user, url, title, contents, tags: tags)
expect(imported_page.topic.tags).to match_array([tag1, tag2])
end
+
+ it "does not update tags if tags are nil or unspecified" do
+ imported_page = TopicEmbed.import(user, url, title, contents)
+ expect(imported_page.topic.tags).to match_array([tag1])
+ imported_page = TopicEmbed.import(user, url, title, contents, tags: nil)
+ expect(imported_page.topic.tags).to match_array([tag1])
+ end
+
+ it "does update tags if tags are empty" do
+ imported_page = TopicEmbed.import(user, url, title, contents, tags: [])
+ expect(imported_page.topic.tags).to match_array([])
+ end
end
context "with specified user and tags" do