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.
This commit is contained in:
Javi Martín
2024-10-15 12:11:04 +02:00
parent 62d2f9e180
commit b870e29170

View File

@@ -14,3 +14,7 @@
<noscript>
<%= stylesheet_link_tag "noscript" %>
</noscript>
<% if Rails.env.test? %>
<meta name="turbolinks-cache-control" content="no-preview">
<% end %>