Skip to content

Commit

Permalink
Use default news image on news article pages
Browse files Browse the repository at this point in the history
In cases where a news article doesn't have an image, we use its primary
publishing organisation's default image.
  • Loading branch information
emmabeynon committed Dec 3, 2018
1 parent c3b7a96 commit c643f75
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/presenters/news_article_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ class NewsArticlePresenter < ContentItemPresenter
include ContentItem::Metadata

def image
content_item["details"]["image"]
content_item["details"].dig("image") || default_news_image
end

private

def default_news_image
organisation = content_item["links"].dig("primary_publishing_organisation")
organisation[0].dig("details", "default_news_image") if organisation.present?
end
end
19 changes: 19 additions & 0 deletions test/presenters/news_article_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ class PresentedNewsArticleTest < NewsArticlePresenterTestCase
test 'presents the locale' do
assert_equal schema_item['locale'], presented_item.locale
end

test 'presents the document\'s image if present' do
assert_equal schema_item['details']['image'], presented_item.image
end

test 'presents the document\'s organisation\'s default_news_image if document\'s image is not present' do
default_news_image = { 'url' => 'http://www.test.dev.gov.uk/default_news_image.jpg' }
example = schema_item
example['details'].delete('image')
example['links'] = {
'primary_publishing_organisation' => [
'details' => {
'default_news_image' => default_news_image
}
]
}
presented_item = present_example(example)
assert_equal default_news_image, presented_item.image
end
end

class HistoryModePresentedNewsArticle < NewsArticlePresenterTestCase
Expand Down

0 comments on commit c643f75

Please sign in to comment.