Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rake-style task arguments for bin/rails #47676

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion railties/lib/rails/commands/rake/rake_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def perform(task, args, config)
Rake.with_application do |rake|
rake.init("rails", [task, *args])
rake.load_rakefile
if unrecognized_task = rake.top_level_tasks.find { |task| !rake.lookup(task) }
if unrecognized_task = rake.top_level_tasks.find { |task| !rake.lookup(task[/[^\[]+/]) }
raise UnrecognizedCommandError.new(unrecognized_task)
end

Expand Down
35 changes: 35 additions & 0 deletions railties/test/commands/rake_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require "isolation/abstract_unit"
require "rails/command"

class Rails::Command::RakeTest < ActiveSupport::TestCase
setup :build_app
teardown :teardown_app

test "runs multiple tasks" do
app_file "lib/tasks/foo.rake", 'task(:foo) { puts "FOO!" }'
app_file "lib/tasks/bar.rake", 'task(:bar) { puts "BAR!" }'

output = run_rake_command "foo", "bar"
assert_match "FOO!", output
assert_match "BAR!", output
end

test "runs task with arguments" do
app_file "lib/tasks/hello.rake", <<~RUBY
namespace :greetings do
task :hello, [:name] do |task, args|
puts "Hello, \#{args.name}!"
end
end
RUBY

assert_match "Hello, World!", run_rake_command("greetings:hello[World]")
end

private
def run_rake_command(*args, **options)
rails args, **options
end
end