2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe 'Merge Request button', feature_category: :projects do
|
2021-04-17 20:07:23 +05:30
|
|
|
include ProjectForksHelper
|
|
|
|
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :public, :repository) }
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
let(:forked_project) { fork_project(project, user, repository: true) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
shared_examples 'Merge request button only shown when allowed' do
|
2022-08-27 11:52:29 +05:30
|
|
|
let(:extra_mr_params) { {} }
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'not logged in' do
|
|
|
|
it 'does not show Create merge request button' do
|
|
|
|
visit url
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
within '.content-wrapper' do
|
|
|
|
expect(page).not_to have_link(label)
|
|
|
|
end
|
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
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'shows Create merge request button', :js do
|
|
|
|
href = project_new_merge_request_path(
|
|
|
|
project,
|
|
|
|
merge_request: {
|
2022-08-27 11:52:29 +05:30
|
|
|
source_branch: 'feature'
|
|
|
|
}.merge(extra_mr_params)
|
2021-04-17 20:07:23 +05:30
|
|
|
)
|
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
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
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-08-17 22:00:37 +05:30
|
|
|
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
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'shows Create merge request button', :js do
|
|
|
|
href = project_new_merge_request_path(
|
|
|
|
forked_project,
|
|
|
|
merge_request: {
|
2022-08-27 11:52:29 +05:30
|
|
|
source_branch: 'feature'
|
|
|
|
}.merge(extra_mr_params)
|
2021-04-17 20:07:23 +05:30
|
|
|
)
|
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' }
|
2018-03-27 19:54:05 +05:30
|
|
|
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-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on compare page' do
|
2021-04-17 20:07:23 +05:30
|
|
|
let(:label) { 'Create merge request' }
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it_behaves_like 'Merge request button only shown when allowed' do
|
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') }
|
2022-08-27 11:52:29 +05:30
|
|
|
let(:extra_mr_params) { { target_project_id: project.id, target_branch: 'master' } }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
it 'shows the correct merge request button when viewing across forks', :js do
|
|
|
|
sign_in(user)
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
href = project_new_merge_request_path(
|
2022-08-27 11:52:29 +05:30
|
|
|
forked_project,
|
2021-04-17 20:07:23 +05:30
|
|
|
merge_request: {
|
|
|
|
source_branch: 'feature',
|
|
|
|
target_project_id: project.id,
|
|
|
|
target_branch: 'master'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
visit project_compare_path(forked_project, from: 'master', to: 'feature', from_project_id: project.id)
|
|
|
|
|
|
|
|
within("#content-body") do
|
|
|
|
expect(page).to have_link(label, href: href)
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|