提交 85c5e829 编写于 作者: J Jonathan Hefner

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.
上级 71014892
......@@ -16,7 +16,6 @@ def perform(task, args, config)
require_rake
Rake.with_application do |rake|
load "rails/tasks.rb"
rake.init("rails", [task, *args])
rake.load_rakefile
if Rails.respond_to?(:root)
......
......@@ -25,6 +25,10 @@ def test_gems_tasks_are_loaded_first_than_application_ones
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册