summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/gitaly_client/operation_service_spec.rb
diff options
context:
space:
mode:
authorEric Eastwood <contact@ericeastwood.com>2017-10-04 10:56:03 -0500
committerEric Eastwood <contact@ericeastwood.com>2017-10-04 10:56:03 -0500
commitdecf0443698a289ea39dbfff3ae5491936466c92 (patch)
tree3053a77cccc41a95f47cdee8411c8babbf8c1dea /spec/lib/gitlab/gitaly_client/operation_service_spec.rb
parent50063d86f0998f6cf8e2ca53aa2a11cb71a2b350 (diff)
parent5a23af928e52350039f1db8eee97278d34d1f1b0 (diff)
downloadgitlab-ce-decf0443698a289ea39dbfff3ae5491936466c92.tar.gz
Merge branch 'master' into 34102-online-view-of-artifacts-fe
Diffstat (limited to 'spec/lib/gitlab/gitaly_client/operation_service_spec.rb')
-rw-r--r--spec/lib/gitlab/gitaly_client/operation_service_spec.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb
new file mode 100644
index 00000000000..769b14687ac
--- /dev/null
+++ b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb
@@ -0,0 +1,55 @@
+require 'spec_helper'
+
+describe Gitlab::GitalyClient::OperationService do
+ let(:project) { create(:project) }
+ let(:repository) { project.repository.raw }
+ let(:client) { described_class.new(repository) }
+
+ describe '#user_create_branch' do
+ let(:user) { create(:user) }
+ let(:gitaly_user) { Gitlab::GitalyClient::Util.gitaly_user(user) }
+ let(:branch_name) { 'new' }
+ let(:start_point) { 'master' }
+ let(:request) do
+ Gitaly::UserCreateBranchRequest.new(
+ repository: repository.gitaly_repository,
+ branch_name: branch_name,
+ start_point: start_point,
+ user: gitaly_user
+ )
+ end
+ let(:gitaly_commit) { build(:gitaly_commit) }
+ let(:commit_id) { gitaly_commit.id }
+ let(:gitaly_branch) do
+ Gitaly::Branch.new(name: branch_name, target_commit: gitaly_commit)
+ end
+ let(:response) { Gitaly::UserCreateBranchResponse.new(branch: gitaly_branch) }
+ let(:commit) { Gitlab::Git::Commit.new(repository, gitaly_commit) }
+
+ subject { client.user_create_branch(branch_name, user, start_point) }
+
+ it 'sends a user_create_branch message and returns a Gitlab::git::Branch' do
+ expect_any_instance_of(Gitaly::OperationService::Stub)
+ .to receive(:user_create_branch).with(request, kind_of(Hash))
+ .and_return(response)
+
+ expect(subject.name).to eq(branch_name)
+ expect(subject.dereferenced_target).to eq(commit)
+ end
+
+ context "when pre_receive_error is present" do
+ let(:response) do
+ Gitaly::UserCreateBranchResponse.new(pre_receive_error: "something failed")
+ end
+
+ it "throws a PreReceive exception" do
+ expect_any_instance_of(Gitaly::OperationService::Stub)
+ .to receive(:user_create_branch).with(request, kind_of(Hash))
+ .and_return(response)
+
+ expect { subject }.to raise_error(
+ Gitlab::Git::HooksService::PreReceiveError, "something failed")
+ end
+ end
+ end
+end