Permalink
Browse files

Disable template, helper and assets options when using http_only!

[Carlos Antonio da Silva & Santiago Pastorino]
  • Loading branch information...
1 parent c825e9a commit 219ff436399c3d28bb09ea841fecfdcfe6606257 @carlosantoniodasilva carlosantoniodasilva committed with spastorino Mar 10, 2012
Showing with 32 additions and 1 deletion.
  1. +14 −1 railties/lib/rails/generators.rb
  2. +18 −0 railties/test/generators_test.rb
@@ -105,9 +105,22 @@ def self.no_color!
Thor::Base.shell = Thor::Shell::Basic
end
- # Configure generators for http only
+ # Configure generators for http only applications. It basically hides
+ # everything that is usually browser related, such as assets and session
+ # migration generators, and completely disable views, helpers and assets
+ # so generators such as scaffold won't create them.
def self.http_only!
hide_namespaces "assets", "css", "js", "session_migration"
+
+ options[:rails].merge!(
+ :assets => false,
+ :helper => false,
+ :javascripts => false,
+ :javascript_engine => nil,
+ :stylesheets => false,
+ :stylesheet_engine => nil,
+ :template_engine => nil
+ )
end
# Track all generators subclasses.
@@ -229,12 +229,30 @@ def test_http_only_hides_generators
end
end
+ def test_http_only_disables_template_and_helper_and_assets_options
+ options = Rails::Generators.options[:rails]
+ disable_options = [:assets, :helper, :javascripts, :javascript_engine,
+ :stylesheets, :stylesheet_engine, :template_engine]
+
+ disable_options.each do |disable_option|
+ assert options[disable_option], "without http only should have generator option #{disable_option} enabled"
+ end
+
+ with_http_only! do
+ disable_options.each do |disable_option|
+ assert !options[disable_option], "http only should have generator option #{disable_option} disabled"
+ end
+ end
+ end
+
private
def with_http_only!
Rails::Generators.http_only!
yield
ensure
Rails::Generators.instance_variable_set(:@http_only, false)
+ Rails::Generators.instance_variable_set(:@hidden_namespaces, nil)
+ Rails::Generators.instance_variable_set(:@options, nil)
end
end

0 comments on commit 219ff43

Please sign in to comment.