From c480cdd918a9023d802bb1edb7702d4900d27a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 2 Mar 2024 23:27:45 +0100 Subject: [PATCH] Don't create records after a visit in polls tests Creating records after starting the browser with the `visit` method sometimes results in database corruption and failing tests on our CI. Splitting some tests or merging them together solves the issue. --- spec/system/polls/polls_spec.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/spec/system/polls/polls_spec.rb b/spec/system/polls/polls_spec.rb index cda25ce3c..ace5c4140 100644 --- a/spec/system/polls/polls_spec.rb +++ b/spec/system/polls/polls_spec.rb @@ -6,23 +6,26 @@ describe "Polls" do end describe "Index" do - scenario "Shows description for open polls" do + scenario "Shows a no open votings message when there are no polls" do visit polls_path - expect(page).not_to have_content "Description for open polls" + expect(page).to have_content "There are no open votings" + expect(page).not_to have_content "Description for open polls" + end + + scenario "Shows active poll description for open polls when defined" do create(:active_poll, description: "Description for open polls") visit polls_path + expect(page).to have_content "Description for open polls" click_link "Expired" + expect(page).not_to have_content "Description for open polls" end scenario "Polls can be listed" do - visit polls_path - expect(page).to have_content("There are no open votings") - polls = [create(:poll, :with_image)] # TODO: generate a list again after switching to zeitwerk visit polls_path @@ -84,14 +87,17 @@ describe "Polls" do expect(page).not_to have_link("Expired") end - scenario "Displays icon correctly" do + scenario "Displays a message asking anonymous users to sign in" do create_list(:poll, 3) visit polls_path expect(page).to have_css(".not-logged-in", count: 3) expect(page).to have_content("You must sign in or sign up to participate") + end + scenario "Displays a message asking unverified users to verify their account" do + create_list(:poll, 3) user = create(:user) login_as(user) @@ -118,6 +124,8 @@ describe "Polls" do login_as(create(:user, :level_two)) visit polls_path + expect(page).not_to have_css ".already-answer" + vote_for_poll_via_web(poll_with_question, question, "Yes") visit polls_path @@ -229,11 +237,7 @@ describe "Polls" do end scenario "Level 1 users" do - visit polls_path - expect(page).not_to have_css ".already-answer" - poll.update!(geozone_restricted_to: [geozone]) - create(:poll_question, :yes_no, poll: poll) login_as(create(:user, geozone: geozone))