debian-mirror-gitlab/spec/policies/project_member_policy_spec.rb

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

70 lines
2.2 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProjectMemberPolicy do
let(:project) { create(:project) }
2023-01-13 00:05:48 +05:30
let(:maintainer) { create(:user) }
2020-07-28 23:09:34 +05:30
let(:member) { create(:project_member, project: project, user: member_user) }
2023-01-13 00:05:48 +05:30
let(:current_user) { maintainer }
2020-07-28 23:09:34 +05:30
2023-01-13 00:05:48 +05:30
subject { described_class.new(current_user, member) }
2020-07-28 23:09:34 +05:30
before do
2023-01-13 00:05:48 +05:30
create(:project_member, :maintainer, project: project, user: maintainer)
2020-07-28 23:09:34 +05:30
end
context 'with regular member' do
let(:member_user) { create(:user) }
2021-06-08 01:23:25 +05:30
it { is_expected.to be_allowed(:read_project) }
2020-07-28 23:09:34 +05:30
it { is_expected.to be_allowed(:update_project_member) }
it { is_expected.to be_allowed(:destroy_project_member) }
it { is_expected.not_to be_allowed(:destroy_project_bot_member) }
end
2022-06-21 17:19:12 +05:30
context 'when user is the holder of personal namespace in which the project resides' do
let(:namespace_holder) { project.namespace.owner }
let(:member) { project.members.find_by!(user: namespace_holder) }
2021-06-08 01:23:25 +05:30
it { is_expected.to be_allowed(:read_project) }
it { is_expected.to be_disallowed(:update_project_member) }
it { is_expected.to be_disallowed(:destroy_project_member) }
end
2020-07-28 23:09:34 +05:30
context 'with a bot member' do
let(:member_user) { create(:user, :project_bot) }
it { is_expected.to be_allowed(:destroy_project_bot_member) }
it { is_expected.not_to be_allowed(:update_project_member) }
it { is_expected.not_to be_allowed(:destroy_project_member) }
end
2023-01-13 00:05:48 +05:30
context 'for access requests' do
let_it_be(:project) { create(:project, :public) }
let_it_be(:user) { create(:user) }
let(:current_user) { user }
context 'for own access request' do
let(:member) { create(:project_member, :access_request, project: project, user: user) }
specify { expect_allowed(:withdraw_member_access_request) }
end
context "for another user's access request" do
let(:member) { create(:project_member, :access_request, project: project, user: create(:user)) }
specify { expect_disallowed(:withdraw_member_access_request) }
end
context 'for own, valid membership' do
let(:member) { create(:project_member, :developer, project: project, user: user) }
specify { expect_disallowed(:withdraw_member_access_request) }
end
end
2020-07-28 23:09:34 +05:30
end