fix config issue with nested hash

This commit is contained in:
wvengen 2014-09-02 16:19:08 +02:00
parent 7a9dd4edec
commit 1c878c3c13
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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}