2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-03 11:16:05 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe MergeRequests::UpdateService, :mailer do
|
2018-02-23 12:30:37 -05:00
|
|
|
include ProjectForksHelper
|
|
|
|
|
2019-10-11 14:06:15 -04:00
|
|
|
let(:group) { create(:group, :public) }
|
2020-10-01 14:10:20 -04:00
|
|
|
let(:project) { create(:project, :private, :repository, group: group) }
|
2014-04-03 11:16:05 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:user2) { create(:user) }
|
2015-11-17 10:53:15 -05:00
|
|
|
let(:user3) { create(:user) }
|
2016-04-21 06:25:21 -04:00
|
|
|
let(:label) { create(:label, project: project) }
|
2016-03-01 11:33:13 -05:00
|
|
|
let(:label2) { create(:label) }
|
2020-10-01 14:10:20 -04:00
|
|
|
let(:milestone) { create(:milestone, project: project) }
|
2014-04-03 11:16:05 -04:00
|
|
|
|
2016-04-21 06:25:21 -04:00
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, :simple, title: 'Old title',
|
2017-03-28 02:25:43 -04:00
|
|
|
description: "FYI #{user2.to_reference}",
|
2019-04-07 14:35:16 -04:00
|
|
|
assignee_ids: [user3.id],
|
2017-08-04 13:14:04 -04:00
|
|
|
source_project: project,
|
|
|
|
author: create(:user))
|
2016-04-21 06:25:21 -04:00
|
|
|
end
|
|
|
|
|
2014-04-03 11:16:05 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user2)
|
|
|
|
project.add_developer(user3)
|
2014-04-03 11:16:05 -04:00
|
|
|
end
|
|
|
|
|
2015-05-26 21:49:04 -04:00
|
|
|
describe 'execute' do
|
2015-10-22 11:18:59 -04:00
|
|
|
def find_note(starting_with)
|
|
|
|
@merge_request.notes.find do |note|
|
|
|
|
note && note.note.start_with?(starting_with)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-08 13:56:41 -04:00
|
|
|
def find_notes(action)
|
|
|
|
@merge_request
|
|
|
|
.notes
|
|
|
|
.joins(:system_note_metadata)
|
|
|
|
.where(system_note_metadata: { action: action })
|
|
|
|
end
|
|
|
|
|
2015-10-22 11:18:59 -04:00
|
|
|
def update_merge_request(opts)
|
|
|
|
@merge_request = MergeRequests::UpdateService.new(project, user, opts).execute(merge_request)
|
|
|
|
@merge_request.reload
|
|
|
|
end
|
|
|
|
|
2015-01-17 19:34:34 -05:00
|
|
|
context 'valid params' do
|
|
|
|
let(:opts) do
|
|
|
|
{
|
2014-04-03 11:16:05 -04:00
|
|
|
title: 'New title',
|
|
|
|
description: 'Also please fix',
|
2019-04-07 14:35:16 -04:00
|
|
|
assignee_ids: [user.id],
|
2020-09-24 05:09:35 -04:00
|
|
|
reviewer_ids: [],
|
2015-02-07 06:14:55 -05:00
|
|
|
state_event: 'close',
|
2015-05-28 21:00:37 -04:00
|
|
|
label_ids: [label.id],
|
2016-02-12 15:41:31 -05:00
|
|
|
target_branch: 'target',
|
2017-08-30 10:57:50 -04:00
|
|
|
force_remove_source_branch: '1',
|
|
|
|
discussion_locked: true
|
2014-04-03 11:16:05 -04:00
|
|
|
}
|
2015-01-17 19:34:34 -05:00
|
|
|
end
|
2015-01-26 01:49:05 -05:00
|
|
|
|
2020-10-01 14:10:20 -04:00
|
|
|
let(:service) { described_class.new(project, current_user, opts) }
|
|
|
|
let(:current_user) { user }
|
2015-01-17 19:34:34 -05:00
|
|
|
|
|
|
|
before do
|
2015-02-12 13:17:35 -05:00
|
|
|
allow(service).to receive(:execute_hooks)
|
2014-04-03 11:16:05 -04:00
|
|
|
|
2015-11-30 11:03:07 -05:00
|
|
|
perform_enqueued_jobs do
|
|
|
|
@merge_request = service.execute(merge_request)
|
|
|
|
@merge_request.reload
|
|
|
|
end
|
2014-04-03 11:16:05 -04:00
|
|
|
end
|
|
|
|
|
2017-11-21 12:13:07 -05:00
|
|
|
it 'matches base expectations' do
|
2017-05-15 05:39:56 -04:00
|
|
|
expect(@merge_request).to be_valid
|
|
|
|
expect(@merge_request.title).to eq('New title')
|
2019-04-07 14:35:16 -04:00
|
|
|
expect(@merge_request.assignees).to match_array([user])
|
2020-09-21 08:09:34 -04:00
|
|
|
expect(@merge_request.reviewers).to match_array([])
|
2017-05-15 05:39:56 -04:00
|
|
|
expect(@merge_request).to be_closed
|
|
|
|
expect(@merge_request.labels.count).to eq(1)
|
|
|
|
expect(@merge_request.labels.first.title).to eq(label.name)
|
|
|
|
expect(@merge_request.target_branch).to eq('target')
|
|
|
|
expect(@merge_request.merge_params['force_remove_source_branch']).to eq('1')
|
2017-08-30 10:57:50 -04:00
|
|
|
expect(@merge_request.discussion_locked).to be_truthy
|
2017-05-15 05:39:56 -04:00
|
|
|
end
|
2014-04-03 11:16:05 -04:00
|
|
|
|
2020-10-01 14:10:20 -04:00
|
|
|
context 'updating milestone' do
|
|
|
|
RSpec.shared_examples 'updates milestone' do
|
|
|
|
it 'sets milestone' do
|
|
|
|
expect(@merge_request.milestone).to eq milestone
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when milestone_id param' do
|
|
|
|
let(:opts) { { milestone_id: milestone.id } }
|
|
|
|
|
|
|
|
it_behaves_like 'updates milestone'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when milestone param' do
|
|
|
|
let(:opts) { { milestone: milestone } }
|
|
|
|
|
|
|
|
it_behaves_like 'updates milestone'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'executes hooks with update action' do
|
2017-11-21 12:13:07 -05:00
|
|
|
expect(service).to have_received(:execute_hooks)
|
|
|
|
.with(
|
|
|
|
@merge_request,
|
|
|
|
'update',
|
|
|
|
old_associations: {
|
|
|
|
labels: [],
|
|
|
|
mentioned_users: [user2],
|
|
|
|
assignees: [user3],
|
2020-09-21 08:09:34 -04:00
|
|
|
reviewers: [],
|
2020-05-14 11:08:14 -04:00
|
|
|
milestone: nil,
|
2019-07-20 05:06:19 -04:00
|
|
|
total_time_spent: 0,
|
|
|
|
description: "FYI #{user2.to_reference}"
|
2017-11-21 12:13:07 -05:00
|
|
|
}
|
|
|
|
)
|
2015-01-17 19:34:34 -05:00
|
|
|
end
|
|
|
|
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'sends email to user2 about assign of new merge request and email to user3 about merge request unassignment', :sidekiq_might_not_need_inline do
|
2015-11-17 10:53:15 -05:00
|
|
|
deliveries = ActionMailer::Base.deliveries
|
|
|
|
email = deliveries.last
|
2019-07-24 04:19:15 -04:00
|
|
|
recipients = deliveries.last(2).flat_map(&:to)
|
2015-11-17 10:53:15 -05:00
|
|
|
expect(recipients).to include(user2.email, user3.email)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(email.subject).to include(merge_request.title)
|
2014-04-03 11:16:05 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'creates system note about merge_request reassign' do
|
2016-11-23 01:55:23 -05:00
|
|
|
note = find_note('assigned to')
|
2015-05-26 21:49:04 -04:00
|
|
|
|
|
|
|
expect(note).not_to be_nil
|
2019-04-07 14:35:16 -04:00
|
|
|
expect(note.note).to include "assigned to #{user.to_reference} and unassigned #{user3.to_reference}"
|
2014-04-03 11:16:05 -04:00
|
|
|
end
|
2020-09-24 05:09:35 -04:00
|
|
|
|
|
|
|
context 'with reviewers' do
|
|
|
|
let(:opts) { { reviewer_ids: [user2.id] } }
|
|
|
|
|
|
|
|
context 'when merge_request_reviewers feature is disabled' do
|
|
|
|
before(:context) do
|
|
|
|
stub_feature_flags(merge_request_reviewers: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create a system note about merge_request review request' do
|
|
|
|
note = find_note('review requested from')
|
|
|
|
|
|
|
|
expect(note).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when merge_request_reviewers feature is enabled' do
|
|
|
|
before(:context) do
|
|
|
|
stub_feature_flags(merge_request_reviewers: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates system note about merge_request review request' do
|
|
|
|
note = find_note('requested review from')
|
|
|
|
|
|
|
|
expect(note).not_to be_nil
|
|
|
|
expect(note.note).to include "requested review from #{user2.to_reference}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-02-07 06:14:55 -05:00
|
|
|
|
2018-09-07 09:39:20 -04:00
|
|
|
it 'creates a resource label event' do
|
|
|
|
event = merge_request.resource_label_events.last
|
2015-05-26 21:49:04 -04:00
|
|
|
|
2018-09-07 09:39:20 -04:00
|
|
|
expect(event).not_to be_nil
|
|
|
|
expect(event.label_id).to eq label.id
|
|
|
|
expect(event.user_id).to eq user.id
|
2015-02-07 06:14:55 -05:00
|
|
|
end
|
2015-05-26 21:49:04 -04:00
|
|
|
|
|
|
|
it 'creates system note about title change' do
|
2016-11-23 01:55:23 -05:00
|
|
|
note = find_note('changed title')
|
2015-05-26 21:49:04 -04:00
|
|
|
|
|
|
|
expect(note).not_to be_nil
|
2016-11-23 01:55:23 -05:00
|
|
|
expect(note.note).to eq 'changed title from **{-Old-} title** to **{+New+} title**'
|
2015-05-26 21:49:04 -04:00
|
|
|
end
|
2015-05-28 21:00:37 -04:00
|
|
|
|
2017-05-05 08:01:50 -04:00
|
|
|
it 'creates system note about description change' do
|
|
|
|
note = find_note('changed the description')
|
|
|
|
|
|
|
|
expect(note).not_to be_nil
|
|
|
|
expect(note.note).to eq('changed the description')
|
|
|
|
end
|
|
|
|
|
2015-05-28 21:00:37 -04:00
|
|
|
it 'creates system note about branch change' do
|
2016-11-23 01:55:23 -05:00
|
|
|
note = find_note('changed target')
|
2015-05-28 21:00:37 -04:00
|
|
|
|
|
|
|
expect(note).not_to be_nil
|
2016-11-23 01:55:23 -05:00
|
|
|
expect(note.note).to eq 'changed target branch from `master` to `target`'
|
2015-05-28 21:00:37 -04:00
|
|
|
end
|
2016-10-11 11:52:49 -04:00
|
|
|
|
2017-09-01 08:03:57 -04:00
|
|
|
it 'creates system note about discussion lock' do
|
2017-10-10 02:35:31 -04:00
|
|
|
note = find_note('locked this merge request')
|
2017-09-01 08:03:57 -04:00
|
|
|
|
|
|
|
expect(note).not_to be_nil
|
2017-10-10 02:35:31 -04:00
|
|
|
expect(note.note).to eq 'locked this merge request'
|
2017-09-01 08:03:57 -04:00
|
|
|
end
|
|
|
|
|
2020-10-01 14:10:20 -04:00
|
|
|
context 'when current user cannot admin issues in the project' do
|
|
|
|
let(:guest) { create(:user) }
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_guest(guest)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters out params that cannot be set without the :admin_merge_request permission' do
|
|
|
|
expect(@merge_request).to be_valid
|
|
|
|
expect(@merge_request.title).to eq('New title')
|
|
|
|
expect(@merge_request.assignees).to match_array([user3])
|
|
|
|
expect(@merge_request).to be_opened
|
|
|
|
expect(@merge_request.labels.count).to eq(0)
|
|
|
|
expect(@merge_request.target_branch).to eq('target')
|
|
|
|
expect(@merge_request.discussion_locked).to be_falsey
|
|
|
|
expect(@merge_request.milestone).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'updating milestone' do
|
|
|
|
RSpec.shared_examples 'does not update milestone' do
|
|
|
|
it 'sets milestone' do
|
|
|
|
expect(@merge_request.milestone).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when milestone_id param' do
|
|
|
|
let(:opts) { { milestone_id: milestone.id } }
|
|
|
|
|
|
|
|
it_behaves_like 'does not update milestone'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when milestone param' do
|
|
|
|
let(:opts) { { milestone: milestone } }
|
|
|
|
|
|
|
|
it_behaves_like 'does not update milestone'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-11 11:52:49 -04:00
|
|
|
context 'when not including source branch removal options' do
|
|
|
|
before do
|
|
|
|
opts.delete(:force_remove_source_branch)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'maintains the original options' do
|
|
|
|
update_merge_request(opts)
|
|
|
|
|
|
|
|
expect(@merge_request.merge_params["force_remove_source_branch"]).to eq("1")
|
|
|
|
end
|
|
|
|
end
|
2020-09-07 08:08:27 -04:00
|
|
|
|
|
|
|
it_behaves_like 'reviewer_ids filter' do
|
|
|
|
let(:opts) { {} }
|
|
|
|
let(:execute) { update_merge_request(opts) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an existing reviewer' do
|
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, :simple, source_project: project, reviewer_ids: [user2.id])
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when merge_request_reviewer feature is enabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(merge_request_reviewer: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:opts) { { reviewer_ids: [IssuableFinder::Params::NONE] } }
|
|
|
|
|
|
|
|
it 'removes reviewers' do
|
|
|
|
expect(update_merge_request(opts).reviewers).to eq []
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-04-03 11:16:05 -04:00
|
|
|
end
|
2015-10-22 11:18:59 -04:00
|
|
|
|
2020-02-13 19:09:07 -05:00
|
|
|
context 'after_save callback to store_mentions' do
|
|
|
|
let(:merge_request) { create(:merge_request, title: 'Old title', description: "simple description", source_branch: 'test', source_project: project, author: user) }
|
|
|
|
let(:labels) { create_pair(:label, project: project) }
|
|
|
|
let(:milestone) { create(:milestone, project: project) }
|
|
|
|
let(:req_opts) { { source_branch: 'feature', target_branch: 'master' } }
|
|
|
|
|
|
|
|
subject { MergeRequests::UpdateService.new(project, user, opts).execute(merge_request) }
|
|
|
|
|
|
|
|
context 'when mentionable attributes change' do
|
|
|
|
let(:opts) { { description: "Description with #{user.to_reference}" }.merge(req_opts) }
|
|
|
|
|
|
|
|
it 'saves mentions' do
|
|
|
|
expect(merge_request).to receive(:store_mentions!).and_call_original
|
|
|
|
|
|
|
|
expect { subject }.to change { MergeRequestUserMention.count }.by(1)
|
|
|
|
|
|
|
|
expect(merge_request.referenced_users).to match_array([user])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when mentionable attributes do not change' do
|
|
|
|
let(:opts) { { label_ids: [label.id, label2.id], milestone_id: milestone.id }.merge(req_opts) }
|
|
|
|
|
|
|
|
it 'does not call store_mentions' do
|
|
|
|
expect(merge_request).not_to receive(:store_mentions!).and_call_original
|
|
|
|
|
|
|
|
expect { subject }.not_to change { MergeRequestUserMention.count }
|
|
|
|
|
|
|
|
expect(merge_request.referenced_users).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when save fails' do
|
|
|
|
let(:opts) { { title: '', label_ids: labels.map(&:id), milestone_id: milestone.id } }
|
|
|
|
|
|
|
|
it 'does not call store_mentions' do
|
|
|
|
expect(merge_request).not_to receive(:store_mentions!).and_call_original
|
|
|
|
|
|
|
|
expect { subject }.not_to change { MergeRequestUserMention.count }
|
|
|
|
|
|
|
|
expect(merge_request.referenced_users).to be_empty
|
|
|
|
expect(merge_request.valid?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
shared_examples_for 'correct merge behavior' do
|
2016-11-24 09:05:15 -05:00
|
|
|
let(:opts) do
|
|
|
|
{
|
|
|
|
merge: merge_request.diff_head_sha
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2017-07-25 13:09:00 -04:00
|
|
|
let(:service) { described_class.new(project, user, opts) }
|
2016-11-24 09:05:15 -05:00
|
|
|
|
|
|
|
context 'without pipeline' do
|
|
|
|
before do
|
|
|
|
merge_request.merge_error = 'Error'
|
|
|
|
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
service.execute(merge_request)
|
|
|
|
@merge_request = MergeRequest.find(merge_request.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'merges the MR', :sidekiq_might_not_need_inline do
|
2017-05-15 05:39:56 -04:00
|
|
|
expect(@merge_request).to be_valid
|
|
|
|
expect(@merge_request.state).to eq('merged')
|
|
|
|
expect(@merge_request.merge_error).to be_nil
|
|
|
|
end
|
2016-11-24 09:05:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with finished pipeline' do
|
|
|
|
before do
|
2019-11-13 07:06:22 -05:00
|
|
|
create(:ci_pipeline,
|
2016-11-24 09:05:15 -05:00
|
|
|
project: project,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha,
|
|
|
|
status: :success)
|
|
|
|
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
@merge_request = service.execute(merge_request)
|
|
|
|
@merge_request = MergeRequest.find(merge_request.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'merges the MR', :sidekiq_might_not_need_inline do
|
2017-05-15 05:39:56 -04:00
|
|
|
expect(@merge_request).to be_valid
|
|
|
|
expect(@merge_request.state).to eq('merged')
|
|
|
|
end
|
2016-11-24 09:05:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with active pipeline' do
|
|
|
|
before do
|
|
|
|
service_mock = double
|
2017-05-19 16:51:07 -04:00
|
|
|
create(
|
2019-11-13 07:06:22 -05:00
|
|
|
:ci_pipeline,
|
2016-11-24 09:05:15 -05:00
|
|
|
project: project,
|
2017-05-19 16:51:07 -04:00
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha,
|
|
|
|
head_pipeline_of: merge_request
|
|
|
|
)
|
2017-03-22 15:36:14 -04:00
|
|
|
|
2019-11-15 10:06:12 -05:00
|
|
|
expect(AutoMerge::MergeWhenPipelineSucceedsService).to receive(:new).with(project, user, { sha: merge_request.diff_head_sha })
|
2017-06-21 09:48:12 -04:00
|
|
|
.and_return(service_mock)
|
2019-05-22 07:45:27 -04:00
|
|
|
allow(service_mock).to receive(:available_for?) { true }
|
2016-11-24 09:05:15 -05:00
|
|
|
expect(service_mock).to receive(:execute).with(merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { service.execute(merge_request) }
|
|
|
|
end
|
|
|
|
|
2016-12-30 14:49:59 -05:00
|
|
|
context 'with a non-authorised user' do
|
2016-11-24 09:05:15 -05:00
|
|
|
let(:visitor) { create(:user) }
|
2017-07-25 13:09:00 -04:00
|
|
|
let(:service) { described_class.new(project, visitor, opts) }
|
2016-11-24 09:05:15 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
merge_request.update_attribute(:merge_error, 'Error')
|
|
|
|
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
@merge_request = service.execute(merge_request)
|
|
|
|
@merge_request = MergeRequest.find(merge_request.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-15 05:39:56 -04:00
|
|
|
it 'does not merge the MR' do
|
|
|
|
expect(@merge_request.state).to eq('opened')
|
|
|
|
expect(@merge_request.merge_error).not_to be_nil
|
|
|
|
end
|
2016-11-24 09:05:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'MR can not be merged when note sha != MR sha' do
|
|
|
|
let(:opts) do
|
|
|
|
{
|
|
|
|
merge: 'other_commit'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
@merge_request = service.execute(merge_request)
|
|
|
|
@merge_request = MergeRequest.find(merge_request.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(@merge_request.state).to eq('opened') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
describe 'merge' do
|
|
|
|
it_behaves_like 'correct merge behavior'
|
|
|
|
|
|
|
|
context 'when merge_orchestration_service feature flag is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(merge_orchestration_service: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'correct merge behavior'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
context 'todos' do
|
|
|
|
let!(:pending_todo) { create(:todo, :assigned, user: user, project: project, target: merge_request, author: user2) }
|
2016-02-16 18:01:14 -05:00
|
|
|
|
2016-02-16 18:18:38 -05:00
|
|
|
context 'when the title change' do
|
|
|
|
before do
|
|
|
|
update_merge_request({ title: 'New title' })
|
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
it 'marks pending todos as done' do
|
|
|
|
expect(pending_todo.reload).to be_done
|
2016-02-16 18:18:38 -05:00
|
|
|
end
|
2017-03-28 02:25:43 -04:00
|
|
|
|
|
|
|
it 'does not create any new todos' do
|
|
|
|
expect(Todo.count).to eq(1)
|
|
|
|
end
|
2016-02-16 18:18:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the description change' do
|
|
|
|
before do
|
2017-03-28 02:25:43 -04:00
|
|
|
update_merge_request({ description: "Also please fix #{user2.to_reference} #{user3.to_reference}" })
|
2016-02-16 18:18:38 -05:00
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
it 'marks pending todos as done' do
|
|
|
|
expect(pending_todo.reload).to be_done
|
2016-02-16 18:18:38 -05:00
|
|
|
end
|
2017-03-28 02:25:43 -04:00
|
|
|
|
|
|
|
it 'creates only 1 new todo' do
|
|
|
|
expect(Todo.count).to eq(2)
|
|
|
|
end
|
2016-02-16 18:18:38 -05:00
|
|
|
end
|
|
|
|
|
2016-02-16 18:01:14 -05:00
|
|
|
context 'when is reassigned' do
|
|
|
|
before do
|
2019-04-07 14:35:16 -04:00
|
|
|
update_merge_request({ assignee_ids: [user2.id] })
|
2016-02-16 18:01:14 -05:00
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
it 'marks previous assignee pending todos as done' do
|
|
|
|
expect(pending_todo.reload).to be_done
|
2016-02-16 18:18:38 -05:00
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
it 'creates a pending todo for new assignee' do
|
2016-02-16 18:01:14 -05:00
|
|
|
attributes = {
|
|
|
|
project: project,
|
|
|
|
author: user,
|
|
|
|
user: user2,
|
2016-02-20 08:59:59 -05:00
|
|
|
target_id: merge_request.id,
|
|
|
|
target_type: merge_request.class.name,
|
|
|
|
action: Todo::ASSIGNED,
|
2016-02-16 18:01:14 -05:00
|
|
|
state: :pending
|
|
|
|
}
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
expect(Todo.where(attributes).count).to eq 1
|
2016-02-16 18:01:14 -05:00
|
|
|
end
|
|
|
|
end
|
2016-02-16 18:18:38 -05:00
|
|
|
|
2020-09-09 08:08:22 -04:00
|
|
|
context 'when reviewers gets changed' do
|
2020-09-21 08:09:34 -04:00
|
|
|
it 'marks pending todo as done' do
|
2020-09-09 08:08:22 -04:00
|
|
|
update_merge_request({ reviewer_ids: [user2.id] })
|
|
|
|
|
|
|
|
expect(pending_todo.reload).to be_done
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a pending todo for new review request' do
|
2020-09-21 08:09:34 -04:00
|
|
|
update_merge_request({ reviewer_ids: [user2.id] })
|
|
|
|
|
2020-09-09 08:08:22 -04:00
|
|
|
attributes = {
|
|
|
|
project: project,
|
|
|
|
author: user,
|
|
|
|
user: user2,
|
|
|
|
target_id: merge_request.id,
|
|
|
|
target_type: merge_request.class.name,
|
|
|
|
action: Todo::REVIEW_REQUESTED,
|
|
|
|
state: :pending
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(Todo.where(attributes).count).to eq 1
|
|
|
|
end
|
2020-09-21 08:09:34 -04:00
|
|
|
|
|
|
|
it 'sends email reviewer change notifications to old and new reviewers', :sidekiq_might_not_need_inline do
|
|
|
|
merge_request.reviewers = [user2]
|
|
|
|
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
update_merge_request({ reviewer_ids: [user3.id] })
|
|
|
|
end
|
|
|
|
|
|
|
|
should_email(user2)
|
|
|
|
should_email(user3)
|
|
|
|
end
|
2020-09-09 08:08:22 -04:00
|
|
|
end
|
|
|
|
|
2018-11-02 12:29:32 -04:00
|
|
|
context 'when the milestone is removed' do
|
|
|
|
let!(:non_subscriber) { create(:user) }
|
|
|
|
|
|
|
|
let!(:subscriber) do
|
|
|
|
create(:user) do |u|
|
|
|
|
merge_request.toggle_subscription(u, project)
|
|
|
|
project.add_developer(u)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'sends notifications for subscribers of changed milestone', :sidekiq_might_not_need_inline do
|
2019-01-14 05:46:39 -05:00
|
|
|
merge_request.milestone = create(:milestone, project: project)
|
2018-11-02 12:29:32 -04:00
|
|
|
|
2020-09-07 11:09:04 -04:00
|
|
|
merge_request.save!
|
2018-11-02 12:29:32 -04:00
|
|
|
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
update_merge_request(milestone_id: "")
|
|
|
|
end
|
|
|
|
|
|
|
|
should_email(subscriber)
|
|
|
|
should_not_email(non_subscriber)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the milestone is changed' do
|
|
|
|
let!(:non_subscriber) { create(:user) }
|
|
|
|
|
|
|
|
let!(:subscriber) do
|
|
|
|
create(:user) do |u|
|
|
|
|
merge_request.toggle_subscription(u, project)
|
|
|
|
project.add_developer(u)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-07 11:08:49 -04:00
|
|
|
it 'marks pending todos as done' do
|
2019-01-14 05:46:39 -05:00
|
|
|
update_merge_request({ milestone: create(:milestone, project: project) })
|
2016-02-16 18:18:38 -05:00
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
expect(pending_todo.reload).to be_done
|
2016-02-16 18:18:38 -05:00
|
|
|
end
|
2017-07-07 11:08:49 -04:00
|
|
|
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'sends notifications for subscribers of changed milestone', :sidekiq_might_not_need_inline do
|
2018-11-02 12:29:32 -04:00
|
|
|
perform_enqueued_jobs do
|
2019-01-14 05:46:39 -05:00
|
|
|
update_merge_request(milestone: create(:milestone, project: project))
|
2018-11-02 12:29:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
should_email(subscriber)
|
|
|
|
should_not_email(non_subscriber)
|
|
|
|
end
|
2016-02-16 18:18:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the labels change' do
|
|
|
|
before do
|
2020-10-02 08:09:03 -04:00
|
|
|
travel_to(1.minute.from_now) do
|
2018-06-01 11:09:08 -04:00
|
|
|
update_merge_request({ label_ids: [label.id] })
|
|
|
|
end
|
2016-02-16 18:18:38 -05:00
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
it 'marks pending todos as done' do
|
|
|
|
expect(pending_todo.reload).to be_done
|
2016-02-16 18:18:38 -05:00
|
|
|
end
|
2018-06-01 11:09:08 -04:00
|
|
|
|
|
|
|
it 'updates updated_at' do
|
2020-05-19 02:08:03 -04:00
|
|
|
expect(merge_request.reload.updated_at).to be > Time.current
|
2018-06-01 11:09:08 -04:00
|
|
|
end
|
2016-02-16 18:18:38 -05:00
|
|
|
end
|
|
|
|
|
2017-05-10 16:54:10 -04:00
|
|
|
context 'when the assignee changes' do
|
|
|
|
it 'updates open merge request counter for assignees when merge request is reassigned' do
|
2019-04-07 14:35:16 -04:00
|
|
|
update_merge_request(assignee_ids: [user2.id])
|
2017-05-10 16:54:10 -04:00
|
|
|
|
|
|
|
expect(user3.assigned_open_merge_requests_count).to eq 0
|
|
|
|
expect(user2.assigned_open_merge_requests_count).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-16 18:18:38 -05:00
|
|
|
context 'when the target branch change' do
|
|
|
|
before do
|
|
|
|
update_merge_request({ target_branch: 'target' })
|
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
it 'marks pending todos as done' do
|
2019-06-10 07:10:02 -04:00
|
|
|
expect(pending_todo.reload).to be_done
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when auto merge is enabled and target branch changed' do
|
|
|
|
before do
|
2019-11-15 10:06:12 -05:00
|
|
|
AutoMergeService.new(project, user, { sha: merge_request.diff_head_sha }).execute(merge_request, AutoMergeService::STRATEGY_MERGE_WHEN_PIPELINE_SUCCEEDS)
|
2019-06-10 07:10:02 -04:00
|
|
|
|
|
|
|
update_merge_request({ target_branch: 'target' })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'marks pending todos as done' do
|
2016-02-20 08:59:59 -05:00
|
|
|
expect(pending_todo.reload).to be_done
|
2016-02-16 18:18:38 -05:00
|
|
|
end
|
|
|
|
end
|
2016-02-16 18:01:14 -05:00
|
|
|
end
|
|
|
|
|
2019-04-04 03:20:43 -04:00
|
|
|
context 'when the merge request is relabeled' do
|
2016-03-01 11:33:13 -05:00
|
|
|
let!(:non_subscriber) { create(:user) }
|
2016-11-04 14:19:08 -04:00
|
|
|
let!(:subscriber) { create(:user) { |u| label.toggle_subscription(u, project) } }
|
2016-02-12 09:58:39 -05:00
|
|
|
|
2016-10-04 08:52:08 -04:00
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(non_subscriber)
|
|
|
|
project.add_developer(subscriber)
|
2016-10-04 08:52:08 -04:00
|
|
|
end
|
|
|
|
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'sends notifications for subscribers of newly added labels', :sidekiq_might_not_need_inline do
|
2016-02-12 09:58:39 -05:00
|
|
|
opts = { label_ids: [label.id] }
|
|
|
|
|
|
|
|
perform_enqueued_jobs do
|
2017-07-25 13:09:00 -04:00
|
|
|
@merge_request = described_class.new(project, user, opts).execute(merge_request)
|
2016-02-12 09:58:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
should_email(subscriber)
|
|
|
|
should_not_email(non_subscriber)
|
|
|
|
end
|
|
|
|
|
2016-03-01 11:33:13 -05:00
|
|
|
context 'when issue has the `label` label' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
merge_request.labels << label
|
|
|
|
end
|
2016-02-12 09:58:39 -05:00
|
|
|
|
2016-03-01 11:33:13 -05:00
|
|
|
it 'does not send notifications for existing labels' do
|
|
|
|
opts = { label_ids: [label.id, label2.id] }
|
2016-02-12 09:58:39 -05:00
|
|
|
|
2016-03-01 11:33:13 -05:00
|
|
|
perform_enqueued_jobs do
|
2017-07-25 13:09:00 -04:00
|
|
|
@merge_request = described_class.new(project, user, opts).execute(merge_request)
|
2016-03-01 11:33:13 -05:00
|
|
|
end
|
2016-02-12 09:58:39 -05:00
|
|
|
|
2016-03-01 11:33:13 -05:00
|
|
|
should_not_email(subscriber)
|
|
|
|
should_not_email(non_subscriber)
|
|
|
|
end
|
2016-02-12 09:58:39 -05:00
|
|
|
|
2016-03-01 11:33:13 -05:00
|
|
|
it 'does not send notifications for removed labels' do
|
|
|
|
opts = { label_ids: [label2.id] }
|
2016-02-12 09:58:39 -05:00
|
|
|
|
2016-03-01 11:33:13 -05:00
|
|
|
perform_enqueued_jobs do
|
2017-07-25 13:09:00 -04:00
|
|
|
@merge_request = described_class.new(project, user, opts).execute(merge_request)
|
2016-03-01 11:33:13 -05:00
|
|
|
end
|
2016-02-12 09:58:39 -05:00
|
|
|
|
2016-03-01 11:33:13 -05:00
|
|
|
should_not_email(subscriber)
|
|
|
|
should_not_email(non_subscriber)
|
2016-02-12 09:58:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-16 12:08:43 -04:00
|
|
|
context 'updating mentions' do
|
|
|
|
let(:mentionable) { merge_request }
|
2019-10-11 14:06:15 -04:00
|
|
|
|
2017-07-25 13:09:00 -04:00
|
|
|
include_examples 'updating mentions', described_class
|
2016-08-15 09:47:16 -04:00
|
|
|
end
|
|
|
|
|
2015-10-22 11:18:59 -04:00
|
|
|
context 'when MergeRequest has tasks' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
update_merge_request({ description: "- [ ] Task 1\n- [ ] Task 2" })
|
|
|
|
end
|
2015-10-22 11:18:59 -04:00
|
|
|
|
|
|
|
it { expect(@merge_request.tasks?).to eq(true) }
|
|
|
|
|
2019-01-29 19:31:31 -05:00
|
|
|
it_behaves_like 'updating a single task'
|
|
|
|
|
2015-10-22 11:18:59 -04:00
|
|
|
context 'when tasks are marked as completed' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
update_merge_request({ description: "- [x] Task 1\n- [X] Task 2" })
|
|
|
|
end
|
2015-10-22 11:18:59 -04:00
|
|
|
|
|
|
|
it 'creates system note about task status change' do
|
2016-11-23 01:55:23 -05:00
|
|
|
note1 = find_note('marked the task **Task 1** as completed')
|
|
|
|
note2 = find_note('marked the task **Task 2** as completed')
|
2015-10-22 11:18:59 -04:00
|
|
|
|
|
|
|
expect(note1).not_to be_nil
|
|
|
|
expect(note2).not_to be_nil
|
2017-06-08 13:56:41 -04:00
|
|
|
|
|
|
|
description_notes = find_notes('description')
|
|
|
|
expect(description_notes.length).to eq(1)
|
2015-10-22 11:18:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when tasks are marked as incomplete' do
|
|
|
|
before do
|
|
|
|
update_merge_request({ description: "- [x] Task 1\n- [X] Task 2" })
|
|
|
|
update_merge_request({ description: "- [ ] Task 1\n- [ ] Task 2" })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates system note about task status change' do
|
2016-11-23 01:55:23 -05:00
|
|
|
note1 = find_note('marked the task **Task 1** as incomplete')
|
|
|
|
note2 = find_note('marked the task **Task 2** as incomplete')
|
2015-10-22 11:18:59 -04:00
|
|
|
|
|
|
|
expect(note1).not_to be_nil
|
|
|
|
expect(note2).not_to be_nil
|
2017-06-08 13:56:41 -04:00
|
|
|
|
|
|
|
description_notes = find_notes('description')
|
|
|
|
expect(description_notes.length).to eq(1)
|
2015-10-22 11:18:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-09-19 03:26:25 -04:00
|
|
|
|
|
|
|
context 'while saving references to issues that the updated merge request closes' do
|
|
|
|
let(:first_issue) { create(:issue, project: project) }
|
|
|
|
let(:second_issue) { create(:issue, project: project) }
|
|
|
|
|
|
|
|
it 'creates a `MergeRequestsClosingIssues` record for each issue' do
|
|
|
|
issue_closing_opts = { description: "Closes #{first_issue.to_reference} and #{second_issue.to_reference}" }
|
|
|
|
service = described_class.new(project, user, issue_closing_opts)
|
|
|
|
allow(service).to receive(:execute_hooks)
|
|
|
|
service.execute(merge_request)
|
|
|
|
|
2016-09-20 16:45:02 -04:00
|
|
|
issue_ids = MergeRequestsClosingIssues.where(merge_request: merge_request).pluck(:issue_id)
|
|
|
|
expect(issue_ids).to match_array([first_issue.id, second_issue.id])
|
2016-09-19 03:26:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes `MergeRequestsClosingIssues` records when issues are not closed anymore' do
|
|
|
|
opts = {
|
|
|
|
title: 'Awesome merge_request',
|
|
|
|
description: "Closes #{first_issue.to_reference} and #{second_issue.to_reference}",
|
|
|
|
source_branch: 'feature',
|
|
|
|
target_branch: 'master',
|
|
|
|
force_remove_source_branch: '1'
|
|
|
|
}
|
|
|
|
|
|
|
|
merge_request = MergeRequests::CreateService.new(project, user, opts).execute
|
|
|
|
|
2016-09-20 16:45:02 -04:00
|
|
|
issue_ids = MergeRequestsClosingIssues.where(merge_request: merge_request).pluck(:issue_id)
|
|
|
|
expect(issue_ids).to match_array([first_issue.id, second_issue.id])
|
2016-09-19 03:26:25 -04:00
|
|
|
|
|
|
|
service = described_class.new(project, user, description: "not closing any issues")
|
|
|
|
allow(service).to receive(:execute_hooks)
|
|
|
|
service.execute(merge_request.reload)
|
|
|
|
|
2016-09-20 16:45:02 -04:00
|
|
|
issue_ids = MergeRequestsClosingIssues.where(merge_request: merge_request).pluck(:issue_id)
|
|
|
|
expect(issue_ids).to be_empty
|
2016-09-19 03:26:25 -04:00
|
|
|
end
|
2016-09-20 08:51:59 -04:00
|
|
|
end
|
2016-12-14 15:45:39 -05:00
|
|
|
|
2019-04-07 14:35:16 -04:00
|
|
|
context 'updating asssignee_ids' do
|
2017-05-04 08:11:15 -04:00
|
|
|
it 'does not update assignee when assignee_id is invalid' do
|
2020-09-07 11:09:04 -04:00
|
|
|
merge_request.update!(assignee_ids: [user.id])
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-04-07 14:35:16 -04:00
|
|
|
update_merge_request(assignee_ids: [-1])
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-04-07 14:35:16 -04:00
|
|
|
expect(merge_request.reload.assignees).to eq([user])
|
2017-05-04 08:11:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'unassigns assignee when user id is 0' do
|
2020-09-07 11:09:04 -04:00
|
|
|
merge_request.update!(assignee_ids: [user.id])
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-04-07 14:35:16 -04:00
|
|
|
update_merge_request(assignee_ids: [0])
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-04-07 14:35:16 -04:00
|
|
|
expect(merge_request.assignee_ids).to be_empty
|
2017-05-04 08:11:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves assignee when user id is valid' do
|
2019-04-07 14:35:16 -04:00
|
|
|
update_merge_request(assignee_ids: [user.id])
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-04-07 14:35:16 -04:00
|
|
|
expect(merge_request.assignee_ids).to eq([user.id])
|
2017-05-04 08:11:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update assignee_id when user cannot read issue' do
|
2019-04-07 14:35:16 -04:00
|
|
|
non_member = create(:user)
|
|
|
|
original_assignees = merge_request.assignees
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-04-07 14:35:16 -04:00
|
|
|
update_merge_request(assignee_ids: [non_member.id])
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-04-07 14:35:16 -04:00
|
|
|
expect(merge_request.reload.assignees).to eq(original_assignees)
|
2017-05-04 08:11:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when issuable feature is private" do
|
|
|
|
levels = [Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PUBLIC]
|
|
|
|
|
|
|
|
levels.each do |level|
|
|
|
|
it "does not update with unauthorized assignee when project is #{Gitlab::VisibilityLevel.level_name(level)}" do
|
|
|
|
assignee = create(:user)
|
2020-09-07 11:09:04 -04:00
|
|
|
project.update!(visibility_level: level)
|
2017-05-04 08:11:15 -04:00
|
|
|
feature_visibility_attr = :"#{merge_request.model_name.plural}_access_level"
|
|
|
|
project.project_feature.update_attribute(feature_visibility_attr, ProjectFeature::PRIVATE)
|
|
|
|
|
2019-07-08 20:41:22 -04:00
|
|
|
expect { update_merge_request(assignee_ids: [assignee]) }.not_to change(merge_request.assignees, :count)
|
2017-05-04 08:11:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-14 15:45:39 -05:00
|
|
|
include_examples 'issuable update service' do
|
|
|
|
let(:open_issuable) { merge_request }
|
|
|
|
let(:closed_issuable) { create(:closed_merge_request, source_project: project) }
|
|
|
|
end
|
2018-02-23 12:30:37 -05:00
|
|
|
|
2018-05-22 21:54:57 -04:00
|
|
|
context 'setting `allow_collaboration`' do
|
2018-10-25 09:48:03 -04:00
|
|
|
let(:target_project) { create(:project, :repository, :public) }
|
|
|
|
let(:source_project) { fork_project(target_project, nil, repository: true) }
|
2018-02-23 12:30:37 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request,
|
|
|
|
source_project: source_project,
|
|
|
|
source_branch: 'fixes',
|
|
|
|
target_project: target_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(ProtectedBranch).to receive(:protected?).with(source_project, 'fixes') { false }
|
|
|
|
end
|
|
|
|
|
2018-05-22 21:54:57 -04:00
|
|
|
it 'does not allow a maintainer of the target project to set `allow_collaboration`' do
|
2018-02-23 12:30:37 -05:00
|
|
|
target_project.add_developer(user)
|
|
|
|
|
2018-05-22 21:54:57 -04:00
|
|
|
update_merge_request(allow_collaboration: true, title: 'Updated title')
|
2018-02-23 12:30:37 -05:00
|
|
|
|
|
|
|
expect(merge_request.title).to eq('Updated title')
|
2018-05-22 21:54:57 -04:00
|
|
|
expect(merge_request.allow_collaboration).to be_falsy
|
2018-02-23 12:30:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is allowed by a user that can push to the source and can update the merge request' do
|
2019-04-07 14:35:16 -04:00
|
|
|
merge_request.update!(assignees: [user])
|
2018-02-23 12:30:37 -05:00
|
|
|
source_project.add_developer(user)
|
|
|
|
|
2018-05-22 21:54:57 -04:00
|
|
|
update_merge_request(allow_collaboration: true, title: 'Updated title')
|
2018-02-23 12:30:37 -05:00
|
|
|
|
|
|
|
expect(merge_request.title).to eq('Updated title')
|
2018-05-22 21:54:57 -04:00
|
|
|
expect(merge_request.allow_collaboration).to be_truthy
|
2018-02-23 12:30:37 -05:00
|
|
|
end
|
|
|
|
end
|
2019-09-25 12:25:40 -04:00
|
|
|
|
|
|
|
context 'updating `force_remove_source_branch`' do
|
|
|
|
let(:target_project) { create(:project, :repository, :public) }
|
|
|
|
let(:source_project) { fork_project(target_project, nil, repository: true) }
|
|
|
|
let(:user) { target_project.owner }
|
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request,
|
|
|
|
source_project: source_project,
|
|
|
|
source_branch: 'fixes',
|
|
|
|
target_project: target_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "cannot be done by members of the target project when they don't have access" do
|
|
|
|
expect { update_merge_request(force_remove_source_branch: true) }
|
|
|
|
.not_to change { merge_request.reload.force_remove_source_branch? }.from(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be done by members of the target project if they can push to the source project' do
|
|
|
|
source_project.add_developer(user)
|
|
|
|
|
|
|
|
expect { update_merge_request(force_remove_source_branch: true) }
|
|
|
|
.to change { merge_request.reload.force_remove_source_branch? }.from(nil).to(true)
|
|
|
|
end
|
|
|
|
end
|
2020-06-29 11:08:56 -04:00
|
|
|
|
|
|
|
it_behaves_like 'issuable record that supports quick actions' do
|
|
|
|
let(:existing_merge_request) { create(:merge_request, source_project: project) }
|
|
|
|
let(:issuable) { described_class.new(project, user, params).execute(existing_merge_request) }
|
|
|
|
end
|
2014-04-03 11:16:05 -04:00
|
|
|
end
|
|
|
|
end
|