Skip to content

Commit

Permalink
Use travel_back when travel_to is used
Browse files Browse the repository at this point in the history
Fixes some flaky specs
  • Loading branch information
thejonroberts committed Sep 23, 2024
1 parent 54064b6 commit 99cff14
Show file tree
Hide file tree
Showing 27 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/helpers/notifications_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
3 changes: 3 additions & 0 deletions spec/lib/tasks/supervisor_weekly_digest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/models/banner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions spec/models/casa_admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions spec/models/casa_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions spec/models/case_court_report_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/models/court_date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions spec/models/supervisor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions spec/models/volunteer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions spec/requests/banners_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/requests/case_court_reports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 2 additions & 0 deletions spec/requests/court_dates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
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) }
Expand Down
4 changes: 4 additions & 0 deletions spec/requests/health_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def setup
expect(chart_data[1]).to eq([10.months.ago.strftime("%b %Y"), 1, 0, 1])
expect(chart_data[2]).to eq([9.months.ago.strftime("%b %Y"), 1, 1, 1])
expect(chart_data[3]).to eq([8.months.ago.strftime("%b %Y"), 0, 0, 0])
travel_back
end

it "returns case contacts creation times in the last year (on the first of the month)" do
Expand All @@ -99,6 +100,7 @@ def setup
expect(chart_data[1]).to eq([10.months.ago.strftime("%b %Y"), 1, 0, 1])
expect(chart_data[2]).to eq([9.months.ago.strftime("%b %Y"), 1, 1, 1])
expect(chart_data[3]).to eq([8.months.ago.strftime("%b %Y"), 0, 0, 0])
travel_back
end
end

Expand Down Expand Up @@ -139,6 +141,7 @@ def setup
expect(chart_data[0]).to eq([11.months.ago.strftime("%b %Y"), 2, 1, 1])
expect(chart_data[1]).to eq([10.months.ago.strftime("%b %Y"), 1, 0, 0])
expect(chart_data[2]).to eq([9.months.ago.strftime("%b %Y"), 1, 1, 1])
travel_back
end

it "returns monthly unique users data for volunteers, supervisors, and admins in the last year (on the first of the month)" do
Expand All @@ -157,6 +160,7 @@ def setup
expect(chart_data[0]).to eq([11.months.ago.strftime("%b %Y"), 2, 1, 1])
expect(chart_data[1]).to eq([10.months.ago.strftime("%b %Y"), 1, 0, 0])
expect(chart_data[2]).to eq([9.months.ago.strftime("%b %Y"), 1, 1, 1])
travel_back
end
end
end
1 change: 1 addition & 0 deletions spec/requests/notifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/services/case_contacts_contact_dates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 3 additions & 0 deletions spec/services/volunteer_birthday_reminder_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@

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)
Expand All @@ -84,6 +86,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)
Expand Down
1 change: 1 addition & 0 deletions spec/support/shared_examples/shows_court_dates_links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions spec/system/bulk_court_dates/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions spec/system/casa_cases/show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/system/case_court_reports/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/system/court_dates/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
before do
travel_to now
end
after { travel_back }

context "as an admin" do
before do
Expand Down
1 change: 1 addition & 0 deletions spec/system/court_dates/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/system/court_dates/view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/system/placements/destroy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?")
Expand Down
1 change: 1 addition & 0 deletions spec/system/placements/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions spec/system/placements/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions spec/system/placements/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 99cff14

Please sign in to comment.