From 1ce2f9a55c21873f334e0c3cbc70e1b56f442442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Annie-Claude=20C=C3=B4t=C3=A9?= Date: Thu, 16 Aug 2018 10:13:58 -0400 Subject: [PATCH] Move 'rails initializers' command to Rails::Command --- .../initializers/initializers_command.rb | 16 ++++++++++ railties/test/commands/initializers_test.rb | 32 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 railties/lib/rails/commands/initializers/initializers_command.rb create mode 100644 railties/test/commands/initializers_test.rb diff --git a/railties/lib/rails/commands/initializers/initializers_command.rb b/railties/lib/rails/commands/initializers/initializers_command.rb new file mode 100644 index 00000000000..6ed50f207ac --- /dev/null +++ b/railties/lib/rails/commands/initializers/initializers_command.rb @@ -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 diff --git a/railties/test/commands/initializers_test.rb b/railties/test/commands/initializers_test.rb new file mode 100644 index 00000000000..bdfbb3021c3 --- /dev/null +++ b/railties/test/commands/initializers_test.rb @@ -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