2016-08-24 12:49:21 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::CurrentSettings do
|
2017-08-17 22:00:37 +05:30
|
|
|
include StubENV
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#current_application_settings' do
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'with DB available' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:connect_to_db?).and_return(true)
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'attempts to use cached values first' do
|
|
|
|
expect(ApplicationSetting).to receive(:current)
|
|
|
|
expect(ApplicationSetting).not_to receive(:last)
|
|
|
|
|
|
|
|
expect(current_application_settings).to be_a(ApplicationSetting)
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'falls back to DB if Redis returns an empty value' do
|
|
|
|
expect(ApplicationSetting).to receive(:last).and_call_original
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(current_application_settings).to be_a(ApplicationSetting)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'falls back to DB if Redis fails' do
|
|
|
|
expect(ApplicationSetting).to receive(:current).and_raise(::Redis::BaseError)
|
|
|
|
expect(ApplicationSetting).to receive(:last).and_call_original
|
|
|
|
|
|
|
|
expect(current_application_settings).to be_a(ApplicationSetting)
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'with DB unavailable' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:connect_to_db?).and_return(false)
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'returns an in-memory ApplicationSetting object' do
|
|
|
|
expect(ApplicationSetting).not_to receive(:current)
|
|
|
|
expect(ApplicationSetting).not_to receive(:last)
|
|
|
|
|
|
|
|
expect(current_application_settings).to be_a(OpenStruct)
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when ENV["IN_MEMORY_APPLICATION_SETTINGS"] is true' do
|
|
|
|
before do
|
|
|
|
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'true')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an in-memory ApplicationSetting object' do
|
|
|
|
expect(ApplicationSetting).not_to receive(:current)
|
|
|
|
expect(ApplicationSetting).not_to receive(:last)
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(current_application_settings).to be_a(ApplicationSetting)
|
|
|
|
expect(current_application_settings).not_to be_persisted
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|