2017-01-20 16:41:03 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
describe 'Merge Request button' do
|
2017-04-06 09:55:11 -04:00
|
|
|
shared_examples 'Merge request button only shown when allowed' do
|
2017-01-20 16:41:03 -05:00
|
|
|
let(:user) { create(:user) }
|
2017-07-24 18:51:14 -04:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:forked_project) { create(:project, :public, :repository, forked_from_project: project) }
|
2017-01-20 16:41:03 -05:00
|
|
|
|
|
|
|
context 'not logged in' do
|
2017-04-06 09:55:11 -04:00
|
|
|
it 'does not show Create merge request button' do
|
2017-01-20 16:41:03 -05:00
|
|
|
visit url
|
|
|
|
|
2017-07-14 09:36:37 -04:00
|
|
|
expect(page).not_to have_link(label)
|
2017-01-20 16:41:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'logged in as developer' do
|
|
|
|
before do
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-07-14 09:36:37 -04:00
|
|
|
project.add_developer(user)
|
2017-01-20 16:41:03 -05:00
|
|
|
end
|
|
|
|
|
2017-04-06 09:55:11 -04:00
|
|
|
it 'shows Create merge request button' do
|
2017-06-29 13:06:35 -04:00
|
|
|
href = project_new_merge_request_path(project,
|
2018-11-07 08:32:20 -05:00
|
|
|
merge_request: { source_branch: 'feature',
|
|
|
|
target_branch: 'master' })
|
2017-01-20 16:41:03 -05:00
|
|
|
|
|
|
|
visit url
|
|
|
|
|
2017-07-14 09:36:37 -04:00
|
|
|
within('#content-body') do
|
2017-01-25 05:07:02 -05:00
|
|
|
expect(page).to have_link(label, href: href)
|
|
|
|
end
|
2017-01-20 16:41:03 -05:00
|
|
|
end
|
2017-01-25 05:11:12 -05:00
|
|
|
|
|
|
|
context 'merge requests are disabled' do
|
|
|
|
before do
|
|
|
|
project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
|
|
|
|
end
|
|
|
|
|
2017-04-06 09:55:11 -04:00
|
|
|
it 'does not show Create merge request button' do
|
2017-01-25 05:11:12 -05:00
|
|
|
visit url
|
|
|
|
|
2017-07-14 09:36:37 -04:00
|
|
|
within('#content-body') do
|
2017-01-25 05:11:12 -05:00
|
|
|
expect(page).not_to have_link(label)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-04-06 06:47:52 -04:00
|
|
|
|
|
|
|
context 'when the project is archived' do
|
|
|
|
it 'hides the link' do
|
|
|
|
project.update!(archived: true)
|
|
|
|
|
|
|
|
visit url
|
|
|
|
|
|
|
|
within("#content-body") do
|
|
|
|
expect(page).not_to have_link(label)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-01-20 16:41:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'logged in as non-member' do
|
|
|
|
before do
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-01-20 16:41:03 -05:00
|
|
|
end
|
|
|
|
|
2017-04-06 09:55:11 -04:00
|
|
|
it 'does not show Create merge request button' do
|
2017-01-20 16:41:03 -05:00
|
|
|
visit url
|
|
|
|
|
2017-07-14 09:36:37 -04:00
|
|
|
within('#content-body') do
|
2017-01-25 05:07:02 -05:00
|
|
|
expect(page).not_to have_link(label)
|
|
|
|
end
|
2017-01-20 16:41:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'on own fork of project' do
|
|
|
|
let(:user) { forked_project.owner }
|
|
|
|
|
2017-04-06 09:55:11 -04:00
|
|
|
it 'shows Create merge request button' do
|
2017-06-29 13:06:35 -04:00
|
|
|
href = project_new_merge_request_path(forked_project,
|
2018-11-07 08:32:20 -05:00
|
|
|
merge_request: { source_branch: 'feature',
|
|
|
|
target_branch: 'master' })
|
2017-01-20 16:41:03 -05:00
|
|
|
|
|
|
|
visit fork_url
|
|
|
|
|
2017-01-25 05:07:02 -05:00
|
|
|
within("#content-body") do
|
|
|
|
expect(page).to have_link(label, href: href)
|
|
|
|
end
|
2017-01-20 16:41:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on branches page' do
|
2017-04-06 09:55:11 -04:00
|
|
|
it_behaves_like 'Merge request button only shown when allowed' do
|
|
|
|
let(:label) { 'Merge request' }
|
2017-11-15 09:56:36 -05:00
|
|
|
let(:url) { project_branches_filtered_path(project, state: 'all', search: 'feature') }
|
|
|
|
let(:fork_url) { project_branches_filtered_path(forked_project, state: 'all', search: 'feature') }
|
2017-01-20 16:41:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on compare page' do
|
2017-04-06 09:55:11 -04:00
|
|
|
it_behaves_like 'Merge request button only shown when allowed' do
|
|
|
|
let(:label) { 'Create merge request' }
|
2017-07-06 12:20:50 -04:00
|
|
|
let(:url) { project_compare_path(project, from: 'master', to: 'feature') }
|
|
|
|
let(:fork_url) { project_compare_path(forked_project, from: 'master', to: 'feature') }
|
2017-01-20 16:41:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on commits page' do
|
2017-04-06 09:55:11 -04:00
|
|
|
it_behaves_like 'Merge request button only shown when allowed' do
|
|
|
|
let(:label) { 'Create merge request' }
|
2017-07-06 12:20:50 -04:00
|
|
|
let(:url) { project_commits_path(project, 'feature') }
|
|
|
|
let(:fork_url) { project_commits_path(forked_project, 'feature') }
|
2017-01-20 16:41:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|