Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add config.allow_debugging option #2644

Merged
merged 1 commit into from

3 participants

Guillermo Iguaran Daniel Schierbeck Santiago Pastorino
Guillermo Iguaran

Add config.allow_debugging option to determine if the debug_assets query param can be passed by user and if debug option can be used in stylesheet_link_tag and javascript_include_tag

Daniel Schierbeck

The two tests contain a lot of awefully redundant code. Perhaps split the test into an AssetDebuggingTest with a common setup method?

Guillermo Iguaran

I remove some redundancy using a auxiliar method to create the files for both tests

Guillermo Iguaran

@spastorino changes done

Santiago Pastorino
Owner

@guilleiguaran can you rebase it please?

Santiago Pastorino spastorino merged commit 976b2be into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 24, 2011
  1. Guillermo Iguaran

    Add config.allow_debugging option to determine if the debug_assets qu…

    guilleiguaran authored
    …ery param can be passed by user
This page is out of date. Refresh to see the latest.
7 actionpack/lib/sprockets/helpers/rails_helper.rb
View
@@ -70,9 +70,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
@@ -157,6 +157,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)
@@ -197,6 +198,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
@@ -30,6 +30,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
@@ -41,4 +41,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
Something went wrong with that request. Please try again.