From 69d3b13c2b236e8b80a56cf85ceeb42ec968a83e Mon Sep 17 00:00:00 2001 From: Jon Roberts Date: Wed, 25 Sep 2024 22:24:12 -0400 Subject: [PATCH] Flaky specs: Use travel_back when travel_to is used (#6054) * Use travel_back when travel_to is used Fixes some flaky specs * lint --- spec/helpers/notifications_helper_spec.rb | 1 + spec/lib/tasks/supervisor_weekly_digest_spec.rb | 3 +++ spec/models/banner_spec.rb | 1 + spec/models/casa_admin_spec.rb | 1 + spec/models/casa_case_spec.rb | 3 +++ spec/models/case_court_report_context_spec.rb | 1 + spec/models/court_date_spec.rb | 2 ++ spec/models/supervisor_spec.rb | 1 + spec/models/volunteer_spec.rb | 1 + spec/requests/banners_spec.rb | 2 ++ spec/requests/case_court_reports_spec.rb | 1 + spec/requests/court_dates_spec.rb | 1 + spec/requests/notifications_spec.rb | 1 + spec/services/case_contacts_contact_dates_spec.rb | 1 + spec/services/volunteer_birthday_reminder_service_spec.rb | 2 ++ spec/support/shared_examples/shows_court_dates_links.rb | 1 + spec/system/bulk_court_dates/new_spec.rb | 1 + spec/system/casa_cases/show_spec.rb | 1 + spec/system/case_court_reports/index_spec.rb | 1 + spec/system/court_dates/edit_spec.rb | 1 + spec/system/court_dates/new_spec.rb | 1 + spec/system/court_dates/view_spec.rb | 1 + spec/system/placements/destroy_spec.rb | 1 + spec/system/placements/edit_spec.rb | 1 + spec/system/placements/index_spec.rb | 1 + spec/system/placements/new_spec.rb | 1 + 26 files changed, 33 insertions(+) diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb index 59c9cdd893..505fb5fdca 100644 --- a/spec/helpers/notifications_helper_spec.rb +++ b/spec/helpers/notifications_helper_spec.rb @@ -20,6 +20,7 @@ notification_created_before_deploy_a.update_attribute(:created_at, 2.days.ago - 1.hour) notification_created_before_deploy_b.update_attribute(:created_at, 3.days.ago) end + after { travel_back } describe "#notifications_after_and_including_deploy" do let(:notifications_after_and_including_deploy) { helper.notifications_after_and_including_deploy(Noticed::Notification.all) } diff --git a/spec/lib/tasks/supervisor_weekly_digest_spec.rb b/spec/lib/tasks/supervisor_weekly_digest_spec.rb index f23e530dda..fef568bf16 100644 --- a/spec/lib/tasks/supervisor_weekly_digest_spec.rb +++ b/spec/lib/tasks/supervisor_weekly_digest_spec.rb @@ -12,6 +12,7 @@ create(:supervisor, active: true) create(:supervisor, active: false) end + after { travel_back } it "only sends to active supervisor" do expect { subject }.to change { ActionMailer::Base.deliveries.count }.by(1) @@ -26,6 +27,8 @@ create(:supervisor, active: true) end + after { travel_back } + it "does not send email" do expect { subject }.not_to change { ActionMailer::Base.deliveries.count } end diff --git a/spec/models/banner_spec.rb b/spec/models/banner_spec.rb index 0e700a184e..184a294d5f 100644 --- a/spec/models/banner_spec.rb +++ b/spec/models/banner_spec.rb @@ -77,6 +77,7 @@ expect(expires_at_in_eastern_time.to_s).to eq("2024-06-13 08:00:00 -0400") expect(expires_at_in_pacific_time).to eq(expires_at_in_eastern_time) + travel_back end end end diff --git a/spec/models/casa_admin_spec.rb b/spec/models/casa_admin_spec.rb index 74ca005ffe..be5be4e86b 100644 --- a/spec/models/casa_admin_spec.rb +++ b/spec/models/casa_admin_spec.rb @@ -38,6 +38,7 @@ user = User.accept_invitation!(invitation_token: casa_admin.invitation_token) expect(user.errors.full_messages).to include("Invitation token is invalid") + travel_back end end diff --git a/spec/models/casa_case_spec.rb b/spec/models/casa_case_spec.rb index 2ecd72031f..d83afd32d2 100644 --- a/spec/models/casa_case_spec.rb +++ b/spec/models/casa_case_spec.rb @@ -308,6 +308,7 @@ before do travel_to the_future end + after { travel_back } context "when the status is completed" do let(:court_report_status) { :completed } @@ -368,6 +369,8 @@ travel_to Date.new(2021, 1, 1) end + after { travel_back } + context "with a past court date" do it "returns the latest past court date as a formatted string" do most_recent_past_court_date = create(:court_date, date: 3.months.ago) diff --git a/spec/models/case_court_report_context_spec.rb b/spec/models/case_court_report_context_spec.rb index 043191517b..f3b1231982 100644 --- a/spec/models/case_court_report_context_spec.rb +++ b/spec/models/case_court_report_context_spec.rb @@ -13,6 +13,7 @@ before do travel_to Date.new(2021, 1, 1) end + after { travel_back } describe "#context" do it "has the right shape" do diff --git a/spec/models/court_date_spec.rb b/spec/models/court_date_spec.rb index ce3e665c77..db94955bb8 100644 --- a/spec/models/court_date_spec.rb +++ b/spec/models/court_date_spec.rb @@ -20,6 +20,7 @@ before do travel_to Date.new(2021, 1, 1) end + after { travel_back } describe "date validation" do it "is not valid before 1989" do @@ -148,6 +149,7 @@ it "contains case number and date" do travel_to Time.zone.local(2020, 1, 2) expect(subject).to eq("AAA123123 - Court Date - 2019-12-26") + travel_back end end end diff --git a/spec/models/supervisor_spec.rb b/spec/models/supervisor_spec.rb index cb016428fe..800acd0041 100644 --- a/spec/models/supervisor_spec.rb +++ b/spec/models/supervisor_spec.rb @@ -26,6 +26,7 @@ user = User.accept_invitation!(invitation_token: supervisor.invitation_token) expect(user.errors.full_messages).to include("Invitation token is invalid") + travel_back end end diff --git a/spec/models/volunteer_spec.rb b/spec/models/volunteer_spec.rb index c7f32ef074..4064b8d3e3 100644 --- a/spec/models/volunteer_spec.rb +++ b/spec/models/volunteer_spec.rb @@ -392,6 +392,7 @@ user = User.accept_invitation!(invitation_token: volunteer.invitation_token) expect(user.errors.full_messages).to include("Invitation token is invalid") + travel_back end end diff --git a/spec/requests/banners_spec.rb b/spec/requests/banners_spec.rb index 7ed673bdb2..20b0db4609 100644 --- a/spec/requests/banners_spec.rb +++ b/spec/requests/banners_spec.rb @@ -87,6 +87,7 @@ context "when client timezone is ahead of UTC" do before { travel_to Time.new(2024, 6, 1, 11, 0, 0, "+03:00") } # 08:00 UTC + after { travel_back } context "when submitted time is behind client but ahead of UTC" do let(:expires_at) { Time.new(2024, 6, 1, 9, 0, 0, "UTC") } # 12:00 +03:00 @@ -112,6 +113,7 @@ context "when client timezone is behind UTC" do before { travel_to Time.new(2024, 6, 1, 11, 0, 0, "-04:00") } # 15:00 UTC + after { travel_back } context "when submitted time is ahead of client and ahead of UTC" do let(:expires_at) { Time.new(2024, 6, 1, 16, 0, 0, "UTC") } # 12:00 -04:00 diff --git a/spec/requests/case_court_reports_spec.rb b/spec/requests/case_court_reports_spec.rb index ab5aae19c9..b2b4e973f6 100644 --- a/spec/requests/case_court_reports_spec.rb +++ b/spec/requests/case_court_reports_spec.rb @@ -176,6 +176,7 @@ before do travel_to server_time end + after { travel_back } it "is different than server" do get request.parsed_body["link"] diff --git a/spec/requests/court_dates_spec.rb b/spec/requests/court_dates_spec.rb index 7484f2d1b8..dc86b76d9b 100644 --- a/spec/requests/court_dates_spec.rb +++ b/spec/requests/court_dates_spec.rb @@ -34,6 +34,7 @@ travel_to Date.new(2021, 1, 1) sign_in admin end + after { travel_back } describe "GET /show" do subject(:show) { get casa_case_court_date_path(casa_case, court_date) } diff --git a/spec/requests/notifications_spec.rb b/spec/requests/notifications_spec.rb index a02957cb60..1f87d8e73c 100644 --- a/spec/requests/notifications_spec.rb +++ b/spec/requests/notifications_spec.rb @@ -4,6 +4,7 @@ before do travel_to Date.new(2021, 1, 1) end + after { travel_back } describe "GET /index" do context "when there are no patch notes" do diff --git a/spec/services/case_contacts_contact_dates_spec.rb b/spec/services/case_contacts_contact_dates_spec.rb index db0760a247..d88aa6da45 100644 --- a/spec/services/case_contacts_contact_dates_spec.rb +++ b/spec/services/case_contacts_contact_dates_spec.rb @@ -4,6 +4,7 @@ before do travel_to Date.new(2021, 6, 1) end + after { travel_back } describe "#contact_dates_details" do subject { described_class.new(interviewees).contact_dates_details } diff --git a/spec/services/volunteer_birthday_reminder_service_spec.rb b/spec/services/volunteer_birthday_reminder_service_spec.rb index f3f1277fad..a30e3f8380 100644 --- a/spec/services/volunteer_birthday_reminder_service_spec.rb +++ b/spec/services/volunteer_birthday_reminder_service_spec.rb @@ -72,6 +72,7 @@ context "when today is the 15th" do before { travel_to(this_month_15th) } + after { travel_back } let!(:volunteer) do create(:volunteer, :with_assigned_supervisor, date_of_birth: next_month) @@ -84,6 +85,7 @@ context "when today is not the 15th" do before { travel_to(this_month_15th + 2.days) } + after { travel_back } it "skips the rake task" do expect { send_reminders }.to change { Noticed::Notification.count }.by(0) diff --git a/spec/support/shared_examples/shows_court_dates_links.rb b/spec/support/shared_examples/shows_court_dates_links.rb index 43bf842921..24d6516852 100644 --- a/spec/support/shared_examples/shows_court_dates_links.rb +++ b/spec/support/shared_examples/shows_court_dates_links.rb @@ -6,6 +6,7 @@ hearing_type = create(:hearing_type, name: "Some Hearing Name") _court_date_with_details = create(:court_date, :with_court_details, casa_case: casa_case, hearing_type: hearing_type) end + after { travel_back } it "shows court orders" do visit edit_casa_case_path(casa_case) diff --git a/spec/system/bulk_court_dates/new_spec.rb b/spec/system/bulk_court_dates/new_spec.rb index 80a3b56dc7..3bc696979c 100644 --- a/spec/system/bulk_court_dates/new_spec.rb +++ b/spec/system/bulk_court_dates/new_spec.rb @@ -40,5 +40,6 @@ visit casa_case_path(casa_case) expect(page).to have_content(hearing_type.name) expect(page).to have_content(court_order_text) + travel_back end end diff --git a/spec/system/casa_cases/show_spec.rb b/spec/system/casa_cases/show_spec.rb index ea12900c49..9abedf1032 100644 --- a/spec/system/casa_cases/show_spec.rb +++ b/spec/system/casa_cases/show_spec.rb @@ -50,6 +50,7 @@ sign_in user visit casa_case_path(casa_case.id) end + after { travel_back } context "when first arriving to 'Generate Court Report' page" do it "generation modal hidden" do diff --git a/spec/system/case_court_reports/index_spec.rb b/spec/system/case_court_reports/index_spec.rb index 076c934053..47bccdf17f 100644 --- a/spec/system/case_court_reports/index_spec.rb +++ b/spec/system/case_court_reports/index_spec.rb @@ -13,6 +13,7 @@ sign_in volunteer visit case_court_reports_path end + after { travel_back } context "when first arriving to 'Generate Court Report' page", js: true do it "generation modal hidden" do diff --git a/spec/system/court_dates/edit_spec.rb b/spec/system/court_dates/edit_spec.rb index 9568ad09fa..1192284cf1 100644 --- a/spec/system/court_dates/edit_spec.rb +++ b/spec/system/court_dates/edit_spec.rb @@ -16,6 +16,7 @@ before do travel_to now end + after { travel_back } context "as an admin" do before do diff --git a/spec/system/court_dates/new_spec.rb b/spec/system/court_dates/new_spec.rb index f6c8893070..beed91a60c 100644 --- a/spec/system/court_dates/new_spec.rb +++ b/spec/system/court_dates/new_spec.rb @@ -18,6 +18,7 @@ visit casa_case_path(casa_case) click_link("Add a court date") end + after { travel_back } context "when all fields are filled" do it "is successful", js: true do diff --git a/spec/system/court_dates/view_spec.rb b/spec/system/court_dates/view_spec.rb index 4dde0e9b1e..e4d980eaed 100644 --- a/spec/system/court_dates/view_spec.rb +++ b/spec/system/court_dates/view_spec.rb @@ -14,6 +14,7 @@ before do travel_to now end + after { travel_back } context "as a volunteer" do it "can download a report which focuses on the court date", js: true do diff --git a/spec/system/placements/destroy_spec.rb b/spec/system/placements/destroy_spec.rb index 5ff11fa5b2..f4a15e7289 100644 --- a/spec/system/placements/destroy_spec.rb +++ b/spec/system/placements/destroy_spec.rb @@ -14,6 +14,7 @@ visit casa_case_placements_path(casa_case, placement) click_on "Delete" end + after { travel_back } it "does not delete on modal close" do expect(page).to have_text("Delete Placement?") diff --git a/spec/system/placements/edit_spec.rb b/spec/system/placements/edit_spec.rb index e7e9609ba0..a4c3c6e9ec 100644 --- a/spec/system/placements/edit_spec.rb +++ b/spec/system/placements/edit_spec.rb @@ -16,6 +16,7 @@ visit casa_case_placement_path(casa_case, placement) click_link("Edit") end + after { travel_back } it "updates placement with valid form data", js: true do expect(page).to have_content("123") diff --git a/spec/system/placements/index_spec.rb b/spec/system/placements/index_spec.rb index 007296f39a..535bc66a28 100644 --- a/spec/system/placements/index_spec.rb +++ b/spec/system/placements/index_spec.rb @@ -21,6 +21,7 @@ sign_in admin visit casa_case_placements_path(casa_case, placements) end + after { travel_back } it "displays all placements for org" do expect(page).to have_text("Reunification") diff --git a/spec/system/placements/new_spec.rb b/spec/system/placements/new_spec.rb index 05a559e553..f1e2b0630d 100644 --- a/spec/system/placements/new_spec.rb +++ b/spec/system/placements/new_spec.rb @@ -16,6 +16,7 @@ visit casa_case_placements_path(casa_case) click_link("New Placement") end + after { travel_back } it "creates placement with valid form data", js: true do expect(page).to have_content("123")