drtom_rails_config 0.5.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Appraisals +11 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile +6 -0
- data/LICENSE.md +27 -0
- data/README.md +317 -0
- data/Rakefile +53 -0
- data/gemfiles/rails_3.gemfile +7 -0
- data/gemfiles/rails_4.1.gemfile +7 -0
- data/gemfiles/rails_4.gemfile +7 -0
- data/lib/generators/rails_config/install_generator.rb +32 -0
- data/lib/generators/rails_config/templates/rails_config.rb +3 -0
- data/lib/generators/rails_config/templates/settings.local.yml +0 -0
- data/lib/generators/rails_config/templates/settings.yml +0 -0
- data/lib/generators/rails_config/templates/settings/development.yml +0 -0
- data/lib/generators/rails_config/templates/settings/production.yml +0 -0
- data/lib/generators/rails_config/templates/settings/test.yml +0 -0
- data/lib/rails_config.rb +64 -0
- data/lib/rails_config/deep_merge.rb +32 -0
- data/lib/rails_config/engine.rb +5 -0
- data/lib/rails_config/integration/rails.rb +34 -0
- data/lib/rails_config/integration/sinatra.rb +26 -0
- data/lib/rails_config/options.rb +118 -0
- data/lib/rails_config/rack/reloader.rb +15 -0
- data/lib/rails_config/railtie.rb +9 -0
- data/lib/rails_config/sources/yaml_source.rb +26 -0
- data/lib/rails_config/tasks.rb +59 -0
- data/lib/rails_config/tasks/heroku.rake +8 -0
- data/lib/rails_config/version.rb +3 -0
- data/rails_config.gemspec +40 -0
- data/spec/app/rails_3/Rakefile +7 -0
- data/spec/app/rails_3/app/assets/javascripts/application.js +13 -0
- data/spec/app/rails_3/app/assets/stylesheets/application.css +13 -0
- data/spec/app/rails_3/app/controllers/application_controller.rb +3 -0
- data/spec/app/rails_3/app/helpers/application_helper.rb +2 -0
- data/spec/app/rails_3/app/models/.gitkeep +0 -0
- data/spec/app/rails_3/app/views/layouts/application.html.erb +14 -0
- data/spec/app/rails_3/bin/bundle +3 -0
- data/spec/app/rails_3/bin/rails +4 -0
- data/spec/app/rails_3/bin/rake +4 -0
- data/spec/app/rails_3/config.ru +4 -0
- data/spec/app/rails_3/config/application.rb +29 -0
- data/spec/app/rails_3/config/boot.rb +5 -0
- data/spec/app/rails_3/config/database.yml +25 -0
- data/spec/app/rails_3/config/environment.rb +5 -0
- data/spec/app/rails_3/config/environments/development.rb +42 -0
- data/spec/app/rails_3/config/environments/production.rb +72 -0
- data/spec/app/rails_3/config/environments/test.rb +42 -0
- data/spec/app/rails_3/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/app/rails_3/config/initializers/inflections.rb +15 -0
- data/spec/app/rails_3/config/initializers/mime_types.rb +5 -0
- data/spec/app/rails_3/config/initializers/secret_token.rb +7 -0
- data/spec/app/rails_3/config/initializers/session_store.rb +8 -0
- data/spec/app/rails_3/config/initializers/wrap_parameters.rb +14 -0
- data/spec/app/rails_3/config/locales/en.yml +5 -0
- data/spec/app/rails_3/config/routes.rb +2 -0
- data/spec/app/rails_3/config/settings.yml +7 -0
- data/spec/app/rails_3/db/.gitkeep +0 -0
- data/spec/app/rails_3/public/404.html +26 -0
- data/spec/app/rails_3/public/422.html +26 -0
- data/spec/app/rails_3/public/500.html +25 -0
- data/spec/app/rails_3/script/rails +6 -0
- data/spec/app/rails_4.1/Rakefile +6 -0
- data/spec/app/rails_4.1/app/assets/javascripts/application.js +13 -0
- data/spec/app/rails_4.1/app/assets/stylesheets/application.css +15 -0
- data/spec/app/rails_4.1/app/controllers/application_controller.rb +5 -0
- data/spec/app/rails_4.1/app/helpers/application_helper.rb +2 -0
- data/spec/app/rails_4.1/app/models/.keep +0 -0
- data/spec/app/rails_4.1/app/views/layouts/application.html.erb +14 -0
- data/spec/app/rails_4.1/bin/bundle +3 -0
- data/spec/app/rails_4.1/bin/rails +4 -0
- data/spec/app/rails_4.1/bin/rake +4 -0
- data/spec/app/rails_4.1/config.ru +4 -0
- data/spec/app/rails_4.1/config/application.rb +27 -0
- data/spec/app/rails_4.1/config/boot.rb +5 -0
- data/spec/app/rails_4.1/config/database.yml +25 -0
- data/spec/app/rails_4.1/config/environment.rb +5 -0
- data/spec/app/rails_4.1/config/environments/development.rb +42 -0
- data/spec/app/rails_4.1/config/environments/production.rb +88 -0
- data/spec/app/rails_4.1/config/environments/test.rb +44 -0
- data/spec/app/rails_4.1/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/app/rails_4.1/config/initializers/cookies_serializer.rb +3 -0
- data/spec/app/rails_4.1/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/app/rails_4.1/config/initializers/inflections.rb +16 -0
- data/spec/app/rails_4.1/config/initializers/mime_types.rb +4 -0
- data/spec/app/rails_4.1/config/initializers/session_store.rb +3 -0
- data/spec/app/rails_4.1/config/initializers/wrap_parameters.rb +14 -0
- data/spec/app/rails_4.1/config/locales/en.yml +23 -0
- data/spec/app/rails_4.1/config/routes.rb +2 -0
- data/spec/app/rails_4.1/config/secrets.yml +22 -0
- data/spec/app/rails_4.1/config/settings.yml +7 -0
- data/spec/app/rails_4.1/db/.keep +0 -0
- data/spec/app/rails_4.1/public/404.html +67 -0
- data/spec/app/rails_4.1/public/422.html +67 -0
- data/spec/app/rails_4.1/public/500.html +66 -0
- data/spec/app/rails_4/Rakefile +6 -0
- data/spec/app/rails_4/app/assets/javascripts/application.js +13 -0
- data/spec/app/rails_4/app/assets/stylesheets/application.css +13 -0
- data/spec/app/rails_4/app/controllers/application_controller.rb +5 -0
- data/spec/app/rails_4/app/helpers/application_helper.rb +2 -0
- data/spec/app/rails_4/app/models/.keep +0 -0
- data/spec/app/rails_4/app/views/layouts/application.html.erb +14 -0
- data/spec/app/rails_4/bin/bundle +3 -0
- data/spec/app/rails_4/bin/rails +4 -0
- data/spec/app/rails_4/bin/rake +4 -0
- data/spec/app/rails_4/config.ru +4 -0
- data/spec/app/rails_4/config/application.rb +27 -0
- data/spec/app/rails_4/config/boot.rb +5 -0
- data/spec/app/rails_4/config/database.yml +25 -0
- data/spec/app/rails_4/config/environment.rb +5 -0
- data/spec/app/rails_4/config/environments/development.rb +34 -0
- data/spec/app/rails_4/config/environments/production.rb +85 -0
- data/spec/app/rails_4/config/environments/test.rb +41 -0
- data/spec/app/rails_4/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/app/rails_4/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/app/rails_4/config/initializers/inflections.rb +16 -0
- data/spec/app/rails_4/config/initializers/mime_types.rb +5 -0
- data/spec/app/rails_4/config/initializers/secret_token.rb +12 -0
- data/spec/app/rails_4/config/initializers/session_store.rb +3 -0
- data/spec/app/rails_4/config/initializers/wrap_parameters.rb +14 -0
- data/spec/app/rails_4/config/locales/en.yml +23 -0
- data/spec/app/rails_4/config/routes.rb +2 -0
- data/spec/app/rails_4/config/settings.yml +7 -0
- data/spec/app/rails_4/db/.keep +0 -0
- data/spec/app/rails_4/public/404.html +58 -0
- data/spec/app/rails_4/public/422.html +58 -0
- data/spec/app/rails_4/public/500.html +57 -0
- data/spec/fixtures/bool_override/config1.yml +2 -0
- data/spec/fixtures/bool_override/config2.yml +2 -0
- data/spec/fixtures/custom_types/hash.yml +7 -0
- data/spec/fixtures/deep_merge/config1.yml +28 -0
- data/spec/fixtures/deep_merge/config2.yml +28 -0
- data/spec/fixtures/deep_merge2/config1.yml +3 -0
- data/spec/fixtures/deep_merge2/config2.yml +2 -0
- data/spec/fixtures/development.yml +4 -0
- data/spec/fixtures/empty1.yml +0 -0
- data/spec/fixtures/empty2.yml +0 -0
- data/spec/fixtures/env/settings.yml +4 -0
- data/spec/fixtures/malformed.yml +6 -0
- data/spec/fixtures/settings.yml +21 -0
- data/spec/fixtures/settings2.yml +1 -0
- data/spec/fixtures/with_erb.yml +4 -0
- data/spec/rails_config_helper.rb +22 -0
- data/spec/rails_config_spec.rb +311 -0
- data/spec/sources/yaml_source_spec.rb +77 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/support/shared_contexts/rake.rb +8 -0
- data/spec/tasks/db_spec.rb +9 -0
- metadata +476 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
size: 1
|
2
|
+
server: google.com
|
3
|
+
inner:
|
4
|
+
something1: "blah1"
|
5
|
+
something2: "blah2"
|
6
|
+
|
7
|
+
inner2:
|
8
|
+
inner2_inner:
|
9
|
+
foo1: "blah1"
|
10
|
+
|
11
|
+
|
12
|
+
arraylist1:
|
13
|
+
- 1
|
14
|
+
- 2
|
15
|
+
- 3
|
16
|
+
|
17
|
+
arraylist2:
|
18
|
+
inner:
|
19
|
+
- 1
|
20
|
+
- 2
|
21
|
+
- 3
|
22
|
+
|
23
|
+
hash_array:
|
24
|
+
- 1
|
25
|
+
- inner:
|
26
|
+
- 1
|
27
|
+
- 2
|
28
|
+
- 3
|
@@ -0,0 +1,28 @@
|
|
1
|
+
server: google.com
|
2
|
+
|
3
|
+
inner:
|
4
|
+
something3: "blah3"
|
5
|
+
|
6
|
+
inner2:
|
7
|
+
inner2_inner:
|
8
|
+
foo2: "blah2"
|
9
|
+
foo3: "blah3"
|
10
|
+
|
11
|
+
arraylist1:
|
12
|
+
- 4
|
13
|
+
- 5
|
14
|
+
- 6
|
15
|
+
|
16
|
+
|
17
|
+
arraylist2:
|
18
|
+
inner:
|
19
|
+
- 4
|
20
|
+
- 5
|
21
|
+
- 6
|
22
|
+
|
23
|
+
hash_array:
|
24
|
+
- 2
|
25
|
+
- inner:
|
26
|
+
- 4
|
27
|
+
- 5
|
28
|
+
- 6
|
File without changes
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
##
|
2
|
+
# Settings for Rails database.yml
|
3
|
+
#
|
4
|
+
databases:
|
5
|
+
development:
|
6
|
+
database: db/development.sqlite3
|
7
|
+
test:
|
8
|
+
database: db/test.sqlite3
|
9
|
+
production:
|
10
|
+
database: db/production.sqlite3
|
11
|
+
##
|
12
|
+
# ...
|
13
|
+
#
|
14
|
+
size: 1
|
15
|
+
server: google.com
|
16
|
+
1: "one"
|
17
|
+
photo_sizes:
|
18
|
+
avatar: [60, 60]
|
19
|
+
root:
|
20
|
+
yahoo.com: 2
|
21
|
+
'google.com': 3
|
@@ -0,0 +1 @@
|
|
1
|
+
another: "something"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
##
|
2
|
+
# RailsConfig Rspec Helpers
|
3
|
+
#
|
4
|
+
|
5
|
+
# Loads ENV vars from a yaml file
|
6
|
+
def load_env(filename)
|
7
|
+
if filename and File.exists?(filename.to_s)
|
8
|
+
result = YAML.load(ERB.new(IO.read(filename.to_s)).result)
|
9
|
+
end
|
10
|
+
result.each { |key, value| ENV[key.to_s] = value.to_s } unless result.nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
# Checks if (default) RailsConfig const is already available
|
14
|
+
def rails_config_available?
|
15
|
+
where = caller[0].split(':')[0].gsub(File.expand_path(File.dirname(__FILE__)), '')
|
16
|
+
|
17
|
+
if defined?(::Settings)
|
18
|
+
puts "RailsConfig available in #{where}"
|
19
|
+
else
|
20
|
+
raise "RailsConfig not available in #{where}"
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,311 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsConfig do
|
4
|
+
it "should get setting files" do
|
5
|
+
config = RailsConfig.setting_files("root/config", "test")
|
6
|
+
config.should eq [
|
7
|
+
'root/config/settings.yml',
|
8
|
+
'root/config/settings/test.yml',
|
9
|
+
'root/config/environments/test.yml',
|
10
|
+
'root/config/settings.local.yml',
|
11
|
+
'root/config/settings/test.local.yml',
|
12
|
+
'root/config/environments/test.local.yml'
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should load a basic config file" do
|
17
|
+
config = RailsConfig.load_files("#{fixture_path}/settings.yml")
|
18
|
+
config.size.should eq 1
|
19
|
+
config.server.should eq "google.com"
|
20
|
+
config['1'].should eq 'one'
|
21
|
+
config.photo_sizes.avatar.should eq [60, 60]
|
22
|
+
config.root['yahoo.com'].should eq 2
|
23
|
+
config.root['google.com'].should eq 3
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should load 2 basic config files" do
|
27
|
+
config = RailsConfig.load_files("#{fixture_path}/settings.yml", "#{fixture_path}/settings2.yml")
|
28
|
+
config.size.should eq 1
|
29
|
+
config.server.should eq "google.com"
|
30
|
+
config.another.should eq "something"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should load empty config for a missing file path" do
|
34
|
+
config = RailsConfig.load_files("#{fixture_path}/some_file_that_doesnt_exist.yml")
|
35
|
+
config.should be_empty
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should load an empty config for multiple missing file paths" do
|
39
|
+
files = ["#{fixture_path}/doesnt_exist1.yml", "#{fixture_path}/doesnt_exist2.yml"]
|
40
|
+
config = RailsConfig.load_files(files)
|
41
|
+
config.should be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should load empty config for an empty setting file" do
|
45
|
+
config = RailsConfig.load_files("#{fixture_path}/empty1.yml")
|
46
|
+
config.should be_empty
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should convert to a hash" do
|
50
|
+
config = RailsConfig.load_files("#{fixture_path}/development.yml").to_hash
|
51
|
+
config[:section][:servers].should be_a_kind_of(Array)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should convert to a json" do
|
55
|
+
config = RailsConfig.load_files("#{fixture_path}/development.yml").to_json
|
56
|
+
JSON.parse(config)["section"]["servers"].should be_a_kind_of(Array)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should load an empty config for multiple missing file paths" do
|
60
|
+
files = ["#{fixture_path}/empty1.yml", "#{fixture_path}/empty2.yml"]
|
61
|
+
config = RailsConfig.load_files(files)
|
62
|
+
config.should be_empty
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should allow overrides" do
|
66
|
+
files = ["#{fixture_path}/settings.yml", "#{fixture_path}/development.yml"]
|
67
|
+
config = RailsConfig.load_files(files)
|
68
|
+
config.server.should eq "google.com"
|
69
|
+
config.size.should eq 2
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should allow full reload of the settings files" do
|
73
|
+
files = ["#{fixture_path}/settings.yml"]
|
74
|
+
RailsConfig.load_and_set_settings(files)
|
75
|
+
Settings.server.should eq "google.com"
|
76
|
+
Settings.size.should eq 1
|
77
|
+
|
78
|
+
files = ["#{fixture_path}/settings.yml", "#{fixture_path}/development.yml"]
|
79
|
+
Settings.reload_from_files(files)
|
80
|
+
Settings.server.should eq "google.com"
|
81
|
+
Settings.size.should eq 2
|
82
|
+
end
|
83
|
+
|
84
|
+
context "ENV variables" do
|
85
|
+
let(:config) do
|
86
|
+
RailsConfig.load_files("#{fixture_path}/settings.yml")
|
87
|
+
end
|
88
|
+
|
89
|
+
before :all do
|
90
|
+
load_env("#{fixture_path}/env/settings.yml")
|
91
|
+
RailsConfig.use_env = true
|
92
|
+
end
|
93
|
+
|
94
|
+
after :all do
|
95
|
+
RailsConfig.use_env = false
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should load basic ENV variables" do
|
99
|
+
config.load_env!
|
100
|
+
config.test_var.should eq "123"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should load nested sections" do
|
104
|
+
config.load_env!
|
105
|
+
config.hash_test.one.should eq "1-1"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should override settings from files" do
|
109
|
+
RailsConfig.load_and_set_settings ["#{fixture_path}/settings.yml"]
|
110
|
+
|
111
|
+
Settings.server.should eq "google.com"
|
112
|
+
Settings.size.should eq "3"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should reload env" do
|
116
|
+
RailsConfig.load_and_set_settings ["#{fixture_path}/settings.yml"]
|
117
|
+
RailsConfig.reload!
|
118
|
+
|
119
|
+
Settings.server.should eq "google.com"
|
120
|
+
Settings.size.should eq "3"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "Nested Settings" do
|
125
|
+
let(:config) do
|
126
|
+
RailsConfig.load_files("#{fixture_path}/development.yml")
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should allow nested sections" do
|
130
|
+
config.section.size.should eq 3
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should allow configuration collections (arrays)" do
|
134
|
+
config.section.servers[0].name.should eq "yahoo.com"
|
135
|
+
config.section.servers[1].name.should eq "amazon.com"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "Settings with ERB tags" do
|
140
|
+
let(:config) do
|
141
|
+
RailsConfig.load_files("#{fixture_path}/with_erb.yml")
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should evaluate ERB tags" do
|
145
|
+
config.computed.should eq 6
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should evaluated nested ERB tags" do
|
149
|
+
config.section.computed1.should eq 1
|
150
|
+
config.section.computed2.should eq 2
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "Deep Merging" do
|
155
|
+
let(:config) do
|
156
|
+
files = ["#{fixture_path}/deep_merge/config1.yml", "#{fixture_path}/deep_merge/config2.yml"]
|
157
|
+
RailsConfig.load_files(files)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should merge hashes from multiple configs" do
|
161
|
+
config.inner.marshal_dump.keys.size.should eq 3
|
162
|
+
config.inner2.inner2_inner.marshal_dump.keys.size.should eq 3
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should NOT merge arrays from multiple configs" do
|
166
|
+
config.arraylist1.size.should eq 3
|
167
|
+
config.arraylist2.inner.size.should eq 3
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "Boolean Overrides" do
|
172
|
+
let(:config) do
|
173
|
+
files = ["#{fixture_path}/bool_override/config1.yml", "#{fixture_path}/bool_override/config2.yml"]
|
174
|
+
RailsConfig.load_files(files)
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should allow overriding of bool settings" do
|
178
|
+
config.override_bool.should eq false
|
179
|
+
config.override_bool_opposite.should eq true
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context "Custom Configuration" do
|
184
|
+
it "should have the default settings constant as 'Settings'" do
|
185
|
+
RailsConfig.const_name.should eq "Settings"
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should be able to assign a different settings constant" do
|
189
|
+
RailsConfig.setup{ |config| config.const_name = "Settings2" }
|
190
|
+
RailsConfig.const_name.should eq "Settings2"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context "Settings with a type value of 'hash'" do
|
195
|
+
let(:config) do
|
196
|
+
files = ["#{fixture_path}/custom_types/hash.yml"]
|
197
|
+
RailsConfig.load_files(files)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should turn that setting into a Real Hash" do
|
201
|
+
config.prices.should be_a(Hash)
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should map the hash values correctly" do
|
205
|
+
config.prices[1].should eq 2.99
|
206
|
+
config.prices[5].should eq 9.99
|
207
|
+
config.prices[15].should eq 19.99
|
208
|
+
config.prices[30].should eq 29.99
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context "Merging hash at runtime" do
|
213
|
+
let(:config) { RailsConfig.load_files("#{fixture_path}/settings.yml") }
|
214
|
+
let(:hash) { {:options => {:suboption => 'value'}, :server => 'amazon.com'} }
|
215
|
+
|
216
|
+
it 'should be chainable' do
|
217
|
+
config.merge!({}).should eq config
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should preserve existing keys' do
|
221
|
+
expect { config.merge!({}) }.to_not change{ config.keys }
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'should recursively merge keys' do
|
225
|
+
config.merge!(hash)
|
226
|
+
config.options.suboption.should eq 'value'
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should rewrite a merged value' do
|
230
|
+
expect { config.merge!(hash) }.to change{ config.server }.from('google.com').to('amazon.com')
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context "Merging nested hash at runtime" do
|
235
|
+
let(:config) { RailsConfig.load_files("#{fixture_path}/deep_merge/config1.yml") }
|
236
|
+
let(:hash) { {:inner => {:something1 => 'changed1', :something3 => 'changed3'} } }
|
237
|
+
|
238
|
+
it 'should preserve first level keys' do
|
239
|
+
expect { config.merge!(hash) }.to_not change{ config.keys }
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should preserve nested key' do
|
243
|
+
config.merge!(hash)
|
244
|
+
config.inner.something2.should eq 'blah2'
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'should add new nested key' do
|
248
|
+
expect { config.merge!(hash) }.to change { config.inner.something3 }.from(nil).to("changed3")
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'should rewrite a merged value' do
|
252
|
+
expect { config.merge!(hash) }.to change{ config.inner.something1 }.from('blah1').to('changed1')
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
context "[] accessors" do
|
257
|
+
let(:config) do
|
258
|
+
files = ["#{fixture_path}/development.yml"]
|
259
|
+
RailsConfig.load_files(files)
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should access attributes using []" do
|
263
|
+
config.section['size'].should eq 3
|
264
|
+
config.section[:size].should eq 3
|
265
|
+
config[:section][:size].should eq 3
|
266
|
+
end
|
267
|
+
|
268
|
+
it "should set values using []=" do
|
269
|
+
config.section[:foo] = 'bar'
|
270
|
+
config.section.foo.should eq 'bar'
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
context "enumerable" do
|
275
|
+
let(:config) do
|
276
|
+
files = ["#{fixture_path}/development.yml"]
|
277
|
+
RailsConfig.load_files(files)
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should enumerate top level parameters" do
|
281
|
+
keys = []
|
282
|
+
config.each { |key, value| keys << key }
|
283
|
+
keys.should eq [:size, :section]
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should enumerate inner parameters" do
|
287
|
+
keys = []
|
288
|
+
config.section.each { |key, value| keys << key }
|
289
|
+
keys.should eq [:size, :servers]
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should have methods defined by Enumerable" do
|
293
|
+
config.map { |key, value| key }.should eq [:size, :section]
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context "keys" do
|
298
|
+
let(:config) do
|
299
|
+
files = ["#{fixture_path}/development.yml"]
|
300
|
+
RailsConfig.load_files(files)
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should return array of keys" do
|
304
|
+
config.keys.should include(:size, :section)
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should return array of keys for nested entry" do
|
308
|
+
config.section.keys.should include(:size, :servers)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|