diff options
author | Rémy Coutable <remy@rymai.me> | 2017-06-21 17:59:13 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-07-06 12:18:25 +0300 |
commit | 186048a404b2f5b84f4472a7d05cbb2309b1e9bf (patch) | |
tree | 8e850caf2a8315b799ee36cfd6be34f230d85b4d /spec/lib/gitlab/performance_bar_spec.rb | |
parent | afd5c34d9f1bf5ad7d85209dfecbaf28c6c12496 (diff) |
Allow to enable the performance bar per user or Flipper group
A `performance_team` Flipper group has been created. By default this
group is nil but this can be customized in `gitlab.yml` via the
performance_bar.allowed_group setting.
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/lib/gitlab/performance_bar_spec.rb')
-rw-r--r-- | spec/lib/gitlab/performance_bar_spec.rb | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/spec/lib/gitlab/performance_bar_spec.rb b/spec/lib/gitlab/performance_bar_spec.rb new file mode 100644 index 00000000000..0f630c243ad --- /dev/null +++ b/spec/lib/gitlab/performance_bar_spec.rb @@ -0,0 +1,91 @@ +require 'spec_helper' + +describe Gitlab::PerformanceBar do + describe '.enabled?' do + it 'returns false when given user is nil' do + expect(described_class.enabled?(nil)).to be_falsy + end + + it 'returns false when feature is disabled' do + user = double('user') + + expect(Feature).to receive(:enabled?) + .with(:gitlab_performance_bar, user).and_return(false) + + expect(described_class.enabled?(user)).to be_falsy + end + + it 'returns true when feature is enabled' do + user = double('user') + + expect(Feature).to receive(:enabled?) + .with(:gitlab_performance_bar, user).and_return(true) + + expect(described_class.enabled?(user)).to be_truthy + end + end + + describe '.allowed_actor?' do + it 'returns false when given actor is not a User' do + actor = double + + expect(described_class.allowed_actor?(actor)).to be_falsy + end + + context 'when given actor is a User' do + let(:actor) { create(:user) } + + before do + stub_performance_bar_setting(allowed_group: 'my-group') + end + + context 'when allowed group does not exist' do + it 'returns false' do + expect(described_class.allowed_actor?(actor)).to be_falsy + end + end + + context 'when allowed group exists' do + let!(:my_group) { create(:group, path: 'my-group') } + + context 'when user is not a member of the allowed group' do + it 'returns false' do + expect(described_class.allowed_actor?(actor)).to be_falsy + end + end + + context 'when user is a member of the allowed group' do + before do + my_group.add_developer(actor) + end + + it 'returns true' do + expect(described_class.allowed_actor?(actor)).to be_truthy + end + end + end + end + end + + describe '.allowed_group' do + before do + stub_performance_bar_setting(allowed_group: 'my-group') + end + + context 'when allowed group does not exist' do + it 'returns false' do + expect(described_class.allowed_group).to be_falsy + end + end + + context 'when allowed group exists' do + let!(:my_group) { create(:group, path: 'my-group') } + + context 'when user is not a member of the allowed group' do + it 'returns false' do + expect(described_class.allowed_group).to eq(my_group) + end + end + end + end +end |