From c47b947a7360f21cc1438462587c6e284b40e230 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 22 Aug 2017 16:24:41 +0200 Subject: Move GitHooksService tests --- spec/lib/gitlab/git/hooks_service_spec.rb | 48 +++++++++++++++++++++++++++++ spec/services/git_hooks_service_spec.rb | 50 ------------------------------- 2 files changed, 48 insertions(+), 50 deletions(-) create mode 100644 spec/lib/gitlab/git/hooks_service_spec.rb delete mode 100644 spec/services/git_hooks_service_spec.rb diff --git a/spec/lib/gitlab/git/hooks_service_spec.rb b/spec/lib/gitlab/git/hooks_service_spec.rb new file mode 100644 index 00000000000..e9c0209fe3b --- /dev/null +++ b/spec/lib/gitlab/git/hooks_service_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe Gitlab::Git::HooksService, seed_helper: true do + let(:committer) { Gitlab::Git::Committer.new('Jane Doe', 'janedoe@example.com', 'user-456') } + let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, 'project-123') } + let(:service) { described_class.new } + + before do + @blankrev = Gitlab::Git::BLANK_SHA + @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) + + service.execute(committer, 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 + service.execute(committer, repository, @blankrev, @newrev, @ref) + 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 + service.execute(committer, repository, @blankrev, @newrev, @ref) + end.to raise_error(Gitlab::Git::HooksService::PreReceiveError) + end + end + end +end diff --git a/spec/services/git_hooks_service_spec.rb b/spec/services/git_hooks_service_spec.rb deleted file mode 100644 index ac7be531526..00000000000 --- a/spec/services/git_hooks_service_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Git::HooksService do - include RepoHelpers - - let(:user) { create(:user) } - let(:project) { create(:project, :repository) } - let(:service) { described_class.new } - - before do - @blankrev = Gitlab::Git::BLANK_SHA - @oldrev = sample_commit.parent_id - @newrev = sample_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) - - service.execute(user, project, @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 - service.execute(user, project, @blankrev, @newrev, @ref) - 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 - service.execute(user, project, @blankrev, @newrev, @ref) - end.to raise_error(Gitlab::Git::HooksService::PreReceiveError) - end - end - end -end -- cgit v1.2.1