Skip to content

Commit 741a875

Browse files
committed
wip
1 parent ad25e27 commit 741a875

File tree

3 files changed

+71
-63
lines changed

3 files changed

+71
-63
lines changed

lib/rails/app_env/credentials.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ def initialize!
99
@initialized = true
1010

1111
@original = Rails.application.config.credentials
12-
Rails.application.config.credentials = ActiveSupport::InheritableOptions.new(
12+
Rails.application.config.credentials = configuration
13+
14+
monkey_patch_rails_credentials_command!
15+
end
16+
17+
def configuration
18+
ActiveSupport::InheritableOptions.new(
1319
content_path: content_path,
1420
key_path: key_path
1521
)
16-
17-
monkey_patch_command!
1822
end
1923

2024
private
@@ -31,8 +35,8 @@ def key_path
3135
path
3236
end
3337

34-
def monkey_patch_command!
35-
require_relative "../command/credentials_command"
38+
def monkey_patch_rails_credentials_command!
39+
require_relative "../rails_ext/credentials_command"
3640
end
3741
end
3842
end
File renamed without changes.
Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,62 @@
1-
# require "minitest/mock"
2-
# require_relative "../../test_helper"
3-
#
4-
# class Rails::AppEnv::CredentialsTest < ActiveSupport::TestCase
5-
# test "Credentials#content_path returns 'config/credentials/{APP_ENV}.yml.enc' if the file exist" do
6-
# Dir.mktmpdir do |tmp_dir|
7-
# Rails.stub :root, Pathname(tmp_dir) do
8-
# Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("fake_foo") do
9-
# path = Rails.root.join("config/credentials/fake_foo.yml.enc")
10-
#
11-
# FileUtils.mkdir_p File.dirname(path)
12-
# FileUtils.touch path
13-
#
14-
# assert_equal path, Rails::AppEnv::Credentials.content_path
15-
# end
16-
# end
17-
# end
18-
# end
19-
#
20-
# test "Credentials#content_path falls back to 'config/credentials.yml.enc' if the file does not exist" do
21-
# Dir.mktmpdir do |tmp_dir|
22-
# Rails.stub :root, Pathname(tmp_dir) do
23-
# Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("fake_foo") do
24-
# path = Rails.root.join("config/credentials.yml.enc")
25-
#
26-
# assert_equal path, Rails::AppEnv::Credentials.content_path
27-
# end
28-
# end
29-
# end
30-
# end
31-
#
32-
# test "Credentials#key_path returns 'config/credentials/{APP_ENV}.key' if the file exist" do
33-
# Dir.mktmpdir do |tmp_dir|
34-
# Rails.stub :root, Pathname(tmp_dir) do
35-
# Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("fake_foo") do
36-
# path = Rails.root.join("config/credentials/fake_foo.key")
37-
#
38-
# FileUtils.mkdir_p File.dirname(path)
39-
# FileUtils.touch path
40-
#
41-
# assert_equal path, Rails::AppEnv::Credentials.key_path
42-
# end
43-
# end
44-
# end
45-
# end
46-
#
47-
# test "Credentials#key_path falls back to 'config/master.key' if the file does not exist" do
48-
# Dir.mktmpdir do |tmp_dir|
49-
# Rails.stub :root, Pathname(tmp_dir) do
50-
# Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("fake_foo") do
51-
# path = Rails.root.join("config/master.key")
52-
#
53-
# assert_equal path, Rails::AppEnv::Credentials.key_path
54-
# end
55-
# end
56-
# end
57-
# end
58-
# end
1+
require "minitest/mock"
2+
require_relative "../../test_helper"
3+
4+
class Rails::AppEnv::CredentialsTest < ActiveSupport::TestCase
5+
test "#configuration is a kind of ActiveSupport::Credentials" do
6+
assert_kind_of ActiveSupport::InheritableOptions, Rails::AppEnv::Credentials.configuration
7+
end
8+
9+
test "#configuration.content_path is config/credentials/{Rails.app_env}.yml.enc" do
10+
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")
14+
15+
FileUtils.mkdir_p File.dirname(path)
16+
FileUtils.touch path
17+
18+
assert_equal path, Rails::AppEnv::Credentials.configuration.content_path
19+
end
20+
end
21+
end
22+
end
23+
24+
test "#configuration.content_path falls back to config/credentials.yml.enc when config/credentials/{Rails.app_env}.yml.enc not exist" do
25+
Dir.mktmpdir do |tmp_dir|
26+
Rails.stub :root, Pathname(tmp_dir) do
27+
Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("foo") do
28+
path = Rails.root.join("config/credentials.yml.enc")
29+
30+
assert_equal path, Rails::AppEnv::Credentials.configuration.content_path
31+
end
32+
end
33+
end
34+
end
35+
36+
test "#configuration.key_path is config/credentials/{APP_ENV}.key" do
37+
Dir.mktmpdir do |tmp_dir|
38+
Rails.stub :root, Pathname(tmp_dir) do
39+
Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("foo") do
40+
path = Rails.root.join("config/credentials/foo.key")
41+
42+
FileUtils.mkdir_p File.dirname(path)
43+
FileUtils.touch path
44+
45+
assert_equal path, Rails::AppEnv::Credentials.configuration.key_path
46+
end
47+
end
48+
end
49+
end
50+
51+
test "#configuration.key_path falls back to config/master.key when config/credentials/{APP_ENV}.key not exist" do
52+
Dir.mktmpdir do |tmp_dir|
53+
Rails.stub :root, Pathname(tmp_dir) do
54+
Rails.stub :app_env, Rails::AppEnv::EnvironmentInquirer.new("foo") do
55+
path = Rails.root.join("config/master.key")
56+
57+
assert_equal path, Rails::AppEnv::Credentials.configuration.key_path
58+
end
59+
end
60+
end
61+
end
62+
end

0 commit comments

Comments
 (0)