From 19f7beaa2c24ca3a086a82f96658ec88a6354276 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 30 Jan 2017 14:12:05 +0530 Subject: [PATCH] FIX: topic links were getting dropped when post is rebaked --- app/jobs/regular/process_post.rb | 6 ++++++ lib/cooked_post_processor.rb | 7 ------- spec/components/cooked_post_processor_spec.rb | 10 ---------- spec/jobs/process_post_spec.rb | 7 +++++++ 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/app/jobs/regular/process_post.rb b/app/jobs/regular/process_post.rb index 0f44be43027..ddfb0ff3d58 100644 --- a/app/jobs/regular/process_post.rb +++ b/app/jobs/regular/process_post.rb @@ -33,11 +33,17 @@ module Jobs Rails.logger.warn("Cooked post processor in FATAL state, bypassing. You need to urgently restart sidekiq\norig: #{orig_cooked}\nrecooked: #{recooked}\ncooked: #{cooked}\npost id: #{post.id}") else post.update_column(:cooked, cp.html) + extract_links(post) post.publish_change_to_clients! :revised end end end + # onebox may have added some links, so extract them now + def extract_links(post) + TopicLink.extract_from(post) + QuotedPost.extract_from(post) + end end end diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index cd563f12eda..7abe28bd65d 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -35,16 +35,9 @@ class CookedPostProcessor optimize_urls pull_hotlinked_images(bypass_bump) grant_badges - extract_links end end - # onebox may have added some links, so extract them now - def extract_links - TopicLink.extract_from(@post) - QuotedPost.extract_from(@post) - end - def has_emoji? (@doc.css("img.emoji") - @doc.css(".quote img")).size > 0 end diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index 46db958932d..ba3a701b264 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -602,16 +602,6 @@ describe CookedPostProcessor do end - context "extracts links" do - let(:post) { Fabricate(:post, raw: "sam has a blog at https://samsaffron.com") } - - it "always re-extracts links on post process" do - TopicLink.destroy_all - CookedPostProcessor.new(post).post_process - expect(TopicLink.count).to eq(1) - end - end - context "grant badges" do let(:cpp) { CookedPostProcessor.new(post) } diff --git a/spec/jobs/process_post_spec.rb b/spec/jobs/process_post_spec.rb index 35c6b8e2443..edff4c7e8c5 100644 --- a/spec/jobs/process_post_spec.rb +++ b/spec/jobs/process_post_spec.rb @@ -46,6 +46,13 @@ describe Jobs::ProcessPost do expect(post.cooked).not_to match(/http/) end + it "always re-extracts links on post process" do + post.update_columns(raw: "sam has a blog at https://samsaffron.com") + TopicLink.destroy_all + Jobs::ProcessPost.new.execute(post_id: post.id) + expect(TopicLink.count).to eq(1) + end + end