From 855f47f386a6c654ffb928c7f542670299b808e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 30 Jun 2021 15:07:31 +0200 Subject: [PATCH 1/2] Create campaings before running campaigns tests We were defining campaigns with `let`. That meant they weren't created until these methods were used in the tests. For the test "Do not track erroneous track_ids", that meant the line `expect(page).not_to have_content campaign2.name.to_s` wasn't really testing anything, since before this line is executed, the campaign2 wasn't in the database at all, and so obviously its name wouldn't be on the stats page. For the test "Track email templates", it meant we were creating the campaign2 record after visiting the campaign1 page with the browser. Creating records in the tests after starting the browser might be the reason why this test has recenty failed in our CI [1]: 1) Email campaigns Track email templates Failure/Error: ds.add params[:event].titleize, Ahoy::Event.where( name: params[:event]).group_by_day(:time).count ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR: bind message supplies 0 parameters, but prepared statement "" requires 1 # ./app/controllers/admin/api/stats_controller.rb:13:in `show' Using `let!` to create the campaings before the browser starts improves the situation. [1] https://github.com/consul/consul/runs/2952333023 --- spec/system/campaigns_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/system/campaigns_spec.rb b/spec/system/campaigns_spec.rb index 27fe905be..392836abd 100644 --- a/spec/system/campaigns_spec.rb +++ b/spec/system/campaigns_spec.rb @@ -1,8 +1,8 @@ require "rails_helper" describe "Email campaigns", :admin do - let(:campaign1) { create(:campaign) } - let(:campaign2) { create(:campaign) } + let!(:campaign1) { create(:campaign) } + let!(:campaign2) { create(:campaign) } scenario "Track email templates" do 3.times { visit root_path(track_id: campaign1.track_id) } From 28e720a1ecce95849ba442363579a6c050f2b5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 30 Jun 2021 15:16:58 +0200 Subject: [PATCH 2/2] Make sure we use non-existent IDs in campaign test Previously, depending on the database status, it could be possible that the ID of the campaign2 record was exactly 999 and this test could fail. --- spec/system/campaigns_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/campaigns_spec.rb b/spec/system/campaigns_spec.rb index 392836abd..60befbc3b 100644 --- a/spec/system/campaigns_spec.rb +++ b/spec/system/campaigns_spec.rb @@ -21,7 +21,7 @@ describe "Email campaigns", :admin do scenario "Do not track erroneous track_ids" do visit root_path(track_id: campaign1.track_id) - visit root_path(track_id: "999") + visit root_path(track_id: Campaign.last.id + 1) visit admin_stats_path click_link campaign1.name