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

WIP inline option

This commit is contained in:
Jonathan Hefner 2020-01-09 15:49:58 -06:00
parent 8ac5a44133
commit dcc3c85c2f
2 changed files with 48 additions and 14 deletions

View file

@ -222,17 +222,13 @@ module Rails
# the generator or an Array that is joined.
#
# generate(:authenticated, "user session")
def generate(*args)
def generate(what, *args)
log :generate, what
options = args.extract_options!
args = Shellwords.split(args.join(" "))
options[:abort_on_failure] = !options[:inline]
log :generate, args.first
in_root do
silence_warnings do
::Rails::Command.invoke("generate", args, options)
end
end
rails_command "generate #{what} #{args.join(" ")}", options
end
# Runs the supplied rake task (invoked with 'rake ...')
@ -252,7 +248,17 @@ module Rails
# rails_command("gems:install", sudo: true)
# rails_command("gems:install", capture: true)
def rails_command(command, options = {})
execute_command :rails, command, options
if options[:inline]
log :rails, command
command, *args = Shellwords.split(command)
in_root do
silence_warnings do
::Rails::Command.invoke(command, args, options)
end
end
else
execute_command :rails, command, options
end
end
# Make an entry in Rails routing file <tt>config/routes.rb</tt>

View file

@ -384,16 +384,28 @@ class ActionsTest < Rails::Generators::TestCase
assert_file "app/models/my_model.rb", /MyModel/
end
test "generate with concatenated arguments" do
test "generate should raise on failure" do
run_generator
action :generate, "model MyModel name:string"
message = capture(:stderr) do
assert_raises SystemExit do
action :generate, "model", "1234567890"
end
end
assert_match(/1234567890/, message)
end
test "generate with inline option" do
run_generator
assert_not_called(generator, :run) do
action :generate, "model", "MyModel", inline: true
end
assert_file "app/models/my_model.rb", /MyModel/
end
test "generate should raise on failure" do
test "generate with inline option should raise on failure" do
run_generator
error = assert_raises do
action :generate, "model", "1234567890"
action :generate, "model", "1234567890", inline: true
end
assert_match(/1234567890/, error.message)
end
@ -503,6 +515,22 @@ class ActionsTest < Rails::Generators::TestCase
end
end
test "rails_command with inline option" do
run_generator
assert_not_called(generator, :run) do
action :rails_command, "generate model MyModel", inline: true
end
assert_file "app/models/my_model.rb", /MyModel/
end
test "rails_command with inline option should raise on failure" do
run_generator
error = assert_raises do
action :rails_command, "generate model 1234567890", inline: true
end
assert_match(/1234567890/, error.message)
end
test "route should add route" do
run_generator
route_commands = ["get 'foo'", "get 'bar'", "get 'baz'"]