debian-mirror-gitlab/spec/controllers/projects/group_links_controller_spec.rb

189 lines
5.2 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Projects::GroupLinksController do
2021-01-03 14:25:43 +05:30
let_it_be(:group) { create(:group, :private) }
let_it_be(:group2) { create(:group, :private) }
let_it_be(:project) { create(:project, :private, group: group2) }
let_it_be(:user) { create(:user) }
2016-06-02 11:05:42 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2016-06-02 11:05:42 +05:30
sign_in(user)
end
describe '#create' do
shared_context 'link project to group' do
before do
2019-02-15 15:39:39 +05:30
post(:create, params: {
namespace_id: project.namespace,
project_id: project,
link_group_id: group.id,
link_group_access: ProjectGroupLink.default_access
})
2016-06-02 11:05:42 +05:30
end
end
2018-11-08 19:23:39 +05:30
context 'when project is not allowed to be shared with a group' do
before do
2018-11-18 11:00:15 +05:30
group.update(share_with_group_lock: false)
2018-11-08 19:23:39 +05:30
end
include_context 'link project to group'
it 'responds with status 404' do
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2018-11-08 19:23:39 +05:30
end
end
2020-03-13 15:44:24 +05:30
context 'when user has access to group they want to link project to' do
2017-09-10 17:25:29 +05:30
before do
group.add_developer(user)
end
2016-06-02 11:05:42 +05:30
include_context 'link project to group'
it 'links project with selected group' do
expect(group.shared_projects).to include project
end
it 'redirects to project group links page' do
2016-06-02 11:05:42 +05:30
expect(response).to redirect_to(
2017-09-10 17:25:29 +05:30
project_project_members_path(project)
2016-06-02 11:05:42 +05:30
)
end
end
2020-03-13 15:44:24 +05:30
context 'when user doers not have access to group they want to link to' do
2016-06-02 11:05:42 +05:30
include_context 'link project to group'
it 'renders 404' do
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-06-02 11:05:42 +05:30
end
it 'does not share project with that group' do
expect(group.shared_projects).not_to include project
2016-06-02 11:05:42 +05:30
end
end
2016-11-03 12:29:30 +05:30
2019-03-13 22:55:13 +05:30
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-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2019-03-13 22:55:13 +05:30
end
it 'does not share project with that group' do
expect(group.shared_projects).not_to include project
end
end
2016-11-03 12:29:30 +05:30
context 'when project group id equal link group id' do
before do
2019-03-13 22:55:13 +05:30
group2.add_developer(user)
2019-02-15 15:39:39 +05:30
post(:create, params: {
namespace_id: project.namespace,
project_id: project,
link_group_id: group2.id,
link_group_access: ProjectGroupLink.default_access
})
2016-11-03 12:29:30 +05:30
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-09-10 17:25:29 +05:30
project_project_members_path(project)
2016-11-03 12:29:30 +05:30
)
end
end
context 'when link group id is not present' do
before do
2019-02-15 15:39:39 +05:30
post(:create, params: {
namespace_id: project.namespace,
project_id: project,
link_group_access: ProjectGroupLink.default_access
})
2016-11-03 12:29:30 +05:30
end
it 'redirects to project group links page' do
expect(response).to redirect_to(
2017-09-10 17:25:29 +05:30
project_project_members_path(project)
2016-11-03 12:29:30 +05:30
)
expect(flash[:alert]).to eq('Please select a group.')
end
end
2019-03-13 22:55:13 +05:30
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-06-02 11:05:42 +05:30
end
2021-01-03 14:25:43 +05:30
describe '#update' do
let_it_be(:link) do
create(
:project_group_link,
{
project: project,
group: group
}
)
end
let(:expiry_date) { 1.month.from_now.to_date }
before do
travel_to Time.now.utc.beginning_of_day
put(
:update,
params: {
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: link.id,
group_link: { group_access: Gitlab::Access::GUEST, expires_at: expiry_date }
},
format: :json
)
end
context 'when `expires_at` is set' do
it 'returns correct json response' do
expect(json_response).to eq({ "expires_in" => "about 1 month", "expires_soon" => false })
end
end
context 'when `expires_at` is not set' do
let(:expiry_date) { nil }
it 'returns empty json response' do
expect(json_response).to be_empty
end
end
end
2016-06-02 11:05:42 +05:30
end