45 lines
1.6 KiB
Ruby
45 lines
1.6 KiB
Ruby
|
require 'rails_helper'
|
||
|
|
||
|
describe GlobalConfigService do
|
||
|
subject(:trigger) { described_class }
|
||
|
|
||
|
describe 'execute' do
|
||
|
context 'when called with default options' do
|
||
|
before do
|
||
|
# to clear redis cache
|
||
|
GlobalConfig.clear_cache
|
||
|
end
|
||
|
|
||
|
it 'set default value if not found on db nor env var' do
|
||
|
value = GlobalConfig.get('ENABLE_ACCOUNT_SIGNUP')
|
||
|
expect(value['ENABLE_ACCOUNT_SIGNUP']).to eq nil
|
||
|
|
||
|
described_class.load('ENABLE_ACCOUNT_SIGNUP', 'true')
|
||
|
|
||
|
value = GlobalConfig.get('ENABLE_ACCOUNT_SIGNUP')
|
||
|
expect(value['ENABLE_ACCOUNT_SIGNUP']).to eq 'true'
|
||
|
expect(InstallationConfig.find_by(name: 'ENABLE_ACCOUNT_SIGNUP')&.value).to eq 'true'
|
||
|
end
|
||
|
|
||
|
it 'get value from env variable if not found on DB' do
|
||
|
with_modified_env ENABLE_ACCOUNT_SIGNUP: 'false' do
|
||
|
expect(InstallationConfig.find_by(name: 'ENABLE_ACCOUNT_SIGNUP')&.value).to eq nil
|
||
|
described_class.load('ENABLE_ACCOUNT_SIGNUP', 'true')
|
||
|
value = GlobalConfig.get('ENABLE_ACCOUNT_SIGNUP')
|
||
|
expect(value['ENABLE_ACCOUNT_SIGNUP']).to eq 'false'
|
||
|
end
|
||
|
end
|
||
|
|
||
|
it 'get value from DB if found' do
|
||
|
# Set a value in db first and make sure this value
|
||
|
# is not respected even when load() method is called with
|
||
|
# another value.
|
||
|
InstallationConfig.where(name: 'ENABLE_ACCOUNT_SIGNUP').first_or_create(value: 'true')
|
||
|
described_class.load('ENABLE_ACCOUNT_SIGNUP', 'false')
|
||
|
value = GlobalConfig.get('ENABLE_ACCOUNT_SIGNUP')
|
||
|
expect(value['ENABLE_ACCOUNT_SIGNUP']).to eq 'true'
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|