forked from diffcrypt/diffcrypt-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication_helper_test.rb
84 lines (68 loc) · 2.47 KB
/
application_helper_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# frozen_string_literal: true
require 'test_helper'
require 'diffcrypt/rails/application_helper'
class MockApplication
include Diffcrypt::Rails::ApplicationHelper
Config = Struct.new(:require_master_key)
def config
Config.new(true)
end
end
module Rails
def self.root
Pathname.new('/app')
end
end
class Diffcrypt::Rails::EncryptedConfigurationTest < Minitest::Test
def setup
@app = ::MockApplication.new
@mock = 'mocked encrypted configuration'
end
def test_that_encrypted_method_loads_encrypted_configuration_with_development_when_master_does_not_exist
init = lambda do |options|
expected_options = {
config_path: Pathname.new('/app/config/credentials/development.yml.enc'),
key_path: Pathname.new('/app/config/credentials/development.key'),
env_key: 'RAILS_MASTER_KEY',
raise_if_missing_key: true,
}
assert_equal expected_options, options
@mock
end
::Diffcrypt::Rails::EncryptedConfiguration.stub :new, init do
assert_equal @mock, @app.encrypted('config/credentials.yml.enc', key_path: 'config/master.key')
end
end
def test_that_encrypted_method_loads_encrypted_configuration_with_master_when_master_exists
init = lambda do |options|
expected_options = {
config_path: Pathname.new('/app/config/credentials.yml.enc'),
key_path: Pathname.new('/app/config/master.key'),
env_key: 'RAILS_MASTER_KEY',
raise_if_missing_key: true,
}
assert_equal expected_options, options
@mock
end
::File.stub :exist?, ->(path) { path == '/app/config/credentials.yml.enc' } do
::Diffcrypt::Rails::EncryptedConfiguration.stub :new, init do
assert_equal @mock, @app.encrypted('config/credentials.yml.enc', key_path: 'config/master.key')
end
end
end
def test_that_encrypted_method_loads_encrypted_configuration_with_development
init = lambda do |options|
expected_options = {
config_path: Pathname.new('/app/config/credentials/development.yml.enc'),
key_path: Pathname.new('/app/config/credentials/development.key'),
env_key: 'RAILS_MASTER_KEY',
raise_if_missing_key: true,
}
assert_equal expected_options, options
'mocked encrypted configuration'
end
::Diffcrypt::Rails::EncryptedConfiguration.stub :new, init do
assert_equal @mock, @app.encrypted('config/credentials/development.yml.enc', key_path: 'config/credentials/development.key')
end
end
end