diff options
Diffstat (limited to 'spec/controllers/projects/project_members_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects/project_members_controller_spec.rb | 133 |
1 files changed, 119 insertions, 14 deletions
diff --git a/spec/controllers/projects/project_members_controller_spec.rb b/spec/controllers/projects/project_members_controller_spec.rb index 74311fa89f3..971eb782fa4 100644 --- a/spec/controllers/projects/project_members_controller_spec.rb +++ b/spec/controllers/projects/project_members_controller_spec.rb @@ -14,32 +14,137 @@ RSpec.describe Projects::ProjectMembersController do expect(response).to have_gitlab_http_status(:ok) end - context 'when project belongs to group' do - let(:user_in_group) { create(:user) } - let(:project_in_group) { create(:project, :public, group: group) } + context 'project members' do + context 'when project belongs to group' do + let(:user_in_group) { create(:user) } + let(:project_in_group) { create(:project, :public, group: group) } + + before do + group.add_owner(user_in_group) + project_in_group.add_maintainer(user) + sign_in(user) + end + + it 'lists inherited project members by default' do + get :index, params: { namespace_id: project_in_group.namespace, project_id: project_in_group } + + expect(assigns(:project_members).map(&:user_id)).to contain_exactly(user.id, user_in_group.id) + end + + it 'lists direct project members only' do + get :index, params: { namespace_id: project_in_group.namespace, project_id: project_in_group, with_inherited_permissions: 'exclude' } + + expect(assigns(:project_members).map(&:user_id)).to contain_exactly(user.id) + end + + it 'lists inherited project members only' do + get :index, params: { namespace_id: project_in_group.namespace, project_id: project_in_group, with_inherited_permissions: 'only' } + + expect(assigns(:project_members).map(&:user_id)).to contain_exactly(user_in_group.id) + end + end + + context 'when invited members are present' do + let!(:invited_member) { create(:project_member, :invited, project: project) } + + before do + project.add_maintainer(user) + sign_in(user) + end + + it 'excludes the invited members from project members list' do + get :index, params: { namespace_id: project.namespace, project_id: project } + + expect(assigns(:project_members).map(&:invite_email)).not_to contain_exactly(invited_member.invite_email) + end + end + end + + context 'group links' do + let!(:project_group_link) { create(:project_group_link, project: project, group: group) } + + it 'lists group links' do + get :index, params: { namespace_id: project.namespace, project_id: project } + + expect(assigns(:group_links).map(&:id)).to contain_exactly(project_group_link.id) + end + + context 'when `search_groups` param is present' do + let(:group_2) { create(:group, :public, name: 'group_2') } + let!(:project_group_link_2) { create(:project_group_link, project: project, group: group_2) } + + it 'lists group links that match search' do + get :index, params: { namespace_id: project.namespace, project_id: project, search_groups: 'group_2' } + + expect(assigns(:group_links).map(&:id)).to contain_exactly(project_group_link_2.id) + end + end + end + + context 'invited members' do + let!(:invited_member) { create(:project_member, :invited, project: project) } before do - group.add_owner(user_in_group) - project_in_group.add_maintainer(user) + project.add_maintainer(user) sign_in(user) end - it 'lists inherited project members by default' do - get :index, params: { namespace_id: project_in_group.namespace, project_id: project_in_group } + context 'when user has `admin_project_member` permissions' do + before do + allow(controller.helpers).to receive(:can_manage_project_members?).with(project).and_return(true) + end + + it 'lists invited members' do + get :index, params: { namespace_id: project.namespace, project_id: project } + + expect(assigns(:invited_members).map(&:invite_email)).to contain_exactly(invited_member.invite_email) + end + end + + context 'when user does not have `admin_project_member` permissions' do + before do + allow(controller.helpers).to receive(:can_manage_project_members?).with(project).and_return(false) + end + + it 'does not list invited members' do + get :index, params: { namespace_id: project.namespace, project_id: project } + + expect(assigns(:invited_members)).to be_nil + end + end + end + + context 'access requests' do + let(:access_requester_user) { create(:user) } - expect(assigns(:project_members).map(&:user_id)).to contain_exactly(user.id, user_in_group.id) + before do + project.request_access(access_requester_user) + project.add_maintainer(user) + sign_in(user) end - it 'lists direct project members only' do - get :index, params: { namespace_id: project_in_group.namespace, project_id: project_in_group, with_inherited_permissions: 'exclude' } + context 'when user has `admin_project_member` permissions' do + before do + allow(controller.helpers).to receive(:can_manage_project_members?).with(project).and_return(true) + end + + it 'lists access requests' do + get :index, params: { namespace_id: project.namespace, project_id: project } - expect(assigns(:project_members).map(&:user_id)).to contain_exactly(user.id) + expect(assigns(:requesters).map(&:user_id)).to contain_exactly(access_requester_user.id) + end end - it 'lists inherited project members only' do - get :index, params: { namespace_id: project_in_group.namespace, project_id: project_in_group, with_inherited_permissions: 'only' } + context 'when user does not have `admin_project_member` permissions' do + before do + allow(controller.helpers).to receive(:can_manage_project_members?).with(project).and_return(false) + end + + it 'does not list access requests' do + get :index, params: { namespace_id: project.namespace, project_id: project } - expect(assigns(:project_members).map(&:user_id)).to contain_exactly(user_in_group.id) + expect(assigns(:requesters)).to be_nil + end end end end |