2016-09-13 17:45:13 +05:30
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe 'Merge request > User uses quick actions', :js do
|
2017-09-10 17:25:29 +05:30
|
|
|
include QuickActionsHelpers
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:user) { project.creator }
|
|
|
|
let(:guest) { create(:user) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project) }
|
|
|
|
let!(:milestone) { create(:milestone, project: project, title: 'ASAP') }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it_behaves_like 'issuable record that supports quick actions in its description and notes', :merge_request do
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:issuable) { create(:merge_request, source_project: project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:new_url_opts) { { merge_request: { source_branch: 'feature', target_branch: 'master' } } }
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
describe 'merge-request-only commands' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project) }
|
|
|
|
let!(:milestone) { create(:milestone, project: project, title: 'ASAP') }
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_master(user)
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
|
|
|
visit project_merge_request_path(project, merge_request)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe 'time tracking' do
|
|
|
|
it_behaves_like 'issuable time tracker'
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
describe 'toggling the WIP prefix in the title from note' do
|
|
|
|
context 'when the current user can toggle the WIP prefix' do
|
|
|
|
it 'adds the WIP: prefix to the title' do
|
|
|
|
write_note("/wip")
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
expect(page).not_to have_content '/wip'
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(page).to have_content 'Commands applied'
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
expect(merge_request.reload.work_in_progress?).to eq true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes the WIP: prefix from the title' do
|
|
|
|
merge_request.title = merge_request.wip_title
|
|
|
|
merge_request.save
|
|
|
|
write_note("/wip")
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/wip'
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(page).to have_content 'Commands applied'
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
expect(merge_request.reload.work_in_progress?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the current user cannot toggle the WIP prefix' do
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_guest(guest)
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_out(:user)
|
|
|
|
sign_in(guest)
|
|
|
|
visit project_merge_request_path(project, merge_request)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not change the WIP prefix' do
|
|
|
|
write_note("/wip")
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/wip'
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(page).not_to have_content 'Commands applied'
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
expect(merge_request.reload.work_in_progress?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe 'merging the MR from the note' do
|
|
|
|
context 'when the current user can merge the MR' do
|
|
|
|
it 'merges the MR' do
|
|
|
|
write_note("/merge")
|
|
|
|
|
|
|
|
expect(page).to have_content 'Commands applied'
|
|
|
|
|
|
|
|
expect(merge_request.reload).to be_merged
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the head diff changes in the meanwhile' do
|
|
|
|
before do
|
|
|
|
merge_request.source_branch = 'another_branch'
|
|
|
|
merge_request.save
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not merge the MR' do
|
|
|
|
write_note("/merge")
|
|
|
|
|
|
|
|
expect(page).not_to have_content 'Your commands have been executed!'
|
|
|
|
|
|
|
|
expect(merge_request.reload).not_to be_merged
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the current user cannot merge the MR' do
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_guest(guest)
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_out(:user)
|
|
|
|
sign_in(guest)
|
|
|
|
visit project_merge_request_path(project, merge_request)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not merge the MR' do
|
|
|
|
write_note("/merge")
|
|
|
|
|
|
|
|
expect(page).not_to have_content 'Your commands have been executed!'
|
|
|
|
|
|
|
|
expect(merge_request.reload).not_to be_merged
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
describe 'adding a due date from note' do
|
|
|
|
it 'does not recognize the command nor create a note' do
|
|
|
|
write_note('/due 2016-08-28')
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/due 2016-08-28'
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '/target_branch command in merge request' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:another_project) { create(:project, :public, :repository) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:new_url_opts) { { merge_request: { source_branch: 'feature' } } }
|
|
|
|
|
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_out(:user)
|
2018-03-17 18:26:18 +05:30
|
|
|
another_project.add_master(user)
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'changes target_branch in new merge_request' do
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_new_merge_request_path(another_project, new_url_opts)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
fill_in "merge_request_title", with: 'My brand new feature'
|
|
|
|
fill_in "merge_request_description", with: "le feature \n/target_branch fix\nFeature description:"
|
|
|
|
click_button "Submit merge request"
|
|
|
|
|
|
|
|
merge_request = another_project.merge_requests.first
|
|
|
|
expect(merge_request.description).to eq "le feature \nFeature description:"
|
|
|
|
expect(merge_request.target_branch).to eq 'fix'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not change target branch when merge request is edited' do
|
|
|
|
new_merge_request = create(:merge_request, source_project: another_project)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
visit edit_project_merge_request_path(another_project, new_merge_request)
|
2017-08-17 22:00:37 +05:30
|
|
|
fill_in "merge_request_description", with: "Want to update target branch\n/target_branch fix\n"
|
|
|
|
click_button "Save changes"
|
|
|
|
|
|
|
|
new_merge_request = another_project.merge_requests.first
|
|
|
|
expect(new_merge_request.description).to include('/target_branch')
|
|
|
|
expect(new_merge_request.target_branch).not_to eq('fix')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '/target_branch command from note' do
|
|
|
|
context 'when the current user can change target branch' do
|
|
|
|
it 'changes target branch from a note' do
|
|
|
|
write_note("message start \n/target_branch merge-test\n message end.")
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
wait_for_requests
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(page).not_to have_content('/target_branch')
|
|
|
|
expect(page).to have_content('message start')
|
|
|
|
expect(page).to have_content('message end.')
|
|
|
|
|
|
|
|
expect(merge_request.reload.target_branch).to eq 'merge-test'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not fail when target branch does not exists' do
|
|
|
|
write_note('/target_branch totally_not_existing_branch')
|
|
|
|
|
|
|
|
expect(page).not_to have_content('/target_branch')
|
|
|
|
|
|
|
|
expect(merge_request.target_branch).to eq 'feature'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when current user can not change target branch' do
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_guest(guest)
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_out(:user)
|
|
|
|
sign_in(guest)
|
|
|
|
visit project_merge_request_path(project, merge_request)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not change target branch' do
|
|
|
|
write_note('/target_branch merge-test')
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/target_branch merge-test'
|
|
|
|
|
|
|
|
expect(merge_request.target_branch).to eq 'feature'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|