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.
This commit is contained in:
Javi Martín
2024-03-02 23:27:45 +01:00
parent 2af1fc72f3
commit c480cdd918

View File

@@ -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))