Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List manifest locations when asset is not found #468

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/sprockets/rails/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ def compute_asset_path(path, options = {})
if asset_path = resolve_asset_path(path, debug)
File.join(assets_prefix || "/", legacy_debug_path(asset_path, debug))
else
message = "The asset #{ path.inspect } is not present in the asset pipeline.\n"
message = String.new("The asset #{ path.inspect } is not present in the asset pipeline.\n")
asset_resolver_strategies.each do |strat|
message << "Checked in manifest file: #{strat.filename}\n" if strat.filename
end

raise AssetNotFound, message unless unknown_asset_fallback

if respond_to?(:public_compute_asset_path)
Expand Down Expand Up @@ -284,6 +288,10 @@ def initialize(view)
raise ArgumentError, 'config.assets.resolve_with includes :manifest, but app.assets_manifest is nil' unless @manifest
end

def filename
@manifest.try(:filename)
end

def asset_path(path, digest, allow_non_precompiled = false)
if digest
digest_path path, allow_non_precompiled
Expand Down Expand Up @@ -320,6 +328,10 @@ def initialize(view)
@check_precompiled_asset = view.check_precompiled_asset
end

def filename
nil
end

def asset_path(path, digest, allow_non_precompiled = false)
# Digests enabled? Do the work to calculate the full asset path.
if digest
Expand Down
1 change: 1 addition & 0 deletions sprockets-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "rake"
s.add_development_dependency "sass"
s.add_development_dependency "uglifier"
s.add_development_dependency "m"

s.author = "Joshua Peek"
s.email = "[email protected]"
Expand Down
19 changes: 19 additions & 0 deletions test/test_railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,25 @@ def test_action_view_helper_when_no_compile
assert_equal app.assets_manifest, @view.assets_manifest
end

def test_lists_manifest_files_on_failed_asset_lookup_in_prod
app.configure do
config.assets.compile = false
config.assets.unknown_asset_fallback = false
end

assert_equal false, app.config.assets.compile

app.initialize!

@view = ActionView::Base.new
error = assert_raises do
@view.asset_path("does_not_exist.js")
end

assert_match(/Checked in manifest/, error.message)
assert_match(/\.sprockets-manifest-/, error.message)
end

def test_sprockets_context_helper
app.initialize!

Expand Down