Skip to content

Commit

Permalink
Ensure template_runner can run script/* ruby scripts under Windows. [#…
Browse files Browse the repository at this point in the history
…1859 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
unknown authored and lifo committed Feb 16, 2009
1 parent 86d8f92 commit 2414fdb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Expand Up @@ -75,7 +75,7 @@ def plugin(name, options)
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..."
Expand Down Expand Up @@ -220,7 +220,7 @@ def generate(what, *args)
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
Expand All @@ -236,6 +236,12 @@ def run(command, log_action = true)
`#{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
Expand Down
16 changes: 13 additions & 3 deletions railties/test/generators/rails_template_runner_test.rb
Expand Up @@ -53,12 +53,12 @@ def test_file_should_write_block_contents_to_file_path
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

Expand Down Expand Up @@ -127,7 +127,7 @@ def test_initializer_should_write_date_to_file_in_config_initializers
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

Expand Down Expand Up @@ -162,6 +162,12 @@ def test_route_should_add_data_to_the_routes_block_in_config_routes
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
Expand All @@ -174,6 +180,10 @@ 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}"
assert_generated_file 'config/environment.rb' do |body|
Expand Down

0 comments on commit 2414fdb

Please sign in to comment.