aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorunknown <jeko1@.npfit.nhs.uk>2009-02-03 13:03:47 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-02-16 20:22:02 +0100
commit2414fdb244cc0ba97620dd3f50e269d2e26c7392 (patch)
tree18e8f3ce8acd407d05c05a54ade4195de2a9a415
parent86d8f922828677e64892c166adf26cd421f0991a (diff)
downloadrails-2414fdb244cc0ba97620dd3f50e269d2e26c7392.tar.gz
rails-2414fdb244cc0ba97620dd3f50e269d2e26c7392.tar.bz2
rails-2414fdb244cc0ba97620dd3f50e269d2e26c7392.zip
Ensure template_runner can run script/* ruby scripts under Windows. [#1859 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
-rw-r--r--railties/lib/rails_generator/generators/applications/app/template_runner.rb10
-rw-r--r--railties/test/generators/rails_template_runner_test.rb16
2 files changed, 21 insertions, 5 deletions
diff --git a/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/railties/lib/rails_generator/generators/applications/app/template_runner.rb
index 84e36ecc1b..eeb6b17661 100644
--- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb
+++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb
@@ -75,7 +75,7 @@ module Rails
end
elsif options[:git] || options[:svn]
in_root do
- run("script/plugin install #{options[:svn] || options[:git]}", false)
+ run_ruby_script("script/plugin install #{options[:svn] || options[:git]}", false)
end
else
log "! no git or svn provided for #{name}. skipping..."
@@ -220,7 +220,7 @@ module Rails
log 'generating', what
argument = args.map(&:to_s).flatten.join(" ")
- in_root { run("script/generate #{what} #{argument}", false) }
+ in_root { run_ruby_script("script/generate #{what} #{argument}", false) }
end
# Executes a command
@@ -236,6 +236,12 @@ module Rails
`#{command}`
end
+ # Executes a ruby script (taking into account WIN32 platform quirks)
+ def run_ruby_script(command, log_action = true)
+ ruby_command = RUBY_PLATFORM=~ /win32/ ? 'ruby ' : ''
+ run("#{ruby_command}#{command}", log_action)
+ end
+
# Runs the supplied rake task
#
# ==== Example
diff --git a/railties/test/generators/rails_template_runner_test.rb b/railties/test/generators/rails_template_runner_test.rb
index fcc020603d..56afc85eba 100644
--- a/railties/test/generators/rails_template_runner_test.rb
+++ b/railties/test/generators/rails_template_runner_test.rb
@@ -53,12 +53,12 @@ class RailsTemplateRunnerTest < GeneratorTestCase
end
def test_plugin_with_git_option_should_run_plugin_install
- expects_run_with_command("script/plugin install #{@git_plugin_uri}")
+ expects_run_ruby_script_with_command("script/plugin install #{@git_plugin_uri}")
run_template_method(:plugin, 'restful-authentication', :git => @git_plugin_uri)
end
def test_plugin_with_svn_option_should_run_plugin_install
- expects_run_with_command("script/plugin install #{@svn_plugin_uri}")
+ expects_run_ruby_script_with_command("script/plugin install #{@svn_plugin_uri}")
run_template_method(:plugin, 'restful-authentication', :svn => @svn_plugin_uri)
end
@@ -127,7 +127,7 @@ class RailsTemplateRunnerTest < GeneratorTestCase
end
def test_generate_should_run_script_generate_with_argument_and_options
- expects_run_with_command('script/generate model MyModel')
+ expects_run_ruby_script_with_command('script/generate model MyModel')
run_template_method(:generate, 'model', 'MyModel')
end
@@ -162,6 +162,12 @@ class RailsTemplateRunnerTest < GeneratorTestCase
assert_generated_file_with_data 'config/routes.rb', route_command
end
+ def test_run_ruby_script_should_add_ruby_to_command_in_win32_environment
+ ruby_command = RUBY_PLATFORM =~ /win32/ ? 'ruby ' : ''
+ expects_run_with_command("#{ruby_command}script/generate model MyModel")
+ run_template_method(:generate, 'model', 'MyModel')
+ end
+
protected
def run_template_method(method_name, *args, &block)
silence_generator do
@@ -174,6 +180,10 @@ class RailsTemplateRunnerTest < GeneratorTestCase
Rails::TemplateRunner.any_instance.stubs(:run).once.with(command, false)
end
+ def expects_run_ruby_script_with_command(command)
+ Rails::TemplateRunner.any_instance.stubs(:run_ruby_script).once.with(command,false)
+ end
+
def assert_rails_initializer_includes(data, message = nil)
message ||= "Rails::Initializer should include #{data}"
assert_generated_file 'config/environment.rb' do |body|