From 4ea8e1a126833ed7b5b6924c569c592b6c92a55e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20B=C4=82LTEANU?= Date: Tue, 13 Oct 2026 00:52:16 +0300 Subject: [PATCH 2/2] Add test coverage for Propshaft::Assembly#manifest_outdated?/#needs_precompile? (#44240). Covers the stable case (on-disk manifest matches current assets -> false), the outdated case (differs -> true), the needs_precompile? no-manifest case, and - the case that would have caught the JSON::ParseError typo immediately - a malformed manifest.json returning true instead of raising. Temporarily swaps the real asset manifest file's content for the duration of each test (restoring/removing it afterwards) since Rails.application.assets is a live singleton and this logic isn't easily exercised in isolation without a real Propshaft::Assembly/Configuration. --- test/unit/initializers/patches_test.rb | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/unit/initializers/patches_test.rb b/test/unit/initializers/patches_test.rb index c26e8173c..e45d60a4c 100644 --- a/test/unit/initializers/patches_test.rb +++ b/test/unit/initializers/patches_test.rb @@ -48,4 +48,60 @@ class PatchesTest < ActiveSupport::TestCase assert_include 'max="9999-12-31"', date_field_tag('start_date') assert_include 'max="2099-12-31"', date_field_tag('issue', 'start_date', max: '2099-12-31') end + + test 'Propshaft::Assembly#manifest_outdated? should return false when the on-disk manifest matches the current assets' do + with_manifest_content(Rails.application.assets.load_path.manifest.to_json) do + assert_not Rails.application.assets.manifest_outdated? + end + end + + test 'Propshaft::Assembly#manifest_outdated? should return true when the on-disk manifest differs from the current assets' do + with_manifest_content('{}') do + assert Rails.application.assets.manifest_outdated? + end + end + + test 'Propshaft::Assembly#manifest_outdated? should return true instead of raising when the manifest file contains invalid JSON' do + with_manifest_content('not valid json') do + assert Rails.application.assets.manifest_outdated? + end + end + + test 'Propshaft::Assembly#needs_precompile? should return true when there is no manifest file' do + without_manifest_file do + assert Rails.application.assets.needs_precompile? + end + end + + 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 + 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? + + yield + ensure + manifest_path.write(original) if original + end end -- 2.54.0 (Apple Git-157)