From 241d6a596a88ecaf2387c50d866b00db62a07615 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Thu, 7 Sep 2017 07:32:39 +0900 Subject: Reorganize secrets test to use only `isolation/abstract_unit` Currently, secrets test uses `abstract_unit` and `isolation/abstract_unit`. This is a bit odd. Therefore, reorganize it so that use only `isolation/abstract_unit`. Context: https://github.com/rails/rails/pull/30520#issuecomment-327409586 --- railties/test/secrets_test.rb | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'railties/test/secrets_test.rb') diff --git a/railties/test/secrets_test.rb b/railties/test/secrets_test.rb index 631c6a13fe..a394f5661e 100644 --- a/railties/test/secrets_test.rb +++ b/railties/test/secrets_test.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "abstract_unit" require "isolation/abstract_unit" require "rails/generators" require "rails/generators/rails/encrypted_secrets/encrypted_secrets_generator" @@ -20,12 +19,13 @@ class Rails::SecretsTest < ActiveSupport::TestCase test "setting read to false skips parsing" do run_secrets_generator do Rails::Secrets.write(<<-end_of_secrets) - test: + production: yeah_yeah: lets-walk-in-the-cool-evening-light end_of_secrets - Rails.application.config.read_encrypted_secrets = false - Rails.application.instance_variable_set(:@secrets, nil) # Dance around caching 💃🕺 + add_to_env_config("production", "config.read_encrypted_secrets = false") + app("production") + assert_not Rails.application.secrets.yeah_yeah end end @@ -82,17 +82,18 @@ class Rails::SecretsTest < ActiveSupport::TestCase test "merging secrets with encrypted precedence" do run_secrets_generator do File.write("config/secrets.yml", <<-end_of_secrets) - test: + production: yeah_yeah: lets-go-walking-down-this-empty-street end_of_secrets Rails::Secrets.write(<<-end_of_secrets) - test: + production: yeah_yeah: lets-walk-in-the-cool-evening-light end_of_secrets - Rails.application.config.read_encrypted_secrets = true - Rails.application.instance_variable_set(:@secrets, nil) # Dance around caching 💃🕺 + add_to_env_config("production", "config.read_encrypted_secrets = true") + app("production") + assert_equal "lets-walk-in-the-cool-evening-light", Rails.application.secrets.yeah_yeah end end @@ -108,7 +109,9 @@ class Rails::SecretsTest < ActiveSupport::TestCase config.dereferenced_secret = Rails.application.secrets.some_secret end_of_config - assert_equal "yeah yeah\n", rails("runner", "-e", "production", "puts Rails.application.config.dereferenced_secret", fork: false) + app("production") + + assert_equal "yeah yeah", Rails.application.config.dereferenced_secret end end @@ -141,7 +144,9 @@ class Rails::SecretsTest < ActiveSupport::TestCase assert_match(/production:\n\s*api_key: 00112233445566778899aabbccddeeff…\n/, File.read(tmp_path)) end - assert_equal "00112233445566778899aabbccddeeff…\n", rails("runner", "-e", "production", "puts Rails.application.secrets.api_key", fork: false) + app("production") + + assert_equal "00112233445566778899aabbccddeeff…", Rails.application.secrets.api_key end end @@ -158,7 +163,9 @@ class Rails::SecretsTest < ActiveSupport::TestCase assert_equal(secrets.dup.force_encoding(Encoding::ASCII_8BIT), IO.binread(tmp_path)) end - assert_equal "00112233445566778899aabbccddeeff…\n", rails("runner", "-e", "production", "puts Rails.application.secrets.api_key", fork: false) + app("production") + + assert_equal "00112233445566778899aabbccddeeff…", Rails.application.secrets.api_key end end @@ -169,9 +176,6 @@ class Rails::SecretsTest < ActiveSupport::TestCase Rails::Generators::EncryptedSecretsGenerator.start end - # Make config.paths["config/secrets"] to be relative to app_path - Rails.application.config.root = app_path - yield end end -- cgit v1.2.3