@@ -43,6 +43,49 @@ module Config::Sources
4343 results = source . load
4444 expect ( results [ 'action_mailer' ] [ 'enabled' ] ) . to eq ( 'true' )
4545 end
46+
47+ describe 'arrays' do
48+ before ( :each ) do
49+ Config . env_parse_arrays = true
50+ end
51+
52+ let ( :source ) do
53+ Config . env_converter = nil
54+ EnvSource . new ( {
55+ 'Settings.SomeConfig.0.0' => 'value1' ,
56+ 'Settings.SomeConfig.0.1' => 'value2' ,
57+ 'Settings.SomeConfig.1.1' => 'value3' ,
58+ 'Settings.SomeConfig.1.2' => 'value4' ,
59+ 'Settings.MixedConfig.1.0' => 'value5' ,
60+ 'Settings.MixedConfig.1.1' => 'value6' ,
61+ 'Settings.MixedConfig.1.custom' => 'value7'
62+ } )
63+ end
64+
65+ let ( :results ) { source . load }
66+
67+ context 'when loading nested configurations' do
68+ it 'converts numeric-keyed hashes to arrays' do
69+ expect ( results [ 'SomeConfig' ] ) . to be_an Array
70+ expect ( results [ 'SomeConfig' ] [ 0 ] ) . to be_an Array
71+ expect ( results [ 'SomeConfig' ] [ 0 ] [ 0 ] ) . to eq ( 'value1' )
72+ expect ( results [ 'SomeConfig' ] [ 0 ] [ 1 ] ) . to eq ( 'value2' )
73+ end
74+
75+ it 'retains hashes for non-sequential numeric keys' do
76+ expect ( results [ 'SomeConfig' ] [ 1 ] ) . to be_a Hash
77+ expect ( results [ 'SomeConfig' ] [ 1 ] [ '1' ] ) . to eq ( 'value3' )
78+ expect ( results [ 'SomeConfig' ] [ 1 ] [ '2' ] ) . to eq ( 'value4' )
79+ end
80+
81+ it 'retains hashes for mixed types' do
82+ expect ( results [ 'MixedConfig' ] [ '1' ] ) . to be_a Hash
83+ expect ( results [ 'MixedConfig' ] [ '1' ] [ '0' ] ) . to eq ( 'value5' )
84+ expect ( results [ 'MixedConfig' ] [ '1' ] [ '1' ] ) . to eq ( 'value6' )
85+ expect ( results [ 'MixedConfig' ] [ '1' ] [ 'custom' ] ) . to eq ( 'value7' )
86+ end
87+ end
88+ end
4689 end
4790
4891 context 'configuration overrides' do
0 commit comments