From 1481462cbfdab4231dc9fa0d0edcc28fc7c9d0c1 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Tue, 17 Oct 2017 20:36:57 +0200 Subject: [PATCH] PERF: Move oneboxing from cook method "email" to postprocessing --- lib/email_cook.rb | 9 ++++----- spec/components/email_cook_spec.rb | 14 ++++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/email_cook.rb b/lib/email_cook.rb index f440be6389c..162643da663 100644 --- a/lib/email_cook.rb +++ b/lib/email_cook.rb @@ -21,12 +21,11 @@ class EmailCook str.scan(EmailCook.url_regexp).each do |m| url = m[0] - val = "#{url}" - - # Onebox consideration if str.strip == url - oneboxed = Oneboxer.onebox(url) - val = oneboxed if oneboxed.present? + # this could be oneboxed + val = %|#{url}| + else + val = %|#{url}| end str.gsub!(url, val) diff --git a/spec/components/email_cook_spec.rb b/spec/components/email_cook_spec.rb index 48e38169e96..22181c29d9a 100644 --- a/spec/components/email_cook_spec.rb +++ b/spec/components/email_cook_spec.rb @@ -27,17 +27,19 @@ LONG_COOKED expect(EmailCook.new(long).cook).to eq(long_cooked.strip) end - it 'autolinks' do - stub_request(:get, "https://www.eviltrout.com").to_return(body: "") - stub_request(:head, "https://www.eviltrout.com").to_return(body: "") - expect(EmailCook.new("https://www.eviltrout.com").cook).to eq("https://www.eviltrout.com
") + it 'creates oneboxed link when the line contains only a link' do + expect(EmailCook.new("https://www.eviltrout.com").cook).to eq('https://www.eviltrout.com
') end it 'autolinks without the beginning of a line' do - expect(EmailCook.new("my site: https://www.eviltrout.com").cook).to eq("my site: https://www.eviltrout.com
") + expect(EmailCook.new("my site: https://www.eviltrout.com").cook).to eq('my site: https://www.eviltrout.com
') + end + + it 'autolinks without the end of a line' do + expect(EmailCook.new("https://www.eviltrout.com is my site").cook).to eq('https://www.eviltrout.com is my site
') end it 'links even within a quote' do - expect(EmailCook.new("> https://www.eviltrout.com").cook).to eq("
https://www.eviltrout.com
") + expect(EmailCook.new("> https://www.eviltrout.com").cook).to eq('
https://www.eviltrout.com
') end end