diff --git a/lib/foodsoft_config.rb b/lib/foodsoft_config.rb index 1975f2c7..16d69804 100644 --- a/lib/foodsoft_config.rb +++ b/lib/foodsoft_config.rb @@ -249,7 +249,9 @@ class FoodsoftConfig # Normalize value recursively (which can be entered as strings, but we want to store it properly) def normalize_value(value) value = value.map(&:normalize_value) if value.is_a? Array - value = Hash[ value.to_a.map{|a| [a[0], normalize_value(a[1])]} ] if value.is_a? Hash + if value.is_a? Hash + value = ActiveSupport::HashWithIndifferentAccess[ value.to_a.map{|a| [a[0], normalize_value(a[1])]} ] + end case value when 'true' then true when 'false' then false diff --git a/spec/integration/config_spec.rb b/spec/integration/config_spec.rb index ee7b2956..9218ee9e 100644 --- a/spec/integration/config_spec.rb +++ b/spec/integration/config_spec.rb @@ -2,6 +2,7 @@ require_relative '../spec_helper' describe 'admin/configs', type: :feature do let(:name) { Faker::Lorem.words(rand(2..4)).join(' ') } + let(:email) { Faker::Internet.email } describe type: :feature, js: true do let(:admin) { create :admin } @@ -35,6 +36,16 @@ describe 'admin/configs', type: :feature do expect(get_full_config).to eq orig_values end + it 'can modify a nested value' do + visit admin_config_path + fill_in 'config_contact_email', with: email + within('form.config') do + find('input[type="submit"]').click + expect(find_field('config_contact_email').value).to eq email + end + expect(FoodsoftConfig[:contact][:email]).to eq email + end + def get_full_config cfg = FoodsoftConfig.to_hash.deep_dup cfg.each {|k,v| v.reject! {|k,v| v.blank?} if v.is_a? Hash}