Skip to content

Commit

Permalink
provide better error message if path is uri [#5914 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
Neeraj Singh authored and josevalim committed Nov 11, 2010
1 parent 154e5d7 commit 793967c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions actionpack/lib/action_view/helpers/asset_tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ def ensure_javascript_sources!(sources)
end

def join_asset_file_contents(paths)
paths.collect { |path| File.read(asset_file_path!(path)) }.join("\n\n")
paths.collect { |path| File.read(asset_file_path!(path, true)) }.join("\n\n")
end

def write_asset_file_contents(joined_asset_path, asset_paths)
Expand All @@ -896,8 +896,10 @@ def asset_file_path(path)
File.join(config.assets_dir, path.split('?').first)
end

def asset_file_path!(path)
unless is_uri?(path)
def asset_file_path!(path, error_if_file_is_uri = false)
if is_uri?(path)
raise(Errno::ENOENT, "Asset file #{path} is uri and cannot be merged into single file") if error_if_file_is_uri
else
absolute_path = asset_file_path(path)
raise(Errno::ENOENT, "Asset file not found at '#{absolute_path}'" ) unless File.exist?(absolute_path)
return absolute_path
Expand Down
11 changes: 11 additions & 0 deletions actionpack/test/template/asset_tag_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,17 @@ def test_caching_javascript_include_tag_when_caching_on_and_missing_javascript_f
assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
end

def test_caching_javascript_include_tag_when_caching_on_and_javascript_file_is_uri
ENV["RAILS_ASSET_ID"] = ""
config.perform_caching = true

assert_raise(Errno::ENOENT) {
javascript_include_tag('bank', 'robber', 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.js', :cache => true)
}

assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
end

def test_caching_javascript_include_tag_when_caching_off_and_missing_javascript_file
ENV["RAILS_ASSET_ID"] = ""
config.perform_caching = false
Expand Down

0 comments on commit 793967c

Please sign in to comment.