1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

assets:precompile should not append asset digests when config.assets.digest is false

This commit is contained in:
Sam Pohlenz 2011-09-01 09:23:51 +09:30
parent b93c3606cb
commit 58b0c97347
2 changed files with 31 additions and 4 deletions

View file

@ -13,8 +13,7 @@ namespace :assets do
# Ensure that action view is loaded and the appropriate sprockets hooks get executed
ActionView::Base
# Always calculate digests and compile files
Rails.application.config.assets.digest = true
# Always compile files
Rails.application.config.assets.compile = true
config = Rails.application.config
@ -32,8 +31,10 @@ namespace :assets do
end
if asset = env.find_asset(logical_path)
manifest[logical_path] = asset.digest_path
filename = target.join(asset.digest_path)
asset_path = config.assets.digest ? asset.digest_path : logical_path
manifest[logical_path] = asset_path
filename = target.join(asset_path)
mkdir_p filename.dirname
asset.write_to(filename)
asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/

View file

@ -67,6 +67,8 @@ module ApplicationTests
test "precompile creates a manifest file with all the assets listed" do
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
app_file "app/assets/javascripts/application.js", "alert();"
# digest is default in false, we must enable it for test environment
app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = true"
capture(:stdout) do
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
@ -84,6 +86,8 @@ module ApplicationTests
app_file "app/assets/javascripts/application.js", "alert();"
FileUtils.mkdir "#{app_path}/shared"
app_file "config/initializers/manifest.rb", "Rails.application.config.assets.manifest = '#{app_path}/shared'"
# digest is default in false, we must enable it for test environment
app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = true"
capture(:stdout) do
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
@ -96,9 +100,12 @@ module ApplicationTests
assert_match /application-([0-z]+)\.css/, assets["application.css"]
end
test "the manifest file should be saved by default in the same assets folder" do
app_file "app/assets/javascripts/application.js", "alert();"
app_file "config/initializers/manifest.rb", "Rails.application.config.assets.prefix = '/x'"
# digest is default in false, we must enable it for test environment
app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = true"
capture(:stdout) do
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
@ -109,6 +116,25 @@ module ApplicationTests
assert_match /application-([0-z]+)\.js/, assets["application.js"]
end
test "precompile does not append asset digests when config.assets.digest is false" do
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
app_file "app/assets/javascripts/application.js", "alert();"
app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = false"
capture(:stdout) do
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
end
assert File.exists?("#{app_path}/public/assets/application.js")
assert File.exists?("#{app_path}/public/assets/application.css")
manifest = "#{app_path}/public/assets/manifest.yml"
assets = YAML.load_file(manifest)
assert_equal "application.js", assets["application.js"]
assert_equal "application.css", assets["application.css"]
end
test "assets do not require any assets group gem when manifest file is present" do
app_file "app/assets/javascripts/application.js", "alert();"