A platform for community discussion. Free, open, simple.
FIX: TopicEmbed.import should update title and author
Kyle Zhao0cc4b4218038
diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rbindex 78ad03ce232..42d078e0033 100644--- a/app/models/topic_embed.rb+++ b/app/models/topic_embed.rb@@ -73,7 +73,13 @@ class TopicEmbed < ActiveRecord::Basepost = embed.post# Update the topic if it changedif post && post.topic && content_sha1 != embed.content_sha1- post.revise(user, { raw: absolutize_urls(url, contents) }, skip_validations: true, bypass_rate_limiter: true)+ post_revision_args = {+ raw: absolutize_urls(url, contents),+ user_id: user.id,+ title: title,+ }++ post.revise(user, post_revision_args, skip_validations: true, bypass_rate_limiter: true)embed.update_column(:content_sha1, content_sha1)endenddiff --git a/spec/jobs/poll_feed_spec.rb b/spec/jobs/poll_feed_spec.rbindex e3b5c6a2035..92f98f685e0 100644--- a/spec/jobs/poll_feed_spec.rb+++ b/spec/jobs/poll_feed_spec.rb@@ -82,6 +82,18 @@ describe Jobs::PollFeed doexpect { poller.poll_feed }.to change { Topic.count }.by(1)expect(Topic.last.user).to eq(feed_author)end++ it "updates the post if it had been polled" do+ embed_url = 'https://blog.discourse.org/2017/09/poll-feed-spec-fixture'+ post = TopicEmbed.import(Fabricate(:user), embed_url, 'old title', 'old content')++ expect { poller.poll_feed }.to_not change { Topic.count }++ post.reload+ expect(post.topic.title).to eq('Poll Feed Spec Fixture')+ expect(post.raw).to include('<p>This is the body & content. </p>')+ expect(post.user).to eq(feed_author)+ endendenddiff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rbindex 5dec573b52f..4974f52cdde 100644--- a/spec/models/topic_embed_spec.rb+++ b/spec/models/topic_embed_spec.rb@@ -41,8 +41,12 @@ describe TopicEmbed doendit "Supports updating the post" do- post = TopicEmbed.import(user, url, title, "muhahaha new contents!")+ new_user = Fabricate(:user)++ post = TopicEmbed.import(new_user, url, title, "muhahaha new contents!")+expect(post.cooked).to match(/new contents/)+ expect(post.user).to eq(new_user)endit "Should leave uppercase Feed Entry URL untouched in content" do