diff options
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) } |