aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-10-06 02:53:00 -0700
committerwycats <wycats@gmail.com>2010-10-06 02:53:00 -0700
commit848eb0d777d2f2907c399c2fe073fedffad14c63 (patch)
treefbab40426c624a71da9b0339932b680cac53f479 /railties/test
parent6774e12afa0f29442aa612ddf6e51d5a1b7a4356 (diff)
downloadrails-848eb0d777d2f2907c399c2fe073fedffad14c63.tar.gz
rails-848eb0d777d2f2907c399c2fe073fedffad14c63.tar.bz2
rails-848eb0d777d2f2907c399c2fe073fedffad14c63.zip
Revert "Clean up the builder abstraction in AppGenerator."
The phrase "clean up" misrepresents the fact that this removes a feature that ships with Rails 3.0. This reverts commit 6774e12afa0f29442aa612ddf6e51d5a1b7a4356.
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/generators/app_generator_test.rb68
1 files changed, 67 insertions, 1 deletions
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 3bd8770710..3653b067c8 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -261,4 +261,70 @@ protected
silence(:stdout){ generator.send(*args, &block) }
end
-end \ No newline at end of file
+end
+
+class CustomAppGeneratorTest < Rails::Generators::TestCase
+ include GeneratorsTestHelper
+ tests Rails::Generators::AppGenerator
+
+ arguments [destination_root]
+
+ def setup
+ Rails.application = TestApp::Application
+ super
+ Rails::Generators::AppGenerator.instance_variable_set('@desc', nil)
+ @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
+ end
+
+ def teardown
+ super
+ Rails::Generators::AppGenerator.instance_variable_set('@desc', nil)
+ Object.class_eval { remove_const :AppBuilder if const_defined?(:AppBuilder) }
+ Rails.application = TestApp::Application.instance
+ end
+
+ def test_builder_option_with_empty_app_builder
+ FileUtils.cd(Rails.root)
+ run_generator([destination_root, "-b", "#{Rails.root}/lib/empty_builder.rb"])
+ DEFAULT_APP_FILES.each{ |path| assert_no_file path }
+ end
+
+ def test_builder_option_with_simple_app_builder
+ FileUtils.cd(Rails.root)
+ run_generator([destination_root, "-b", "#{Rails.root}/lib/simple_builder.rb"])
+ (DEFAULT_APP_FILES - ['config.ru']).each{ |path| assert_no_file path }
+ assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }]
+ end
+
+ def test_builder_option_with_relative_path
+ here = File.expand_path(File.dirname(__FILE__))
+ FileUtils.cd(here)
+ run_generator([destination_root, "-b", "../fixtures/lib/simple_builder.rb"])
+ (DEFAULT_APP_FILES - ['config.ru']).each{ |path| assert_no_file path }
+ assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }]
+ end
+
+ def test_builder_option_with_tweak_app_builder
+ FileUtils.cd(Rails.root)
+ run_generator([destination_root, "-b", "#{Rails.root}/lib/tweak_builder.rb"])
+ DEFAULT_APP_FILES.each{ |path| assert_file path }
+ assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }]
+ end
+
+ def test_builder_option_with_http
+ path = "http://gist.github.com/103208.txt"
+ template = "class AppBuilder; end"
+ template.instance_eval "def read; self; end" # Make the string respond to read
+
+ generator([destination_root], :builder => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
+ capture(:stdout) { generator.invoke_all }
+
+ DEFAULT_APP_FILES.each{ |path| assert_no_file path }
+ end
+
+protected
+
+ def action(*args, &block)
+ silence(:stdout){ generator.send(*args, &block) }
+ end
+end