File tree Expand file tree Collapse file tree 3 files changed +55
-3
lines changed Expand file tree Collapse file tree 3 files changed +55
-3
lines changed Original file line number Diff line number Diff line change @@ -138,9 +138,10 @@ def collapse_hashes(v, args)
138
138
else
139
139
v
140
140
end
141
-
142
- if out . is_a? ( Hash )
143
- collapse_hashes ( out , args )
141
+ if out . is_a? ( Hash ) && !args . empty?
142
+ collapse_hashes ( out , args )
143
+ elsif out . is_a? ( Hash ) && out . has_key? ( 'default' )
144
+ out [ 'default' ]
144
145
else
145
146
out
146
147
end
Original file line number Diff line number Diff line change
1
+ shipping_config :
2
+ default : Defaulted
3
+ domestic :
4
+ service : MyService
5
+ countries :
6
+ - " US"
7
+ non_shippable_regions :
8
+ - " US-AS"
9
+ - " US-GU"
10
+ - " US-MP"
11
+ - " US-PR"
12
+ - " US-UM"
13
+ - " US-VI"
14
+ - " US-AF"
15
+ - " US-AA"
16
+ - " US-AC"
17
+ - " US-AE"
18
+ - " US-AM"
19
+ - " US-AP"
20
+ - " US-FM"
21
+ - " US-PW"
22
+ - " US-MH"
23
+ international :
24
+ service : Foo
25
+ countries :
26
+ - " GU"
27
+ - " VI"
28
+ - " AS"
29
+ - " MP"
30
+ - " UM"
31
+ - " FR"
32
+ - " GR"
33
+ - " RU"
34
+ shipping_carrier : Bar
Original file line number Diff line number Diff line change 126
126
end
127
127
128
128
end
129
+ context "Complex nested configs" do
130
+ before :each do
131
+ Setting . reload (
132
+ :path => File . join ( File . dirname ( __FILE__ ) ) + '/fixtures' ,
133
+ :files => [ 'shipping.yml' ]
134
+ )
135
+ end
136
+ it "should build correct tree with arrays and default values " do
137
+ Setting . shipping_config . should == "Defaulted"
138
+ Setting . shipping_config ( :domestic , :non_shippable_regions ) . first . should == "US-AS"
139
+ Setting . shipping_config ( :international , :service ) . should == 'Foo'
140
+ Setting . shipping_config ( :international , :countries ) . size . should > 0
141
+ Setting . shipping_config ( :international , :shipping_carrier ) . should == 'Bar'
142
+ #backward compatibility:
143
+ Setting . shipping_config ( :domestic ) [ 'non_shippable_regions' ] . size . should > 0
144
+ end
145
+ end
129
146
end
You can’t perform that action at this time.
0 commit comments