summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/current_settings_spec.rb
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2017-07-10 13:29:16 +0100
committerNick Thomas <nick@gitlab.com>2017-07-10 15:40:51 +0100
commitaeb2869f666a73a039b5ac05bc5973547456ee33 (patch)
treed68a0bc1bcc0188e7847c4f9953da6ab9e534e10 /spec/lib/gitlab/current_settings_spec.rb
parentcd735170d3bc5e71d46ba1e37249ae713b7842f8 (diff)
downloadgitlab-ce-aeb2869f666a73a039b5ac05bc5973547456ee33.tar.gz
Prevent bad data being added to application settings when Redis is unavailable
Diffstat (limited to 'spec/lib/gitlab/current_settings_spec.rb')
-rw-r--r--spec/lib/gitlab/current_settings_spec.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/spec/lib/gitlab/current_settings_spec.rb b/spec/lib/gitlab/current_settings_spec.rb
index a566f24f6a6..d57ffcae8e1 100644
--- a/spec/lib/gitlab/current_settings_spec.rb
+++ b/spec/lib/gitlab/current_settings_spec.rb
@@ -27,10 +27,23 @@ describe Gitlab::CurrentSettings do
end
it 'falls back to DB if Redis fails' do
+ db_settings = ApplicationSetting.create!(ApplicationSetting.defaults)
+
expect(ApplicationSetting).to receive(:cached).and_raise(::Redis::BaseError)
- expect(ApplicationSetting).to receive(:last).and_call_original
+ expect(Rails.cache).to receive(:fetch).with(ApplicationSetting::CACHE_KEY).and_raise(Redis::BaseError)
- expect(current_application_settings).to be_a(ApplicationSetting)
+ expect(current_application_settings).to eq(db_settings)
+ end
+
+ it 'creates default ApplicationSettings if none are present' do
+ expect(ApplicationSetting).to receive(:cached).and_raise(::Redis::BaseError)
+ expect(Rails.cache).to receive(:fetch).with(ApplicationSetting::CACHE_KEY).and_raise(Redis::BaseError)
+
+ settings = current_application_settings
+
+ expect(settings).to be_a(ApplicationSetting)
+ expect(settings).to be_persisted
+ expect(settings).to have_attributes(ApplicationSetting.defaults)
end
context 'with migrations pending' do