The personal finance app for everyone (by everyone)
Ruby
Fix flaky sign_out teardown in six test suites (#3208)
Brandonbf5ceff26926
diff --git a/test/controllers/mfa_controller_test.rb b/test/controllers/mfa_controller_test.rbindex 39aa2953ad..ea098eba98 100644--- a/test/controllers/mfa_controller_test.rb+++ b/test/controllers/mfa_controller_test.rb@@ -8,9 +8,12 @@ class MfaControllerTest < ActionDispatch::IntegrationTestenddef sign_out- @user.sessions.each do |session|- delete session_path(session)- end+ # Deleting sessions through the controller de-authenticates the request the+ # moment our own session dies, so every later delete in the loop is a+ # silent no-op and whichever sessions sort after it survive. The order is+ # unspecified, which made every suite that signs out this way flaky.+ # Teardown hygiene is not the behavior under test, so destroy directly.+ @user.sessions.destroy_allendtest "redirects to root if MFA already enabled" dodiff --git a/test/controllers/onboardings_controller_test.rb b/test/controllers/onboardings_controller_test.rbindex d1bfbe4cf4..43e72da673 100644--- a/test/controllers/onboardings_controller_test.rb+++ b/test/controllers/onboardings_controller_test.rb@@ -210,8 +210,11 @@ endprivatedef sign_out- @user.sessions.each do |session|- delete session_path(session)- end+ # Deleting sessions through the controller de-authenticates the request the+ # moment our own session dies, so every later delete in the loop is a+ # silent no-op and whichever sessions sort after it survive. The order is+ # unspecified, which made every suite that signs out this way flaky.+ # Teardown hygiene is not the behavior under test, so destroy directly.+ @user.sessions.destroy_allendenddiff --git a/test/controllers/passkey_sessions_controller_test.rb b/test/controllers/passkey_sessions_controller_test.rbindex 07b1d8e235..7d17e84fea 100644--- a/test/controllers/passkey_sessions_controller_test.rb+++ b/test/controllers/passkey_sessions_controller_test.rb@@ -226,7 +226,12 @@ class PasskeySessionsControllerTest < ActionDispatch::IntegrationTestenddef sign_out- @user.sessions.each { |session| delete session_path(session) }+ # Deleting sessions through the controller de-authenticates the request the+ # moment our own session dies, so every later delete in the loop is a+ # silent no-op and whichever sessions sort after it survive. The order is+ # unspecified, which made every suite that signs out this way flaky.+ # Teardown hygiene is not the behavior under test, so destroy directly.+ @user.sessions.destroy_allenddef with_webauthn_config(rp_id:, allowed_origins:)diff --git a/test/controllers/snaptrade_items_controller_test.rb b/test/controllers/snaptrade_items_controller_test.rbindex 4f9f832848..7274ac1392 100644--- a/test/controllers/snaptrade_items_controller_test.rb+++ b/test/controllers/snaptrade_items_controller_test.rb@@ -7,9 +7,12 @@ class SnaptradeItemsControllerTest < ActionDispatch::IntegrationTestenddef sign_out- @user.sessions.each do |session|- delete session_path(session)- end+ # Deleting sessions through the controller de-authenticates the request the+ # moment our own session dies, so every later delete in the loop is a+ # silent no-op and whichever sessions sort after it survive. The order is+ # unspecified, which made every suite that signs out this way flaky.+ # Teardown hygiene is not the behavior under test, so destroy directly.+ @user.sessions.destroy_allend# A deployment with a confidential OAuth client: both the browser redirect anddiff --git a/test/controllers/transactions/categorizes_controller_test.rb b/test/controllers/transactions/categorizes_controller_test.rbindex 8c40f32861..a1e96b2507 100644--- a/test/controllers/transactions/categorizes_controller_test.rb+++ b/test/controllers/transactions/categorizes_controller_test.rb@@ -176,7 +176,12 @@ class Transactions::CategorizesControllerTest < ActionDispatch::IntegrationTestprivatedef sign_out- @user.sessions.each { |s| delete session_path(s) }+ # Deleting sessions through the controller de-authenticates the request the+ # moment our own session dies, so every later delete in the loop is a+ # silent no-op and whichever sessions sort after it survive. The order is+ # unspecified, which made every suite that signs out this way flaky.+ # Teardown hygiene is not the behavior under test, so destroy directly.+ @user.sessions.destroy_allend# POST /transactions/categorizediff --git a/test/integration/active_storage_authorization_test.rb b/test/integration/active_storage_authorization_test.rbindex 9c30d4f91b..0a118df080 100644--- a/test/integration/active_storage_authorization_test.rb+++ b/test/integration/active_storage_authorization_test.rb@@ -288,7 +288,9 @@ class ActiveStorageAuthorizationTest < ActionDispatch::IntegrationTestprivatedef sign_out(user)- user.sessions.each { |session| delete session_path(session) }+ # Deleting through the controller de-authenticates mid-loop and later+ # deletes silently no-op; destroy directly, no order to break.+ user.sessions.destroy_allenddef with_protected_record_types(*types)