diff options
-rw-r--r-- | actionpack/lib/sprockets/assets.rake | 9 | ||||
-rw-r--r-- | railties/test/application/assets_test.rb | 26 |
2 files changed, 31 insertions, 4 deletions
diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake index f1fc7857a7..a8128d9a82 100644 --- a/actionpack/lib/sprockets/assets.rake +++ b/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)$/ diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 721d082908..a412b7d99b 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -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();" |