Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2644 from guilleiguaran/allow-assets-debugging

Add config.allow_debugging option
  • Loading branch information...
commit 19c14035a0ccfa5fda3bb286633242ddd38fe879 1 parent 8ac61f5
Santiago Pastorino spastorino authored
7 actionpack/lib/sprockets/helpers/rails_helper.rb
View
@@ -71,9 +71,10 @@ def asset_path(source, default_ext = nil, body = false, protocol = nil)
private
def debug_assets?
- params[:debug_assets] == '1' ||
- params[:debug_assets] == 'true' ||
- Rails.application.config.assets.debug
+ Rails.application.config.assets.allow_debugging &&
+ (Rails.application.config.assets.debug ||
+ params[:debug_assets] == '1' ||
+ params[:debug_assets] == 'true')
end
# Override to specify an alternative prefix for asset path generation.
2  actionpack/test/template/sprockets_helper_test.rb
View
@@ -160,6 +160,7 @@ def url_for(*args)
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.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)
@@ -200,6 +201,7 @@ def url_for(*args)
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.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)
13 railties/lib/rails/application/configuration.rb
View
@@ -33,12 +33,13 @@ def initialize(*)
@cache_store = [ :file_store, "#{root}/tmp/cache/" ]
@assets = ActiveSupport::OrderedOptions.new
- @assets.enabled = false
- @assets.paths = []
- @assets.precompile = [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ]
- @assets.prefix = "/assets"
- @assets.version = ''
- @assets.debug = false
+ @assets.enabled = false
+ @assets.paths = []
+ @assets.precompile = [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ]
+ @assets.prefix = "/assets"
+ @assets.version = ''
+ @assets.debug = false
+ @assets.allow_debugging = false
@assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ]
@assets.js_compressor = nil
3  railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
View
@@ -25,6 +25,9 @@
# 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
3  railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
View
@@ -36,4 +36,7 @@
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
+
+ # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
+ config.assets.allow_debugging = true
end
42 railties/test/application/assets_test.rb
View
@@ -135,5 +135,47 @@ def index
assert_match "alert();", last_response.body
assert_equal 200, last_response.status
end
+
+ test "assets are concatenated when debug is off and allow_debugging is off either if debug_assets param is provided" do
+ app_with_assets_in_view
+
+ # config.assets.debug and config.assets.allow_debugging are false for production environment
+ ENV["RAILS_ENV"] = "production"
+ require "#{app_path}/config/environment"
+
+ class ::PostsController < ActionController::Base ; end
+
+ # the debug_assets params isn't used if allow_debugging is off
+ get '/posts?debug_assets=true'
+ assert_match /<script src="\/assets\/application-([0-z]+)\.js" type="text\/javascript"><\/script>/, last_response.body
+ assert_not_match /<script src="\/assets\/xmlhr-([0-z]+)\.js" type="text\/javascript"><\/script>/, last_response.body
+ end
+
+ test "assets aren't concatened when allow_debugging is on and debug_assets params is true" do
+ app_with_assets_in_view
+ app_file "config/initializers/allow_debugging.rb", "Rails.application.config.assets.allow_debugging = true"
+
+ ENV["RAILS_ENV"] = "production"
+ require "#{app_path}/config/environment"
+
+ class ::PostsController < ActionController::Base ; end
+
+ get '/posts?debug_assets=true'
+ assert_match /<script src="\/assets\/application-([0-z]+)\.js\?body=1" type="text\/javascript"><\/script>/, last_response.body
+ assert_match /<script src="\/assets\/xmlhr-([0-z]+)\.js\?body=1" type="text\/javascript"><\/script>/, last_response.body
+ end
+
+ private
+ def app_with_assets_in_view
+ app_file "app/assets/javascripts/application.js", "//= require_tree ."
+ app_file "app/assets/javascripts/xmlhr.js", "function f1() { alert(); }"
+ app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'application' %>"
+
+ app_file "config/routes.rb", <<-RUBY
+ AppTemplate::Application.routes.draw do
+ match '/posts', :to => "posts#index"
+ end
+ RUBY
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.