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

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

191 lines
6.4 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-02-05 20:25:01 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Projects::ImportsController do
2016-02-05 20:25:01 +05:30
let(:user) { create(:user) }
2018-11-08 19:23:39 +05:30
let(:project) { create(:project) }
before do
2021-01-29 00:20:46 +05:30
sign_in(user) if user
2018-11-08 19:23:39 +05:30
end
2016-02-05 20:25:01 +05:30
describe 'GET #show' do
2021-01-29 00:20:46 +05:30
context 'when user is not authenticated and the project is public' do
let(:user) { nil }
let(:project) { create(:project, :public) }
it 'returns 404 response' do
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }
expect(response).to have_gitlab_http_status(:not_found)
end
end
2020-07-28 23:09:34 +05:30
context 'when the user has maintainer rights' do
before do
project.add_maintainer(user)
2016-02-05 20:25:01 +05:30
end
2020-07-28 23:09:34 +05:30
context 'when repository does not exists' do
2016-02-05 20:25:01 +05:30
it 'renders template' do
2019-02-15 15:39:39 +05:30
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }
2016-02-05 20:25:01 +05:30
expect(response).to render_template :show
end
it 'sets flash.now if params is present' do
2020-07-28 23:09:34 +05:30
get :show, params: { namespace_id: project.namespace.to_param, project_id: project, continue: { to: '/', notice_now: 'Started' } }
2016-02-05 20:25:01 +05:30
2020-07-28 23:09:34 +05:30
expect(flash.now[:notice]).to eq 'Started'
2016-02-05 20:25:01 +05:30
end
end
2020-07-28 23:09:34 +05:30
context 'when repository exists' do
let(:project) { create(:project_empty_repo, import_url: 'https://github.com/vim/vim.git') }
let(:import_state) { project.import_state }
2016-02-05 20:25:01 +05:30
2020-07-28 23:09:34 +05:30
context 'when import is in progress' do
before do
2021-04-29 21:17:54 +05:30
import_state.update!(status: :started)
2020-07-28 23:09:34 +05:30
end
2016-02-05 20:25:01 +05:30
2020-07-28 23:09:34 +05:30
it 'renders template' do
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }
2016-02-05 20:25:01 +05:30
2020-07-28 23:09:34 +05:30
expect(response).to render_template :show
end
it 'sets flash.now if params is present' do
get :show, params: { namespace_id: project.namespace.to_param, project_id: project, continue: { to: '/', notice_now: 'In progress' } }
expect(flash.now[:notice]).to eq 'In progress'
end
2016-02-05 20:25:01 +05:30
end
2020-07-28 23:09:34 +05:30
context 'when import failed' do
before do
2021-04-29 21:17:54 +05:30
import_state.update!(status: :failed)
2020-07-28 23:09:34 +05:30
end
2016-02-05 20:25:01 +05:30
2020-07-28 23:09:34 +05:30
it 'redirects to new_namespace_project_import_path' do
2019-02-15 15:39:39 +05:30
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }
2016-02-05 20:25:01 +05:30
2020-07-28 23:09:34 +05:30
expect(response).to redirect_to new_project_import_path(project)
2016-02-05 20:25:01 +05:30
end
end
2020-07-28 23:09:34 +05:30
context 'when import finished' do
before do
2021-04-29 21:17:54 +05:30
import_state.update!(status: :finished)
2020-07-28 23:09:34 +05:30
end
2016-02-05 20:25:01 +05:30
2020-07-28 23:09:34 +05:30
context 'when project is a fork' do
it 'redirects to namespace_project_path' do
allow_any_instance_of(Project).to receive(:forked?).and_return(true)
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }
expect(flash[:notice]).to eq 'The project was successfully forked.'
expect(response).to redirect_to project_path(project)
end
2016-02-05 20:25:01 +05:30
end
2020-07-28 23:09:34 +05:30
context 'when project is external' do
it 'redirects to namespace_project_path' do
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }
expect(flash[:notice]).to eq 'The project was successfully imported.'
expect(response).to redirect_to project_path(project)
end
2016-02-05 20:25:01 +05:30
end
2020-07-28 23:09:34 +05:30
context 'when continue params is present' do
let(:params) do
{
to: project_path(project),
notice: 'Finished'
}
end
it 'redirects to internal params[:to]' do
get :show, params: { namespace_id: project.namespace.to_param, project_id: project, continue: params }
expect(flash[:notice]).to eq params[:notice]
expect(response).to redirect_to params[:to]
end
2016-02-05 20:25:01 +05:30
2020-07-28 23:09:34 +05:30
it 'does not redirect to external params[:to]' do
params[:to] = "//google.com"
get :show, params: { namespace_id: project.namespace.to_param, project_id: project, continue: params }
expect(response).not_to redirect_to params[:to]
end
2016-02-05 20:25:01 +05:30
end
2020-07-28 23:09:34 +05:30
end
2017-08-17 22:00:37 +05:30
2020-07-28 23:09:34 +05:30
context 'when import never happened' do
before do
2021-04-29 21:17:54 +05:30
import_state.update!(status: :none)
2020-07-28 23:09:34 +05:30
end
2017-08-17 22:00:37 +05:30
2020-07-28 23:09:34 +05:30
it 'redirects to namespace_project_path' do
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }
expect(response).to redirect_to project_path(project)
2017-08-17 22:00:37 +05:30
end
2016-02-05 20:25:01 +05:30
end
end
2020-07-28 23:09:34 +05:30
end
context 'when project is in group' do
let(:project) { create(:project_empty_repo, import_url: 'https://github.com/vim/vim.git', namespace: group) }
context 'when user has developer access to group and import is in progress' do
let(:import_state) { project.import_state }
2016-04-02 18:10:28 +05:30
before do
2020-07-28 23:09:34 +05:30
group.add_developer(user)
import_state.update!(status: :started)
2016-04-02 18:10:28 +05:30
end
2020-07-28 23:09:34 +05:30
context 'when group allows developers to create projects' do
let(:group) { create(:group, project_creation_level: Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS) }
2016-04-02 18:10:28 +05:30
2020-07-28 23:09:34 +05:30
it 'renders template' do
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }
expect(response).to render_template :show
end
end
context 'when group prohibits developers to create projects' do
let(:group) { create(:group, project_creation_level: Gitlab::Access::MAINTAINER_PROJECT_ACCESS) }
it 'returns 404 response' do
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }
expect(response).to have_gitlab_http_status(:not_found)
end
2016-04-02 18:10:28 +05:30
end
end
2016-02-05 20:25:01 +05:30
end
end
2019-07-31 22:56:46 +05:30
describe 'POST #create' do
let(:params) { { import_url: 'https://github.com/vim/vim.git', import_url_user: 'user', import_url_password: 'password' } }
let(:project) { create(:project) }
before do
2020-07-28 23:09:34 +05:30
project.add_maintainer(user)
2019-07-31 22:56:46 +05:30
allow(RepositoryImportWorker).to receive(:perform_async)
post :create, params: { project: params, namespace_id: project.namespace.to_param, project_id: project }
end
it 'sets import_url to the project' do
expect(project.reload.import_url).to eq('https://user:password@github.com/vim/vim.git')
end
end
2016-02-05 20:25:01 +05:30
end