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
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_master(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
|
2017-02-23 18:55:01 -05:00
|
|
|
post(:create, namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2016-04-18 04:56:10 -04:00
|
|
|
link_group_id: group.id,
|
|
|
|
link_group_access: ProjectGroupLink.default_access)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has access to group he 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
|
|
|
|
|
|
|
|
context 'when user doers not have access to group he want to link to' do
|
|
|
|
include_context 'link project to group'
|
|
|
|
|
|
|
|
it 'renders 404' do
|
|
|
|
expect(response.status).to eq 404
|
|
|
|
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
|
|
|
|
|
|
|
context 'when project group id equal link group id' do
|
|
|
|
before do
|
2017-02-23 18:55:01 -05:00
|
|
|
post(:create, namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2016-09-01 13:23:39 -04:00
|
|
|
link_group_id: group2.id,
|
|
|
|
link_group_access: ProjectGroupLink.default_access)
|
|
|
|
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
|
2017-02-23 18:55:01 -05:00
|
|
|
post(:create, namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2016-09-01 13:23:39 -04:00
|
|
|
link_group_access: ProjectGroupLink.default_access)
|
|
|
|
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
|
2016-04-18 04:56:10 -04:00
|
|
|
end
|
|
|
|
end
|