2015-11-26 00:20:40 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 10:55:49 +00:00
|
|
|
describe GitHooksService, services: true do
|
2015-11-26 00:20:40 +00:00
|
|
|
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
|
2015-12-01 05:22:45 +00:00
|
|
|
context 'when receive hooks were successful' do
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'calls post-receive hook' do
|
2016-07-04 12:30:22 +00:00
|
|
|
hook = double(trigger: [true, nil])
|
2015-12-01 05:22:45 +00:00
|
|
|
expect(Gitlab::Git::Hook).to receive(:new).exactly(3).times.and_return(hook)
|
|
|
|
|
2017-01-26 13:18:04 +00:00
|
|
|
service.execute(user, @repo_path, @blankrev, @newrev, @ref) { }
|
2015-11-26 00:20:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-01 05:22:45 +00:00
|
|
|
context 'when pre-receive hook failed' do
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'does not call post-receive hook' do
|
2016-07-04 12:30:22 +00:00
|
|
|
expect(service).to receive(:run_hook).with('pre-receive').and_return([false, ''])
|
2015-11-26 00:20:40 +00:00
|
|
|
expect(service).not_to receive(:run_hook).with('post-receive')
|
|
|
|
|
2015-12-01 17:31:44 +00:00
|
|
|
expect do
|
|
|
|
service.execute(user, @repo_path, @blankrev, @newrev, @ref)
|
|
|
|
end.to raise_error(GitHooksService::PreReceiveError)
|
2015-11-26 00:20:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-01 05:22:45 +00:00
|
|
|
context 'when update hook failed' do
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'does not call post-receive hook' do
|
2016-07-04 12:30:22 +00:00
|
|
|
expect(service).to receive(:run_hook).with('pre-receive').and_return([true, nil])
|
|
|
|
expect(service).to receive(:run_hook).with('update').and_return([false, ''])
|
2015-12-01 05:22:45 +00:00
|
|
|
expect(service).not_to receive(:run_hook).with('post-receive')
|
|
|
|
|
2015-12-01 17:31:44 +00:00
|
|
|
expect do
|
|
|
|
service.execute(user, @repo_path, @blankrev, @newrev, @ref)
|
|
|
|
end.to raise_error(GitHooksService::PreReceiveError)
|
2015-12-01 05:22:45 +00:00
|
|
|
end
|
|
|
|
end
|
2015-11-26 00:20:40 +00:00
|
|
|
end
|
|
|
|
end
|