summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/current_settings_spec.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-06-25 23:29:28 -0700
committerStan Hu <stanhu@gmail.com>2016-06-29 14:04:59 -0700
commitc600cf83488398cf66b10af85ed9490fe9457bd4 (patch)
treee5d2328ece33a987235ab28ca7a51df463ffdcac /spec/lib/gitlab/current_settings_spec.rb
parent84113d7e725dcf6f9a3945853475f0cede957fec (diff)
downloadgitlab-ce-c600cf83488398cf66b10af85ed9490fe9457bd4.tar.gz
Fix database migrations when Redis is not running
If Redis were not running or USE_DB were set to false, the application settings retrieval would fail completely. This change only attempts to use the cache if the system actually wants to connect to the DB and rescues any failures in talking to Redis. Closes #17557
Diffstat (limited to 'spec/lib/gitlab/current_settings_spec.rb')
-rw-r--r--spec/lib/gitlab/current_settings_spec.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/lib/gitlab/current_settings_spec.rb b/spec/lib/gitlab/current_settings_spec.rb
new file mode 100644
index 00000000000..f2d2f7b5d31
--- /dev/null
+++ b/spec/lib/gitlab/current_settings_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+describe Gitlab::CurrentSettings do
+ describe '#current_application_settings' do
+ it 'attempts to use cached values first' do
+ allow_any_instance_of(Gitlab::CurrentSettings).to receive(:connect_to_db?).and_return(true)
+ expect(ApplicationSetting).to receive(:cached).and_call_original
+ expect(ApplicationSetting).not_to receive(:last)
+
+ expect(current_application_settings).to be_a(ApplicationSetting)
+ end
+
+ it 'does not attempt to connect to DB or Redis' do
+ allow_any_instance_of(Gitlab::CurrentSettings).to receive(:connect_to_db?).and_return(false)
+ expect(ApplicationSetting).not_to receive(:current)
+ expect(ApplicationSetting).not_to receive(:last)
+
+ expect(current_application_settings).to eq fake_application_settings
+ end
+
+ it 'falls back to DB if Redis fails' do
+ allow_any_instance_of(Gitlab::CurrentSettings).to receive(:connect_to_db?).and_return(true)
+ expect(ApplicationSetting).to receive(:cached).and_raise(::Redis::BaseError)
+ expect(ApplicationSetting).to receive(:last).and_call_original
+
+ expect(current_application_settings).to be_a(ApplicationSetting)
+ end
+ end
+end