Browse files

Merge pull request #3011 from guilleiguaran/disable-sprockets-server

Don't mount Sprockets if config.assets.compile is disabled
  • Loading branch information...
2 parents 3b8a7cf + a89d39e commit 410b0ec1b712ce34f0fafb6505876d21e8007db7 @spastorino spastorino committed Sep 13, 2011
Showing with 17 additions and 3 deletions.
  1. +4 −2 actionpack/lib/sprockets/railtie.rb
  2. +13 −1 railties/test/application/assets_test.rb
View
6 actionpack/lib/sprockets/railtie.rb
@@ -67,8 +67,10 @@ class Railtie < ::Rails::Railtie
end
end
- app.routes.prepend do
- mount app.assets => config.assets.prefix
+ if config.assets.compile
+ app.routes.prepend do
+ mount app.assets => config.assets.prefix
+ end
end
if config.assets.digest
View
14 railties/test/application/assets_test.rb
@@ -38,7 +38,7 @@ def app
test "assets do not require compressors until it is used" do
app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();"
- add_to_config "config.assets.compile = true"
+ app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true"
ENV["RAILS_ENV"] = "production"
require "#{app_path}/config/environment"
@@ -178,6 +178,7 @@ def app
test "assets do not require any assets group gem when manifest file is present" do
app_file "app/assets/javascripts/application.js", "alert();"
+ app_file "config/initializers/serve_static_assets.rb", "Rails.application.config.serve_static_assets = true"
ENV["RAILS_ENV"] = "production"
capture(:stdout) do
@@ -314,6 +315,17 @@ class ::PostsController < ActionController::Base ; end
assert_equal 0, files.length, "Expected no assets, but found #{files.join(', ')}"
end
+ test "assets routes are not drawn when compilation is disabled" do
+ app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();"
+ add_to_config "config.assets.compile = false"
+
+ ENV["RAILS_ENV"] = "production"
+ require "#{app_path}/config/environment"
+
+ get "/assets/demo.js"
+ assert_equal 404, last_response.status
+ end
+
test "does not stream session cookies back" do
app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();"

0 comments on commit 410b0ec

Please sign in to comment.