提交 36334bf9 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #28527 from rst/fix_runner_argv_28515

Correctly reset ARGV for "rails runner `CODE' arg arg arg..."
......@@ -16,7 +16,7 @@ def self.banner(*)
"#{super} [<'Some.ruby(code)'> | <filename.rb>]"
end
def perform(code_or_file = nil, *file_argv)
def perform(code_or_file = nil, *command_argv)
unless code_or_file
help
exit 1
......@@ -27,9 +27,10 @@ def perform(code_or_file = nil, *file_argv)
require_application_and_environment!
Rails.application.load_runner
ARGV.replace(command_argv)
if File.exist?(code_or_file)
$0 = code_or_file
ARGV.replace(file_argv)
Kernel.load code_or_file
else
begin
......
......@@ -35,6 +35,14 @@ def test_should_run_ruby_statement
assert_match "42", Dir.chdir(app_path) { `bin/rails runner "puts User.count"` }
end
def test_should_set_argv_when_running_code
output = Dir.chdir(app_path) {
# Both long and short args, at start and end of ARGV
`bin/rails runner "puts ARGV.join(',')" --foo a1 -b a2 a3 --moo`
}
assert_equal "--foo,a1,-b,a2,a3,--moo", output.chomp
end
def test_should_run_file
app_file "bin/count_users.rb", <<-SCRIPT
puts User.count
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册