From 0cc4b4218038fd5fb8a7007de4329f46ed1bbc90 Mon Sep 17 00:00:00 2001 From: Kyle Zhao Date: Wed, 18 Apr 2018 15:22:43 -0400 Subject: [PATCH] FIX: TopicEmbed.import should update title and author --- app/models/topic_embed.rb | 8 +++++++- spec/jobs/poll_feed_spec.rb | 12 ++++++++++++ spec/models/topic_embed_spec.rb | 6 +++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rb index 78ad03ce232..42d078e0033 100644 --- a/app/models/topic_embed.rb +++ b/app/models/topic_embed.rb @@ -73,7 +73,13 @@ class TopicEmbed < ActiveRecord::Base post = embed.post # Update the topic if it changed if 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) end end diff --git a/spec/jobs/poll_feed_spec.rb b/spec/jobs/poll_feed_spec.rb index e3b5c6a2035..92f98f685e0 100644 --- a/spec/jobs/poll_feed_spec.rb +++ b/spec/jobs/poll_feed_spec.rb @@ -82,6 +82,18 @@ describe Jobs::PollFeed do expect { 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('

This is the body & content.

') + expect(post.user).to eq(feed_author) + end end end diff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rb index 5dec573b52f..4974f52cdde 100644 --- a/spec/models/topic_embed_spec.rb +++ b/spec/models/topic_embed_spec.rb @@ -41,8 +41,12 @@ describe TopicEmbed do end it "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) end it "Should leave uppercase Feed Entry URL untouched in content" do