mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 20:22:45 +08:00
FIX: "false" didn't work as locale_default
This commit is contained in:
parent
e847bb33d5
commit
1a01385e88
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user