Skip to content

Commit

Permalink
Merge pull request #3160 from alphagov/fix-publication-externallinks
Browse files Browse the repository at this point in the history
Fix publication external links
  • Loading branch information
andysellick authored Apr 18, 2024
2 parents 817bbac + 5a3fef7 commit 5ed16ed
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/presenters/publication_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def documents
docs = content_item["details"]["attachments"].select { |a| !a.key?("locale") || a["locale"] == locale }
docs.each do |doc|
doc["type"] = "html" unless doc["content_type"]
doc["type"] = "external" if doc["attachment_type"] == "external"
doc["alternative_format_contact_email"] = nil if doc["accessible"] == true
end
end
Expand Down
31 changes: 31 additions & 0 deletions test/integration/publication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,37 @@ class PublicationTest < ActionDispatch::IntegrationTest
end
end

test "renders external links correctly" do
overrides = {
"details" => {
"attachments" => [{
"accessible" => true,
"alternative_format_contact_email" => "[email protected]",
"attachment_type" => "external",
"id" => "PUBLIC_1392629965.pdf",
"title" => "Number of ex-regular service personnel now part of FR20",
"url" => "https://not-a-real-website-hopefully",
"command_paper_number" => "",
"hoc_paper_number" => "",
"isbn" => "",
"unique_reference" => "",
"unnumbered_command_paper" => false,
"unnumbered_hoc_paper" => false,
"content_type" => "application/pdf",
"file_size" => 932,
"filename" => "PUBLIC_1392629965.pdf",
"number_of_pages" => 2,
"locale" => "en",
}],
},
}
setup_and_visit_content_item("publication-with-featured-attachments", overrides)
within "#documents" do
assert page.has_text?("https://not-a-real-website-hopefully")
assert page.has_no_text?("HTML")
end
end

test "withdrawn publication" do
setup_and_visit_content_item("withdrawn_publication")
assert page.has_css?("title", text: "[Withdrawn]", visible: false)
Expand Down

0 comments on commit 5ed16ed

Please sign in to comment.