Files
nairobi/spec/system/campaigns_spec.rb
Javi Martín 006128da57 Query the database before a visit in campaigns test
This test was failing sometimes. One possible cause (although it might
not be the only one) is we were querying the database with
`Campaing.last` after starting the process running the browser with a
`visit`. In the past doing so has resulted in database inconsistencies
while running the tests.

Since after running the test more than 1500 times we weren't able to
reproduce the failure, it's possible that this change doesn't fix the
issue which caused the test to fail, but in the worst case scenario we
reduce the number of possible reasons why it fails.
2021-11-18 15:04:22 +01:00

38 lines
952 B
Ruby

require "rails_helper"
describe "Email campaigns", :admin do
let!(:campaign1) { create(:campaign) }
let!(:campaign2) { create(:campaign) }
scenario "Track email templates" do
3.times { visit root_path(track_id: campaign1.track_id) }
5.times { visit root_path(track_id: campaign2.track_id) }
visit admin_stats_path
click_link campaign1.name
expect(page).to have_content "#{campaign1.name} (3)"
click_link "Go back"
click_link campaign2.name
expect(page).to have_content "#{campaign2.name} (5)"
end
scenario "Do not track erroneous track_ids" do
invalid_id = Campaign.last.id + 1
visit root_path(track_id: campaign1.track_id)
visit root_path(track_id: invalid_id)
visit admin_stats_path
expect(page).to have_content campaign1.name
expect(page).not_to have_content campaign2.name
click_link campaign1.name
expect(page).to have_content "#{campaign1.name} (1)"
end
end