summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-12-07 12:07:22 +0100
committerDouwe Maan <douwe@gitlab.com>2015-12-07 12:07:22 +0100
commit6368717852937a5fc84421db1088a8fea1c3bb2f (patch)
treea481623fd8a22dda0c39c86650718472db3502f3 /spec/services
parent234f4bf20fb338f2164976fd39203fbc671afd29 (diff)
parentf5ec1ebe2caa0d8b4ccccb671ae6a4cc99cddbe0 (diff)
downloadgitlab-ce-6368717852937a5fc84421db1088a8fea1c3bb2f.tar.gz
Merge branch 'issue_1156'
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/git_hooks_service_spec.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/services/git_hooks_service_spec.rb b/spec/services/git_hooks_service_spec.rb
new file mode 100644
index 00000000000..7e018d3c9fe
--- /dev/null
+++ b/spec/services/git_hooks_service_spec.rb
@@ -0,0 +1,53 @@
+require 'spec_helper'
+
+describe GitHooksService do
+ include RepoHelpers
+
+ let(:user) { create :user }
+ let(:project) { create :project }
+ let(:service) { GitHooksService.new }
+
+ before do
+ @blankrev = Gitlab::Git::BLANK_SHA
+ @oldrev = sample_commit.parent_id
+ @newrev = sample_commit.id
+ @ref = 'refs/heads/feature'
+ @repo_path = project.repository.path_to_repo
+ end
+
+ describe '#execute' do
+
+ context 'when receive hooks were successful' do
+ it 'should call post-receive hook' do
+ hook = double(trigger: true)
+ expect(Gitlab::Git::Hook).to receive(:new).exactly(3).times.and_return(hook)
+
+ expect(service.execute(user, @repo_path, @blankrev, @newrev, @ref) { }).to eq(true)
+ end
+ end
+
+ context 'when pre-receive hook failed' do
+ it 'should not call post-receive hook' do
+ expect(service).to receive(:run_hook).with('pre-receive').and_return(false)
+ expect(service).not_to receive(:run_hook).with('post-receive')
+
+ expect do
+ service.execute(user, @repo_path, @blankrev, @newrev, @ref)
+ end.to raise_error(GitHooksService::PreReceiveError)
+ end
+ end
+
+ context 'when update hook failed' do
+ it 'should not call post-receive hook' do
+ expect(service).to receive(:run_hook).with('pre-receive').and_return(true)
+ expect(service).to receive(:run_hook).with('update').and_return(false)
+ expect(service).not_to receive(:run_hook).with('post-receive')
+
+ expect do
+ service.execute(user, @repo_path, @blankrev, @newrev, @ref)
+ end.to raise_error(GitHooksService::PreReceiveError)
+ end
+ end
+
+ end
+end