aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/actions.rb27
-rw-r--r--railties/test/generators/actions_test.rb10
2 files changed, 26 insertions, 11 deletions
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index 5fa487b78e..57309112b5 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -207,18 +207,23 @@ module Rails
in_root { run_ruby_script("bin/rails generate #{what} #{argument}", verbose: false) }
end
- # Runs the supplied rake task
+ # Runs the supplied rake task (invoked with 'rake ...')
#
# rake("db:migrate")
# rake("db:migrate", env: "production")
# rake("gems:install", sudo: true)
def rake(command, options={})
- log :rake, command
- env = options[:env] || ENV["RAILS_ENV"] || 'development'
- sudo = options[:sudo] && RbConfig::CONFIG['host_os'] !~ /mswin|mingw/ ? 'sudo ' : ''
- in_root { run("#{sudo}#{extify(:rails)} #{command} RAILS_ENV=#{env}", verbose: false) }
+ execute_command :rake, command, options
+ end
+
+ # Runs the supplied rake task (invoked with 'rails ...')
+ #
+ # rails("db:migrate")
+ # rails("db:migrate", env: "production")
+ # rails("gems:install", sudo: true)
+ def rails_command(command, options={})
+ execute_command :rails, command, options
end
- alias :rails_command :rake
# Just run the capify command in root
#
@@ -271,6 +276,16 @@ module Rails
end
end
+
+ # Runs the supplied command using either "rake ..." or "rails ..."
+ # based on the executor parameter provided.
+ def execute_command(executor, command, options={})
+ log executor, command
+ env = options[:env] || ENV["RAILS_ENV"] || 'development'
+ sudo = options[:sudo] && RbConfig::CONFIG['host_os'] !~ /mswin|mingw/ ? 'sudo ' : ''
+ in_root { run("#{sudo}#{extify(executor)} #{command} RAILS_ENV=#{env}", verbose: false) }
+ end
+
# Add an extension to the given name based on the platform.
def extify(name)
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index 58394a11f0..3b2b3c37d0 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -202,7 +202,7 @@ class ActionsTest < Rails::Generators::TestCase
end
def test_rails_should_run_rake_command_with_default_env
- assert_called_with(generator, :run, ["rails log:clear RAILS_ENV=development", verbose: false]) do
+ assert_called_with(generator, :run, ["rake log:clear RAILS_ENV=development", verbose: false]) do
with_rails_env nil do
action :rake, 'log:clear'
end
@@ -210,13 +210,13 @@ class ActionsTest < Rails::Generators::TestCase
end
def test_rails_with_env_option_should_run_rake_command_in_env
- assert_called_with(generator, :run, ['rails log:clear RAILS_ENV=production', verbose: false]) do
+ assert_called_with(generator, :run, ['rake log:clear RAILS_ENV=production', verbose: false]) do
action :rake, 'log:clear', env: 'production'
end
end
test "rails command with RAILS_ENV variable should run rake command in env" do
- assert_called_with(generator, :run, ['rails log:clear RAILS_ENV=production', verbose: false]) do
+ assert_called_with(generator, :run, ['rake log:clear RAILS_ENV=production', verbose: false]) do
with_rails_env "production" do
action :rake, 'log:clear'
end
@@ -224,7 +224,7 @@ class ActionsTest < Rails::Generators::TestCase
end
test "env option should win over RAILS_ENV variable when running rake" do
- assert_called_with(generator, :run, ['rails log:clear RAILS_ENV=production', verbose: false]) do
+ assert_called_with(generator, :run, ['rake log:clear RAILS_ENV=production', verbose: false]) do
with_rails_env "staging" do
action :rake, 'log:clear', env: 'production'
end
@@ -232,7 +232,7 @@ class ActionsTest < Rails::Generators::TestCase
end
test "rails command with sudo option should run rake command with sudo" do
- assert_called_with(generator, :run, ["sudo rails log:clear RAILS_ENV=development", verbose: false]) do
+ assert_called_with(generator, :run, ["sudo rake log:clear RAILS_ENV=development", verbose: false]) do
with_rails_env nil do
action :rake, 'log:clear', sudo: true
end