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

124 lines
3.9 KiB
Ruby
Raw Normal View History

2016-02-05 20:25:01 +05:30
require 'spec_helper'
describe Projects::ImportsController do
let(:user) { create(:user) }
2018-11-08 19:23:39 +05:30
let(:project) { create(:project) }
before do
sign_in(user)
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2018-11-08 19:23:39 +05:30
end
2016-02-05 20:25:01 +05:30
describe 'GET #show' do
context 'when repository does not exists' do
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
2019-02-15 15:39:39 +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
expect(flash.now[:notice]).to eq 'Started'
end
end
context 'when repository exists' do
let(:project) { create(:project_empty_repo, import_url: 'https://github.com/vim/vim.git') }
2019-02-15 15:39:39 +05:30
let(:import_state) { project.import_state }
2016-02-05 20:25:01 +05:30
context 'when import is in progress' do
before do
2019-02-15 15:39:39 +05:30
import_state.update(status: :started)
2016-02-05 20:25:01 +05:30
end
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
2019-02-15 15:39:39 +05:30
get :show, params: { namespace_id: project.namespace.to_param, project_id: project, continue: { to: '/', notice_now: 'In progress' } }
2016-02-05 20:25:01 +05:30
expect(flash.now[:notice]).to eq 'In progress'
end
end
context 'when import failed' do
before do
2019-02-15 15:39:39 +05:30
import_state.update(status: :failed)
2016-02-05 20:25:01 +05:30
end
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
2017-09-10 17:25:29 +05:30
expect(response).to redirect_to new_project_import_path(project)
2016-02-05 20:25:01 +05:30
end
end
context 'when import finished' do
before do
2019-02-15 15:39:39 +05:30
import_state.update(status: :finished)
2016-02-05 20:25:01 +05:30
end
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)
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(flash[:notice]).to eq 'The project was successfully forked.'
2017-09-10 17:25:29 +05:30
expect(response).to redirect_to project_path(project)
2016-02-05 20:25:01 +05:30
end
end
context 'when project is external' do
it 'redirects to namespace_project_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
expect(flash[:notice]).to eq 'The project was successfully imported.'
2017-09-10 17:25:29 +05:30
expect(response).to redirect_to project_path(project)
2016-02-05 20:25:01 +05:30
end
end
context 'when continue params is present' do
let(:params) do
{
2017-09-10 17:25:29 +05:30
to: project_path(project),
2016-02-05 20:25:01 +05:30
notice: 'Finished'
}
end
2017-08-17 22:00:37 +05:30
it 'redirects to internal params[:to]' do
2019-02-15 15:39:39 +05:30
get :show, params: { namespace_id: project.namespace.to_param, project_id: project, continue: params }
2016-02-05 20:25:01 +05:30
expect(flash[:notice]).to eq params[:notice]
expect(response).to redirect_to params[:to]
end
2017-08-17 22:00:37 +05:30
it 'does not redirect to external params[:to]' do
params[:to] = "//google.com"
2019-02-15 15:39:39 +05:30
get :show, params: { namespace_id: project.namespace.to_param, project_id: project, continue: params }
2017-08-17 22:00:37 +05:30
expect(response).not_to redirect_to params[:to]
end
2016-02-05 20:25:01 +05:30
end
end
2016-04-02 18:10:28 +05:30
context 'when import never happened' do
before do
2019-02-15 15:39:39 +05:30
import_state.update(status: :none)
2016-04-02 18:10:28 +05:30
end
it 'redirects to namespace_project_path' do
2019-02-15 15:39:39 +05:30
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }
2016-04-02 18:10:28 +05:30
2017-09-10 17:25:29 +05:30
expect(response).to redirect_to project_path(project)
2016-04-02 18:10:28 +05:30
end
end
2016-02-05 20:25:01 +05:30
end
end
end