Commit 6ae25290 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Remove KeysObserver

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 77c0a6db
......@@ -29,6 +29,10 @@ class Key < ActiveRecord::Base
delegate :name, :email, to: :user, prefix: true
after_create :add_to_shell
after_create :notify_user
after_destroy :remove_from_shell
def strip_white_space
self.key = key.strip unless key.blank?
end
......@@ -42,6 +46,26 @@ class Key < ActiveRecord::Base
"key-#{id}"
end
def add_to_shell
GitlabShellWorker.perform_async(
:add_key,
shell_id,
key
)
end
def notify_user
NotificationService.new.new_key(self)
end
def remove_from_shell
GitlabShellWorker.perform_async(
:remove_key,
shell_id,
key,
)
end
private
def generate_fingerpint
......
class KeyObserver < BaseObserver
def after_create(key)
GitlabShellWorker.perform_async(
:add_key,
key.shell_id,
key.key
)
notification.new_key(key)
end
def after_destroy(key)
GitlabShellWorker.perform_async(
:remove_key,
key.shell_id,
key.key,
)
end
end
......@@ -21,7 +21,6 @@ module Gitlab
# Activate observers that should always be running.
config.active_record.observers = :milestone_observer,
:project_activity_cache_observer,
:key_observer,
:merge_request_observer,
:note_observer,
:project_observer,
......
......@@ -68,4 +68,18 @@ describe Key do
build(:invalid_key).should_not be_valid
end
end
context 'callbacks' do
it 'should add new key to authorized_file' do
@key = build(:personal_key, id: 7)
GitlabShellWorker.should_receive(:perform_async).with(:add_key, @key.shell_id, @key.key)
@key.save
end
it 'should remove key from authorized_file' do
@key = create(:personal_key)
GitlabShellWorker.should_receive(:perform_async).with(:remove_key, @key.shell_id, @key.key)
@key.destroy
end
end
end
require 'spec_helper'
describe KeyObserver do
before do
@key = create(:personal_key)
@observer = KeyObserver.instance
end
context :after_create do
it do
GitlabShellWorker.should_receive(:perform_async).with(:add_key, @key.shell_id, @key.key)
@observer.after_create(@key)
end
end
context :after_destroy do
it do
GitlabShellWorker.should_receive(:perform_async).with(:remove_key, @key.shell_id, @key.key)
@observer.after_destroy(@key)
end
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