summaryrefslogtreecommitdiff
path: root/spec/services/git
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-01 12:11:01 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-01 12:11:01 +0000
commit08b3b98051f56cfc1774db5c92c183cf33ed8bdd (patch)
treed93e764b9ac3fd30eaf827a1017fbb40a7abf40c /spec/services/git
parenta928c5170fa58e4aef91ebca6c4fc9ec7cea812e (diff)
downloadgitlab-ce-08b3b98051f56cfc1774db5c92c183cf33ed8bdd.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/git')
-rw-r--r--spec/services/git/branch_push_service_spec.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/services/git/branch_push_service_spec.rb b/spec/services/git/branch_push_service_spec.rb
index d74d6be425b..5d73794c1ec 100644
--- a/spec/services/git/branch_push_service_spec.rb
+++ b/spec/services/git/branch_push_service_spec.rb
@@ -704,4 +704,68 @@ RSpec.describe Git::BranchPushService, services: true do
service.execute
service
end
+
+ context 'Jira Connect hooks' do
+ let_it_be(:project) { create(:project, :repository) }
+ let(:branch_to_sync) { nil }
+ let(:commits_to_sync) { [] }
+ let(:params) do
+ { change: { oldrev: oldrev, newrev: newrev, ref: ref } }
+ end
+
+ subject do
+ described_class.new(project, user, params)
+ end
+
+ shared_examples 'enqueues Jira sync worker' do
+ specify do
+ Sidekiq::Testing.fake! do
+ expect(JiraConnect::SyncBranchWorker).to receive(:perform_async)
+ .with(project.id, branch_to_sync, commits_to_sync)
+ .and_call_original
+
+ expect { subject.execute }.to change(JiraConnect::SyncBranchWorker.jobs, :size).by(1)
+ end
+ end
+ end
+
+ shared_examples 'does not enqueue Jira sync worker' do
+ specify do
+ Sidekiq::Testing.fake! do
+ expect { subject.execute }.not_to change(JiraConnect::SyncBranchWorker.jobs, :size)
+ end
+ end
+ end
+
+ context 'with a Jira subscription' do
+ before do
+ create(:jira_connect_subscription, namespace: project.namespace)
+ end
+
+ context 'branch name contains Jira issue key' do
+ let(:branch_to_sync) { 'branch-JIRA-123' }
+ let(:ref) { "refs/heads/#{branch_to_sync}" }
+
+ it_behaves_like 'enqueues Jira sync worker'
+ end
+
+ context 'commit message contains Jira issue key' do
+ let(:commits_to_sync) { [newrev] }
+
+ before do
+ allow_any_instance_of(Commit).to receive(:safe_message).and_return('Commit with key JIRA-123')
+ end
+
+ it_behaves_like 'enqueues Jira sync worker'
+ end
+
+ context 'branch name and commit message does not contain Jira issue key' do
+ it_behaves_like 'does not enqueue Jira sync worker'
+ end
+ end
+
+ context 'without a Jira subscription' do
+ it_behaves_like 'does not enqueue Jira sync worker'
+ end
+ end
end