A platform for community discussion. Free, open, simple.
FIX: Topic embedding importer should accept string tags (#27624)
Jean099cf71bccb8
diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rbindex 53466cbcb33..41544bdeb2e 100644--- a/app/models/topic_embed.rb+++ b/app/models/topic_embed.rb@@ -122,7 +122,7 @@ class TopicEmbed < ActiveRecord::Baseendexisting_tag_names = post.topic.tags.pluck(:name).sort- incoming_tag_names = Array(tags).map(&:name).sort+ incoming_tag_names = Array(tags).map { |tag| tag.respond_to?(:name) ? tag.name : tag }.sorttags_changed = existing_tag_names != incoming_tag_namesdiff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rbindex b9888fcdbce..9fcb21efab4 100644--- a/spec/models/topic_embed_spec.rb+++ b/spec/models/topic_embed_spec.rb@@ -349,6 +349,30 @@ RSpec.describe TopicEmbed doendend+ context "when importing a topic embed with string tags" do+ fab!(:tag1) { Fabricate(:tag, name: "interesting") }+ fab!(:tag2) { Fabricate(:tag, name: "article") }+ let(:tags) { [tag1.name, tag2.name] }++ it "associates the specified tags with the existing topic" do+ imported_page = TopicEmbed.import(user, url, title, contents, tags: tags)+ expect(imported_page.topic.tags).to match_array([tag1, tag2])+ end+ end++ context "when updating an existing topic embed with string tags" do+ fab!(:tag1) { Fabricate(:tag, name: "interesting") }+ fab!(:tag2) { Fabricate(:tag, name: "article") }+ let(:tags) { [tag1, tag2] }++ before { TopicEmbed.import(user, url, title, contents, tags: [tag1.name]) }++ it "associates the specified tags with the existing topic" do+ imported_page = TopicEmbed.import(user, url, title, contents, tags: tags)+ expect(imported_page.topic.tags).to match_array([tag1, tag2])+ end+ end+context "with specified user and tags" dofab!(:tag1) { Fabricate(:tag, name: "interesting") }fab!(:tag2) { Fabricate(:tag, name: "article") }