Skip to content

Commit

Permalink
Merge pull request #1443 from alphagov/handle-missing-document-types
Browse files Browse the repository at this point in the history
Don't show failed translation message for missing document types
  • Loading branch information
kevindew authored Aug 14, 2019
2 parents 3fa8b9e + 0d98a26 commit 0b19af4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/presenters/document_collection_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def group_document_links(group, group_index)
},
metadata: {
public_updated_at: Time.zone.parse(link["public_updated_at"]),
document_type: I18n.t("content_item.schema_name.#{link['document_type']}", count: 1)
document_type: I18n.t("content_item.schema_name.#{link['document_type']}",
count: 1,
default: nil),
},
}
end
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 @@ -73,6 +73,21 @@ class PresentedDocumentCollection < TestCase

assert_equal documents, presented_item.group_document_links({ "documents" => [document_ids.first] }, 0)
end

test 'it handles the document type lacking a translation' do
schema_data = schema_item

document = schema_data["links"]["documents"].first.tap do |link|
link["document_type"] = "non-existant"
end

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

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

class GroupWithMissingDocument < TestCase
Expand Down

0 comments on commit 0b19af4

Please sign in to comment.