1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #3167 from dmitriy-kiriyenko/honour_rails_env_environment_variable_when_running_rake

RAILS_ENV environment variable is ignored when running rake from thor script using Rails::Generators::Actions
This commit is contained in:
José Valim 2011-09-29 06:19:26 -07:00
commit 4284e137ab
2 changed files with 17 additions and 1 deletions

View file

@ -252,7 +252,7 @@ module Rails
# #
def rake(command, options={}) def rake(command, options={})
log :rake, command log :rake, command
env = options[:env] || 'development' env = options[:env] || ENV["RAILS_ENV"] || 'development'
sudo = options[:sudo] && RbConfig::CONFIG['host_os'] !~ /mswin|mingw/ ? 'sudo ' : '' sudo = options[:sudo] && RbConfig::CONFIG['host_os'] !~ /mswin|mingw/ ? 'sudo ' : ''
in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", :verbose => false) } in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", :verbose => false) }
end end

View file

@ -189,6 +189,22 @@ class ActionsTest < Rails::Generators::TestCase
action :rake, 'log:clear', :env => 'production' action :rake, 'log:clear', :env => 'production'
end end
def test_rake_with_rails_env_variable_should_run_rake_command_in_env
generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', :verbose => false)
old_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "production"
action :rake, 'log:clear'
ensure
ENV["RAILS_ENV"] = old_env
end
def test_env_option_should_win_over_rails_env_variable_when_running_rake
generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', :verbose => false)
old_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "staging"
action :rake, 'log:clear', :env => 'production'
ensure
ENV["RAILS_ENV"] = old_env
end
def test_rake_with_sudo_option_should_run_rake_command_with_sudo def test_rake_with_sudo_option_should_run_rake_command_with_sudo
generator.expects(:run).once.with('sudo rake log:clear RAILS_ENV=development', :verbose => false) generator.expects(:run).once.with('sudo rake log:clear RAILS_ENV=development', :verbose => false)
action :rake, 'log:clear', :sudo => true action :rake, 'log:clear', :sudo => true