Skip to content

Commit af3b6c3

Browse files
committed
Fix false positive test related to wrong app root path.
Without setting root config, `config.paths["config/secrets"]` located in https://github.com/rails/rails/blob/84eb498f84ebc5d1be0b0db6f7bca9da3d679ca6/railties/lib/rails/application.rb#L390 always returned empty list.
1 parent 84eb498 commit af3b6c3

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

railties/test/secrets_test.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def teardown
8989
yeah_yeah: lets-walk-in-the-cool-evening-light
9090
end_of_secrets
9191

92-
Rails.application.config.root = app_path
9392
Rails.application.config.read_encrypted_secrets = true
9493
Rails.application.instance_variable_set(:@secrets, nil) # Dance around caching 💃🕺
9594
assert_equal "lets-walk-in-the-cool-evening-light", Rails.application.secrets.yeah_yeah
@@ -113,19 +112,17 @@ def teardown
113112

114113
test "do not update secrets.yml.enc when secretes do not change" do
115114
run_secrets_generator do
116-
Dir.chdir(app_path) do
117-
Rails::Secrets.read_for_editing do |tmp_path|
118-
File.write(tmp_path, "Empty streets, empty nights. The Downtown Lights.")
119-
end
115+
Rails::Secrets.read_for_editing do |tmp_path|
116+
File.write(tmp_path, "Empty streets, empty nights. The Downtown Lights.")
117+
end
120118

121-
FileUtils.cp("config/secrets.yml.enc", "config/secrets.yml.enc.bk")
119+
FileUtils.cp("config/secrets.yml.enc", "config/secrets.yml.enc.bk")
122120

123-
Rails::Secrets.read_for_editing do |tmp_path|
124-
File.write(tmp_path, "Empty streets, empty nights. The Downtown Lights.")
125-
end
126-
127-
assert_equal File.read("config/secrets.yml.enc.bk"), File.read("config/secrets.yml.enc")
121+
Rails::Secrets.read_for_editing do |tmp_path|
122+
File.write(tmp_path, "Empty streets, empty nights. The Downtown Lights.")
128123
end
124+
125+
assert_equal File.read("config/secrets.yml.enc.bk"), File.read("config/secrets.yml.enc")
129126
end
130127
end
131128

@@ -170,6 +167,9 @@ def run_secrets_generator
170167
Rails::Generators::EncryptedSecretsGenerator.start
171168
end
172169

170+
# Make config.paths["config/secrets"] to be relative to app_path
171+
Rails.application.config.root = app_path
172+
173173
yield
174174
end
175175
end

0 commit comments

Comments
 (0)