summaryrefslogtreecommitdiff
path: root/spec/models/application_setting_spec.rb
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2016-11-03 14:12:20 +0000
committerNick Thomas <nick@gitlab.com>2016-11-04 04:01:08 +0000
commitc1388d0efb79b755c06b9db19fc4ad47af7cf0a3 (patch)
tree4f1bbfca15dc287d2b14a68f4e5167c18f5a1b10 /spec/models/application_setting_spec.rb
parent3a8a7c1251cef4098ffbc54718ba21736c5e2800 (diff)
downloadgitlab-ce-c1388d0efb79b755c06b9db19fc4ad47af7cf0a3.tar.gz
Allow multiple repository storage shards to be enabled, and automatically round-robin between them
Diffstat (limited to 'spec/models/application_setting_spec.rb')
-rw-r--r--spec/models/application_setting_spec.rb56
1 files changed, 52 insertions, 4 deletions
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index cc215d252f9..2b76e056f3c 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -41,14 +41,62 @@ describe ApplicationSetting, models: true do
subject { setting }
end
- context 'repository storages inclussion' do
+ # Upgraded databases will have this sort of content
+ context 'repository_storages is a String, not an Array' do
+ before { setting.__send__(:raw_write_attribute, :repository_storages, 'default') }
+
+ it { expect(setting.repository_storages_before_type_cast).to eq('default') }
+ it { expect(setting.repository_storages).to eq(['default']) }
+ end
+
+ context 'repository storages' do
before do
- storages = { 'custom' => 'tmp/tests/custom_repositories' }
+ storages = {
+ 'custom1' => 'tmp/tests/custom_repositories_1',
+ 'custom2' => 'tmp/tests/custom_repositories_2',
+ 'custom3' => 'tmp/tests/custom_repositories_3',
+
+ }
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end
- it { is_expected.to allow_value('custom').for(:repository_storage) }
- it { is_expected.not_to allow_value('alternative').for(:repository_storage) }
+ describe 'inclusion' do
+ it { is_expected.to allow_value('custom1').for(:repository_storages) }
+ it { is_expected.to allow_value(['custom2', 'custom3']).for(:repository_storages) }
+ it { is_expected.not_to allow_value('alternative').for(:repository_storages) }
+ it { is_expected.not_to allow_value(['alternative', 'custom1']).for(:repository_storages) }
+ end
+
+ describe 'presence' do
+ it { is_expected.not_to allow_value([]).for(:repository_storages) }
+ it { is_expected.not_to allow_value("").for(:repository_storages) }
+ it { is_expected.not_to allow_value(nil).for(:repository_storages) }
+ end
+
+ describe '.pick_repository_storage' do
+ it 'uses Array#sample to pick a random storage' do
+ array = double('array', sample: 'random')
+ expect(setting).to receive(:repository_storages).and_return(array)
+
+ expect(setting.pick_repository_storage).to eq('random')
+ end
+
+ describe '#repository_storage' do
+ it 'returns the first storage' do
+ setting.repository_storages = ['good', 'bad']
+
+ expect(setting.repository_storage).to eq('good')
+ end
+ end
+
+ describe '#repository_storage=' do
+ it 'overwrites repository_storages' do
+ setting.repository_storage = 'overwritten'
+
+ expect(setting.repository_storages).to eq(['overwritten'])
+ end
+ end
+ end
end
end