Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #2782 from spohlenz/precompile-without-digests

assets:precompile should not append asset digests when config.assets.digest is false
  • Loading branch information...
commit 8b049a152fb880aebf60ce4800f228e1535939d2 2 parents 9bfaef0 + a5619c0
@josevalim josevalim authored
View
9 actionpack/lib/sprockets/assets.rake
@@ -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
26 railties/test/application/assets_test.rb
@@ -67,6 +67,8 @@ def app
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 @@ def app
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 @@ def app
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 @@ def app
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();"
Please sign in to comment.
Something went wrong with that request. Please try again.