debian-mirror-gitlab/spec/services/projects/enable_deploy_key_service_spec.rb

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

40 lines
1,007 B
Ruby
Raw Permalink Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Projects::EnableDeployKeyService, feature_category: :continuous_delivery do
2016-09-13 17:45:13 +05:30
let(:deploy_key) { create(:deploy_key, public: true) }
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2022-08-27 11:52:29 +05:30
let(:user) { project.creator }
2016-09-13 17:45:13 +05:30
let!(:params) { { key_id: deploy_key.id } }
it 'enables the key' do
expect do
service.execute
end.to change { project.deploy_keys.count }.from(0).to(1)
end
context 'trying to add an unaccessable key' do
let(:another_key) { create(:another_key) }
let!(:params) { { key_id: another_key.id } }
it 'returns nil if the key cannot be added' do
expect(service.execute).to be nil
end
end
2017-08-17 22:00:37 +05:30
context 'add the same key twice' do
before do
project.deploy_keys << deploy_key
end
it 'returns existing key' do
expect(service.execute).to eq(deploy_key)
end
end
2016-09-13 17:45:13 +05:30
def service
Projects::EnableDeployKeyService.new(project, user, params)
end
end