A platform for community discussion. Free, open, simple.
FIX: Raise error after exhausting retries in development asset lookup (#39935)
discourse-patch-triage[bot]ef6ece39e336
diff --git a/lib/freedom_patches/propshaft_patches.rb b/lib/freedom_patches/propshaft_patches.rbindex 24203874656..5d6875f488e 100644--- a/lib/freedom_patches/propshaft_patches.rb+++ b/lib/freedom_patches/propshaft_patches.rb@@ -15,14 +15,15 @@ Propshaft::Helper.prepend(beginsuperrescue Propshaft::MissingAssetError => e- if Rails.env.development?+ if Rails.env.test?+ # Assets might not be compiled in test mode. Just return a fake path+ "/assets/#{path.sub(".", "-aaaaaaaa.")}"+ elsif Rails.env.development?# Ember-cli might've replaced the assetsRails.application.assets.load_path.send(:clear_cache)attempts += 1retry if attempts < 3- elsif Rails.env.test?- # Assets might not be compiled in test mode. Just return a fake path- "/assets/#{path.sub(".", "-aaaaaaaa.")}"+ raise eelseraise eenddiff --git a/spec/lib/freedom_patches/propshaft_patches_spec.rb b/spec/lib/freedom_patches/propshaft_patches_spec.rbnew file mode 100644index 00000000000..da2db76aaa1--- /dev/null+++ b/spec/lib/freedom_patches/propshaft_patches_spec.rb@@ -0,0 +1,33 @@+# frozen_string_literal: true++RSpec.describe Propshaft::Helper do+ describe "#compute_asset_path" do+ it "raises after exhausting retries in development" do+ Rails.env.stubs(:development?).returns(true)+ Rails.env.stubs(:test?).returns(false)++ Rails.application.assets.load_path.expects(:clear_cache).times(3)++ helper_module = described_class+ helper = Class.new { include helper_module }.new+ missing_asset_path = "__nonexistent_propshaft_asset__.js"++ expect { helper.compute_asset_path(missing_asset_path) }.to raise_error(+ Propshaft::MissingAssetError,+ /#{missing_asset_path}/,+ )+ end++ it "uses the test fallback when the test environment stubs development" do+ Rails.env.stubs(:development?).returns(true)++ helper_module = described_class+ helper = Class.new { include helper_module }.new+ missing_asset_path = "__nonexistent_propshaft_asset__.js"++ expect(helper.compute_asset_path(missing_asset_path)).to eq(+ "/assets/__nonexistent_propshaft_asset__-aaaaaaaa.js",+ )+ end+ end+end