diff options
Diffstat (limited to 'spec/models/application_setting_spec.rb')
-rw-r--r-- | spec/models/application_setting_spec.rb | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 166a4474abf..4b7281d593a 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -214,6 +214,151 @@ describe ApplicationSetting, models: true do end end + describe 'performance bar settings' do + before do + Flipper.unregister_groups + Flipper.register(:performance_team) + end + + after do + Flipper.unregister_groups + end + + describe 'performance_bar_allowed_group_id=' do + it 'does not persist an invalid group path' do + setting.performance_bar_allowed_group_id = 'foo' + + expect(setting.performance_bar_allowed_group_id).to be_nil + end + + context 'with a path to an existing group' do + let(:group) { create(:group) } + + it 'persists a valid group path and clears allowed user IDs cache' do + expect(Gitlab::PerformanceBar).to receive(:expire_allowed_user_ids_cache) + + setting.performance_bar_allowed_group_id = group.full_path + + expect(setting.performance_bar_allowed_group_id).to eq(group.id) + end + + context 'when the given path is the same' do + before do + setting.performance_bar_allowed_group_id = group.full_path + end + + it 'clears the cached allowed user IDs' do + expect(Gitlab::PerformanceBar).not_to receive(:expire_allowed_user_ids_cache) + + setting.performance_bar_allowed_group_id = group.full_path + end + end + end + end + + describe 'performance_bar_allowed_group' do + context 'with no performance_bar_allowed_group_id saved' do + it 'returns nil' do + expect(setting.performance_bar_allowed_group).to be_nil + end + end + + context 'with a performance_bar_allowed_group_id saved' do + let(:group) { create(:group) } + + before do + setting.performance_bar_allowed_group_id = group.full_path + end + + it 'returns the group' do + expect(setting.performance_bar_allowed_group).to eq(group) + end + end + end + + describe 'performance_bar_enabled?' do + context 'with the Performance Bar is enabled globally' do + before do + Feature.enable(:performance_bar) + end + + it 'returns true' do + expect(setting).to be_performance_bar_enabled + end + end + + context 'with the Performance Bar is enabled for the performance_team group' do + before do + Feature.enable_group(:performance_bar, :performance_team) + end + + it 'returns true' do + expect(setting).to be_performance_bar_enabled + end + end + + context 'with the Performance Bar is enabled for a specific user' do + before do + Feature.enable(:performance_team, create(:user)) + end + + it 'returns false' do + expect(setting).not_to be_performance_bar_enabled + end + end + end + + describe 'performance_bar_enabled=' do + context 'when the performance bar is enabled' do + before do + Feature.enable(:performance_bar) + end + + context 'when passing true' do + it 'does not clear allowed user IDs cache' do + expect(Gitlab::PerformanceBar).not_to receive(:expire_allowed_user_ids_cache) + setting.performance_bar_enabled = true + + expect(setting).to be_performance_bar_enabled + end + end + + context 'when passing false' do + it 'disables the performance bar and clears allowed user IDs cache' do + expect(Gitlab::PerformanceBar).to receive(:expire_allowed_user_ids_cache) + setting.performance_bar_enabled = false + + expect(setting).not_to be_performance_bar_enabled + end + end + end + + context 'when the performance bar is disabled' do + before do + Feature.disable(:performance_bar) + end + + context 'when passing true' do + it 'enables the performance bar and clears allowed user IDs cache' do + expect(Gitlab::PerformanceBar).to receive(:expire_allowed_user_ids_cache) + setting.performance_bar_enabled = true + + expect(setting).to be_performance_bar_enabled + end + end + + context 'when passing false' do + it 'does not clear allowed user IDs cache' do + expect(Gitlab::PerformanceBar).not_to receive(:expire_allowed_user_ids_cache) + setting.performance_bar_enabled = false + + expect(setting).not_to be_performance_bar_enabled + end + end + end + end + end + describe 'usage ping settings' do context 'when the usage ping is disabled in gitlab.yml' do before do |