From ae7954ee6296ca01e5ac5ebdab99237968431873 Mon Sep 17 00:00:00 2001 From: Adrian Clay Date: Wed, 8 Nov 2017 15:13:38 +0000 Subject: [PATCH] Wait for travel advice to be published before asserting When publishing the initial travel advice for a country, the travel advice publisher first sends over a version with a blank summary before sending a version with the actual content. Related to 03e929d9 Occasionally the tests would pick up that blank summary document and assert against that instead of the subsequent document. Waiting for the content to be published remedies this race condition. --- spec/support/travel_advice_publisher_helpers.rb | 5 +++++ spec/travel_advice_publisher/creating_draft_spec.rb | 3 +-- spec/travel_advice_publisher/creating_live_spec.rb | 3 +-- spec/travel_advice_publisher/upload_attachments_spec.rb | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/spec/support/travel_advice_publisher_helpers.rb b/spec/support/travel_advice_publisher_helpers.rb index 426b7b16..9b3d7758 100644 --- a/spec/support/travel_advice_publisher_helpers.rb +++ b/spec/support/travel_advice_publisher_helpers.rb @@ -66,6 +66,11 @@ def visit_travel_advice_publisher(path = "/") visit(Plek.find("travel-advice-publisher") + path) end + def reload_until_travel_advice_summary_displayed(url, summary) + reload_url_until_status_code(url, 200) + reload_url_until_match(url, :has_text?, ignore_quotes_regex(summary)) + end + def self.included(base) if SignonHelpers::use_signon? default_permissions = %w[gds_editor] diff --git a/spec/travel_advice_publisher/creating_draft_spec.rb b/spec/travel_advice_publisher/creating_draft_spec.rb index a95188ac..cbdeac9b 100644 --- a/spec/travel_advice_publisher/creating_draft_spec.rb +++ b/spec/travel_advice_publisher/creating_draft_spec.rb @@ -33,8 +33,7 @@ def when_i_create_a_draft_of_chad def then_i_can_preview_it_on_draft_gov_uk url = find_link("Preview saved version")[:href] - reload_url_until_status_code(url, 200) - reload_url_until_match(url, :has_text?, ignore_quotes_regex(summary)) + reload_until_travel_advice_summary_displayed(url, summary) @window = window_opened_by { click_link("Preview saved version") } within_window(@window) do diff --git a/spec/travel_advice_publisher/creating_live_spec.rb b/spec/travel_advice_publisher/creating_live_spec.rb index 2cba820b..5ea7a3b3 100644 --- a/spec/travel_advice_publisher/creating_live_spec.rb +++ b/spec/travel_advice_publisher/creating_live_spec.rb @@ -31,8 +31,7 @@ def when_i_create_a_live_edition_of_malta def then_i_can_view_it_on_gov_uk url = find_link("view")[:href] - reload_url_until_status_code(url, 200) - reload_url_until_match(url, :has_text?, ignore_quotes_regex(summary)) + reload_until_travel_advice_summary_displayed(url, summary) @window = window_opened_by { click_link("view") } within_window(@window) do diff --git a/spec/travel_advice_publisher/upload_attachments_spec.rb b/spec/travel_advice_publisher/upload_attachments_spec.rb index 2a1342b6..3a71cbca 100644 --- a/spec/travel_advice_publisher/upload_attachments_spec.rb +++ b/spec/travel_advice_publisher/upload_attachments_spec.rb @@ -33,7 +33,7 @@ def and_i_upload_files_to_it def then_i_can_view_these_files_on_draft_gov_uk url = find_link("Preview saved version")[:href] - reload_url_until_status_code(url, 200) + reload_until_travel_advice_summary_displayed(url, summary) window = window_opened_by { click_link("Preview saved version") } within_window(window) do