FIX: Topic embedding importer should accept string tags (#27624)

* FIX: Embedding importer should accept string tags
This commit is contained in:
Jean 2024-06-26 12:34:55 -04:00 committed by GitHub
parent 01e36cbb47
commit 099cf71bcc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -122,7 +122,7 @@ class TopicEmbed < ActiveRecord::Base
end end
existing_tag_names = post.topic.tags.pluck(:name).sort existing_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 }.sort
tags_changed = existing_tag_names != incoming_tag_names tags_changed = existing_tag_names != incoming_tag_names

View File

@ -349,6 +349,30 @@ RSpec.describe TopicEmbed do
end end
end end
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" do context "with specified user and tags" do
fab!(:tag1) { Fabricate(:tag, name: "interesting") } fab!(:tag1) { Fabricate(:tag, name: "interesting") }
fab!(:tag2) { Fabricate(:tag, name: "article") } fab!(:tag2) { Fabricate(:tag, name: "article") }