2016-01-25 18:00:23 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::ImportsController do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
describe 'GET #show' do
|
|
|
|
context 'when repository does not exists' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-01-25 18:00:23 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders template' do
|
2017-02-23 18:55:01 -05:00
|
|
|
get :show, namespace_id: project.namespace.to_param, project_id: project
|
2016-01-25 18:00:23 -05:00
|
|
|
|
|
|
|
expect(response).to render_template :show
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets flash.now if params is present' do
|
2017-02-23 18:55:01 -05:00
|
|
|
get :show, namespace_id: project.namespace.to_param, project_id: project, continue: { to: '/', notice_now: 'Started' }
|
2016-01-25 18:00:23 -05:00
|
|
|
|
|
|
|
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') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when import is in progress' do
|
|
|
|
before do
|
|
|
|
project.update_attribute(:import_status, :started)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders template' do
|
2017-02-23 18:55:01 -05:00
|
|
|
get :show, namespace_id: project.namespace.to_param, project_id: project
|
2016-01-25 18:00:23 -05:00
|
|
|
|
|
|
|
expect(response).to render_template :show
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets flash.now if params is present' do
|
2017-02-23 18:55:01 -05:00
|
|
|
get :show, namespace_id: project.namespace.to_param, project_id: project, continue: { to: '/', notice_now: 'In progress' }
|
2016-01-25 18:00:23 -05:00
|
|
|
|
|
|
|
expect(flash.now[:notice]).to eq 'In progress'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when import failed' do
|
|
|
|
before do
|
|
|
|
project.update_attribute(:import_status, :failed)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to new_namespace_project_import_path' do
|
2017-02-23 18:55:01 -05:00
|
|
|
get :show, namespace_id: project.namespace.to_param, project_id: project
|
2016-01-25 18:00:23 -05:00
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
expect(response).to redirect_to new_project_import_path(project)
|
2016-01-25 18:00:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when import finished' do
|
|
|
|
before do
|
|
|
|
project.update_attribute(:import_status, :finished)
|
|
|
|
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)
|
|
|
|
|
2017-02-23 18:55:01 -05:00
|
|
|
get :show, namespace_id: project.namespace.to_param, project_id: project
|
2016-01-25 18:00:23 -05:00
|
|
|
|
|
|
|
expect(flash[:notice]).to eq 'The project was successfully forked.'
|
2017-06-29 13:06:35 -04:00
|
|
|
expect(response).to redirect_to project_path(project)
|
2016-01-25 18:00:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project is external' do
|
|
|
|
it 'redirects to namespace_project_path' do
|
2017-02-23 18:55:01 -05:00
|
|
|
get :show, namespace_id: project.namespace.to_param, project_id: project
|
2016-01-25 18:00:23 -05:00
|
|
|
|
|
|
|
expect(flash[:notice]).to eq 'The project was successfully imported.'
|
2017-06-29 13:06:35 -04:00
|
|
|
expect(response).to redirect_to project_path(project)
|
2016-01-25 18:00:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when continue params is present' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
2017-06-29 13:06:35 -04:00
|
|
|
to: project_path(project),
|
2016-01-25 18:00:23 -05:00
|
|
|
notice: 'Finished'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2017-04-05 17:17:49 -04:00
|
|
|
it 'redirects to internal params[:to]' do
|
2017-02-23 18:55:01 -05:00
|
|
|
get :show, namespace_id: project.namespace.to_param, project_id: project, continue: params
|
2016-01-25 18:00:23 -05:00
|
|
|
|
|
|
|
expect(flash[:notice]).to eq params[:notice]
|
|
|
|
expect(response).to redirect_to params[:to]
|
|
|
|
end
|
2017-04-05 17:17:49 -04:00
|
|
|
|
|
|
|
it 'does not redirect to external params[:to]' do
|
|
|
|
params[:to] = "//google.com"
|
|
|
|
|
|
|
|
get :show, namespace_id: project.namespace.to_param, project_id: project, continue: params
|
|
|
|
expect(response).not_to redirect_to params[:to]
|
|
|
|
end
|
2016-01-25 18:00:23 -05:00
|
|
|
end
|
|
|
|
end
|
2016-02-17 09:05:44 -05:00
|
|
|
|
|
|
|
context 'when import never happened' do
|
|
|
|
before do
|
|
|
|
project.update_attribute(:import_status, :none)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to namespace_project_path' do
|
2017-02-23 18:55:01 -05:00
|
|
|
get :show, namespace_id: project.namespace.to_param, project_id: project
|
2016-02-17 09:05:44 -05:00
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
expect(response).to redirect_to project_path(project)
|
2016-02-17 09:05:44 -05:00
|
|
|
end
|
|
|
|
end
|
2016-01-25 18:00:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|