diff options
-rw-r--r-- | actionpack/lib/sprockets/assets.rake | 18 | ||||
-rw-r--r-- | railties/test/application/assets_test.rb | 20 |
2 files changed, 33 insertions, 5 deletions
diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake index 65f0ad4cc8..e29661e4e7 100644 --- a/actionpack/lib/sprockets/assets.rake +++ b/actionpack/lib/sprockets/assets.rake @@ -19,12 +19,16 @@ namespace :assets do # Ensure that action view is loaded and the appropriate sprockets hooks get executed ActionView::Base - # Always compile files - Rails.application.config.assets.compile = true - config = Rails.application.config + config.assets.compile = true + config.assets.digest = false if ENV["RAILS_ASSETS_NONDIGEST"] + env = Rails.application.assets + # Always compile files and avoid use of existing precompiled assets + config.assets.compile = true + config.assets.digests = {} + target = File.join(Rails.public_path, config.assets.prefix) static_compiler = Sprockets::StaticCompiler.new(env, target, :digest => config.assets.digest) @@ -32,8 +36,12 @@ namespace :assets do manifest_path = config.assets.manifest || target FileUtils.mkdir_p(manifest_path) - File.open("#{manifest_path}/manifest.yml", 'wb') do |f| - YAML.dump(manifest, f) + unless ENV["RAILS_ASSETS_NONDIGEST"] + File.open("#{manifest_path}/manifest.yml", 'wb') do |f| + YAML.dump(manifest, f) + end + ENV["RAILS_ASSETS_NONDIGEST"] = "true" + ruby $0, *ARGV end end end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index e9985fa643..118ffff44b 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -63,7 +63,9 @@ module ApplicationTests precompile! files = Dir["#{app_path}/public/assets/application-*.js"] + files << Dir["#{app_path}/public/assets/application.js"].first files << Dir["#{app_path}/public/assets/foo/application-*.js"].first + files << Dir["#{app_path}/public/assets/foo/application.js"].first files.each do |file| assert_not_nil file, "Expected application.js asset to be generated, but none found" assert_equal "alert()", File.read(file) @@ -254,6 +256,24 @@ module ApplicationTests assert_match(/\/assets\/rails-([0-z]+)\.png/, File.read(file)) end + test "precompile shouldn't use the digests present in manifest.yml" do + app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" + + ENV["RAILS_ENV"] = "production" + precompile! + + manifest = "#{app_path}/public/assets/manifest.yml" + assets = YAML.load_file(manifest) + asset_path = assets["application.css"] + + app_file "app/assets/images/rails.png", "image changed" + + precompile! + assets = YAML.load_file(manifest) + + assert_not_equal asset_path, assets["application.css"] + end + test "precompile appends the md5 hash to files referenced with asset_path and run in production as default even using RAILS_GROUPS=assets" do app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" add_to_config "config.assets.compile = true" |