From 36e9fe9c2c0221c13ecf8b2aa6accdb8a96311b7 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Thu, 24 Dec 2020 09:17:07 +0530 Subject: [PATCH] FIX: allow oneboxes with title and image (#449) --- lib/onebox/engine/allowlisted_generic_onebox.rb | 13 ++++++++++--- lib/onebox/version.rb | 2 +- .../engine/allowlisted_generic_onebox_spec.rb | 9 ++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/onebox/engine/allowlisted_generic_onebox.rb b/lib/onebox/engine/allowlisted_generic_onebox.rb index f1b0cdb1..767c5998 100644 --- a/lib/onebox/engine/allowlisted_generic_onebox.rb +++ b/lib/onebox/engine/allowlisted_generic_onebox.rb @@ -286,7 +286,7 @@ def generic_html return image_html if is_image? return embedded_html if is_embedded? return card_html if is_card? - return article_html if has_text? + return article_html if (has_text? || is_image_article?) end def is_card? @@ -301,8 +301,15 @@ def is_article? end def has_text? - !Onebox::Helpers.blank?(data[:title]) && - !Onebox::Helpers.blank?(data[:description]) + has_title? && !Onebox::Helpers.blank?(data[:description]) + end + + def has_title? + !Onebox::Helpers.blank?(data[:title]) + end + + def is_image_article? + has_title? && has_image? end def is_image? diff --git a/lib/onebox/version.rb b/lib/onebox/version.rb index 64cfebe7..a4d202cf 100644 --- a/lib/onebox/version.rb +++ b/lib/onebox/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Onebox - VERSION = "2.2.0" + VERSION = "2.2.1" end diff --git a/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb b/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb index dec75cd2..7b7acfc0 100644 --- a/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb +++ b/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb @@ -178,15 +178,18 @@ def generic_html end describe 'missing description' do - context 'does not work without description' do + context 'works without description if image is present' do let(:cnn_url) { "https://edition.cnn.com/2020/05/15/health/gallery/coronavirus-people-adopting-pets-photos/index.html" } before do fake(cnn_url, response('cnn')) end - it 'does not onebox' do + it 'shows basic onebox' do onebox = described_class.new(cnn_url) - expect(onebox.to_html).to be_nil + expect(onebox.to_html).not_to be_nil + expect(onebox.to_html).to include("https://edition.cnn.com/2020/05/15/health/gallery/coronavirus-people-adopting-pets-photos/index.html") + expect(onebox.to_html).to include("https://cdn.cnn.com/cnnnext/dam/assets/200427093451-10-coronavirus-people-adopting-pets-super-tease.jpg") + expect(onebox.to_html).to include("People are fostering and adopting pets during the pandemic") end end end