2016-09-29 09:46:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'projects/merge_requests/show.html.haml' do
|
2016-11-03 12:29:30 +05:30
|
|
|
include Devise::Test::ControllerHelpers
|
2018-03-17 18:26:18 +05:30
|
|
|
include ProjectForksHelper
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:forked_project) { fork_project(project, user, repository: true) }
|
|
|
|
let(:unlink_project) { Projects::UnlinkForkService.new(forked_project, user) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:note) { create(:note_on_merge_request, project: project, noteable: closed_merge_request) }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
let(:closed_merge_request) do
|
|
|
|
create(:closed_merge_request,
|
2018-03-17 18:26:18 +05:30
|
|
|
source_project: forked_project,
|
2016-09-29 09:46:39 +05:30
|
|
|
target_project: project,
|
|
|
|
author: user)
|
|
|
|
end
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
def preload_view_requirements
|
|
|
|
# This will load the status fields of the author of the note and merge request
|
|
|
|
# to avoid queries in when rendering the view being tested.
|
|
|
|
closed_merge_request.author.status
|
|
|
|
note.author.status
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
before do
|
|
|
|
assign(:project, project)
|
|
|
|
assign(:merge_request, closed_merge_request)
|
|
|
|
assign(:commits_count, 0)
|
2017-08-17 22:00:37 +05:30
|
|
|
assign(:note, note)
|
|
|
|
assign(:noteable, closed_merge_request)
|
|
|
|
assign(:notes, [])
|
|
|
|
assign(:pipelines, Ci::Pipeline.none)
|
2019-02-15 15:39:39 +05:30
|
|
|
assign(:issuable_sidebar, serialize_issuable_sidebar(user, project, closed_merge_request))
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
preload_view_requirements
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
allow(view).to receive_messages(current_user: user,
|
|
|
|
can?: true,
|
|
|
|
current_application_settings: Gitlab::CurrentSettings.current_application_settings)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
describe 'merge request assignee sidebar' do
|
|
|
|
context 'when assignee is allowed to merge' do
|
|
|
|
it 'does not show a warning icon' do
|
|
|
|
closed_merge_request.update(assignee_id: user.id)
|
|
|
|
project.add_maintainer(user)
|
|
|
|
assign(:issuable_sidebar, serialize_issuable_sidebar(user, project, closed_merge_request))
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).not_to have_css('.cannot-be-merged')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when assignee is not allowed to merge' do
|
|
|
|
it 'shows a warning icon' do
|
|
|
|
reporter = create(:user)
|
|
|
|
project.add_reporter(reporter)
|
|
|
|
closed_merge_request.update(assignee_id: reporter.id)
|
|
|
|
assign(:issuable_sidebar, serialize_issuable_sidebar(user, project, closed_merge_request))
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_css('.cannot-be-merged')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
context 'when the merge request is closed' do
|
|
|
|
it 'shows the "Reopen" button' do
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_css('a', visible: true, text: 'Reopen')
|
|
|
|
expect(rendered).to have_css('a', visible: false, text: 'Close')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not show the "Reopen" button when the source project does not exist' do
|
|
|
|
unlink_project.execute
|
|
|
|
closed_merge_request.reload
|
2018-11-18 11:00:15 +05:30
|
|
|
preload_view_requirements
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_css('a', visible: false, text: 'Reopen')
|
|
|
|
expect(rendered).to have_css('a', visible: false, text: 'Close')
|
|
|
|
end
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
context 'when the merge request is open' do
|
|
|
|
it 'closes the merge request if the source project does not exist' do
|
2018-11-18 11:00:15 +05:30
|
|
|
closed_merge_request.update(state: 'open')
|
2018-03-17 18:26:18 +05:30
|
|
|
forked_project.destroy
|
|
|
|
# Reload merge request so MergeRequest#source_project turns to `nil`
|
|
|
|
closed_merge_request.reload
|
2018-11-18 11:00:15 +05:30
|
|
|
preload_view_requirements
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
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
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
def serialize_issuable_sidebar(user, project, merge_request)
|
|
|
|
MergeRequestSerializer
|
|
|
|
.new(current_user: user, project: project)
|
|
|
|
.represent(closed_merge_request, serializer: 'sidebar')
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|