Project

General

Profile

Defect #44240 » 0002-Add-test-coverage-for-Propshaft-Assembly-manifest_ou.patch

Marius BĂLTEANU, 2026-10-12 23:58

View differences:

test/unit/initializers/patches_test.rb
48 48
    assert_include 'max="9999-12-31"', date_field_tag('start_date')
49 49
    assert_include 'max="2099-12-31"', date_field_tag('issue', 'start_date', max: '2099-12-31')
50 50
  end
51

  
52
  test 'Propshaft::Assembly#manifest_outdated? should return false when the on-disk manifest matches the current assets' do
53
    with_manifest_content(Rails.application.assets.load_path.manifest.to_json) do
54
      assert_not Rails.application.assets.manifest_outdated?
55
    end
56
  end
57

  
58
  test 'Propshaft::Assembly#manifest_outdated? should return true when the on-disk manifest differs from the current assets' do
59
    with_manifest_content('{}') do
60
      assert Rails.application.assets.manifest_outdated?
61
    end
62
  end
63

  
64
  test 'Propshaft::Assembly#manifest_outdated? should return true instead of raising when the manifest file contains invalid JSON' do
65
    with_manifest_content('not valid json') do
66
      assert Rails.application.assets.manifest_outdated?
67
    end
68
  end
69

  
70
  test 'Propshaft::Assembly#needs_precompile? should return true when there is no manifest file' do
71
    without_manifest_file do
72
      assert Rails.application.assets.needs_precompile?
73
    end
74
  end
75

  
76
  private
77

  
78
  # Temporarily replaces the content of the real asset manifest file with
79
  # +content+ for the duration of the block, restoring (or removing) it
80
  # afterwards.
81
  def with_manifest_content(content)
82
    manifest_path = Rails.application.assets.config.manifest_path
83
    manifest_path.dirname.mkpath
84
    original = manifest_path.read if manifest_path.exist?
85

  
86
    manifest_path.write(content)
87
    yield
88
  ensure
89
    if original
90
      manifest_path.write(original)
91
    elsif manifest_path.exist?
92
      manifest_path.delete
93
    end
94
  end
95

  
96
  # Temporarily removes the real asset manifest file for the duration of the
97
  # block, restoring it afterwards if it existed.
98
  def without_manifest_file
99
    manifest_path = Rails.application.assets.config.manifest_path
100
    original = manifest_path.read if manifest_path.exist?
101
    manifest_path.delete if manifest_path.exist?
102

  
103
    yield
104
  ensure
105
    manifest_path.write(original) if original
106
  end
51 107
end
(2-2/3)