From b870e291703f6d41099bd65f0f23f974bafa9823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 15 Oct 2024 12:11:04 +0200 Subject: [PATCH 1/2] Disable turbolinks previews in the test environment When clicking the browser's back button, browsers usually don't reload the page but show a cached version of the page. Turbolinks takes this one step further. When clicking on a link to a page that's already cached, turbolinks displays the cached version of the page and then it reloads it. I don't really like this behavior but, since it affects the whole application and we're about to release a patch version :), for now we're keeping it this way in the development and production environments. In the test environment, however, we're disabling these previews because they might lead to requests leaking between tests. For example, a test that visits the investments index, then goes to "check my votes", then clicks on "Go back" and finishes by checking some content on this page will result in those checks being done against the cached version of the page. If these checks pass before turbolinks reloads the page, the "Go back" request will finish during the test that runs immediately after this one, resulting in unpredictable results. Disabling the previews solves the issue. --- app/views/layouts/_common_head.html.erb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/views/layouts/_common_head.html.erb b/app/views/layouts/_common_head.html.erb index aad2c35e9..f78fe6d8d 100644 --- a/app/views/layouts/_common_head.html.erb +++ b/app/views/layouts/_common_head.html.erb @@ -14,3 +14,7 @@ + +<% if Rails.env.test? %> + +<% end %> From 27a4dc14718be14f31a0e30a03a1e8eb830ad60e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 15 Oct 2024 12:13:53 +0200 Subject: [PATCH 2/2] Check page content in ballots specs Even after disabling the turbolinks previews in the previous commit (which is still necessary, even with the changes in this commit), these tests were still finishing before the "Go back" requests did. To reproduce an issue caused by this behavior, run: ``` rspec spec/system/budgets/ballots_spec.rb:425 spec/system/users_auth_spec.rb:701 --seed 40358 ``` Apparently, a `have_current_path` expectation isn't enough to check that the request has finished and it only checks that the request to that path has started or it's being processed. Adding an additional expectation to check that the content of the page has changed solves the issue. --- spec/system/budgets/ballots_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/system/budgets/ballots_spec.rb b/spec/system/budgets/ballots_spec.rb index 981d26c12..2d35fc40b 100644 --- a/spec/system/budgets/ballots_spec.rb +++ b/spec/system/budgets/ballots_spec.rb @@ -444,6 +444,7 @@ describe "Ballots" do click_link "Go back" expect(page).to have_current_path(budget_investments_path(budget, heading_id: new_york.id)) + expect(page).to have_link "Check my votes" end scenario "before adding any investments" do @@ -459,6 +460,7 @@ describe "Ballots" do click_link "Go back" expect(page).to have_current_path(budget_investments_path(budget, heading_id: new_york.id)) + expect(page).to have_link "Check my votes" end end