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 Admin::ProjectsController do
|
2017-09-10 17:25:29 +05:30
|
|
|
let!(:project) { create(:project, :public) }
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(create(:admin))
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
it 'retrieves the project for the given visibility level' do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :index, params: { visibility_level: [Gitlab::VisibilityLevel::PUBLIC] }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(response.body).to match(project.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not retrieve the project' do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :index, params: { visibility_level: [Gitlab::VisibilityLevel::INTERNAL] }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
expect(response.body).not_to match(project.name)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it 'retrieves archived and non archived corrupted projects when last_repository_check_failed is true' do
|
|
|
|
archived_corrupted_project = create(:project, :public, :archived, :last_repository_check_failed, name: 'CorruptedArchived', path: 'A')
|
|
|
|
corrupted_project = create(:project, :public, :last_repository_check_failed, name: 'CorruptedOnly', path: 'C')
|
|
|
|
|
|
|
|
get :index, params: { last_repository_check_failed: true }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response.body).not_to match(project.name)
|
|
|
|
expect(response.body).to match(archived_corrupted_project.name)
|
|
|
|
expect(response.body).to match(corrupted_project.name)
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'does not respond with projects pending deletion' do
|
|
|
|
pending_delete_project = create(:project, pending_delete: true)
|
|
|
|
|
|
|
|
get :index
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(response.body).not_to match(pending_delete_project.name)
|
|
|
|
expect(response.body).to match(project.name)
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
it 'does not have N+1 queries', :use_clean_rails_memory_store_caching, :request_store do
|
|
|
|
get :index
|
|
|
|
|
|
|
|
control_count = ActiveRecord::QueryRecorder.new { get :index }.count
|
|
|
|
|
|
|
|
create(:project)
|
|
|
|
|
|
|
|
expect { get :index }.not_to exceed_query_limit(control_count)
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe 'GET /projects.json' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
before do
|
|
|
|
get :index, format: :json
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to respond_with(:success) }
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
describe 'GET /projects/:id' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
it 'renders show page' do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :show, params: { namespace_id: project.namespace.path, id: project.path }
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(response.body).to match(project.name)
|
|
|
|
end
|
|
|
|
end
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
describe 'PUT /projects/transfer/:id' do
|
|
|
|
let_it_be(:project, reload: true) { create(:project) }
|
|
|
|
let_it_be(:new_namespace) { create(:namespace) }
|
|
|
|
|
|
|
|
it 'updates namespace' do
|
|
|
|
put :transfer, params: { namespace_id: project.namespace.path, new_namespace_id: new_namespace.id, id: project.path }
|
|
|
|
|
|
|
|
project.reload
|
|
|
|
|
|
|
|
expect(project.namespace).to eq(new_namespace)
|
|
|
|
expect(response).to have_gitlab_http_status(:redirect)
|
|
|
|
expect(response).to redirect_to(admin_project_path(project))
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project transfer fails' do
|
|
|
|
it 'flashes error' do
|
|
|
|
old_namespace = project.namespace
|
|
|
|
|
|
|
|
put :transfer, params: { namespace_id: old_namespace.path, new_namespace_id: nil, id: project.path }
|
|
|
|
|
|
|
|
project.reload
|
|
|
|
|
|
|
|
expect(project.namespace).to eq(old_namespace)
|
|
|
|
expect(response).to have_gitlab_http_status(:redirect)
|
|
|
|
expect(response).to redirect_to(admin_project_path(project))
|
|
|
|
expect(flash[:alert]).to eq s_('TransferProject|Please select a new namespace for your project.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|