2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-18 04:56:10 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::GroupLinksController do
|
|
|
|
let(:group) { create(:group, :private) }
|
2016-09-01 13:23:39 -04:00
|
|
|
let(:group2) { create(:group, :private) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :private, group: group2) }
|
2016-04-18 04:56:10 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2016-04-18 04:56:10 -04:00
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#create' do
|
|
|
|
shared_context 'link project to group' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
post(:create, params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
link_group_id: group.id,
|
|
|
|
link_group_access: ProjectGroupLink.default_access
|
|
|
|
})
|
2016-04-18 04:56:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-22 09:15:31 -04:00
|
|
|
context 'when project is not allowed to be shared with a group' do
|
|
|
|
before do
|
2018-07-02 06:43:06 -04:00
|
|
|
group.update(share_with_group_lock: false)
|
2018-05-22 09:15:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
include_context 'link project to group'
|
|
|
|
|
|
|
|
it 'responds with status 404' do
|
2020-01-28 07:08:44 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2018-05-22 09:15:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-07 10:09:52 -05:00
|
|
|
context 'when user has access to group they want to link project to' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
group.add_developer(user)
|
|
|
|
end
|
|
|
|
|
2016-04-18 04:56:10 -04:00
|
|
|
include_context 'link project to group'
|
|
|
|
|
|
|
|
it 'links project with selected group' do
|
|
|
|
expect(group.shared_projects).to include project
|
|
|
|
end
|
|
|
|
|
2016-05-23 14:16:35 -04:00
|
|
|
it 'redirects to project group links page' do
|
2016-04-18 04:56:10 -04:00
|
|
|
expect(response).to redirect_to(
|
2017-07-07 10:40:41 -04:00
|
|
|
project_project_members_path(project)
|
2016-04-18 04:56:10 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-07 10:09:52 -05:00
|
|
|
context 'when user doers not have access to group they want to link to' do
|
2016-04-18 04:56:10 -04:00
|
|
|
include_context 'link project to group'
|
|
|
|
|
|
|
|
it 'renders 404' do
|
2020-03-31 17:08:05 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-04-18 04:56:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not share project with that group' do
|
2016-05-23 19:37:59 -04:00
|
|
|
expect(group.shared_projects).not_to include project
|
2016-04-18 04:56:10 -04:00
|
|
|
end
|
|
|
|
end
|
2016-09-01 13:23:39 -04:00
|
|
|
|
2019-02-12 07:29:47 -05:00
|
|
|
context 'when user does not have access to the public group' do
|
|
|
|
let(:group) { create(:group, :public) }
|
|
|
|
|
|
|
|
include_context 'link project to group'
|
|
|
|
|
|
|
|
it 'renders 404' do
|
2020-03-31 17:08:05 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-02-12 07:29:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not share project with that group' do
|
|
|
|
expect(group.shared_projects).not_to include project
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-01 13:23:39 -04:00
|
|
|
context 'when project group id equal link group id' do
|
|
|
|
before do
|
2019-02-12 07:29:47 -05:00
|
|
|
group2.add_developer(user)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
post(:create, params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
link_group_id: group2.id,
|
|
|
|
link_group_access: ProjectGroupLink.default_access
|
|
|
|
})
|
2016-09-01 13:23:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not share project with selected group' do
|
|
|
|
expect(group2.shared_projects).not_to include project
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to project group links page' do
|
|
|
|
expect(response).to redirect_to(
|
2017-07-07 10:40:41 -04:00
|
|
|
project_project_members_path(project)
|
2016-09-01 13:23:39 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when link group id is not present' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
post(:create, params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
link_group_access: ProjectGroupLink.default_access
|
|
|
|
})
|
2016-09-01 13:23:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to project group links page' do
|
|
|
|
expect(response).to redirect_to(
|
2017-07-07 10:40:41 -04:00
|
|
|
project_project_members_path(project)
|
2016-09-01 13:23:39 -04:00
|
|
|
)
|
|
|
|
expect(flash[:alert]).to eq('Please select a group.')
|
|
|
|
end
|
|
|
|
end
|
2019-02-12 07:29:47 -05:00
|
|
|
|
|
|
|
context 'when link is not persisted in the database' do
|
|
|
|
before do
|
|
|
|
allow(::Projects::GroupLinks::CreateService).to receive_message_chain(:new, :execute)
|
|
|
|
.and_return({ status: :error, http_status: 409, message: 'error' })
|
|
|
|
|
|
|
|
post(:create, params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
link_group_id: group.id,
|
|
|
|
link_group_access: ProjectGroupLink.default_access
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to project group links page' do
|
|
|
|
expect(response).to redirect_to(
|
|
|
|
project_project_members_path(project)
|
|
|
|
)
|
|
|
|
expect(flash[:alert]).to eq('error')
|
|
|
|
end
|
|
|
|
end
|
2016-04-18 04:56:10 -04:00
|
|
|
end
|
|
|
|
end
|