Skip to content

Commit ce9ae31

Browse files
committed
Prevent errors for missing public_updated_at
This stops document collections raising errors when a public_updated_at value is not set on a document. This is often the case with draft GOV.UK documents, however Whitehall tends to fill in this field which is why this error hasn't been seen before.
1 parent 5b7bb65 commit ce9ae31

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

app/presenters/document_collection_presenter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def group_document_links(group, group_index)
4040
}
4141
},
4242
metadata: {
43-
public_updated_at: Time.zone.parse(link["public_updated_at"]),
43+
public_updated_at: link["public_updated_at"]&.then { |time| Time.zone.parse(time) },
4444
document_type: I18n.t("content_item.schema_name.#{link['document_type']}",
4545
count: 1,
4646
default: nil),

test/presenters/document_collection_presenter_test.rb

+15
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ class PresentedDocumentCollection < TestCase
8888

8989
assert_nil grouped.first[:metadata][:document_type]
9090
end
91+
92+
test 'it handles public_updated_at not being specified' do
93+
schema_data = schema_item
94+
95+
document = schema_data["links"]["documents"].first.tap do |link|
96+
link.delete("public_updated_at")
97+
end
98+
99+
grouped = present_example(schema_data).group_document_links(
100+
{ "documents" => [document["content_id"]] },
101+
0,
102+
)
103+
104+
assert_nil grouped.first[:metadata][:public_updated_at]
105+
end
91106
end
92107

93108
class GroupWithMissingDocument < TestCase

0 commit comments

Comments
 (0)