Commit b13c89b1 authored by Rajendra Kadam's avatar Rajendra Kadam

Add DestroyService for GPG keys and use for deleting gpg keys via API

parent 1119b3d6
# frozen_string_literal: true
module GpgKeys
class DestroyService < Keys::BaseService
def execute(key)
key.destroy
end
end
end
......@@ -374,9 +374,10 @@ module API
key = user.gpg_keys.find_by(id: params[:key_id])
not_found!('GPG Key') unless key
key.destroy
no_content!
destroy_conditionally!(key) do |key|
destroy_service = ::GpgKeys::DestroyService.new(current_user)
destroy_service.execute(key)
end
end
# rubocop: enable CodeReuse/ActiveRecord
......
# frozen_string_literal: true
require 'spec_helper'
describe GpgKeys::DestroyService do
let(:user) { create(:user) }
subject { described_class.new(user) }
it 'destroys the GPG key' do
gpg_key = create(:gpg_key)
expect { subject.execute(gpg_key) }.to change(GpgKey, :count).by(-1)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment