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

Rails::Generators::Actions#execute_command allows option capture

This commit is contained in:
bogdanvlviv 2017-10-11 10:08:10 +03:00
parent 0835527d6b
commit f4af77ab5d
No known key found for this signature in database
GPG key ID: E4ACD76A6DB6DFDD
2 changed files with 23 additions and 1 deletions

View file

@ -221,6 +221,7 @@ module Rails
# rake("db:migrate")
# rake("db:migrate", env: "production")
# rake("gems:install", sudo: true)
# rake("gems:install", capture: true)
def rake(command, options = {})
execute_command :rake, command, options
end
@ -230,6 +231,7 @@ module Rails
# rails_command("db:migrate")
# rails_command("db:migrate", env: "production")
# rails_command("gems:install", sudo: true)
# rails_command("gems:install", capture: true)
def rails_command(command, options = {})
execute_command :rails, command, options
end
@ -292,7 +294,11 @@ module Rails
log executor, command
env = options[:env] || ENV["RAILS_ENV"] || "development"
sudo = options[:sudo] && !Gem.win_platform? ? "sudo " : ""
in_root { run("#{sudo}#{extify(executor)} #{command} RAILS_ENV=#{env}", verbose: false) }
config = { verbose: false }
config.merge!(capture: options[:capture]) if options[:capture]
in_root { run("#{sudo}#{extify(executor)} #{command} RAILS_ENV=#{env}", config) }
end
# Add an extension to the given name based on the platform.

View file

@ -308,6 +308,14 @@ class ActionsTest < Rails::Generators::TestCase
end
end
test "rake command with capture option should run rake command with capture" do
assert_called_with(generator, :run, ["rake log:clear RAILS_ENV=development", verbose: false, capture: true]) do
with_rails_env nil do
action :rake, "log:clear", capture: true
end
end
end
test "rails command should run rails_command with default env" do
assert_called_with(generator, :run, ["rails log:clear RAILS_ENV=development", verbose: false]) do
with_rails_env nil do
@ -346,6 +354,14 @@ class ActionsTest < Rails::Generators::TestCase
end
end
test "rails command with capture option should run rails_command with capture" do
assert_called_with(generator, :run, ["rails log:clear RAILS_ENV=development", verbose: false, capture: true]) do
with_rails_env nil do
action :rails_command, "log:clear", capture: true
end
end
end
def test_capify_should_run_the_capify_command
content = capture(:stderr) do
assert_called_with(generator, :run, ["capify .", verbose: false]) do