Improve error message when attempting to reopen MR and there's a new open MR for the same branch

This commit is contained in:
Akos Gyimesi 2018-01-13 12:06:03 +01:00 committed by Nick Thomas
parent 2e3cefa6cd
commit 5fd5dad492
No known key found for this signature in database
GPG key ID: 2A313A47AFADACE9
3 changed files with 17 additions and 1 deletions

View file

@ -122,6 +122,10 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
respond_to do |format| respond_to do |format|
format.html do format.html do
if merge_request_params[:state_event] && @merge_request.errors.any?
flash[:alert] = @merge_request.errors.values.flatten.to_sentence
end
if @merge_request.valid? if @merge_request.valid?
redirect_to([@merge_request.target_project.namespace.becomes(Namespace), @merge_request.target_project, @merge_request]) redirect_to([@merge_request.target_project.namespace.becomes(Namespace), @merge_request.target_project, @merge_request])
else else

View file

@ -547,7 +547,7 @@ class MergeRequest < ActiveRecord::Base
similar_mrs = similar_mrs.where('id not in (?)', self.id) if self.id similar_mrs = similar_mrs.where('id not in (?)', self.id) if self.id
if similar_mrs.any? if similar_mrs.any?
errors.add :validate_branches, errors.add :validate_branches,
"Cannot Create: This merge request already exists: #{similar_mrs.pluck(:title)}" "Cannot open this Merge Request because another open Merge Request already exists for this source branch: #{similar_mrs.first.title}"
end end
end end
end end

View file

@ -290,6 +290,18 @@ describe Projects::MergeRequestsController do
it_behaves_like 'update invalid issuable', MergeRequest it_behaves_like 'update invalid issuable', MergeRequest
end end
context 'there are two merge requests with the same source branch' do
it "does not allow to reopen a closed merge request if another one is open" do
merge_request.close!
create(:merge_request, source_project: merge_request.source_project, source_branch: merge_request.source_branch)
update_merge_request(state_event: 'reopen')
expect(controller).to set_flash[:alert].to(/another open Merge Request already exists for this source branch/)
expect(merge_request.reload).to be_closed
end
end
end end
describe 'POST merge' do describe 'POST merge' do