-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1178 from alphagov/default-to-placeholder-image-f…
…or-newslike-content Default to placeholder image for newslike content
- Loading branch information
Showing
6 changed files
with
62 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module ContentItem | ||
module NewsImage | ||
def image | ||
content_item.dig("details", "image") || default_news_image || placeholder_image | ||
end | ||
|
||
private | ||
|
||
def default_news_image | ||
organisation = content_item.dig("links", "primary_publishing_organisation") | ||
organisation[0].dig("details", "default_news_image") if organisation.present? | ||
end | ||
|
||
def placeholder_image | ||
"https://assets.publishing.service.gov.uk/government/assets/placeholder.jpg" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "test_helper" | ||
|
||
class ContentItemNewsImageTest < ActiveSupport::TestCase | ||
class DummyContentItem | ||
include ContentItem::NewsImage | ||
attr_accessor :content_item | ||
|
||
def initialize | ||
@content_item = { | ||
"base_path" => "/a/base/path", | ||
"details" => {}, | ||
"links" => {}, | ||
} | ||
end | ||
end | ||
|
||
test "presents the document's image if present" do | ||
item = DummyContentItem.new | ||
image = { "url" => "http://www.test.dev.gov.uk/lead_image.jpg" } | ||
item.content_item["details"]["image"] = image | ||
|
||
assert_equal image, item.image | ||
end | ||
|
||
test "presents the document's organisation's default_news_image if document's image is not present" do | ||
item = DummyContentItem.new | ||
default_news_image = { "url" => "http://www.test.dev.gov.uk/default_news_image.jpg" } | ||
item.content_item["links"]["primary_publishing_organisation"] = [ | ||
"details" => { "default_news_image" => default_news_image } | ||
] | ||
|
||
assert_equal default_news_image, item.image | ||
end | ||
|
||
test "presents a placeholder image if document has no image or default news image" do | ||
item = DummyContentItem.new | ||
placeholder_image = "https://assets.publishing.service.gov.uk/government/assets/placeholder.jpg" | ||
|
||
assert_equal placeholder_image, item.image | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters