aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-03-10 17:24:36 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2012-03-14 12:46:24 -0300
commit219ff436399c3d28bb09ea841fecfdcfe6606257 (patch)
tree9752058046c2614be445038c34c9c8f904db82fd
parentc825e9a5eaa8060a3745c5275b6829c37c6545a7 (diff)
downloadrails-219ff436399c3d28bb09ea841fecfdcfe6606257.tar.gz
rails-219ff436399c3d28bb09ea841fecfdcfe6606257.tar.bz2
rails-219ff436399c3d28bb09ea841fecfdcfe6606257.zip
Disable template, helper and assets options when using http_only!
[Carlos Antonio da Silva & Santiago Pastorino]
-rw-r--r--railties/lib/rails/generators.rb15
-rw-r--r--railties/test/generators_test.rb18
2 files changed, 32 insertions, 1 deletions
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 44121f45ce..f70c9ebab9 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -105,9 +105,22 @@ module Rails
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.
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index 44797a6ac8..eae34da9c0 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -229,6 +229,22 @@ class GeneratorsTest < Rails::Generators::TestCase
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!
@@ -236,5 +252,7 @@ class GeneratorsTest < Rails::Generators::TestCase
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