FIX: TopicEmbed.import should update title and author

This commit is contained in:
Kyle Zhao 2018-04-18 15:22:43 -04:00 committed by Sam
parent a2bc2ca08f
commit 0cc4b42180
3 changed files with 24 additions and 2 deletions

View File

@ -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

View File

@ -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('<p>This is the body &amp; content. </p>')
expect(post.user).to eq(feed_author)
end
end
end

View File

@ -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