diff --git a/app/presenters/publication_presenter.rb b/app/presenters/publication_presenter.rb
index 7514029e9..f042be7e1 100644
--- a/app/presenters/publication_presenter.rb
+++ b/app/presenters/publication_presenter.rb
@@ -11,7 +11,10 @@ def details
end
def documents
- content_item["details"]["documents"].to_a.join("")
+ return [] unless content_item["details"]["attachments"]
+
+ docs = content_item["details"]["attachments"].select { |a| a["locale"] == locale }
+ docs.each { |t| t["type"] = "html" unless t["content_type"] }
end
def featured_attachments
diff --git a/app/views/content_items/_attachments_list.html.erb b/app/views/content_items/_attachments_list.html.erb
new file mode 100644
index 000000000..327bacba2
--- /dev/null
+++ b/app/views/content_items/_attachments_list.html.erb
@@ -0,0 +1,21 @@
+<%
+ attachments ||= nil
+ featured_attachments ||= []
+ attachment_details = featured_attachments.filter_map { |id| @content_item&.attachment_details(id) }
+%>
+
+ <%= render 'govuk_publishing_components/components/heading',
+ text: title,
+ mobile_top_margin: true
+ %>
+ <% if attachment_details.length > 0 %>
+ <% add_gem_component_stylesheet("details") %>
+ <% attachment_details.each do |details| %>
+ <%= render 'govuk_publishing_components/components/attachment', {
+ heading_level: 3,
+ attachment: details,
+ margin_bottom: 6
+ } %>
+ <% end %>
+ <% end %>
+
diff --git a/app/views/content_items/publication.html.erb b/app/views/content_items/publication.html.erb
index 66b40dd80..322d5ea65 100644
--- a/app/views/content_items/publication.html.erb
+++ b/app/views/content_items/publication.html.erb
@@ -49,10 +49,10 @@
<% end %>
- <%= render "attachments",
+ <%= render "attachments_list",
title: t("publication.documents", count: 5), # This should always be pluralised.
- legacy_pre_rendered_documents: @content_item.documents,
- attachments: @content_item.featured_attachments
+ attachments: @content_item.documents,
+ featured_attachments: @content_item.featured_attachments
%>
diff --git a/test/integration/publication_test.rb b/test/integration/publication_test.rb
index ed2c3ac22..c0406ed3f 100644
--- a/test/integration/publication_test.rb
+++ b/test/integration/publication_test.rb
@@ -32,12 +32,38 @@ class PublicationTest < ActionDispatch::IntegrationTest
assert_footer_has_published_dates("Published 3 May 2016")
end
- test "renders document attachments (as-is and directly)" do
- setup_and_visit_content_item("publication")
+ test "does not render non-featured attachments" do
+ overrides = {
+ "details" => {
+ "attachments" => [{
+ "accessible" => false,
+ "alternative_format_contact_email" => "customerservices@publicguardian.gov.uk",
+ "attachment_type" => "file",
+ "command_paper_number" => "",
+ "content_type" => "application/pdf",
+ "file_size" => 123_456,
+ "filename" => "veolia-permit.pdf",
+ "hoc_paper_number" => "",
+ "id" => "violia-permit",
+ "isbn" => "",
+ "locale" => "en",
+ "title" => "Permit: Veolia ES (UK) Limited",
+ "unique_reference" => "",
+ "unnumbered_command_paper" => false,
+ "unnumbered_hoc_paper" => false,
+ "url" => "https://assets.publishing.service.gov.uk/media/123abc/veolia-permit.zip",
+ }],
+ "featured_attachments" => [],
+ },
+ }
+
+ setup_and_visit_content_item("publication", overrides)
within "#documents" do
- assert page.has_text?("Permit: Veolia ES (UK) Limited")
+ assert page.has_no_text?("Permit: Veolia ES (UK) Limited")
end
+ end
+ test "renders featured document attachments using components" do
setup_and_visit_content_item("publication-with-featured-attachments")
within "#documents" do
assert page.has_text?("Number of ex-regular service personnel now part of FR20")
diff --git a/test/presenters/publication_presenter_test.rb b/test/presenters/publication_presenter_test.rb
index ad11cba5d..94907fdde 100644
--- a/test/presenters/publication_presenter_test.rb
+++ b/test/presenters/publication_presenter_test.rb
@@ -10,7 +10,6 @@ def schema_name
assert_equal schema_item["schema_name"], presented_item.schema_name
assert_equal schema_item["title"], presented_item.title
assert_equal schema_item["details"]["body"], presented_item.details
- assert_equal schema_item["details"]["documents"].join(""), presented_item.documents
end
test "#published returns a formatted date of the day the content item became public" do