Skip to content

Commit

Permalink
DEV: Allow TopicEmbed.import to optionally receive a list of tags (#1…
Browse files Browse the repository at this point in the history
…4301)

This will be used by the rss-polling plugin
  • Loading branch information
xfalcox committed Sep 13, 2021
1 parent b90eb0d commit 2e0992c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/models/topic_embed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def self.imported_from_html(url)
end

# Import an article from a source (RSS/Atom/Other)
def self.import(user, url, title, contents, category_id: nil, cook_method: nil)
def self.import(user, url, title, contents, category_id: nil, cook_method: nil, tags: nil)
return unless url =~ /^https?\:\/\//

if SiteSetting.embed_truncate && cook_method.nil?
Expand Down Expand Up @@ -58,7 +58,8 @@ def self.import(user, url, title, contents, category_id: nil, cook_method: nil)
raw: absolutize_urls(url, contents),
skip_validations: true,
cook_method: cook_method,
category: category_id || eh.try(:category_id)
category: category_id || eh.try(:category_id),
tags: SiteSetting.tagging_enabled ? tags : nil,
}
if SiteSetting.embed_unlisted?
create_args[:visible] = false
Expand Down
8 changes: 8 additions & 0 deletions spec/models/topic_embed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
let(:contents) { "<p>hello world new post <a href='/hello'>hello</a> <img src='/images/wat.jpg'></p>" }
fab!(:embeddable_host) { Fabricate(:embeddable_host) }
fab!(:category) { Fabricate(:category) }
fab!(:tag) { Fabricate(:tag) }

it "returns nil when the URL is malformed" do
expect(TopicEmbed.import(user, "invalid url", title, contents)).to eq(nil)
Expand Down Expand Up @@ -104,6 +105,13 @@
expect(imported_post.topic.category).to eq(category)
end

it "creates the topic with the tag passed as a parameter" do
Jobs.run_immediately!
SiteSetting.tagging_enabled = true
imported_post = TopicEmbed.import(user, "http://eviltrout.com/abcd", title, "some random content", tags: [tag.name])
expect(imported_post.topic.tags).to include(tag)
end

it "respects overriding the cook_method when asked" do
Jobs.run_immediately!
SiteSetting.embed_support_markdown = false
Expand Down

0 comments on commit 2e0992c

Please sign in to comment.