| 75 |
75 |
|
| 76 |
76 |
private
|
| 77 |
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 |
78 |
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
|
|
79 |
with_temporary_manifest_path do |manifest_path|
|
|
80 |
manifest_path.write(content)
|
|
81 |
yield
|
| 93 |
82 |
end
|
| 94 |
83 |
end
|
| 95 |
84 |
|
| 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?
|
|
85 |
def without_manifest_file(&)
|
|
86 |
with_temporary_manifest_path(&)
|
|
87 |
end
|
| 102 |
88 |
|
| 103 |
|
yield
|
|
89 |
# Points the asset manifest path to a temporary directory so that tests
|
|
90 |
# never touch public/assets, which is shared with parallel test workers.
|
|
91 |
def with_temporary_manifest_path
|
|
92 |
config = Rails.application.assets.config
|
|
93 |
original_manifest_path = config.manifest_path
|
|
94 |
Dir.mktmpdir do |dir|
|
|
95 |
config.manifest_path = Pathname(dir).join('.manifest.json')
|
|
96 |
yield config.manifest_path
|
|
97 |
end
|
| 104 |
98 |
ensure
|
| 105 |
|
manifest_path.write(original) if original
|
|
99 |
config.manifest_path = original_manifest_path
|
| 106 |
100 |
end
|
| 107 |
101 |
end
|