diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 16:05:49 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 16:05:49 +0000 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /spec/models/member_spec.rb | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) | |
download | gitlab-ce-0f94cf6ca9d272d8e0fda4a7a597866cf3dc1fc0.tar.gz |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc4216-0-stable
Diffstat (limited to 'spec/models/member_spec.rb')
-rw-r--r-- | spec/models/member_spec.rb | 117 |
1 files changed, 26 insertions, 91 deletions
diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 6a52f12553f..eea96e5e4ae 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -16,7 +16,6 @@ RSpec.describe Member, feature_category: :subgroups do describe 'Associations' do it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:member_namespace) } - it { is_expected.to belong_to(:member_role) } it { is_expected.to have_one(:member_task) } end @@ -173,96 +172,6 @@ RSpec.describe Member, feature_category: :subgroups do end end end - - context 'member role access level' do - let_it_be_with_reload(:member) { create(:group_member, access_level: Gitlab::Access::DEVELOPER) } - - context 'when no member role is associated' do - it 'is valid' do - expect(member).to be_valid - end - end - - context 'when member role is associated' do - let!(:member_role) do - create( - :member_role, - members: [member], - base_access_level: Gitlab::Access::DEVELOPER, - namespace: member.member_namespace - ) - end - - context 'when member role matches access level' do - it 'is valid' do - expect(member).to be_valid - end - end - - context 'when member role does not match access level' do - it 'is invalid' do - member_role.base_access_level = Gitlab::Access::MAINTAINER - - expect(member).not_to be_valid - end - end - - context 'when access_level is changed' do - it 'is invalid' do - member.access_level = Gitlab::Access::MAINTAINER - - expect(member).not_to be_valid - expect(member.errors[:access_level]).to include( - _("cannot be changed since member is associated with a custom role") - ) - end - end - end - end - - context 'member role namespace' do - let_it_be_with_reload(:member) { create(:group_member) } - - context 'when no member role is associated' do - it 'is valid' do - expect(member).to be_valid - end - end - - context 'when member role is associated' do - let_it_be(:member_role) do - create(:member_role, members: [member], namespace: member.group, base_access_level: member.access_level) - end - - context 'when member#member_namespace is a group within hierarchy of member_role#namespace' do - it 'is valid' do - member.member_namespace = create(:group, parent: member_role.namespace) - - expect(member).to be_valid - end - end - - context 'when member#member_namespace is a project within hierarchy of member_role#namespace' do - it 'is valid' do - project = create(:project, group: member_role.namespace) - member.member_namespace = Namespace.find(project.parent_id) - - expect(member).to be_valid - end - end - - context 'when member#member_namespace is outside hierarchy of member_role#namespace' do - it 'is invalid' do - member.member_namespace = create(:group) - - expect(member).not_to be_valid - expect(member.errors[:member_namespace]).to include( - _("must be in same hierarchy as custom role's namespace") - ) - end - end - end - end end describe 'Scopes & finders' do @@ -774,6 +683,24 @@ RSpec.describe Member, feature_category: :subgroups do end end + describe '.filter_by_user_type' do + let_it_be(:service_account) { create(:user, :service_account) } + let_it_be(:service_account_member) { create(:group_member, user: service_account) } + let_it_be(:other_member) { create(:group_member) } + + context 'when the user type is valid' do + it 'returns service accounts' do + expect(described_class.filter_by_user_type('service_account')).to match_array([service_account_member]) + end + end + + context 'when the user type is invalid' do + it 'returns nil' do + expect(described_class.filter_by_user_type('invalid_type')).to eq(nil) + end + end + end + describe '#accept_request' do let(:member) { create(:project_member, requested_at: Time.current.utc) } @@ -971,6 +898,14 @@ RSpec.describe Member, feature_category: :subgroups do end end + describe '.pluck_user_ids' do + let(:member) { create(:group_member) } + + it 'plucks the user ids' do + expect(described_class.where(id: member).pluck_user_ids).to match([member.user_id]) + end + end + describe '#send_invitation_reminder' do subject { member.send_invitation_reminder(0) } |