aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/sprockets/assets.rake6
-rw-r--r--actionpack/lib/sprockets/helpers/rails_helper.rb29
-rw-r--r--actionpack/lib/sprockets/railtie.rb6
-rw-r--r--actionpack/test/template/sprockets_helper_test.rb6
-rw-r--r--railties/lib/rails/application/configuration.rb5
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt3
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt6
-rw-r--r--railties/test/application/assets_test.rb32
8 files changed, 41 insertions, 52 deletions
diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake
index 7ee82ee530..54907abb39 100644
--- a/actionpack/lib/sprockets/assets.rake
+++ b/actionpack/lib/sprockets/assets.rake
@@ -47,10 +47,8 @@ namespace :assets do
env.precompile(*assets)
end
- if config.assets.manifest
- File.open("#{target}/manifest.yml", 'w') do |f|
- YAML.dump(manifest, f)
- end
+ File.open("#{target}/manifest.yml", 'w') do |f|
+ YAML.dump(manifest, f)
end
end
end
diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb
index 8e7eb182fd..975dc9e80c 100644
--- a/actionpack/lib/sprockets/helpers/rails_helper.rb
+++ b/actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -61,7 +61,7 @@ module Sprockets
def debug_assets?
begin
config = Rails.application.config.assets
- config.allow_debugging && (config.debug || params[:debug_assets])
+ config.compile && (config.debug || params[:debug_assets])
rescue NoMethodError
false
end
@@ -114,22 +114,21 @@ module Sprockets
return digest
end
- if digest.nil? && Rails.application.config.assets.precompile_only
- raise AssetNotPrecompiledError
- end
-
- if asset = asset_environment[logical_path]
- return asset.digest_path
+ if Rails.application.config.assets.compile
+ if asset = asset_environment[logical_path]
+ return asset.digest_path
+ end
+ return logical_path
+ else
+ raise AssetNotPrecompiledError.new("#{logical_path} isn't precompiled")
end
-
- logical_path
end
def rewrite_asset_path(source, dir)
if source[0] == ?/
source
else
- source = digest_for(source) if performing_caching?
+ source = digest_for(source) if Rails.application.config.assets.digest
source = File.join(dir, source)
source = "/#{source}" unless source =~ /^\//
source
@@ -143,16 +142,6 @@ module Sprockets
source
end
end
-
- def performing_caching?
- # When included in Sprockets::Context, we need to ask the
- # top-level config as the controller is not available.
- if config.action_controller.present?
- config.action_controller.perform_caching
- else
- config.perform_caching
- end
- end
end
end
end
diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb
index 680cb980ff..4adfd000f8 100644
--- a/actionpack/lib/sprockets/railtie.rb
+++ b/actionpack/lib/sprockets/railtie.rb
@@ -26,10 +26,8 @@ module Sprockets
end
end
- if config.assets.manifest
- if File.exist?(path = File.join(Rails.public_path, config.assets.prefix, "manifest.yml"))
- config.assets.digests = YAML.load_file(path)
- end
+ if File.exist?(path = File.join(Rails.public_path, config.assets.prefix, "manifest.yml"))
+ config.assets.digests = YAML.load_file(path)
end
ActiveSupport.on_load(:action_view) do
diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb
index 6c1f97a44a..ae4cb1f0aa 100644
--- a/actionpack/test/template/sprockets_helper_test.rb
+++ b/actionpack/test/template/sprockets_helper_test.rb
@@ -30,6 +30,8 @@ class SprocketsHelperTest < ActionView::TestCase
@config = config
@config.action_controller ||= ActiveSupport::InheritableOptions.new
@config.perform_caching = true
+ @config.assets.digest = true
+ @config.assets.compile = true
end
def url_for(*args)
@@ -157,7 +159,7 @@ class SprocketsHelperTest < ActionView::TestCase
assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\n<script src="/assets/application-[0-9a-f]+.js\?body=1" type="text/javascript"></script>},
javascript_include_tag(:application, :debug => true)
- @config.assets.allow_debugging = true
+ @config.assets.compile = true
@config.assets.debug = true
assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\n<script src="/assets/application-[0-9a-f]+.js\?body=1" type="text/javascript"></script>},
javascript_include_tag(:application)
@@ -198,7 +200,7 @@ class SprocketsHelperTest < ActionView::TestCase
assert_match %r{<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/application-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />},
stylesheet_link_tag(:application, :debug => true)
- @config.assets.allow_debugging = true
+ @config.assets.compile = true
@config.assets.debug = true
assert_match %r{<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/application-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />},
stylesheet_link_tag(:application)
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 7f4db0a19f..85e0cd5061 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -41,9 +41,8 @@ module Rails
@assets.prefix = "/assets"
@assets.version = ''
@assets.debug = false
- @assets.allow_debugging = false
- @assets.manifest = true
- @assets.precompile_only = false
+ @assets.compile = true
+ @assets.digest = false
@assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ]
@assets.js_compressor = nil
@assets.css_compressor = nil
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
index 33f9939ffe..47078e3af9 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
@@ -30,9 +30,6 @@
# Do not compress assets
config.assets.compress = false
- # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
- config.assets.allow_debugging = true
-
# Expands the lines which load the assets
config.assets.debug = true
end
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
index de56d47688..b4754cfc6d 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -14,6 +14,12 @@
# Compress JavaScripts and CSS
config.assets.compress = true
+ # Don't fallback to assets pipeline if a precompiled asset is missed
+ config.assets.compile = false
+
+ # Generate digests for assets URLs
+ config.assets.digest = true
+
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb
index 9df10e84d8..a4d7fc92f5 100644
--- a/railties/test/application/assets_test.rb
+++ b/railties/test/application/assets_test.rb
@@ -37,6 +37,8 @@ module ApplicationTests
test "assets do not require compressors until it is used" do
app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();"
+ app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true"
+
ENV["RAILS_ENV"] = "production"
require "#{app_path}/config/environment"
@@ -62,18 +64,7 @@ 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
+ 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();"
@@ -88,7 +79,7 @@ module ApplicationTests
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
+ test "assets do not require any assets group gem when manifest file is present" do
app_file "app/assets/javascripts/application.js", "alert();"
ENV["RAILS_ENV"] = "production"
@@ -108,10 +99,8 @@ module ApplicationTests
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();"
+ test "assets raise AssetNotPrecompiledError when manifest file is present and requested file isn't precompiled" do
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
@@ -120,15 +109,25 @@ module ApplicationTests
RUBY
ENV["RAILS_ENV"] = "production"
+ capture(:stdout) do
+ Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
+ end
+
+ # Create file after of precompile
+ app_file "app/assets/javascripts/app.js", "alert();"
+
require "#{app_path}/config/environment"
class ::PostsController < ActionController::Base ; end
get '/posts'
assert_match /AssetNotPrecompiledError/, last_response.body
+ assert_match /app.js isn't precompiled/, 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') %>"
+ # 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 RAILS_ENV=test` }
@@ -139,6 +138,7 @@ module ApplicationTests
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') %>"
+ app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true"
ENV["RAILS_ENV"] = nil
capture(:stdout) do