Close merge request if open without source project

This commit is contained in:
Katarzyna Kobierska 2016-09-22 15:49:53 +02:00
parent dde9623183
commit 25edb0709c
2 changed files with 17 additions and 2 deletions

View file

@ -417,8 +417,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def validates_merge_request
# If source project was removed and merge request for some reason
# wasn't close (Ex. mr from fork to origin)
return invalid_mr if !@merge_request.source_project && @merge_request.open?
# wasn't close (Ex. mr from fork to origin) merge request will be closed
if !@merge_request.source_project && @merge_request.open?
@merge_request.close
end
# Show git not found page
# if there is no saved commits between source & target branch

View file

@ -41,4 +41,17 @@ describe 'projects/merge_requests/show.html.haml' do
expect(rendered).to have_css('a', visible: false, text: 'Close')
end
end
context 'when the merge request is open' do
it 'closes open merge request' do
closed_merge_request.update_attributes(state: 'open')
fork_project.destroy
render
expect(closed_merge_request.reload.state).to eq('closed')
expect(rendered).to have_css('a', visible: false, text: 'Reopen')
expect(rendered).to have_css('a', visible: false, text: 'Close')
end
end
end