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

38 lines
929 B
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe Projects::EnableDeployKeyService 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) }
2016-09-13 17:45:13 +05:30
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-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