|
2 | 2 | require_relative "../../test_helper" |
3 | 3 |
|
4 | 4 | class Rails::AppEnv::CredentialsTest < ActiveSupport::TestCase |
| 5 | + test "#initialize! can only be invoked once" do |
| 6 | + reset_credentials |
| 7 | + |
| 8 | + Rails::AppEnv::Credentials.initialize! |
| 9 | + |
| 10 | + assert_raises Rails::AppEnv::Credentials::AlreadyInitializedError do |
| 11 | + Rails::AppEnv::Credentials.initialize! |
| 12 | + end |
| 13 | + end |
| 14 | + |
| 15 | + test "#initialize! backup original Rails.application.config.credentials" do |
| 16 | + reset_credentials |
| 17 | + |
| 18 | + expected = Object.new |
| 19 | + |
| 20 | + Rails.application.config.stub :credentials, expected do |
| 21 | + Rails::AppEnv::Credentials.initialize! |
| 22 | + end |
| 23 | + |
| 24 | + assert_same expected, Rails::AppEnv::Credentials.original |
| 25 | + end |
| 26 | + |
5 | 27 | test "#configuration is a kind of ActiveSupport::Credentials" do |
6 | 28 | assert_kind_of ActiveSupport::InheritableOptions, Rails::AppEnv::Credentials.configuration |
7 | 29 | end |
8 | 30 |
|
9 | 31 | test "#configuration.content_path is config/credentials/{Rails.app_env}.yml.enc" do |
10 | 32 | Dir.mktmpdir do |tmp_dir| |
11 | | - Rails.stub :root, Pathname(tmp_dir) do |
12 | | - Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("foo") do |
13 | | - path = Rails.root.join("config/credentials/foo.yml.enc") |
| 33 | + Rails.stub :root, Pathname(tmp_dir) do |
| 34 | + Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("foo") do |
| 35 | + path = Rails.root.join("config/credentials/foo.yml.enc") |
14 | 36 |
|
15 | | - FileUtils.mkdir_p File.dirname(path) |
16 | | - FileUtils.touch path |
| 37 | + FileUtils.mkdir_p File.dirname(path) |
| 38 | + FileUtils.touch path |
17 | 39 |
|
18 | | - assert_equal path, Rails::AppEnv::Credentials.configuration.content_path |
19 | | - end |
| 40 | + assert_equal path, Rails::AppEnv::Credentials.configuration.content_path |
20 | 41 | end |
21 | 42 | end |
| 43 | + end |
22 | 44 | end |
23 | 45 |
|
24 | 46 | test "#configuration.content_path falls back to config/credentials.yml.enc when config/credentials/{Rails.app_env}.yml.enc not exist" do |
@@ -59,4 +81,11 @@ class Rails::AppEnv::CredentialsTest < ActiveSupport::TestCase |
59 | 81 | end |
60 | 82 | end |
61 | 83 | end |
| 84 | + |
| 85 | + private |
| 86 | + |
| 87 | + def reset_credentials |
| 88 | + Rails::AppEnv::Credentials.instance_variable_set :@initialized, nil |
| 89 | + Rails::AppEnv::Credentials.instance_variable_set :@original, nil |
| 90 | + end |
62 | 91 | end |
0 commit comments