From d11bcd669a72c9a647aa7cb85d78deefc9059de8 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 3 Feb 2009 13:03:47 +0000 Subject: [PATCH] Patched template_runner and associated tests to run correctly in WIN32 environment --- .../generators/applications/app/template_runner.rb | 10 ++++++++-- .../test/generators/rails_template_runner_test.rb | 16 +++++++++++++--- 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 84e36ec..8440bfe 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 @@ -235,6 +235,12 @@ module Rails log 'executing', "#{command} from #{Dir.pwd}" if log_action `#{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 # diff --git a/railties/test/generators/rails_template_runner_test.rb b/railties/test/generators/rails_template_runner_test.rb index fcc0206..22ae336 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 @@ -161,6 +161,12 @@ class RailsTemplateRunnerTest < GeneratorTestCase run_template_method(:route, route_command) 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) @@ -173,6 +179,10 @@ class RailsTemplateRunnerTest < GeneratorTestCase def expects_run_with_command(command) 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}" -- 1.6.0.2.1172.ga5ed0