diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/observers/key_observer_spec.rb | 34 | ||||
-rw-r--r-- | spec/spec_helper.rb | 3 | ||||
-rw-r--r-- | spec/support/gitolite_stub.rb | 35 | ||||
-rw-r--r-- | spec/support/monkeypatch.rb | 30 |
4 files changed, 72 insertions, 30 deletions
diff --git a/spec/observers/key_observer_spec.rb b/spec/observers/key_observer_spec.rb new file mode 100644 index 00000000000..7f2a76a320c --- /dev/null +++ b/spec/observers/key_observer_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9fb0ad7e249..06909f392bb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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) diff --git a/spec/support/gitolite_stub.rb b/spec/support/gitolite_stub.rb new file mode 100644 index 00000000000..2a907f99bc8 --- /dev/null +++ b/spec/support/gitolite_stub.rb @@ -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 diff --git a/spec/support/monkeypatch.rb b/spec/support/monkeypatch.rb index 855a31f06de..04bbb6fb680 100644 --- a/spec/support/monkeypatch.rb +++ b/spec/support/monkeypatch.rb @@ -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 |