diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/finders/user_groups_counter_spec.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/finders/user_groups_counter_spec.rb')
-rw-r--r-- | spec/finders/user_groups_counter_spec.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/finders/user_groups_counter_spec.rb b/spec/finders/user_groups_counter_spec.rb new file mode 100644 index 00000000000..49587e6dada --- /dev/null +++ b/spec/finders/user_groups_counter_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe UserGroupsCounter do + subject { described_class.new(user_ids).execute } + + describe '#execute' do + let_it_be(:user) { create(:user) } + let_it_be(:group1) { create(:group) } + let_it_be(:group_member1) { create(:group_member, source: group1, user_id: user.id, access_level: Gitlab::Access::OWNER) } + let_it_be(:user_ids) { [user.id] } + + it 'returns authorized group count for the user' do + expect(subject[user.id]).to eq(1) + end + + context 'when request to join group is pending' do + let_it_be(:pending_group) { create(:group) } + let_it_be(:pending_group_member) { create(:group_member, requested_at: Time.current.utc, source: pending_group, user_id: user.id) } + + it 'does not include pending group in the count' do + expect(subject[user.id]).to eq(1) + end + end + + context 'when user is part of sub group' do + let_it_be(:sub_group) { create(:group, parent: create(:group)) } + let_it_be(:sub_group_member1) { create(:group_member, source: sub_group, user_id: user.id, access_level: Gitlab::Access::DEVELOPER) } + + it 'includes sub group in the count' do + expect(subject[user.id]).to eq(2) + end + end + + context 'when user is part of namespaced project' do + let_it_be(:project) { create(:project, group: create(:group)) } + let_it_be(:project_member) { create(:project_member, source: project, user_id: user.id, access_level: Gitlab::Access::REPORTER) } + + it 'includes the project group' do + expect(subject[user.id]).to eq(2) + end + end + end +end |