Skip to content

Commit

Permalink
FIX: allow oneboxes with title and image (discourse#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitjalan authored Dec 24, 2020
1 parent f93beb3 commit 36e9fe9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
13 changes: 10 additions & 3 deletions lib/onebox/engine/allowlisted_generic_onebox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/onebox/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Onebox
VERSION = "2.2.0"
VERSION = "2.2.1"
end
9 changes: 6 additions & 3 deletions spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 36e9fe9

Please sign in to comment.