diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 5 | ||||
-rw-r--r-- | actionpack/lib/sprockets/helpers/rails_helper.rb | 25 | ||||
-rw-r--r-- | actionpack/test/template/sprockets_helper_test.rb | 7 |
3 files changed, 28 insertions, 9 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 2de084cfd6..d5befc0419 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,10 @@ ## Rails 3.2.11 (unreleased) ## +* Prevent unnecessary asset compilation when using javascript_include_tag on + files with non-standard extensions. + + *Noah Silas* + * Do not append second slash to root_url when using `trailing_slash: true` Fix #8700. Backport #8701. diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 690c71b472..a1e504be25 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -157,18 +157,25 @@ module Sprockets end def rewrite_extension(source, dir, ext) - source_ext = File.extname(source) - if ext && source_ext != ".#{ext}" - if !source_ext.empty? && (asset = asset_environment[source]) && - asset.pathname.to_s =~ /#{source}\Z/ - source - else - "#{source}.#{ext}" - end - else + source_ext = File.extname(source)[1..-1] + + if !ext || ext == source_ext + source + elsif source_ext.blank? + "#{source}.#{ext}" + elsif exact_match_present?(source) source + else + "#{source}.#{ext}" end end + + def exact_match_present?(source) + pathname = asset_environment.resolve(source) + pathname.to_s =~ /#{Regexp.escape(source)}\Z/ + rescue Sprockets::FileNotFound + false + end end end end diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index e944cfaee3..07ebd18f99 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -268,6 +268,13 @@ class SprocketsHelperTest < ActionView::TestCase javascript_include_tag(:application) end + test "precompiled assets with an extension when no JS runtime is available" do + @config.assets.compile = false + @config.assets.digests = {'foo.min.js' => 'foo.min-f00.js'} + Sprockets::Index.any_instance.stubs(:build_asset).raises + assert_nothing_raised { javascript_include_tag('foo.min') } + end + test "stylesheet path through asset_path" do assert_match %r{/assets/application-[0-9a-f]+.css}, asset_path(:application, :ext => "css") |