diff options
author | Guillermo Iguaran <guilleiguaran@gmail.com> | 2011-08-29 16:28:11 -0500 |
---|---|---|
committer | Guillermo Iguaran <guilleiguaran@gmail.com> | 2011-08-31 12:41:28 -0500 |
commit | dffdd829930e664cef522f34730d5987be348596 (patch) | |
tree | 6ccbfc5d488ac58269484e9bc932a269d07bc9ab /railties | |
parent | 508f33f35c9ce7a8973c1cf3466223313dfcfb24 (diff) | |
download | rails-dffdd829930e664cef522f34730d5987be348596.tar.gz rails-dffdd829930e664cef522f34730d5987be348596.tar.bz2 rails-dffdd829930e664cef522f34730d5987be348596.zip |
Read digests of assets from manifest.yml if config.assets.manifest is on
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 9 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/config/application.rb | 4 | ||||
-rw-r--r-- | railties/test/application/assets_test.rb | 65 |
3 files changed, 74 insertions, 4 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 5d7bd3282d..7f4db0a19f 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -42,10 +42,11 @@ module Rails @assets.version = '' @assets.debug = false @assets.allow_debugging = false - - @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] - @assets.js_compressor = nil - @assets.css_compressor = nil + @assets.manifest = true + @assets.precompile_only = false + @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] + @assets.js_compressor = nil + @assets.css_compressor = nil end def compiled_asset_path diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 3891829150..30a75200cb 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -52,6 +52,10 @@ module <%= app_const_base %> <% unless options.skip_sprockets? -%> # Enable the asset pipeline config.assets.enabled = true + + # Create a manifest with the hashes of your assets when you run "rake assets:precompile". + # Use this if you don't have a JavaScript engine in your production servers + config.assets.manifest = true <% end -%> end end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index a8d1382e94..9df10e84d8 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -62,6 +62,71 @@ module ApplicationTests end end + test "precompile don't create a manifest file when manifest option is off" do + app_file "app/assets/javascripts/application.js", "alert();" + app_file "config/initializers/manifest.rb", "Rails.application.config.assets.manifest = false" + + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + + assert !File.exist?("#{app_path}/public/assets/manifest.yml") + end + + test "precompile creates a manifest file with all the assets listed when manifest option is on" do + app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" + app_file "app/assets/javascripts/application.js", "alert();" + + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + + manifest = "#{app_path}/public/assets/manifest.yml" + + assets = YAML.load_file(manifest) + assert_match /application-([0-z]+)\.js/, assets["application.js"] + assert_match /application-([0-z]+)\.css/, assets["application.css"] + end + + test "assets do not require any assets group gem when manifest option is on and manifest file is present" do + app_file "app/assets/javascripts/application.js", "alert();" + + ENV["RAILS_ENV"] = "production" + capture(:stdout) do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + manifest = "#{app_path}/public/assets/manifest.yml" + assets = YAML.load_file(manifest) + asset_path = assets["application.js"] + + require "#{app_path}/config/environment" + + # Checking if Uglifier is defined we can know if Sprockets was reached or not + assert !defined?(Uglifier) + get "/assets/#{asset_path}" + assert_match "alert()", last_response.body + assert !defined?(Uglifier) + end + + test "assets raise AssetNotPrecompiledError if config.assets.precompile_only is on and file isn't precompiled" do + app_file "app/assets/javascripts/app.js", "alert();" + app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'app' %>" + app_file "config/initializers/precompile_only.rb", "Rails.application.config.assets.precompile_only = true" + + app_file "config/routes.rb", <<-RUBY + AppTemplate::Application.routes.draw do + match '/posts', :to => "posts#index" + end + RUBY + + ENV["RAILS_ENV"] = "production" + require "#{app_path}/config/environment" + class ::PostsController < ActionController::Base ; end + + get '/posts' + assert_match /AssetNotPrecompiledError/, last_response.body + end + test "precompile appends the md5 hash to files referenced with asset_path and run in the provided RAILS_ENV" do app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" |