mirror of https://github.com/rails/rails
Merge pull request #33631 from anniecodes/initializers-command
Move the initializers rake task to Rails::Command
This commit is contained in:
commit
cc14bf77ca
|
@ -1,3 +1,7 @@
|
|||
* Deprecate `rake initializers` in favor of `rails initializers`.
|
||||
|
||||
*Annie-Claude Côté*
|
||||
|
||||
* Deprecate `rake dev:cache` in favor of `rails dev:cache`.
|
||||
|
||||
*Annie-Claude Côté*
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Rails
|
||||
module Command
|
||||
class InitializersCommand < Base # :nodoc:
|
||||
desc "Print out all defined initializers in the order they are invoked by Rails."
|
||||
def perform
|
||||
require_application_and_environment!
|
||||
|
||||
Rails.application.initializers.tsort_each do |initializer|
|
||||
puts "#{initializer.context_class}.#{initializer.name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,8 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails/command"
|
||||
require "active_support/deprecation"
|
||||
|
||||
desc "Print out all defined initializers in the order they are invoked by Rails."
|
||||
task initializers: :environment do
|
||||
Rails.application.initializers.tsort_each do |initializer|
|
||||
puts "#{initializer.context_class}.#{initializer.name}"
|
||||
end
|
||||
task :initializers do
|
||||
ActiveSupport::Deprecation.warn("Using `bin/rake initializers` is deprecated and will be removed in Rails 6.1. Use `bin/rails initializers` instead.\n")
|
||||
Rails::Command.invoke "initializers"
|
||||
end
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "isolation/abstract_unit"
|
||||
|
||||
module ApplicationTests
|
||||
module RakeTests
|
||||
class RakeInitializersTest < ActiveSupport::TestCase
|
||||
setup :build_app
|
||||
teardown :teardown_app
|
||||
|
||||
test "`rake initializers` prints out defined initializers invoked by Rails" do
|
||||
capture(:stderr) do
|
||||
initial_output = run_rake_initializers
|
||||
initial_output_length = initial_output.split("\n").length
|
||||
|
||||
assert_operator initial_output_length, :>, 0
|
||||
assert_not initial_output.include?("set_added_test_module")
|
||||
|
||||
add_to_config <<-RUBY
|
||||
initializer(:set_added_test_module) { }
|
||||
RUBY
|
||||
|
||||
final_output = run_rake_initializers
|
||||
final_output_length = final_output.split("\n").length
|
||||
|
||||
assert_equal 1, (final_output_length - initial_output_length)
|
||||
assert final_output.include?("set_added_test_module")
|
||||
end
|
||||
end
|
||||
|
||||
test "`rake initializers` outputs a deprecation warning" do
|
||||
stderr = capture(:stderr) { run_rake_initializers }
|
||||
assert_match(/DEPRECATION WARNING: Using `bin\/rake initializers` is deprecated and will be removed in Rails 6.1/, stderr)
|
||||
end
|
||||
|
||||
private
|
||||
def run_rake_initializers
|
||||
Dir.chdir(app_path) { `bin/rake initializers` }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,32 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "isolation/abstract_unit"
|
||||
require "rails/command"
|
||||
|
||||
class Rails::Command::InitializersTest < ActiveSupport::TestCase
|
||||
setup :build_app
|
||||
teardown :teardown_app
|
||||
|
||||
test "`rails initializers` prints out defined initializers invoked by Rails" do
|
||||
initial_output = run_initializers_command
|
||||
initial_output_length = initial_output.split("\n").length
|
||||
|
||||
assert_operator initial_output_length, :>, 0
|
||||
assert_not initial_output.include?("set_added_test_module")
|
||||
|
||||
add_to_config <<-RUBY
|
||||
initializer(:set_added_test_module) { }
|
||||
RUBY
|
||||
|
||||
final_output = run_initializers_command
|
||||
final_output_length = final_output.split("\n").length
|
||||
|
||||
assert_equal 1, (final_output_length - initial_output_length)
|
||||
assert final_output.include?("set_added_test_module")
|
||||
end
|
||||
|
||||
private
|
||||
def run_initializers_command
|
||||
rails "initializers"
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue