Remove KeysObserver

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2014-04-02 21:13:05 +03:00
parent 77c0a6db4b
commit 6ae2529041
No known key found for this signature in database
GPG key ID: 627C5F589F467F17
5 changed files with 38 additions and 43 deletions

View file

@ -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

View file

@ -1,19 +0,0 @@
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

View file

@ -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,

View file

@ -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

View file

@ -1,23 +0,0 @@
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