diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/models/member_spec.rb | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/models/member_spec.rb')
-rw-r--r-- | spec/models/member_spec.rb | 70 |
1 files changed, 67 insertions, 3 deletions
diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 52f47f0a211..39807747cc0 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -16,14 +16,14 @@ RSpec.describe Member do it { is_expected.to validate_presence_of(:user) } it { is_expected.to validate_presence_of(:source) } - it { is_expected.to validate_inclusion_of(:access_level).in_array(Gitlab::Access.all_values) } it_behaves_like 'an object with email-formated attributes', :invite_email do subject { build(:project_member) } end context "when an invite email is provided" do - let(:member) { build(:project_member, invite_email: "user@example.com", user: nil) } + let_it_be(:project) { create(:project) } + let(:member) { build(:project_member, source: project, invite_email: "user@example.com", user: nil) } it "doesn't require a user" do expect(member).to be_valid @@ -149,6 +149,7 @@ RSpec.describe Member do accepted_request_user = create(:user).tap { |u| project.request_access(u) } @accepted_request_member = project.requesters.find_by(user_id: accepted_request_user.id).tap { |m| m.accept_request } + @member_with_minimal_access = create(:group_member, :minimal_access, source: group) end describe '.access_for_user_ids' do @@ -179,6 +180,15 @@ RSpec.describe Member do it { expect(described_class.non_invite).to include @accepted_request_member } end + describe '.non_minimal_access' do + it { expect(described_class.non_minimal_access).to include @maintainer } + it { expect(described_class.non_minimal_access).to include @invited_member } + it { expect(described_class.non_minimal_access).to include @accepted_invite_member } + it { expect(described_class.non_minimal_access).to include @requested_member } + it { expect(described_class.non_minimal_access).to include @accepted_request_member } + it { expect(described_class.non_minimal_access).not_to include @member_with_minimal_access } + end + describe '.request' do it { expect(described_class.request).not_to include @maintainer } it { expect(described_class.request).not_to include @invited_member } @@ -256,6 +266,34 @@ RSpec.describe Member do it { is_expected.not_to include @blocked_maintainer } it { is_expected.not_to include @blocked_developer } end + + describe '.active' do + subject { described_class.active.to_a } + + it { is_expected.to include @owner } + it { is_expected.to include @maintainer } + it { is_expected.to include @invited_member } + it { is_expected.to include @accepted_invite_member } + it { is_expected.not_to include @requested_member } + it { is_expected.to include @accepted_request_member } + it { is_expected.not_to include @blocked_maintainer } + it { is_expected.not_to include @blocked_developer } + it { is_expected.not_to include @member_with_minimal_access } + end + + describe '.active_without_invites_and_requests' do + subject { described_class.active_without_invites_and_requests.to_a } + + it { is_expected.to include @owner } + it { is_expected.to include @maintainer } + it { is_expected.not_to include @invited_member } + it { is_expected.to include @accepted_invite_member } + it { is_expected.not_to include @requested_member } + it { is_expected.to include @accepted_request_member } + it { is_expected.not_to include @blocked_maintainer } + it { is_expected.not_to include @blocked_developer } + it { is_expected.not_to include @member_with_minimal_access } + end end describe "Delegate methods" do @@ -630,6 +668,32 @@ RSpec.describe Member do end end + describe '.find_by_invite_token' do + let!(:member) { create(:project_member, invite_email: "user@example.com", user: nil) } + + it 'finds the member' do + expect(described_class.find_by_invite_token(member.raw_invite_token)).to eq member + end + end + + describe "#invite_to_unknown_user?" do + subject { member.invite_to_unknown_user? } + + let(:member) { create(:project_member, invite_email: "user@example.com", invite_token: '1234', user: user) } + + context 'when user is nil' do + let(:user) { nil } + + it { is_expected.to eq(true) } + end + + context 'when user is set' do + let(:user) { build(:user) } + + it { is_expected.to eq(false) } + end + end + describe "destroying a record", :delete do it "refreshes user's authorized projects" do project = create(:project, :private) @@ -655,7 +719,7 @@ RSpec.describe Member do describe 'create member' do let!(:source) { create(source_type) } - subject { create(member_type, :guest, user: user, source_type => source) } + subject { create(member_type, :guest, user: user, source: source) } include_examples 'update highest role with exclusive lease' end |