2016-07-26 07:57:43 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'projects/merge_requests/show.html.haml' do
|
2016-09-21 19:06:33 -04:00
|
|
|
include Devise::Test::ControllerHelpers
|
2016-07-26 07:57:43 -04:00
|
|
|
|
2016-08-17 07:12:13 -04:00
|
|
|
let(:user) { create(:user) }
|
2016-07-26 07:57:43 -04:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:fork_project) { create(:project, forked_from_project: project) }
|
2016-08-17 07:12:13 -04:00
|
|
|
let(:unlink_project) { Projects::UnlinkForkService.new(fork_project, user) }
|
2016-12-29 14:30:50 -05:00
|
|
|
let(:note) { create(:note_on_merge_request, project: project, noteable: closed_merge_request) }
|
2016-08-09 09:43:15 -04:00
|
|
|
|
|
|
|
let(:closed_merge_request) do
|
|
|
|
create(:closed_merge_request,
|
2016-07-26 07:57:43 -04:00
|
|
|
source_project: fork_project,
|
2016-08-17 07:12:13 -04:00
|
|
|
target_project: project,
|
|
|
|
author: user)
|
2016-07-26 07:57:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
assign(:project, project)
|
2016-08-09 09:43:15 -04:00
|
|
|
assign(:merge_request, closed_merge_request)
|
2016-07-26 07:57:43 -04:00
|
|
|
assign(:commits_count, 0)
|
2016-12-29 14:30:50 -05:00
|
|
|
assign(:note, note)
|
|
|
|
assign(:noteable, closed_merge_request)
|
|
|
|
assign(:notes, [])
|
|
|
|
assign(:pipelines, Ci::Pipeline.none)
|
2016-07-26 07:57:43 -04:00
|
|
|
|
2016-12-29 14:30:50 -05:00
|
|
|
allow(view).to receive_messages(current_user: user, can?: true)
|
2016-07-26 07:57:43 -04:00
|
|
|
end
|
|
|
|
|
2016-08-10 09:36:30 -04:00
|
|
|
context 'when the merge request is closed' do
|
|
|
|
it 'shows the "Reopen" button' do
|
2016-07-26 07:57:43 -04:00
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_css('a', visible: true, text: 'Reopen')
|
|
|
|
expect(rendered).to have_css('a', visible: false, text: 'Close')
|
|
|
|
end
|
|
|
|
|
2016-08-10 09:36:30 -04:00
|
|
|
it 'does not show the "Reopen" button when the source project does not exist' do
|
2016-08-17 07:12:13 -04:00
|
|
|
unlink_project.execute
|
|
|
|
closed_merge_request.reload
|
2016-08-10 09:36:30 -04:00
|
|
|
|
2016-07-26 07:57:43 -04:00
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_css('a', visible: false, text: 'Reopen')
|
|
|
|
expect(rendered).to have_css('a', visible: false, text: 'Close')
|
|
|
|
end
|
|
|
|
end
|
2016-09-22 09:49:53 -04:00
|
|
|
|
|
|
|
context 'when the merge request is open' do
|
2016-09-23 04:18:54 -04:00
|
|
|
it 'closes the merge request if the source project does not exist' do
|
2016-09-22 09:49:53 -04:00
|
|
|
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
|
2016-07-26 07:57:43 -04:00
|
|
|
end
|