2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-05 05:35:44 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Projects::EnableDeployKeyService do
|
2016-08-05 05:35:44 -04:00
|
|
|
let(:deploy_key) { create(:deploy_key, public: true) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-08-05 05:35:44 -04:00
|
|
|
let(:user) { project.creator}
|
|
|
|
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-05-01 01:22:11 -04:00
|
|
|
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-08-05 05:35:44 -04:00
|
|
|
def service
|
2016-08-08 14:32:10 -04:00
|
|
|
Projects::EnableDeployKeyService.new(project, user, params)
|
2016-08-05 05:35:44 -04:00
|
|
|
end
|
|
|
|
end
|