25
25
}
26
26
end
27
27
28
- def setup_env
28
+ def setup_env ( options )
29
29
options . each do |k , v |
30
30
ENV [ "DYNAMO_DB_SESSION_#{ k . to_s . upcase } " ] = v . to_s
31
31
end
32
32
end
33
33
34
- def teardown_env
34
+ def teardown_env ( options )
35
35
options . each_key { |k | ENV . delete ( "DYNAMO_DB_SESSION_#{ k . to_s . upcase } " ) }
36
36
end
37
37
@@ -41,44 +41,75 @@ def teardown_env
41
41
allow ( Aws ::DynamoDB ::Client ) . to receive ( :new ) . and_return ( client )
42
42
end
43
43
44
- it 'configures defaults without runtime, YAML or ENV options' do
44
+ it 'configures defaults without runtime, ENV, or YAML options' do
45
45
cfg = Aws ::SessionStore ::DynamoDB ::Configuration . new
46
46
expect ( cfg . to_hash ) . to include ( defaults )
47
47
end
48
48
49
- it 'configures with ENV with precedence over defaults' do
50
- setup_env
51
- cfg = Aws ::SessionStore ::DynamoDB ::Configuration . new
52
- expect ( cfg . to_hash ) . to include ( options )
53
- teardown_env
49
+ it 'configures with YAML with precedence over defaults' do
50
+ Tempfile . create ( 'dynamo_db_session_store.yml' ) do |f |
51
+ f << options . transform_keys ( &:to_s ) . to_yaml
52
+ f . rewind
53
+ cfg = Aws ::SessionStore ::DynamoDB ::Configuration . new ( config_file : f . path )
54
+ expect ( cfg . to_hash ) . to include ( options )
55
+ end
56
+ end
57
+
58
+ it 'configures with ENV with precedence over YAML' do
59
+ setup_env ( options )
60
+ Tempfile . create ( 'dynamo_db_session_store.yml' ) do |f |
61
+ f << { table_name : 'OldTable' , table_key : 'OldKey' } . transform_keys ( &:to_s ) . to_yaml
62
+ f . rewind
63
+ cfg = Aws ::SessionStore ::DynamoDB ::Configuration . new ( config_file : f . path )
64
+ expect ( cfg . to_hash ) . to include ( options )
65
+ ensure
66
+ teardown_env ( options )
67
+ end
68
+ end
69
+
70
+ it 'configures in code with full precedence' do
71
+ old = { table_name : 'OldTable' , table_key : 'OldKey' }
72
+ setup_env ( options . merge ( old ) )
73
+ Tempfile . create ( 'dynamo_db_session_store.yml' ) do |f |
74
+ f << old . transform_keys ( &:to_s ) . to_yaml
75
+ f . rewind
76
+ cfg = Aws ::SessionStore ::DynamoDB ::Configuration . new ( options . merge ( config_file : f . path ) )
77
+ expect ( cfg . to_hash ) . to include ( options )
78
+ ensure
79
+ teardown_env ( options . merge ( old ) )
80
+ end
54
81
end
55
82
56
- it 'configs with YAML with precedence over ENV' do
57
- setup_env
83
+ it 'allows for config file to be configured with ENV' do
58
84
Tempfile . create ( 'dynamo_db_session_store.yml' ) do |f |
59
85
f << options . transform_keys ( &:to_s ) . to_yaml
60
86
f . rewind
61
87
ENV [ 'DYNAMO_DB_SESSION_CONFIG_FILE' ] = f . path
62
88
cfg = Aws ::SessionStore ::DynamoDB ::Configuration . new
63
- ENV . delete ( 'DYNAMO_DB_SESSION_CONFIG_FILE' )
64
89
expect ( cfg . to_hash ) . to include ( options )
90
+ ensure
91
+ ENV . delete ( 'DYNAMO_DB_SESSION_CONFIG_FILE' )
65
92
end
66
- teardown_env
67
93
end
68
94
69
- it 'configures with runtime options with full precedence' do
70
- setup_env
95
+ it 'ignores unsupported keys in ENV' do
96
+ ENV [ 'DYNAMO_DB_SESSION_DYNAMO_DB_CLIENT' ] = 'Client'
97
+ ENV [ 'DYNAMO_DB_SESSION_ERROR_HANDLER' ] = 'Handler'
98
+ cfg = Aws ::SessionStore ::DynamoDB ::Configuration . new
99
+ expect ( cfg . to_hash ) . to include ( defaults )
100
+ ensure
101
+ ENV . delete ( 'DYNAMO_DB_SESSION_DYNAMO_DB_CLIENT' )
102
+ ENV . delete ( 'DYNAMO_DB_SESSION_ERROR_HANDLER' )
103
+ end
104
+
105
+ it 'ignores unsupported keys in YAML' do
71
106
Tempfile . create ( 'dynamo_db_session_store.yml' ) do |f |
72
- f << { table_name : 'OldTable' , table_key : 'OldKey' } . transform_keys ( &:to_s ) . to_yaml
107
+ options = { dynamo_db_client : 'Client' , error_handler : 'Handler' , config_file : 'File' }
108
+ f << options . transform_keys ( &:to_s ) . to_yaml
73
109
f . rewind
74
- cfg = Aws ::SessionStore ::DynamoDB ::Configuration . new (
75
- options . merge (
76
- config_file : f . path
77
- )
78
- )
79
- expect ( cfg . to_hash ) . to include ( options )
110
+ cfg = Aws ::SessionStore ::DynamoDB ::Configuration . new ( config_file : f . path )
111
+ expect ( cfg . to_hash ) . to include ( defaults . merge ( config_file : f . path ) )
80
112
end
81
- teardown_env
82
113
end
83
114
84
115
it 'raises an exception when wrong path for file' do
0 commit comments