Skip to content

Commit

Permalink
Ensure that rails templates methods are invoked with the proper exten…
Browse files Browse the repository at this point in the history
…sions [#2531 status:resolved]
  • Loading branch information
josevalim committed Jul 4, 2009
1 parent 8ff214e commit 35925a8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
17 changes: 11 additions & 6 deletions railties/lib/generators/actions.rb
Expand Up @@ -78,7 +78,6 @@ def gem(name, options = {})
#
def environment(data=nil, options={}, &block)
sentinel = "Rails::Initializer.run do |config|"

data = block.call if !data && block_given?

in_root do
Expand Down Expand Up @@ -214,9 +213,9 @@ def generate(what, *args)
#
def rake(command, options={})
log :rake, command
env = options[:env] || 'development'
sudo = options[:sudo] ? 'sudo ' : ''
in_root { run("#{sudo}rake #{command} RAILS_ENV=#{env}", false) }
env = options[:env] || 'development'
sudo = options[:sudo] && RUBY_PLATFORM !~ /win32|mswin/ ? 'sudo ' : ''
in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", false) }
end

# Just run the capify command in root
Expand All @@ -227,7 +226,7 @@ def rake(command, options={})
#
def capify!
log :capify, ""
in_root { run('capify .', false) }
in_root { run("#{extify(:capify)} .", false) }
end

# Add Rails to /vendor/rails
Expand All @@ -238,7 +237,7 @@ def capify!
#
def freeze!(args = {})
log :vendor, "rails"
in_root { run('rake rails:freeze:edge', false) }
in_root { run("#{extify(:rake)} rails:freeze:edge", false) }
end

# Make an entry in Rails routing file conifg/routes.rb
Expand Down Expand Up @@ -269,6 +268,12 @@ def log(*args)
end
end

# Add the ruby command extension to the given name.
#
def extify(name)
"#{name}#{File.extname(Thor::Util.ruby_command)}"
end

end
end
end
18 changes: 18 additions & 0 deletions railties/test/generators/actions_test.rb
Expand Up @@ -151,16 +151,34 @@ def test_rake_with_sudo_option_should_run_rake_command_with_sudo
action :rake, 'log:clear', :sudo => true
end

def test_rake_uses_ruby_extension
Thor::Util.expects(:ruby_command).returns('ruby.bat')
generator.expects(:run).once.with('rake.bat log:clear RAILS_ENV=development', false)
action :rake, 'log:clear'
end

def test_capify_should_run_the_capify_command
generator.expects(:run).once.with('capify .', false)
action :capify!
end

def test_capify_uses_ruby_extension
Thor::Util.expects(:ruby_command).returns('ruby.bat')
generator.expects(:run).once.with('capify.bat .', false)
action :capify!
end

def test_freeze_should_freeze_rails_edge
generator.expects(:run).once.with('rake rails:freeze:edge', false)
action :freeze!
end

def test_freeze_uses_ruby_extension
Thor::Util.expects(:ruby_command).returns('ruby.bat')
generator.expects(:run).once.with('rake.bat rails:freeze:edge', false)
action :freeze!
end

def test_route_should_add_data_to_the_routes_block_in_config_routes
run_generator
route_command = "map.route '/login', :controller => 'sessions', :action => 'new'"
Expand Down

0 comments on commit 35925a8

Please sign in to comment.