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).
This commit is contained in:
Javi Martín
2024-06-17 16:46:39 +02:00
parent a20f32401f
commit c7267f9729
3 changed files with 8 additions and 18 deletions

View File

@@ -32,8 +32,7 @@ describe "BudgetPolls", :with_frozen_time do
expect(Poll::Voter.count).to eq(1) expect(Poll::Voter.count).to eq(1)
expect(Poll::Voter.first.origin).to eq("booth") expect(Poll::Voter.first.origin).to eq("booth")
visit root_path logout
click_link "Sign out"
login_as(admin.user) login_as(admin.user)
visit admin_poll_recounts_path(poll) visit admin_poll_recounts_path(poll)

View File

@@ -74,8 +74,7 @@ describe "Voters" do
document_number: "12345678Z") document_number: "12345678Z")
expect(user).not_to be_level_two_verified expect(user).not_to be_level_two_verified
visit root_path logout
click_link "Sign out"
login_through_form_as_officer(officer.user) login_through_form_as_officer(officer.user)
visit new_officing_residence_path visit new_officing_residence_path

View File

@@ -90,8 +90,7 @@ describe "Voter" do
expect(Poll::Voter.count).to eq(1) expect(Poll::Voter.count).to eq(1)
expect(Poll::Voter.first.origin).to eq("booth") expect(Poll::Voter.first.origin).to eq("booth")
visit root_path logout
click_link "Sign out"
login_as(admin.user) login_as(admin.user)
visit admin_poll_recounts_path(poll) visit admin_poll_recounts_path(poll)
@@ -148,8 +147,7 @@ describe "Voter" do
vote_for_poll_via_web(poll, question, "Yes") vote_for_poll_via_web(poll, question, "Yes")
expect(Poll::Voter.count).to eq(1) expect(Poll::Voter.count).to eq(1)
click_link "Sign out" logout
login_through_form_as_officer(officer.user) login_through_form_as_officer(officer.user)
visit new_officing_residence_path visit new_officing_residence_path
@@ -165,9 +163,7 @@ describe "Voter" do
vote_for_poll_via_booth vote_for_poll_via_booth
visit root_path logout
click_link "Sign out"
login_as user login_as user
visit poll_path(poll) visit poll_path(poll)
@@ -178,8 +174,7 @@ describe "Voter" do
"You can not participate again." "You can not participate again."
expect(Poll::Voter.count).to eq(1) expect(Poll::Voter.count).to eq(1)
visit root_path logout
click_link "Sign out"
login_as(admin.user) login_as(admin.user)
visit admin_poll_recounts_path(poll) visit admin_poll_recounts_path(poll)
@@ -199,9 +194,7 @@ describe "Voter" do
login_through_form_as_officer(officer.user) login_through_form_as_officer(officer.user)
vote_for_poll_via_booth vote_for_poll_via_booth
visit root_path logout
click_link "Sign out"
login_as user login_as user
visit account_path visit account_path
click_link "Verify my account" click_link "Verify my account"
@@ -219,8 +212,7 @@ describe "Voter" do
"You can not participate again." "You can not participate again."
expect(Poll::Voter.count).to eq(1) expect(Poll::Voter.count).to eq(1)
visit root_path logout
click_link "Sign out"
login_as(admin.user) login_as(admin.user)
visit admin_poll_recounts_path(poll) visit admin_poll_recounts_path(poll)