Skip to content

Commit

Permalink
Merge pull request #1449 from alphagov/handle-draft-collections
Browse files Browse the repository at this point in the history
Prevent errors for missing public_updated_at
  • Loading branch information
kevindew authored Aug 20, 2019
2 parents 5b7bb65 + ce9ae31 commit 8363266
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/presenters/document_collection_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def group_document_links(group, group_index)
}
},
metadata: {
public_updated_at: Time.zone.parse(link["public_updated_at"]),
public_updated_at: link["public_updated_at"]&.then { |time| Time.zone.parse(time) },
document_type: I18n.t("content_item.schema_name.#{link['document_type']}",
count: 1,
default: nil),
Expand Down
15 changes: 15 additions & 0 deletions test/presenters/document_collection_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ class PresentedDocumentCollection < TestCase

assert_nil grouped.first[:metadata][:document_type]
end

test 'it handles public_updated_at not being specified' do
schema_data = schema_item

document = schema_data["links"]["documents"].first.tap do |link|
link.delete("public_updated_at")
end

grouped = present_example(schema_data).group_document_links(
{ "documents" => [document["content_id"]] },
0,
)

assert_nil grouped.first[:metadata][:public_updated_at]
end
end

class GroupWithMissingDocument < TestCase
Expand Down

0 comments on commit 8363266

Please sign in to comment.