diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-02-07 12:26:39 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-02-07 12:26:39 +0400 |
commit | 4e1757bfda0530238e3ab4208b47789e196d5602 (patch) | |
tree | e63d4cf8b97ada54d4be1d99a02b68df7c04a099 /spec | |
parent | 4bfb98ddc90bcc6076e2819619fec7607e74358b (diff) | |
parent | d09d87e3b022f6b7cba0988c4377e44196e35939 (diff) |
Merge branch 'gitlab-shell' of dev.gitlabhq.com:gitlab/gitlabhq
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitolite_config_spec.rb | 16 | ||||
-rw-r--r-- | spec/lib/gitolite_spec.rb | 26 | ||||
-rw-r--r-- | spec/lib/shell_spec.rb | 17 | ||||
-rw-r--r-- | spec/models/key_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/protected_branch_spec.rb | 15 | ||||
-rw-r--r-- | spec/observers/key_observer_spec.rb | 6 | ||||
-rw-r--r-- | spec/spec_helper.rb | 3 | ||||
-rw-r--r-- | spec/support/gitolite_stub.rb | 21 | ||||
-rw-r--r-- | spec/support/stubbed_repository.rb | 21 | ||||
-rw-r--r-- | spec/workers/post_receive_spec.rb | 4 |
11 files changed, 45 insertions, 90 deletions
diff --git a/spec/lib/gitolite_config_spec.rb b/spec/lib/gitolite_config_spec.rb deleted file mode 100644 index c3ce0db569a..00000000000 --- a/spec/lib/gitolite_config_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'spec_helper' - -describe Gitlab::GitoliteConfig do - let(:gitolite) { Gitlab::GitoliteConfig.new } - - it { should respond_to :write_key } - it { should respond_to :rm_key } - it { should respond_to :update_project } - it { should respond_to :update_project! } - it { should respond_to :update_projects } - it { should respond_to :destroy_project } - it { should respond_to :destroy_project! } - it { should respond_to :apply } - it { should respond_to :admin_all_repo } - it { should respond_to :admin_all_repo! } -end diff --git a/spec/lib/gitolite_spec.rb b/spec/lib/gitolite_spec.rb deleted file mode 100644 index 7ba4a633fb1..00000000000 --- a/spec/lib/gitolite_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Gitolite do - let(:project) { double('Project', id: 7, path: 'diaspora') } - let(:gitolite_config) { double('Gitlab::GitoliteConfig') } - let(:gitolite) { Gitlab::Gitolite.new } - - before do - gitolite.stub(config: gitolite_config) - Project.stub(find: project) - end - - it { should respond_to :set_key } - it { should respond_to :remove_key } - - it { should respond_to :update_repository } - it { should respond_to :create_repository } - it { should respond_to :remove_repository } - - it { gitolite.url_to_repo('diaspora').should == Gitlab.config.gitolite.ssh_path_prefix + "diaspora.git" } - - it "should call config update" do - gitolite_config.should_receive(:update_project!) - gitolite.update_repository(project.id) - end -end diff --git a/spec/lib/shell_spec.rb b/spec/lib/shell_spec.rb new file mode 100644 index 00000000000..1c546e59235 --- /dev/null +++ b/spec/lib/shell_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Gitlab::Shell do + let(:project) { double('Project', id: 7, path: 'diaspora') } + let(:gitolite) { Gitlab::Shell.new } + + before do + Project.stub(find: project) + end + + it { should respond_to :add_key } + it { should respond_to :remove_key } + it { should respond_to :add_repository } + it { should respond_to :remove_repository } + + it { gitolite.url_to_repo('diaspora').should == Gitlab.config.gitolite.ssh_path_prefix + "diaspora.git" } +end diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb index 6d2310df5c0..94b952cf932 100644 --- a/spec/models/key_spec.rb +++ b/spec/models/key_spec.rb @@ -46,9 +46,9 @@ describe Key do key.should_not be_valid end - it "does accept the same key for another project" do + it "does not accept the same key for another project" do key = build(:key, project_id: 0) - key.should be_valid + key.should_not be_valid end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 6e67ca8233d..3dccb482375 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -77,8 +77,6 @@ describe Project do it { should respond_to(:url_to_repo) } it { should respond_to(:repo_exists?) } it { should respond_to(:satellite) } - it { should respond_to(:update_repository) } - it { should respond_to(:destroy_repository) } it { should respond_to(:observe_push) } it { should respond_to(:update_merge_requests) } it { should respond_to(:execute_hooks) } diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb index c4d2e2f49f5..6e830393e32 100644 --- a/spec/models/protected_branch_spec.rb +++ b/spec/models/protected_branch_spec.rb @@ -24,19 +24,4 @@ describe ProtectedBranch do it { should validate_presence_of(:project) } it { should validate_presence_of(:name) } end - - describe 'Callbacks' do - let(:branch) { build(:protected_branch) } - - it 'call update_repository after save' do - branch.should_receive(:update_repository) - branch.save - end - - it 'call update_repository after destroy' do - branch.save - branch.should_receive(:update_repository) - branch.destroy - end - end end diff --git a/spec/observers/key_observer_spec.rb b/spec/observers/key_observer_spec.rb index 11f975cc57d..0a886a57afd 100644 --- a/spec/observers/key_observer_spec.rb +++ b/spec/observers/key_observer_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe KeyObserver do before do @key = double('Key', - identifier: 'admin_654654', + shell_id: 'key-32', key: '== a vaild ssh key', projects: [], is_deploy_key: false @@ -14,14 +14,14 @@ describe KeyObserver do context :after_save do it do - GitoliteWorker.should_receive(:perform_async).with(:set_key, @key.identifier, @key.key, @key.projects.map(&:id)) + GitoliteWorker.should_receive(:perform_async).with(:add_key, @key.shell_id, @key.key) @observer.after_save(@key) end end context :after_destroy do it do - GitoliteWorker.should_receive(:perform_async).with(:remove_key, @key.identifier, @key.projects.map(&:id)) + GitoliteWorker.should_receive(:perform_async).with(:remove_key, @key.shell_id, @key.key) @observer.after_destroy(@key) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dbac3c54901..bb314e60eb7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,7 +24,6 @@ RSpec.configure do |config| config.mock_with :rspec config.include LoginHelpers, type: :request - config.include GitoliteStub config.include FactoryGirl::Syntax::Methods config.include Devise::TestHelpers, type: :controller @@ -34,8 +33,6 @@ RSpec.configure do |config| config.use_transactional_fixtures = false config.before do - stub_gitolite! - # Use tmp dir for FS manipulations temp_repos_path = Rails.root.join('tmp', 'test-git-base-path') Gitlab.config.gitolite.stub(repos_path: temp_repos_path) diff --git a/spec/support/gitolite_stub.rb b/spec/support/gitolite_stub.rb deleted file mode 100644 index 574bb5a12a3..00000000000 --- a/spec/support/gitolite_stub.rb +++ /dev/null @@ -1,21 +0,0 @@ -module GitoliteStub - def stub_gitolite! - stub_gitlab_gitolite - stub_gitolite_admin - end - - def stub_gitolite_admin - gitolite_admin = double('Gitolite::GitoliteAdmin') - gitolite_admin.as_null_object - - Gitolite::GitoliteAdmin.stub(new: gitolite_admin) - end - - def stub_gitlab_gitolite - gitolite_config = double('Gitlab::GitoliteConfig') - gitolite_config.stub(apply: ->() { yield(self) }) - gitolite_config.as_null_object - - Gitlab::GitoliteConfig.stub(new: gitolite_config) - end -end diff --git a/spec/support/stubbed_repository.rb b/spec/support/stubbed_repository.rb index e092f8a4776..434cab6516e 100644 --- a/spec/support/stubbed_repository.rb +++ b/spec/support/stubbed_repository.rb @@ -1,5 +1,6 @@ require "repository" require "project" +require "shell" # Stubs out all Git repository access done by models so that specs can run # against fake repositories without Grit complaining that they don't exist. @@ -36,3 +37,23 @@ class GitLabTestRepo < Repository @repo ||= Grit::Repo.new(Rails.root.join('tmp', 'repositories', 'gitlabhq')) end end + +module Gitlab + class Shell + def add_repository name + true + end + + def remove_repository name + true + end + + def add_key id, key + true + end + + def remove_key id, key + true + end + end +end diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb index f408c89afdd..f1a69b1b2e4 100644 --- a/spec/workers/post_receive_spec.rb +++ b/spec/workers/post_receive_spec.rb @@ -11,7 +11,7 @@ describe PostReceive do context "web hook" do let(:project) { create(:project) } let(:key) { create(:key, user: project.owner) } - let(:key_id) { key.identifier } + let(:key_id) { key.shell_id } it "fetches the correct project" do Project.should_receive(:find_with_namespace).with(project.path_with_namespace).and_return(project) @@ -19,7 +19,7 @@ describe PostReceive do end it "does not run if the author is not in the project" do - Key.stub(find_by_identifier: nil) + Key.stub(find_by_id: nil) project.should_not_receive(:observe_push) project.should_not_receive(:execute_hooks) |