From 4ec28aaa35732ae233963706d570ecf1e92547ed Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Sat, 24 Oct 2026 15:29:31 +0900 Subject: [PATCH] Use a temporary asset manifest in PatchesTest to avoid conflicts between parallel workers --- test/unit/initializers/patches_test.rb | 38 +++++++++++--------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/test/unit/initializers/patches_test.rb b/test/unit/initializers/patches_test.rb index e45d60a4c..e5094be8b 100644 --- a/test/unit/initializers/patches_test.rb +++ b/test/unit/initializers/patches_test.rb @@ -75,33 +75,27 @@ class PatchesTest < ActiveSupport::TestCase private - # Temporarily replaces the content of the real asset manifest file with - # +content+ for the duration of the block, restoring (or removing) it - # afterwards. def with_manifest_content(content) - manifest_path = Rails.application.assets.config.manifest_path - manifest_path.dirname.mkpath - original = manifest_path.read if manifest_path.exist? - - manifest_path.write(content) - yield - ensure - if original - manifest_path.write(original) - elsif manifest_path.exist? - manifest_path.delete + with_temporary_manifest_path do |manifest_path| + manifest_path.write(content) + yield end end - # Temporarily removes the real asset manifest file for the duration of the - # block, restoring it afterwards if it existed. - def without_manifest_file - manifest_path = Rails.application.assets.config.manifest_path - original = manifest_path.read if manifest_path.exist? - manifest_path.delete if manifest_path.exist? + def without_manifest_file(&) + with_temporary_manifest_path(&) + end - yield + # Points the asset manifest path to a temporary directory so that tests + # never touch public/assets, which is shared with parallel test workers. + def with_temporary_manifest_path + config = Rails.application.assets.config + original_manifest_path = config.manifest_path + Dir.mktmpdir do |dir| + config.manifest_path = Pathname(dir).join('.manifest.json') + yield config.manifest_path + end ensure - manifest_path.write(original) if original + config.manifest_path = original_manifest_path end end -- 2.55.0