diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-20 03:09:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-20 03:09:13 +0300 |
commit | c0bc64e25edb4d7c3ac1d89de720f94782be5d2e (patch) | |
tree | 7cce86fcd83c9ba6fe7c3eb418f19a982d6eff3d /spec/lib | |
parent | 1cd61065a0d86b492be5086906429ac5956e3672 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/current_settings_spec.rb | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/spec/lib/gitlab/current_settings_spec.rb b/spec/lib/gitlab/current_settings_spec.rb index 7fc50438c95..17b2218e05c 100644 --- a/spec/lib/gitlab/current_settings_spec.rb +++ b/spec/lib/gitlab/current_settings_spec.rb @@ -88,6 +88,8 @@ RSpec.describe Gitlab::CurrentSettings, feature_category: :shared do end describe '#current_application_settings', :use_clean_rails_memory_store_caching do + let_it_be(:organization_settings) { create(:organization_setting, restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL]) } + it 'allows keys to be called directly' do described_class.update!(home_page_url: 'http://mydomain.com', signup_enabled: false) @@ -97,10 +99,58 @@ RSpec.describe Gitlab::CurrentSettings, feature_category: :shared do expect(described_class.metrics_sample_interval).to be(15) end - it 'retrieves settings using ApplicationSettingFetcher' do - expect(Gitlab::ApplicationSettingFetcher).to receive(:current_application_settings).and_call_original + context 'when key is in ApplicationSettingFetcher' do + it 'retrieves settings using ApplicationSettingFetcher' do + expect(Gitlab::ApplicationSettingFetcher).to receive(:current_application_settings).and_call_original + + described_class.home_page_url + end + end + + context 'when key is in OrganizationSetting' do + before do + allow(Gitlab::ApplicationSettingFetcher).to receive(:current_application_settings).and_return(nil) + end + + context 'and the current organization is known' do + before do + allow(Organizations::OrganizationSetting).to receive(:for_current_organization).and_return(organization_settings) + end + + it 'retrieves settings using OrganizationSetting' do + expect(described_class.restricted_visibility_levels).to eq(organization_settings.restricted_visibility_levels) + end + end + + context 'and the current organization is unknown' do + before do + allow(Organizations::OrganizationSetting).to receive(:for_current_organization).and_return(nil) + end + + it 'raises NoMethodError' do + expect { described_class.foo }.to raise_error(NoMethodError) + end + end + end + + context 'when key is in both sources' do + it 'for test purposes, ensure the values are different' do + expect( + Gitlab::ApplicationSettingFetcher.current_application_settings.restricted_visibility_levels + ).not_to eq(organization_settings.restricted_visibility_levels) + end - described_class.home_page_url + it 'prefers ApplicationSettingFetcher' do + expect(described_class.restricted_visibility_levels).to eq( + Gitlab::ApplicationSettingFetcher.current_application_settings.restricted_visibility_levels + ) + end + end + + context 'when key is in neither' do + it 'raises NoMethodError' do + expect { described_class.foo }.to raise_error(NoMethodError) + end end end |