From bad1041b82df941d588ae2565f62424d88104933 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 9 Dec 2018 15:00:01 +0900 Subject: Add test for reads environment credential file with environment variable key --- railties/test/credentials_test.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/credentials_test.rb b/railties/test/credentials_test.rb index 03370e0fc7..11765b0de5 100644 --- a/railties/test/credentials_test.rb +++ b/railties/test/credentials_test.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true require "isolation/abstract_unit" +require "env_helpers" class Rails::CredentialsTest < ActiveSupport::TestCase - include ActiveSupport::Testing::Isolation + include ActiveSupport::Testing::Isolation, EnvHelpers setup :build_app teardown :teardown_app @@ -38,6 +39,21 @@ class Rails::CredentialsTest < ActiveSupport::TestCase end end + test "reads credentials using environment variable key" do + with_credentials do |content, key| + Dir.chdir(app_path) do + Dir.mkdir("config/credentials") + File.write("config/credentials/production.yml.enc", content) + end + + switch_env("RAILS_MASTER_KEY", key) do + app("production") + + assert_equal "revealed", Rails.application.credentials.mystery + end + end + end + private def with_credentials key = "2117e775dc2024d4f49ddf3aeb585919" -- cgit v1.2.3