aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Thau <rst@smartleaf.com>2017-03-21 23:07:07 -0400
committerRobert Thau <rst@smartleaf.com>2017-03-22 12:04:19 -0400
commita06a643e0572b8c983738c068ae637d020188c97 (patch)
tree2f72d566f55050dba816468e1c92f5d691d20cf6
parent34fe2a4fc778d18b7fe6bdf3629c1481bee789b9 (diff)
downloadrails-a06a643e0572b8c983738c068ae637d020188c97.tar.gz
rails-a06a643e0572b8c983738c068ae637d020188c97.tar.bz2
rails-a06a643e0572b8c983738c068ae637d020188c97.zip
Correctly reset ARGV for "rails runner `CODE' arg arg arg..."
The code itself should not be in the ARGV vector. Fixes #28515
-rw-r--r--railties/lib/rails/commands/runner/runner_command.rb5
-rw-r--r--railties/test/application/runner_test.rb8
2 files changed, 11 insertions, 2 deletions
diff --git a/railties/lib/rails/commands/runner/runner_command.rb b/railties/lib/rails/commands/runner/runner_command.rb
index 056ad980b9..6864a9726b 100644
--- a/railties/lib/rails/commands/runner/runner_command.rb
+++ b/railties/lib/rails/commands/runner/runner_command.rb
@@ -16,7 +16,7 @@ module Rails
"#{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 @@ module Rails
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
diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb
index 7d058f6ee6..e8fac442bd 100644
--- a/railties/test/application/runner_test.rb
+++ b/railties/test/application/runner_test.rb
@@ -35,6 +35,14 @@ module ApplicationTests
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