2017-01-20 21:41:03 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
feature 'Merge Request button', feature: true do
|
2017-04-06 13:55:11 +00:00
|
|
|
shared_examples 'Merge request button only shown when allowed' do
|
2017-01-20 21:41:03 +00:00
|
|
|
let(:user) { create(:user) }
|
2017-01-25 10:07:02 +00:00
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:forked_project) { create(:project, :public, forked_from_project: project) }
|
2017-01-20 21:41:03 +00:00
|
|
|
|
|
|
|
context 'not logged in' do
|
2017-04-06 13:55:11 +00:00
|
|
|
it 'does not show Create merge request button' do
|
2017-01-20 21:41:03 +00:00
|
|
|
visit url
|
|
|
|
|
2017-01-25 10:07:02 +00:00
|
|
|
within("#content-body") do
|
|
|
|
expect(page).not_to have_link(label)
|
|
|
|
end
|
2017-01-20 21:41:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'logged in as developer' do
|
|
|
|
before do
|
|
|
|
login_as(user)
|
|
|
|
project.team << [user, :developer]
|
|
|
|
end
|
|
|
|
|
2017-04-06 13:55:11 +00:00
|
|
|
it 'shows Create merge request button' do
|
2017-01-20 21:41:03 +00:00
|
|
|
href = new_namespace_project_merge_request_path(project.namespace,
|
|
|
|
project,
|
|
|
|
merge_request: { source_branch: 'feature',
|
|
|
|
target_branch: 'master' })
|
|
|
|
|
|
|
|
visit url
|
|
|
|
|
2017-01-25 10:07:02 +00:00
|
|
|
within("#content-body") do
|
|
|
|
expect(page).to have_link(label, href: href)
|
|
|
|
end
|
2017-01-20 21:41:03 +00:00
|
|
|
end
|
2017-01-25 10:11:12 +00:00
|
|
|
|
|
|
|
context 'merge requests are disabled' do
|
|
|
|
before do
|
|
|
|
project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
|
|
|
|
end
|
|
|
|
|
2017-04-06 13:55:11 +00:00
|
|
|
it 'does not show Create merge request button' do
|
2017-01-25 10:11:12 +00:00
|
|
|
visit url
|
|
|
|
|
|
|
|
within("#content-body") do
|
|
|
|
expect(page).not_to have_link(label)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-01-20 21:41:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'logged in as non-member' do
|
|
|
|
before do
|
|
|
|
login_as(user)
|
|
|
|
end
|
|
|
|
|
2017-04-06 13:55:11 +00:00
|
|
|
it 'does not show Create merge request button' do
|
2017-01-20 21:41:03 +00:00
|
|
|
visit url
|
|
|
|
|
2017-01-25 10:07:02 +00:00
|
|
|
within("#content-body") do
|
|
|
|
expect(page).not_to have_link(label)
|
|
|
|
end
|
2017-01-20 21:41:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'on own fork of project' do
|
|
|
|
let(:user) { forked_project.owner }
|
|
|
|
|
2017-04-06 13:55:11 +00:00
|
|
|
it 'shows Create merge request button' do
|
2017-01-20 21:41:03 +00:00
|
|
|
href = new_namespace_project_merge_request_path(forked_project.namespace,
|
|
|
|
forked_project,
|
|
|
|
merge_request: { source_branch: 'feature',
|
|
|
|
target_branch: 'master' })
|
|
|
|
|
|
|
|
visit fork_url
|
|
|
|
|
2017-01-25 10:07:02 +00:00
|
|
|
within("#content-body") do
|
|
|
|
expect(page).to have_link(label, href: href)
|
|
|
|
end
|
2017-01-20 21:41:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on branches page' do
|
2017-04-06 13:55:11 +00:00
|
|
|
it_behaves_like 'Merge request button only shown when allowed' do
|
|
|
|
let(:label) { 'Merge request' }
|
2017-01-20 21:41:03 +00:00
|
|
|
let(:url) { namespace_project_branches_path(project.namespace, project) }
|
|
|
|
let(:fork_url) { namespace_project_branches_path(forked_project.namespace, forked_project) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on compare page' do
|
2017-04-06 13:55:11 +00:00
|
|
|
it_behaves_like 'Merge request button only shown when allowed' do
|
|
|
|
let(:label) { 'Create merge request' }
|
2017-01-20 21:41:03 +00:00
|
|
|
let(:url) { namespace_project_compare_path(project.namespace, project, from: 'master', to: 'feature') }
|
|
|
|
let(:fork_url) { namespace_project_compare_path(forked_project.namespace, forked_project, from: 'master', to: 'feature') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on commits page' do
|
2017-04-06 13:55:11 +00:00
|
|
|
it_behaves_like 'Merge request button only shown when allowed' do
|
|
|
|
let(:label) { 'Create merge request' }
|
2017-01-20 21:41:03 +00:00
|
|
|
let(:url) { namespace_project_commits_path(project.namespace, project, 'feature') }
|
|
|
|
let(:fork_url) { namespace_project_commits_path(forked_project.namespace, forked_project, 'feature') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|