Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent errors for missing public_updated_at #1449

Merged
merged 1 commit into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) },
1pretz1 marked this conversation as resolved.
Show resolved Hide resolved
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