Skip to content

Commit

Permalink
Merge pull request #2039 from alphagov/flaky-test
Browse files Browse the repository at this point in the history
Fix flaky random publication tests
  • Loading branch information
kevindew authored Mar 10, 2021
2 parents cd46bcf + 37b8b4b commit 7090299
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
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

0 comments on commit 7090299

Please sign in to comment.