From 30880b861fb6096bd4d5189b03b621dab77d8821 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Wed, 13 Aug 2025 05:31:26 +0000 Subject: [PATCH] Run Setting.clear_cache after each test in order to decrease the number of random failing tests (#43130). Patch by Katsuya HIDAKA (user:hidakatsuya). git-svn-id: https://svn.redmine.org/redmine/trunk@23915 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/functional/reactions_controller_test.rb | 4 ---- test/functional/settings_controller_test.rb | 5 ----- test/functional/sys_controller_test.rb | 4 ---- test/helpers/reactions_helper_test.rb | 4 ---- test/test_helper.rb | 5 +++++ test/unit/lib/redmine/reaction_test.rb | 4 ---- test/unit/mail_handler_test.rb | 4 ---- test/unit/setting_test.rb | 9 --------- 8 files changed, 5 insertions(+), 34 deletions(-) diff --git a/test/functional/reactions_controller_test.rb b/test/functional/reactions_controller_test.rb index b65794969..0d33a1f6f 100644 --- a/test/functional/reactions_controller_test.rb +++ b/test/functional/reactions_controller_test.rb @@ -26,10 +26,6 @@ class ReactionsControllerTest < Redmine::ControllerTest @request.session[:user_id] = users(:users_002).id end - teardown do - Setting.clear_cache - end - test 'create for issue' do issue = issues(:issues_002) diff --git a/test/functional/settings_controller_test.rb b/test/functional/settings_controller_test.rb index a27333c7e..ef17883ec 100644 --- a/test/functional/settings_controller_test.rb +++ b/test/functional/settings_controller_test.rb @@ -25,11 +25,6 @@ class SettingsControllerTest < Redmine::ControllerTest @request.session[:user_id] = 1 # admin end - def teardown - Setting.delete_all - Setting.clear_cache - end - def test_index get :index assert_response :success diff --git a/test/functional/sys_controller_test.rb b/test/functional/sys_controller_test.rb index 7c4bab6a2..c88ac8177 100644 --- a/test/functional/sys_controller_test.rb +++ b/test/functional/sys_controller_test.rb @@ -25,10 +25,6 @@ class SysControllerTest < Redmine::ControllerTest Setting.enabled_scm = %w(Subversion Git) end - def teardown - Setting.clear_cache - end - def test_projects_with_repository_enabled get :projects assert_response :success diff --git a/test/helpers/reactions_helper_test.rb b/test/helpers/reactions_helper_test.rb index 1c5c82418..061576364 100644 --- a/test/helpers/reactions_helper_test.rb +++ b/test/helpers/reactions_helper_test.rb @@ -27,10 +27,6 @@ class ReactionsHelperTest < ActionView::TestCase Setting.reactions_enabled = '1' end - teardown do - Setting.clear_cache - end - test 'reaction_id_for generates a DOM id' do assert_equal "reaction_issue_1", reaction_id_for(issues(:issues_001)) end diff --git a/test/test_helper.rb b/test/test_helper.rb index aa7e43b01..a59f70c85 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -61,6 +61,11 @@ class ActiveSupport::TestCase self.use_transactional_tests = true self.use_instantiated_fixtures = false + # Clear Settings cache after each test to prevent test interference + teardown do + Setting.clear_cache + end + def uploaded_test_file(name, mime) fixture_file_upload(name.to_s, mime, true) end diff --git a/test/unit/lib/redmine/reaction_test.rb b/test/unit/lib/redmine/reaction_test.rb index f3228a3bd..cf64ead3d 100644 --- a/test/unit/lib/redmine/reaction_test.rb +++ b/test/unit/lib/redmine/reaction_test.rb @@ -26,10 +26,6 @@ class Redmine::ReactionTest < ActiveSupport::TestCase Setting.reactions_enabled = '1' end - teardown do - Setting.clear_cache - end - test 'preload_reaction_details preloads ReactionDetail for all objects in the collection' do User.current = users(:users_002) diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index e05b64b0c..8556d1e6c 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -28,10 +28,6 @@ class MailHandlerTest < ActiveSupport::TestCase User.current = nil end - def teardown - Setting.clear_cache - end - def test_add_issue_with_specific_overrides issue = submit_email( diff --git a/test/unit/setting_test.rb b/test/unit/setting_test.rb index cbfabbb02..79b44fa91 100644 --- a/test/unit/setting_test.rb +++ b/test/unit/setting_test.rb @@ -24,15 +24,7 @@ class SettingTest < ActiveSupport::TestCase User.current = nil end - def teardown - Setting.delete_all - Setting.clear_cache - end - def test_read_default - Setting.delete_all - Setting.clear_cache - assert_equal "Redmine", Setting.app_title assert Setting.self_registration? assert !Setting.login_required? @@ -127,7 +119,6 @@ class SettingTest < ActiveSupport::TestCase assert_equal 'UTF-8', Setting.commit_update_keywords.first['keywords'].encoding.name ensure Setting.where(:name => 'commit_update_keywords').delete_all - Setting.clear_cache end def test_mail_from_format_should_be_validated