From d91775b4aa704676bddd7a264be0a8e3f0572c4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 2 Jun 2022 19:03:11 +0200 Subject: [PATCH] Make database queries before starting the browser When we perform database queries in tests after the process running the browser has started, we sometimes get failures in our test suite due to both the tests and the browser accessing the database at the same time. --- spec/system/admin/poll/booths_spec.rb | 3 +-- spec/system/admin/poll/polls_spec.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/system/admin/poll/booths_spec.rb b/spec/system/admin/poll/booths_spec.rb index eb6cead7e..a930bf9f6 100644 --- a/spec/system/admin/poll/booths_spec.rb +++ b/spec/system/admin/poll/booths_spec.rb @@ -13,7 +13,7 @@ describe "Admin booths", :admin do end scenario "Index" do - 3.times { create(:poll_booth) } + booths = 3.times.map { create(:poll_booth) } visit admin_root_path @@ -22,7 +22,6 @@ describe "Admin booths", :admin do click_link "Booths location" end - booths = Poll::Booth.all booths.each do |booth| within("#booth_#{booth.id}") do expect(page).to have_content booth.name diff --git a/spec/system/admin/poll/polls_spec.rb b/spec/system/admin/poll/polls_spec.rb index afeaaf8da..a677ca0cc 100644 --- a/spec/system/admin/poll/polls_spec.rb +++ b/spec/system/admin/poll/polls_spec.rb @@ -212,6 +212,7 @@ describe "Admin polls", :admin do booth.booth_assignments.each do |booth_assignment| 3.times { create(:poll_officer_assignment, booth_assignment: booth_assignment) } end + officers = Poll::Officer.all visit admin_poll_path(poll) @@ -219,7 +220,6 @@ describe "Admin polls", :admin do expect(page).to have_css ".officer", count: 3 - officers = Poll::Officer.all officers.each do |officer| within("#officer_#{officer.id}") do expect(page).to have_content officer.name