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.
This commit is contained in:
Javi Martín
2022-06-02 19:03:11 +02:00
parent 0dded3fa22
commit d91775b4aa
2 changed files with 2 additions and 3 deletions

View File

@@ -13,7 +13,7 @@ describe "Admin booths", :admin do
end end
scenario "Index" do scenario "Index" do
3.times { create(:poll_booth) } booths = 3.times.map { create(:poll_booth) }
visit admin_root_path visit admin_root_path
@@ -22,7 +22,6 @@ describe "Admin booths", :admin do
click_link "Booths location" click_link "Booths location"
end end
booths = Poll::Booth.all
booths.each do |booth| booths.each do |booth|
within("#booth_#{booth.id}") do within("#booth_#{booth.id}") do
expect(page).to have_content booth.name expect(page).to have_content booth.name

View File

@@ -212,6 +212,7 @@ describe "Admin polls", :admin do
booth.booth_assignments.each do |booth_assignment| booth.booth_assignments.each do |booth_assignment|
3.times { create(:poll_officer_assignment, booth_assignment: booth_assignment) } 3.times { create(:poll_officer_assignment, booth_assignment: booth_assignment) }
end end
officers = Poll::Officer.all
visit admin_poll_path(poll) visit admin_poll_path(poll)
@@ -219,7 +220,6 @@ describe "Admin polls", :admin do
expect(page).to have_css ".officer", count: 3 expect(page).to have_css ".officer", count: 3
officers = Poll::Officer.all
officers.each do |officer| officers.each do |officer|
within("#officer_#{officer.id}") do within("#officer_#{officer.id}") do
expect(page).to have_content officer.name expect(page).to have_content officer.name