blob: 793365ef3dc3bb8b8d96cb673eb3caa9d2737009 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# 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
test "prints out initializers only specified in environment option" do
add_to_config <<-RUBY
initializer(:set_added_development_module) { } if Rails.env.development?
initializer(:set_added_production_module) { } if Rails.env.production?
RUBY
output = run_initializers_command.split("\n")
assert_includes output, "AppTemplate::Application.set_added_development_module"
assert_not_includes output, "AppTemplate::Application.set_added_production_module"
output = run_initializers_command(["-e", "production"]).split("\n")
assert_not_includes output, "AppTemplate::Application.set_added_development_module"
assert_includes output, "AppTemplate::Application.set_added_production_module"
end
private
def run_initializers_command(args = [])
rails "initializers", args
end
end
|