Introduce a new Keys::DestroyService service
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
c75ae23729
commit
6d81905faf
|
@ -23,7 +23,7 @@ class Profiles::KeysController < Profiles::ApplicationController
|
|||
|
||||
def destroy
|
||||
@key = current_user.keys.find(params[:id])
|
||||
@key.destroy
|
||||
Keys::DestroyService.new(current_user).execute(@key)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to profile_keys_url, status: 302 }
|
||||
|
|
|
@ -2,7 +2,7 @@ module Keys
|
|||
class BaseService
|
||||
attr_accessor :user, :params
|
||||
|
||||
def initialize(user, params)
|
||||
def initialize(user, params = {})
|
||||
@user, @params = user, params
|
||||
@ip_address = @params.delete(:ip_address)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
module Keys
|
||||
class DestroyService < ::Keys::BaseService
|
||||
def execute(key)
|
||||
key.destroy if destroy_possible?(key)
|
||||
end
|
||||
|
||||
# overriden in EE::Keys::DestroyService
|
||||
def destroy_possible?(key)
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Keys::DestroyService do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
subject { described_class.new(user) }
|
||||
|
||||
it 'destroys a key' do
|
||||
key = create(:key)
|
||||
|
||||
expect { subject.execute(key) }.to change(Key, :count).by(-1)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue