Use similar interface to access gitolite

Simplified gitolite handle logic
Stubn over monkeypatch
Stub only specific methods in Gitlab:Gitolite
Moved grach auth to lib
added specs for keys observer
removes SshKey role
This commit is contained in:
randx 2012-08-29 00:04:06 +03:00
parent aded7056fd
commit 7cdc5b9e04
20 changed files with 155 additions and 88 deletions

View file

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

View file

@ -27,6 +27,7 @@ RSpec.configure do |config|
config.mock_with :rspec
config.include LoginHelpers, type: :request
config.include GitoliteStub
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
@ -39,6 +40,8 @@ RSpec.configure do |config|
end
config.before do
stub_gitolite!
# !!! Observers disabled by default in tests
ActiveRecord::Base.observers.disable(:all)
# ActiveRecord::Base.observers.enable(:all)

View file

@ -0,0 +1,35 @@
module GitoliteStub
def stub_gitolite!
stub_gitlab_gitolite
stub_gitolite_admin
end
def stub_gitolite_admin
gitolite_repo = mock(
clean_permissions: true,
add_permission: true
)
gitolite_config = mock(
add_repo: true,
get_repo: gitolite_repo,
has_repo?: true
)
gitolite_admin = double(
'Gitolite::GitoliteAdmin',
config: gitolite_config,
save: true,
)
Gitolite::GitoliteAdmin.stub(new: gitolite_admin)
end
def stub_gitlab_gitolite
gitlab_gitolite = Gitlab::Gitolite.new
Gitlab::Gitolite.stub(new: gitlab_gitolite)
gitlab_gitolite.stub(configure: ->() { yield(self) })
gitlab_gitolite.stub(update_keys: true)
end
end

View file

@ -1,14 +1,6 @@
# Stubbing Project <-> git host path
# create project using Factory only
class Project
def update_repository
true
end
def destroy_repository
true
end
def path_to_repo
File.join(Rails.root, "tmp", "tests", path)
end
@ -18,22 +10,6 @@ class Project
end
end
class Key
def update_repository
true
end
def repository_delete_key
true
end
end
class UsersProject
def update_repository
true
end
end
class FakeSatellite
def exists?
true
@ -43,9 +19,3 @@ class FakeSatellite
true
end
end
class ProtectedBranch
def update_repository
true
end
end