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

Fix flaky random publication tests #2039

Merged
merged 2 commits into from
Mar 10, 2021
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/content_item/attachments.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ContentItem
module Attachments
def attachment_details(attachment_id)
content_item["details"]["attachments"].find do |attachment|
content_item.dig("details", "attachments")&.find do |attachment|
attachment["id"] == attachment_id
end
end
Expand Down
9 changes: 5 additions & 4 deletions app/views/content_items/_attachments.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<% if legacy_pre_rendered_documents.present? || attachments.any? %>
<% attachments ||= [] %>
<% attachment_details = attachments.filter_map { |id| @content_item&.attachment_details(id) } %>
<% if legacy_pre_rendered_documents.present? || attachment_details.any? %>
<section id="<%= title.parameterize %>">
<%= render 'govuk_publishing_components/components/heading',
text: title,
Expand All @@ -11,15 +13,14 @@
<%= raw(legacy_pre_rendered_documents) %>
<% end %>
<% else %>
<% attachments.each do |attachment_id| %>
<% attachment_details.each do |details| %>
<div class="attachment">
<%= render 'govuk_publishing_components/components/attachment', {
heading_level: 3,
attachment: @content_item.attachment_details(attachment_id)
attachment: details
} %>
</div>
<% end %>
<% end %>

</section>
<% end %>
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def setup_and_visit_content_item_with_taxons(name, taxons)

def setup_and_visit_random_content_item(document_type: nil)
content_item = GovukSchemas::RandomExample.for_schema(frontend_schema: schema_type) do |payload|
payload.merge("document_type" => document_type) unless document_type.nil?
payload.merge!("document_type" => document_type) unless document_type.nil?
payload
end

Expand Down