summaryrefslogtreecommitdiff
path: root/spec/services/merge_requests/push_options_handler_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/merge_requests/push_options_handler_service_spec.rb')
-rw-r--r--spec/services/merge_requests/push_options_handler_service_spec.rb101
1 files changed, 100 insertions, 1 deletions
diff --git a/spec/services/merge_requests/push_options_handler_service_spec.rb b/spec/services/merge_requests/push_options_handler_service_spec.rb
index 87c3fc6a2d8..5f76f6f5c44 100644
--- a/spec/services/merge_requests/push_options_handler_service_spec.rb
+++ b/spec/services/merge_requests/push_options_handler_service_spec.rb
@@ -5,11 +5,16 @@ require 'spec_helper'
RSpec.describe MergeRequests::PushOptionsHandlerService do
include ProjectForksHelper
- let_it_be(:project) { create(:project, :public, :repository) }
+ let_it_be(:parent_group) { create(:group, :public) }
+ let_it_be(:child_group) { create(:group, :public, parent: parent_group) }
+ let_it_be(:project) { create(:project, :public, :repository, group: child_group) }
let_it_be(:user1) { create(:user, developer_projects: [project]) }
let_it_be(:user2) { create(:user, developer_projects: [project]) }
let_it_be(:user3) { create(:user, developer_projects: [project]) }
let_it_be(:forked_project) { fork_project(project, user1, repository: true) }
+ let_it_be(:parent_group_milestone) { create(:milestone, group: parent_group, title: 'ParentGroupMilestone1.0') }
+ let_it_be(:child_group_milestone) { create(:milestone, group: child_group, title: 'ChildGroupMilestone1.0') }
+ let_it_be(:project_milestone) { create(:milestone, project: project, title: 'ProjectMilestone1.0') }
let(:service) { described_class.new(project: project, current_user: user1, changes: changes, push_options: push_options) }
let(:source_branch) { 'fix' }
@@ -59,6 +64,16 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
end
end
+ shared_examples_for 'a service that can set the milestone of a merge request' do
+ subject(:last_mr) { MergeRequest.last }
+
+ it 'sets the milestone' do
+ service.execute
+
+ expect(last_mr.milestone&.title).to eq(expected_milestone)
+ end
+ end
+
shared_examples_for 'a service that can set the merge request to merge when pipeline succeeds' do
subject(:last_mr) { MergeRequest.last }
@@ -514,6 +529,90 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
it_behaves_like 'with the project default branch'
end
+ describe '`milestone` push option' do
+ context 'with a valid milestone' do
+ let(:expected_milestone) { project_milestone.title }
+ let(:push_options) { { milestone: project_milestone.title } }
+
+ context 'with a new branch' do
+ let(:changes) { new_branch_changes }
+
+ it_behaves_like 'a service that does not create a merge request'
+
+ it 'adds an error to the service' do
+ service.execute
+
+ expect(service.errors).to include(error_mr_required)
+ end
+
+ context 'when coupled with the `create` push option' do
+ let(:push_options) { { create: true, milestone: project_milestone.title } }
+
+ it_behaves_like 'a service that can create a merge request'
+ it_behaves_like 'a service that can set the milestone of a merge request'
+ end
+ end
+
+ context 'with an existing branch but no open MR' do
+ let(:changes) { existing_branch_changes }
+
+ it_behaves_like 'a service that does not create a merge request'
+
+ it 'adds an error to the service' do
+ service.execute
+
+ expect(service.errors).to include(error_mr_required)
+ end
+
+ context 'when coupled with the `create` push option' do
+ let(:push_options) { { create: true, milestone: project_milestone.title } }
+
+ it_behaves_like 'a service that can create a merge request'
+ it_behaves_like 'a service that can set the milestone of a merge request'
+ end
+ end
+
+ context 'with an existing branch that has a merge request open' do
+ let(:changes) { existing_branch_changes }
+ let!(:merge_request) { create(:merge_request, source_project: project, source_branch: source_branch)}
+
+ it_behaves_like 'a service that does not create a merge request'
+ it_behaves_like 'a service that can set the milestone of a merge request'
+ end
+
+ it_behaves_like 'with a deleted branch'
+ it_behaves_like 'with the project default branch'
+ end
+
+ context 'with invalid milestone' do
+ let(:expected_milestone) { nil }
+ let(:changes) { new_branch_changes }
+ let(:push_options) { { create: true, milestone: 'invalid_milestone' } }
+
+ it_behaves_like 'a service that can set the milestone of a merge request'
+ end
+
+ context 'with an ancestor milestone' do
+ let(:changes) { existing_branch_changes }
+
+ context 'with immediate parent milestone' do
+ let(:push_options) { { create: true, milestone: child_group_milestone.title } }
+ let(:expected_milestone) { child_group_milestone.title }
+
+ it_behaves_like 'a service that can create a merge request'
+ it_behaves_like 'a service that can set the milestone of a merge request'
+ end
+
+ context 'with multi-level ancestor milestone' do
+ let(:push_options) { { create: true, milestone: parent_group_milestone.title } }
+ let(:expected_milestone) { parent_group_milestone.title }
+
+ it_behaves_like 'a service that can create a merge request'
+ it_behaves_like 'a service that can set the milestone of a merge request'
+ end
+ end
+ end
+
shared_examples 'with an existing branch that has a merge request open in foss' do
let(:changes) { existing_branch_changes }
let!(:merge_request) { create(:merge_request, source_project: project, source_branch: source_branch)}