gitlab-org--gitlab-foss/spec/lib/gitlab/git/hooks_service_spec.rb

49 lines
1.7 KiB
Ruby
Raw Normal View History

require 'spec_helper'
2017-08-22 10:24:41 -04:00
describe Gitlab::Git::HooksService, seed_helper: true do
let(:user) { Gitlab::Git::User.new('janedoe', 'Jane Doe', 'janedoe@example.com', 'user-456') }
2017-08-22 10:24:41 -04:00
let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, 'project-123') }
let(:service) { described_class.new }
before do
@blankrev = Gitlab::Git::BLANK_SHA
2017-08-22 10:24:41 -04:00
@oldrev = SeedRepo::Commit::PARENT_ID
@newrev = SeedRepo::Commit::ID
@ref = 'refs/heads/feature'
end
describe '#execute' do
context 'when receive hooks were successful' do
it 'calls post-receive hook' do
hook = double(trigger: [true, nil])
expect(Gitlab::Git::Hook).to receive(:new).exactly(3).times.and_return(hook)
2017-09-13 12:16:56 -04:00
service.execute(user, repository, @blankrev, @newrev, @ref) { }
end
end
context 'when pre-receive hook failed' do
it 'does 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
2017-09-13 12:16:56 -04:00
service.execute(user, repository, @blankrev, @newrev, @ref)
2017-08-22 08:18:09 -04:00
end.to raise_error(Gitlab::Git::HooksService::PreReceiveError)
end
end
context 'when update hook failed' do
it 'does not call post-receive hook' do
expect(service).to receive(:run_hook).with('pre-receive').and_return([true, nil])
expect(service).to receive(:run_hook).with('update').and_return([false, ''])
expect(service).not_to receive(:run_hook).with('post-receive')
expect do
2017-09-13 12:16:56 -04:00
service.execute(user, repository, @blankrev, @newrev, @ref)
2017-08-22 08:18:09 -04:00
end.to raise_error(Gitlab::Git::HooksService::PreReceiveError)
end
end
end
end