1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add config.allow_debugging option to determine if the debug_assets query param can be passed by user

This commit is contained in:
Guillermo Iguaran 2011-08-22 23:19:25 -05:00
parent 52207ecc81
commit 827cdae6fb
6 changed files with 61 additions and 9 deletions

View file

@ -70,9 +70,10 @@ module Sprockets
private private
def debug_assets? def debug_assets?
Rails.application.config.assets.allow_debugging &&
(Rails.application.config.assets.debug ||
params[:debug_assets] == '1' || params[:debug_assets] == '1' ||
params[:debug_assets] == 'true' || params[:debug_assets] == 'true')
Rails.application.config.assets.debug
end end
# Override to specify an alternative prefix for asset path generation. # Override to specify an alternative prefix for asset path generation.

View file

@ -157,6 +157,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>}, 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) javascript_include_tag(:application, :debug => true)
@config.assets.allow_debugging = true
@config.assets.debug = 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>}, 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) javascript_include_tag(:application)
@ -197,6 +198,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" />}, 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) stylesheet_link_tag(:application, :debug => true)
@config.assets.allow_debugging = true
@config.assets.debug = 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" />}, 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) stylesheet_link_tag(:application)

View file

@ -39,6 +39,7 @@ module Rails
@assets.prefix = "/assets" @assets.prefix = "/assets"
@assets.version = '' @assets.version = ''
@assets.debug = false @assets.debug = false
@assets.allow_debugging = false
@assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ]
@assets.js_compressor = nil @assets.js_compressor = nil

View file

@ -30,6 +30,9 @@
# Do not compress assets # Do not compress assets
config.assets.compress = false 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 # Expands the lines which load the assets
config.assets.debug = true config.assets.debug = true
end end

View file

@ -41,4 +41,7 @@
# Print deprecation notices to the stderr # Print deprecation notices to the stderr
config.active_support.deprecation = :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 end

View file

@ -135,5 +135,47 @@ module ApplicationTests
assert_match "alert();", last_response.body assert_match "alert();", last_response.body
assert_equal 200, last_response.status assert_equal 200, last_response.status
end 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
end end