debian-mirror-gitlab/spec/controllers/projects/settings/repository_controller_spec.rb

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

135 lines
4.4 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Projects::Settings::RepositoryController do
2017-08-17 22:00:37 +05:30
let(:project) { create(:project_empty_repo, :public) }
let(:user) { create(:user) }
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2017-08-17 22:00:37 +05:30
sign_in(user)
end
describe 'GET show' do
it 'renders show with 200 status code' do
2019-02-15 15:39:39 +05:30
get :show, params: { namespace_id: project.namespace, project_id: project }
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2017-08-17 22:00:37 +05:30
expect(response).to render_template(:show)
end
end
2019-02-15 15:39:39 +05:30
describe 'PUT cleanup' do
let(:object_map) { fixture_file_upload('spec/fixtures/bfg_object_map.txt') }
2021-01-29 00:20:46 +05:30
it 'enqueues a project cleanup' do
expect(Projects::CleanupService)
.to receive(:enqueue)
.with(project, user, anything)
.and_return(status: :success)
2019-02-15 15:39:39 +05:30
2021-01-29 00:20:46 +05:30
put :cleanup, params: { namespace_id: project.namespace, project_id: project, project: { bfg_object_map: object_map } }
2019-02-15 15:39:39 +05:30
expect(response).to redirect_to project_settings_repository_path(project)
end
2022-04-04 11:22:00 +05:30
context 'when project cleanup returns an error', :aggregate_failures do
it 'shows an error' do
expect(Projects::CleanupService)
.to receive(:enqueue)
.with(project, user, anything)
.and_return(status: :error, message: 'error message')
put :cleanup, params: { namespace_id: project.namespace, project_id: project, project: { bfg_object_map: object_map } }
expect(controller).to set_flash[:alert].to('error message')
expect(response).to redirect_to project_settings_repository_path(project)
end
end
2019-02-15 15:39:39 +05:30
end
2020-04-25 10:58:03 +05:30
describe 'POST create_deploy_token' do
context 'when ajax_new_deploy_token feature flag is disabled for the project' do
before do
2020-05-24 23:13:21 +05:30
stub_feature_flags(ajax_new_deploy_token: false)
2020-04-25 10:58:03 +05:30
end
it_behaves_like 'a created deploy token' do
let(:entity) { project }
let(:create_entity_params) { { namespace_id: project.namespace, project_id: project } }
let(:deploy_token_type) { DeployToken.deploy_token_types[:project_type] }
end
end
context 'when ajax_new_deploy_token feature flag is enabled for the project' do
let(:good_deploy_token_params) do
{
name: 'name',
expires_at: 1.day.from_now.to_s,
username: 'deployer',
read_repository: '1',
deploy_token_type: DeployToken.deploy_token_types[:project_type]
}
end
2020-10-24 23:57:45 +05:30
2020-04-25 10:58:03 +05:30
let(:request_params) do
{
namespace_id: project.namespace.to_param,
project_id: project.to_param,
deploy_token: deploy_token_params
}
end
subject { post :create_deploy_token, params: request_params, format: :json }
context('a good request') do
let(:deploy_token_params) { good_deploy_token_params }
let(:expected_response) do
{
'id' => be_a(Integer),
'name' => deploy_token_params[:name],
'username' => deploy_token_params[:username],
2020-05-24 23:13:21 +05:30
'expires_at' => Time.zone.parse(deploy_token_params[:expires_at]),
2020-04-25 10:58:03 +05:30
'token' => be_a(String),
2021-06-08 01:23:25 +05:30
'expired' => false,
'revoked' => false,
2020-04-25 10:58:03 +05:30
'scopes' => deploy_token_params.inject([]) do |scopes, kv|
key, value = kv
2020-10-24 23:57:45 +05:30
key.to_s.start_with?('read_') && value.to_i != 0 ? scopes << key.to_s : scopes
2020-04-25 10:58:03 +05:30
end
}
end
it 'creates the deploy token' do
subject
expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/deploy_token')
expect(json_response).to match(expected_response)
end
end
context('a bad request') do
let(:deploy_token_params) { good_deploy_token_params.except(:read_repository) }
let(:expected_response) { { 'message' => "Scopes can't be blank" } }
it 'does not create the deploy token' do
subject
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response).to match(expected_response)
end
end
context('an invalid request') do
let(:deploy_token_params) { good_deploy_token_params.except(:name) }
it 'raises a validation error' do
expect { subject }.to raise_error(ActiveRecord::StatementInvalid)
end
end
end
end
2017-08-17 22:00:37 +05:30
end