debian-mirror-gitlab/spec/lib/gitlab/performance_bar_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

109 lines
3 KiB
Ruby
Raw Permalink Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::PerformanceBar do
2020-05-24 23:13:21 +05:30
it { expect(described_class.l1_cache_backend).to eq(Gitlab::ProcessMemoryCache.cache_backend) }
2019-09-30 21:07:59 +05:30
it { expect(described_class.l2_cache_backend).to eq(Rails.cache) }
2021-06-08 01:23:25 +05:30
describe '.allowed_for_user?' do
2017-09-10 17:25:29 +05:30
let(:user) { create(:user) }
before do
stub_application_setting(performance_bar_allowed_group_id: -1)
end
it 'returns false when given user is nil' do
2021-06-08 01:23:25 +05:30
expect(described_class.allowed_for_user?(nil)).to be_falsy
2017-09-10 17:25:29 +05:30
end
2018-05-09 12:01:36 +05:30
it 'returns true when given user is an admin' do
user = build_stubbed(:user, :admin)
2021-06-08 01:23:25 +05:30
expect(described_class.allowed_for_user?(user)).to be_truthy
2018-05-09 12:01:36 +05:30
end
2017-09-10 17:25:29 +05:30
it 'returns false when allowed_group_id is nil' do
expect(described_class).to receive(:allowed_group_id).and_return(nil)
2021-06-08 01:23:25 +05:30
expect(described_class.allowed_for_user?(user)).to be_falsy
2017-09-10 17:25:29 +05:30
end
context 'when allowed group ID does not exist' do
it 'returns false' do
2021-06-08 01:23:25 +05:30
expect(described_class.allowed_for_user?(user)).to be_falsy
2017-09-10 17:25:29 +05:30
end
end
context 'when allowed group exists' do
let!(:my_group) { create(:group, path: 'my-group') }
before do
stub_application_setting(performance_bar_allowed_group_id: my_group.id)
end
context 'when user is not a member of the allowed group' do
it 'returns false' do
2021-06-08 01:23:25 +05:30
expect(described_class.allowed_for_user?(user)).to be_falsy
2017-09-10 17:25:29 +05:30
end
2020-05-24 23:13:21 +05:30
context 'caching of allowed user IDs' do
2021-06-08 01:23:25 +05:30
subject { described_class.allowed_for_user?(user) }
2020-05-24 23:13:21 +05:30
before do
# Warm the caches
2021-06-08 01:23:25 +05:30
described_class.allowed_for_user?(user)
2020-05-24 23:13:21 +05:30
end
it_behaves_like 'allowed user IDs are cached'
end
2017-09-10 17:25:29 +05:30
end
context 'when user is a member of the allowed group' do
before do
my_group.add_developer(user)
end
it 'returns true' do
2021-06-08 01:23:25 +05:30
expect(described_class.allowed_for_user?(user)).to be_truthy
2017-09-10 17:25:29 +05:30
end
2020-05-24 23:13:21 +05:30
context 'caching of allowed user IDs' do
2021-06-08 01:23:25 +05:30
subject { described_class.allowed_for_user?(user) }
2020-05-24 23:13:21 +05:30
before do
# Warm the caches
2021-06-08 01:23:25 +05:30
described_class.allowed_for_user?(user)
2020-05-24 23:13:21 +05:30
end
it_behaves_like 'allowed user IDs are cached'
end
2017-09-10 17:25:29 +05:30
end
end
2019-10-12 21:52:04 +05:30
context 'when allowed group is nested' do
2017-09-10 17:25:29 +05:30
let!(:nested_my_group) { create(:group, parent: create(:group, path: 'my-org'), path: 'my-group') }
before do
create(:group, path: 'my-group')
nested_my_group.add_developer(user)
stub_application_setting(performance_bar_allowed_group_id: nested_my_group.id)
end
it 'returns the nested group' do
2021-06-08 01:23:25 +05:30
expect(described_class.allowed_for_user?(user)).to be_truthy
2017-09-10 17:25:29 +05:30
end
end
2019-10-12 21:52:04 +05:30
context 'when a nested group has the same path' do
2017-09-10 17:25:29 +05:30
before do
create(:group, :nested, path: 'my-group').add_developer(user)
end
it 'returns false' do
2021-06-08 01:23:25 +05:30
expect(described_class.allowed_for_user?(user)).to be_falsy
2017-09-10 17:25:29 +05:30
end
end
end
end