From fa69b2c03582f5817572050a4373e365d9071b5d Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Fri, 16 Dec 2016 20:10:21 -0500 Subject: `ARGV.shift` before calling Rails generators Gems like rspec-rails depend on `ARGV` being shifted, and `scaffold` (for example) not being the first item in `ARGV`. This should allow rspec-rails to be passing on Rails master. --- railties/lib/rails/commands/generate/generate_command.rb | 2 ++ railties/test/application/generators_test.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/commands/generate/generate_command.rb b/railties/lib/rails/commands/generate/generate_command.rb index 59b2febc43..aa8dab71b0 100644 --- a/railties/lib/rails/commands/generate/generate_command.rb +++ b/railties/lib/rails/commands/generate/generate_command.rb @@ -14,6 +14,8 @@ module Rails require_application_and_environment! load_generators + ARGV.shift + Rails::Generators.invoke generator, args, behavior: :invoke, destination_root: Rails::Command.root end end diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 0153f94504..d75577c5f6 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -169,5 +169,20 @@ module ApplicationTests assert File.exist?(File.join(rails_root, "app/views/notifier_mailer/foo.text.erb")) assert File.exist?(File.join(rails_root, "app/views/notifier_mailer/foo.html.erb")) end + + test "ARGV is mutated as expected" do + require "#{app_path}/config/environment" + Rails::Command.const_set("APP_PATH", "rails/all") + + FileUtils.cd(rails_root) do + ARGV = ["mailer", "notifier", "foo"] + Rails::Command.const_set("ARGV", ARGV) + Rails::Command.invoke :generate, ARGV + + assert_equal ["notifier", "foo"], ARGV + end + + Rails::Command.send(:remove_const, "APP_PATH") + end end end -- cgit v1.2.3