BigW Consortium Gitlab

key_observer_spec.rb 732 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
require 'spec_helper'

describe KeyObserver do
  before do 
    @key = double('Key',
      identifier: 'admin_654654',
      key: '== a vaild ssh key',
      projects: [],
      is_deploy_key: false
    )

    @gitolite = double('Gitlab::Gitolite',
      set_key: true,
      remove_key: true
    )

    @observer = KeyObserver.instance
    @observer.stub(:git_host => @gitolite)
  end

  context :after_save do
    it do
      @gitolite.should_receive(:set_key).with(@key.identifier, @key.key, @key.projects)
      @observer.after_save(@key)
    end
  end

  context :after_destroy do 
    it do
      @gitolite.should_receive(:remove_key).with(@key.identifier, @key.projects)
      @observer.after_destroy(@key)
    end
  end
end