diff --git a/lib/site_settings/defaults_provider.rb b/lib/site_settings/defaults_provider.rb index 6340ff91b9f..9ebae9aa512 100644 --- a/lib/site_settings/defaults_provider.rb +++ b/lib/site_settings/defaults_provider.rb @@ -38,8 +38,10 @@ class SiteSettings::DefaultsProvider end def get(name, locale = DEFAULT_LOCALE) - @defaults.dig(locale.to_sym, name.to_sym) || - @defaults.dig(DEFAULT_LOCALE.to_sym, name.to_sym) + value = @defaults.dig(locale.to_sym, name.to_sym) + return value unless value.nil? + + @defaults.dig(DEFAULT_LOCALE.to_sym, name.to_sym) end alias [] get diff --git a/spec/components/site_settings/defaults_provider_spec.rb b/spec/components/site_settings/defaults_provider_spec.rb index e4ca9a91091..948f66e0c0c 100644 --- a/spec/components/site_settings/defaults_provider_spec.rb +++ b/spec/components/site_settings/defaults_provider_spec.rb @@ -37,14 +37,15 @@ describe SiteSettings::DefaultsProvider do describe 'expose default cache according to locale' do before do settings.setting(:test_override, 'default', locale_default: { zh_CN: 'cn' }) + settings.setting(:test_boolean_override, true, locale_default: { zh_CN: false }) settings.setting(:test_default, 'test', regex: '^\S+$') settings.refresh! end describe '.all' do it 'returns all values according to locale' do - expect(settings.defaults.all).to eq(test_override: 'default', test_default: 'test') - expect(settings.defaults.all('zh_CN')).to eq(test_override: 'cn', test_default: 'test') + expect(settings.defaults.all).to eq(test_override: 'default', test_default: 'test', test_boolean_override: true) + expect(settings.defaults.all('zh_CN')).to eq(test_override: 'cn', test_default: 'test', test_boolean_override: false) end end @@ -57,6 +58,15 @@ describe SiteSettings::DefaultsProvider do expect(settings.defaults.get('test_override')).to eq 'default' end + it 'returns the locale_default value if it exists' do + expect(settings.defaults.get(:test_override, :zh_CN)).to eq 'cn' + expect(settings.defaults.get(:test_override, :de)).to eq 'default' + expect(settings.defaults.get(:test_default, :zh_CN)).to eq 'test' + end + + it 'returns the correct locale_default for boolean site settings' do + expect(settings.defaults.get(:test_boolean_override, :zh_CN)).to eq false + end end describe '.set_regardless_of_locale' do