debian-mirror-gitlab/spec/features/projects/merge_request_button_spec.rb

105 lines
3.1 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
feature 'Merge Request button' do
2017-08-17 22:00:37 +05:30
shared_examples 'Merge request button only shown when allowed' do
let(:user) { create(:user) }
2017-09-10 17:25:29 +05:30
let(:project) { create(:project, :public, :repository) }
let(:forked_project) { create(:project, :public, :repository, forked_from_project: project) }
2017-08-17 22:00:37 +05:30
context 'not logged in' do
it 'does not show Create merge request button' do
visit url
2017-09-10 17:25:29 +05:30
expect(page).not_to have_link(label)
2017-08-17 22:00:37 +05:30
end
end
context 'logged in as developer' do
before do
2017-09-10 17:25:29 +05:30
sign_in(user)
project.add_developer(user)
2017-08-17 22:00:37 +05:30
end
it 'shows Create merge request button' do
2017-09-10 17:25:29 +05:30
href = project_new_merge_request_path(project,
merge_request: { source_branch: 'feature',
target_branch: 'master' })
2017-08-17 22:00:37 +05:30
visit url
2017-09-10 17:25:29 +05:30
within('#content-body') do
2017-08-17 22:00:37 +05:30
expect(page).to have_link(label, href: href)
end
end
context 'merge requests are disabled' do
before do
project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
end
it 'does not show Create merge request button' do
visit url
2017-09-10 17:25:29 +05:30
within('#content-body') do
2017-08-17 22:00:37 +05:30
expect(page).not_to have_link(label)
end
end
end
end
context 'logged in as non-member' do
before do
2017-09-10 17:25:29 +05:30
sign_in(user)
2017-08-17 22:00:37 +05:30
end
it 'does not show Create merge request button' do
visit url
2017-09-10 17:25:29 +05:30
within('#content-body') do
2017-08-17 22:00:37 +05:30
expect(page).not_to have_link(label)
end
end
context 'on own fork of project' do
let(:user) { forked_project.owner }
it 'shows Create merge request button' do
2017-09-10 17:25:29 +05:30
href = project_new_merge_request_path(forked_project,
merge_request: { source_branch: 'feature',
target_branch: 'master' })
2017-08-17 22:00:37 +05:30
visit fork_url
within("#content-body") do
expect(page).to have_link(label, href: href)
end
end
end
end
end
context 'on branches page' do
it_behaves_like 'Merge request button only shown when allowed' do
let(:label) { 'Merge request' }
2017-09-10 17:25:29 +05:30
let(:url) { project_branches_path(project, search: 'feature') }
let(:fork_url) { project_branches_path(forked_project, search: 'feature') }
2017-08-17 22:00:37 +05:30
end
end
context 'on compare page' do
it_behaves_like 'Merge request button only shown when allowed' do
let(:label) { 'Create merge request' }
2017-09-10 17:25:29 +05:30
let(:url) { project_compare_path(project, from: 'master', to: 'feature') }
let(:fork_url) { project_compare_path(forked_project, from: 'master', to: 'feature') }
2017-08-17 22:00:37 +05:30
end
end
context 'on commits page' do
it_behaves_like 'Merge request button only shown when allowed' do
let(:label) { 'Create merge request' }
2017-09-10 17:25:29 +05:30
let(:url) { project_commits_path(project, 'feature') }
let(:fork_url) { project_commits_path(forked_project, 'feature') }
2017-08-17 22:00:37 +05:30
end
end
end