Skip to content

Commit d830ced

Browse files
author
Edwin Cruz
committed
Fixing bug with arrays, it was appending new values instead of replacing them
1 parent 5f15681 commit d830ced

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

lib/setting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Hash
55
def recursive_merge!(other)
66
other.keys.each do |k|
77
if self[k].is_a?(Array) && other[k].is_a?(Array)
8-
self[k] += other[k]
8+
self[k] = other[k]
99
elsif self[k].is_a?(Hash) && other[k].is_a?(Hash)
1010
self[k].recursive_merge!(other[k])
1111
else

mc-settings.gemspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
Gem::Specification.new do |s|
77
s.name = %q{mc-settings}
8-
s.version = "0.1.0"
8+
s.version = "0.1.2"
99

1010
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11-
s.authors = ["Edwin Cruz", "Colin Shield"]
12-
s.date = %q{2010-12-28}
11+
s.authors = ["Edwin Cruz", "Konstantin Gredeskoul"]
12+
s.date = %q{2011-01-18}
1313
s.description = %q{implement custom keys indenendently of environment}
1414
s.email = %q{rubydev@modcloth.com}
1515
s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
2727
"lib/mc-settings.rb",
2828
"lib/setting.rb",
2929
"mc-settings.gemspec",
30+
"spec/fixtures/joes-colors.yml",
3031
"spec/fixtures/sample.yml",
3132
"spec/mc_settings_spec.rb",
3233
"spec/spec_helper.rb",

spec/mc_settings_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
it "should create keys if it does not exist" do
5353
Setting.test_specific.should == "exist"
5454
end
55+
56+
context "working with arrays" do
57+
it "should replace the whole array instead of appending new values" do
58+
Setting.nested_array.should == ['first', 'four', 'five']
59+
end
60+
end
5561
end
5662

5763
context "When running with threads" do

spec/support/settings_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def stub_setting_files
2020
default: 7
2121
flag_false:
2222
default: false
23+
nested_array:
24+
- first
25+
- second
26+
- third
2327
CONTENT
2428
test = <<-CONTENT
2529
one: test
@@ -30,6 +34,10 @@ def stub_setting_files
3034
six:
3135
extra: "recursively overriden"
3236
test_specific: "exist"
37+
nested_array:
38+
- first
39+
- four
40+
- five
3341
CONTENT
3442

3543
empty = <<-CONTENT

0 commit comments

Comments
 (0)