mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:16:22 +08:00
FIX: Topic embedding importer should accept string tags (#27624)
* FIX: Embedding importer should accept string tags
This commit is contained in:
parent
01e36cbb47
commit
099cf71bcc
|
@ -122,7 +122,7 @@ class TopicEmbed < ActiveRecord::Base
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -349,6 +349,30 @@ RSpec.describe TopicEmbed do
|
|||
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
|
||||
fab!(:tag1) { Fabricate(:tag, name: "interesting") }
|
||||
fab!(:tag2) { Fabricate(:tag, name: "article") }
|
||||
|
|
Loading…
Reference in New Issue
Block a user