DEV: Allow passing a category parameter when importing a topic (#14069)
This will be used in the rss pooling plugin to address the feature request at https://meta.discourse.org/t/-/200644?u=falco
This commit is contained in:
parent
823f22ae5e
commit
560c13211a
|
@ -27,7 +27,7 @@ class TopicEmbed < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
# Import an article from a source (RSS/Atom/Other)
|
# Import an article from a source (RSS/Atom/Other)
|
||||||
def self.import(user, url, title, contents)
|
def self.import(user, url, title, contents, category_id: nil)
|
||||||
return unless url =~ /^https?\:\/\//
|
return unless url =~ /^https?\:\/\//
|
||||||
|
|
||||||
if SiteSetting.embed_truncate
|
if SiteSetting.embed_truncate
|
||||||
|
@ -58,7 +58,7 @@ class TopicEmbed < ActiveRecord::Base
|
||||||
raw: absolutize_urls(url, contents),
|
raw: absolutize_urls(url, contents),
|
||||||
skip_validations: true,
|
skip_validations: true,
|
||||||
cook_method: cook_method,
|
cook_method: cook_method,
|
||||||
category: eh.try(:category_id)
|
category: category_id || eh.try(:category_id)
|
||||||
}
|
}
|
||||||
if SiteSetting.embed_unlisted?
|
if SiteSetting.embed_unlisted?
|
||||||
create_args[:visible] = false
|
create_args[:visible] = false
|
||||||
|
|
|
@ -16,6 +16,7 @@ describe TopicEmbed do
|
||||||
let(:url) { 'http://eviltrout.com/123' }
|
let(:url) { 'http://eviltrout.com/123' }
|
||||||
let(:contents) { "<p>hello world new post <a href='/hello'>hello</a> <img src='/images/wat.jpg'></p>" }
|
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!(:embeddable_host) { Fabricate(:embeddable_host) }
|
||||||
|
fab!(:category) { Fabricate(:category) }
|
||||||
|
|
||||||
it "returns nil when the URL is malformed" do
|
it "returns nil when the URL is malformed" do
|
||||||
expect(TopicEmbed.import(user, "invalid url", title, contents)).to eq(nil)
|
expect(TopicEmbed.import(user, "invalid url", title, contents)).to eq(nil)
|
||||||
|
@ -95,6 +96,14 @@ describe TopicEmbed do
|
||||||
imported_post = TopicEmbed.import(user, "http://eviltrout.com/abcd", title, "some random content")
|
imported_post = TopicEmbed.import(user, "http://eviltrout.com/abcd", title, "some random content")
|
||||||
expect(imported_post.topic).to be_visible
|
expect(imported_post.topic).to be_visible
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "creates the topic in the category passed as a parameter" do
|
||||||
|
Jobs.run_immediately!
|
||||||
|
SiteSetting.embed_unlisted = false
|
||||||
|
imported_post = TopicEmbed.import(user, "http://eviltrout.com/abcd", title, "some random content", category_id: category.id)
|
||||||
|
expect(imported_post.topic.category).not_to eq(embeddable_host.category)
|
||||||
|
expect(imported_post.topic.category).to eq(category)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "post creation supports markdown rendering" do
|
context "post creation supports markdown rendering" do
|
||||||
|
|
Loading…
Reference in New Issue