summaryrefslogtreecommitdiff
path: root/spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb')
-rw-r--r--spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb36
1 files changed, 30 insertions, 6 deletions
diff --git a/spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb b/spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
index 160c7786bf2..f285517cdac 100644
--- a/spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
+++ b/spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
@@ -54,14 +54,38 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
end
describe "#trigger" do
- let(:build) { create(:ci_build, ref: mr_merge_if_green_enabled.source_branch, status: "success") }
+ context 'build with ref' do
+ let(:build) { create(:ci_build, ref: mr_merge_if_green_enabled.source_branch, status: "success") }
- it "merges all merge requests with merge when build succeeds enabled" do
- allow_any_instance_of(MergeRequest).to receive(:ci_commit).and_return(ci_commit)
- allow(ci_commit).to receive(:success?).and_return(true)
+ it "merges all merge requests with merge when build succeeds enabled" do
+ allow_any_instance_of(MergeRequest).to receive(:ci_commit).and_return(ci_commit)
+ allow(ci_commit).to receive(:success?).and_return(true)
+
+ expect(MergeWorker).to receive(:perform_async)
+ service.trigger(build)
+ end
+ end
+
+ context 'commit status without ref' do
+ let(:commit_status) { create(:generic_commit_status, status: 'success') }
- expect(MergeWorker).to receive(:perform_async)
- service.trigger(build)
+ it "doesn't merge a requests for status on other branch" do
+ allow(project.repository).to receive(:branch_names_contains).with(commit_status.sha).and_return([])
+
+ expect(MergeWorker).to_not receive(:perform_async)
+ service.trigger(commit_status)
+ end
+
+ it 'discovers branches and merges all merge requests when status is success' do
+ allow(project.repository).to receive(:branch_names_contains).
+ with(commit_status.sha).and_return([mr_merge_if_green_enabled.source_branch])
+ allow(ci_commit).to receive(:success?).and_return(true)
+ allow_any_instance_of(MergeRequest).to receive(:ci_commit).and_return(ci_commit)
+ allow(ci_commit).to receive(:success?).and_return(true)
+
+ expect(MergeWorker).to receive(:perform_async)
+ service.trigger(commit_status)
+ end
end
context 'properly handles multiple stages' do