From c7267f9729b5fd9d47b75d41aca0748f82bc3d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 17 Jun 2024 16:46:39 +0200 Subject: [PATCH] Use logout to sign out in tests We were doing it most of the time, but in some cases we were clicking the "Sign out" link instead. These actions aren't the same, just like using `login_as` is not the same as visiting the sign in page and submitting the form. Some of these tests failed sometimes because the user wasn't signed in after using `login_as`. One possible cause could be that we weren't adding an expectation after clicking the "Sign out" link. So using `logout` adds consistency, simplifies the code, and might reduce the chance of these tests failing in the future (although they might still fail in the future because some of these tests check the database after a `visit` call). --- spec/system/budget_polls/voter_spec.rb | 3 +-- spec/system/officing/voters_spec.rb | 3 +-- spec/system/polls/voter_spec.rb | 20 ++++++-------------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/spec/system/budget_polls/voter_spec.rb b/spec/system/budget_polls/voter_spec.rb index 45377cdd3..80a975ad9 100644 --- a/spec/system/budget_polls/voter_spec.rb +++ b/spec/system/budget_polls/voter_spec.rb @@ -32,8 +32,7 @@ describe "BudgetPolls", :with_frozen_time do expect(Poll::Voter.count).to eq(1) expect(Poll::Voter.first.origin).to eq("booth") - visit root_path - click_link "Sign out" + logout login_as(admin.user) visit admin_poll_recounts_path(poll) diff --git a/spec/system/officing/voters_spec.rb b/spec/system/officing/voters_spec.rb index 63143123d..84d0844d1 100644 --- a/spec/system/officing/voters_spec.rb +++ b/spec/system/officing/voters_spec.rb @@ -74,8 +74,7 @@ describe "Voters" do document_number: "12345678Z") expect(user).not_to be_level_two_verified - visit root_path - click_link "Sign out" + logout login_through_form_as_officer(officer.user) visit new_officing_residence_path diff --git a/spec/system/polls/voter_spec.rb b/spec/system/polls/voter_spec.rb index da1a8ff2a..52d2a352a 100644 --- a/spec/system/polls/voter_spec.rb +++ b/spec/system/polls/voter_spec.rb @@ -90,8 +90,7 @@ describe "Voter" do expect(Poll::Voter.count).to eq(1) expect(Poll::Voter.first.origin).to eq("booth") - visit root_path - click_link "Sign out" + logout login_as(admin.user) visit admin_poll_recounts_path(poll) @@ -148,8 +147,7 @@ describe "Voter" do vote_for_poll_via_web(poll, question, "Yes") expect(Poll::Voter.count).to eq(1) - click_link "Sign out" - + logout login_through_form_as_officer(officer.user) visit new_officing_residence_path @@ -165,9 +163,7 @@ describe "Voter" do vote_for_poll_via_booth - visit root_path - click_link "Sign out" - + logout login_as user visit poll_path(poll) @@ -178,8 +174,7 @@ describe "Voter" do "You can not participate again." expect(Poll::Voter.count).to eq(1) - visit root_path - click_link "Sign out" + logout login_as(admin.user) visit admin_poll_recounts_path(poll) @@ -199,9 +194,7 @@ describe "Voter" do login_through_form_as_officer(officer.user) vote_for_poll_via_booth - visit root_path - click_link "Sign out" - + logout login_as user visit account_path click_link "Verify my account" @@ -219,8 +212,7 @@ describe "Voter" do "You can not participate again." expect(Poll::Voter.count).to eq(1) - visit root_path - click_link "Sign out" + logout login_as(admin.user) visit admin_poll_recounts_path(poll)