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

Load Rails Rake tasks only once

In #39137, a new `Rake::Application` instance was created per Rake
command invocation.  To ensure that the Rails tasks were defined for
each `Rake::Application`, `rails/tasks.rb` was loaded per instance.
However, `Rake::Application#load_rakefile` loads the application's
Rakefile, which should invoke `Rails.application.load_tasks`, which, in
turn, also loads the Rails tasks.  When a Rake task is defined more than
once, all definition blocks are executed when the task is run.  Hence,
Rails task blocks were being executed twice.

This commit removes the unnecessary load and avoids double execution.

Fixes #40136.
This commit is contained in:
Jonathan Hefner 2020-08-30 11:34:26 -05:00
parent 7101489293
commit 85c5e82935
2 changed files with 4 additions and 1 deletions

View file

@ -16,7 +16,6 @@ module Rails
require_rake
Rake.with_application do |rake|
load "rails/tasks.rb"
rake.init("rails", [task, *args])
rake.load_rakefile
if Rails.respond_to?(:root)

View file

@ -25,6 +25,10 @@ module ApplicationTests
assert $task_loaded
end
test "framework tasks are evaluated only once" do
assert_equal ["Rails version"], rails("about").scan(/^Rails version/)
end
test "task backtrace is silenced" do
add_to_config <<-RUBY
rake_tasks do