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

363 lines
9.9 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'Project fork' do
2018-03-17 18:26:18 +05:30
include ProjectForksHelper
let(:user) { create(:user) }
2021-06-08 01:23:25 +05:30
let(:project) { create(:project, :public, :repository, description: 'some description') }
2018-03-17 18:26:18 +05:30
before do
2021-03-11 19:13:27 +05:30
sign_in(user)
2018-03-17 18:26:18 +05:30
end
2021-04-17 20:07:23 +05:30
shared_examples 'fork button on project page' do
it 'allows user to fork project from the project page' do
2021-03-11 19:13:27 +05:30
visit project_path(project)
2021-04-17 20:07:23 +05:30
expect(page).not_to have_css('a.disabled', text: 'Fork')
2021-03-11 19:13:27 +05:30
end
2021-04-17 20:07:23 +05:30
context 'user has exceeded personal project limit' do
before do
user.update!(projects_limit: 0)
2021-03-11 19:13:27 +05:30
end
2021-04-17 20:07:23 +05:30
it 'disables fork button on project page' do
visit project_path(project)
2021-03-11 19:13:27 +05:30
2021-04-17 20:07:23 +05:30
expect(page).to have_css('a.disabled', text: 'Fork')
2021-03-11 19:13:27 +05:30
end
end
2018-03-17 18:26:18 +05:30
end
2021-04-17 20:07:23 +05:30
shared_examples 'create fork page' do |fork_page_text|
2020-03-13 15:44:24 +05:30
before do
project.project_feature.update_attribute(
:forking_access_level, forking_access_level)
end
context 'forking is enabled' do
let(:forking_access_level) { ProjectFeature::ENABLED }
it 'enables fork button' do
visit project_path(project)
expect(page).to have_css('a', text: 'Fork')
2020-10-24 23:57:45 +05:30
expect(page).not_to have_css('a.disabled', text: 'Select')
2020-03-13 15:44:24 +05:30
end
it 'renders new project fork page' do
visit new_project_fork_path(project)
expect(page.status_code).to eq(200)
2021-04-17 20:07:23 +05:30
expect(page).to have_text(fork_page_text)
2020-03-13 15:44:24 +05:30
end
end
context 'forking is disabled' do
let(:forking_access_level) { ProjectFeature::DISABLED }
2022-01-26 12:08:38 +05:30
it 'render a disabled fork button' do
2020-03-13 15:44:24 +05:30
visit project_path(project)
2022-01-26 12:08:38 +05:30
expect(page).to have_css('a.disabled', text: 'Fork')
expect(page).to have_css('a.count', text: '0')
2020-03-13 15:44:24 +05:30
end
it 'does not render new project fork page' do
visit new_project_fork_path(project)
expect(page.status_code).to eq(404)
end
end
context 'forking is private' do
let(:forking_access_level) { ProjectFeature::PRIVATE }
before do
2021-04-29 21:17:54 +05:30
project.update!(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
2020-03-13 15:44:24 +05:30
end
context 'user is not a team member' do
2022-01-26 12:08:38 +05:30
it 'render a disabled fork button' do
2020-03-13 15:44:24 +05:30
visit project_path(project)
2022-01-26 12:08:38 +05:30
expect(page).to have_css('a.disabled', text: 'Fork')
expect(page).to have_css('a.count', text: '0')
2020-03-13 15:44:24 +05:30
end
it 'does not render new project fork page' do
visit new_project_fork_path(project)
expect(page.status_code).to eq(404)
end
end
context 'user is a team member' do
before do
project.add_developer(user)
end
it 'enables fork button' do
visit project_path(project)
expect(page).to have_css('a', text: 'Fork')
2022-01-26 12:08:38 +05:30
expect(page).to have_css('a.count', text: '0')
2020-03-13 15:44:24 +05:30
expect(page).not_to have_css('a.disabled', text: 'Fork')
end
it 'renders new project fork page' do
visit new_project_fork_path(project)
expect(page.status_code).to eq(200)
2021-04-17 20:07:23 +05:30
expect(page).to have_text(fork_page_text)
2020-03-13 15:44:24 +05:30
end
end
end
end
2021-04-17 20:07:23 +05:30
it_behaves_like 'fork button on project page'
it_behaves_like 'create fork page', 'Fork project'
2018-05-09 12:01:36 +05:30
2021-04-29 21:17:54 +05:30
context 'fork form', :js do
let(:group) { create(:group) }
let(:user) { create(:group_member, :maintainer, user: create(:user), group: group ).user }
def submit_form
select(group.name)
click_button 'Fork project'
end
it 'forks the project', :sidekiq_might_not_need_inline do
visit new_project_fork_path(project)
submit_form
expect(page).to have_content 'Forked from'
end
it 'shows the new forked project on the forks page' do
visit new_project_fork_path(project)
submit_form
wait_for_requests
visit project_forks_path(project)
page.within('.js-projects-list-holder') do
expect(page).to have_content("#{group.name} / #{project.name}")
end
end
it 'shows the filled in info forked project on the forks page' do
fork_name = 'some-name'
visit new_project_fork_path(project)
fill_in('fork-name', with: fork_name, fill_options: { clear: :backspace })
fill_in('fork-slug', with: fork_name, fill_options: { clear: :backspace })
submit_form
wait_for_requests
visit project_forks_path(project)
page.within('.js-projects-list-holder') do
expect(page).to have_content("#{group.name} / #{fork_name}")
end
end
end
2021-04-17 20:07:23 +05:30
context 'with fork_project_form feature flag disabled' do
before do
stub_feature_flags(fork_project_form: false)
sign_in(user)
2018-05-09 12:01:36 +05:30
end
2021-04-17 20:07:23 +05:30
it_behaves_like 'fork button on project page'
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
context 'user has exceeded personal project limit' do
before do
user.update!(projects_limit: 0)
end
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
context 'with a group to fork to' do
let!(:group) { create(:group).tap { |group| group.add_owner(user) } }
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
it 'allows user to fork only to the group on fork page', :js do
visit new_project_fork_path(project)
2018-05-09 12:01:36 +05:30
2021-10-27 15:23:28 +05:30
to_personal_namespace = find('[data-qa-selector=fork_namespace_button].disabled') # rubocop:disable QA/SelectorUsage
to_group = find(".fork-groups button[data-qa-name=#{group.name}]") # rubocop:disable QA/SelectorUsage
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
expect(to_personal_namespace).not_to be_nil
expect(to_group).not_to be_disabled
end
end
2018-05-09 12:01:36 +05:30
end
2021-04-17 20:07:23 +05:30
it_behaves_like 'create fork page', ' Select a namespace to fork the project '
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
it 'forks the project', :sidekiq_might_not_need_inline do
visit project_path(project)
2018-11-20 20:47:30 +05:30
2021-04-17 20:07:23 +05:30
click_link 'Fork'
2018-11-20 20:47:30 +05:30
2021-04-17 20:07:23 +05:30
page.within '.fork-thumbnail-container' do
click_link 'Select'
end
2018-11-20 20:47:30 +05:30
2021-04-17 20:07:23 +05:30
expect(page).to have_content 'Forked from'
2018-11-20 20:47:30 +05:30
2021-04-17 20:07:23 +05:30
visit project_path(project)
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
expect(page).to have_content(/new merge request/i)
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
page.within '.nav-sidebar' do
2021-04-29 21:17:54 +05:30
first(:link, 'Merge requests').click
2021-04-17 20:07:23 +05:30
end
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
expect(page).to have_content(/new merge request/i)
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
page.within '#content-body' do
click_link('New merge request')
end
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
expect(current_path).to have_content(/#{user.namespace.path}/i)
2018-05-09 12:01:36 +05:30
end
2021-04-17 20:07:23 +05:30
it 'shows avatars when Gravatar is disabled' do
stub_application_setting(gravatar_enabled: false)
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
visit project_path(project)
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
click_link 'Fork'
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
page.within('.fork-thumbnail-container') do
2021-06-08 01:23:25 +05:30
expect(page).to have_css('span.identicon')
2021-04-17 20:07:23 +05:30
end
2018-05-09 12:01:36 +05:30
end
2021-04-17 20:07:23 +05:30
it 'shows the forked project on the list' do
2018-05-09 12:01:36 +05:30
visit project_path(project)
click_link 'Fork'
page.within '.fork-thumbnail-container' do
2020-10-24 23:57:45 +05:30
click_link 'Select'
2018-05-09 12:01:36 +05:30
end
visit project_forks_path(project)
2021-04-17 20:07:23 +05:30
forked_project = user.fork_of(project.reload)
2018-05-09 12:01:36 +05:30
page.within('.js-projects-list-holder') do
2021-04-17 20:07:23 +05:30
expect(page).to have_content("#{forked_project.namespace.human_name} / #{forked_project.name}")
2018-05-09 12:01:36 +05:30
end
2021-04-17 20:07:23 +05:30
forked_project.update!(path: 'test-crappy-path')
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
visit project_forks_path(project)
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
page.within('.js-projects-list-holder') do
expect(page).to have_content("#{forked_project.namespace.human_name} / #{forked_project.name}")
end
end
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
context 'when the project is private' do
let(:project) { create(:project, :repository) }
let(:another_user) { create(:user, name: 'Mike') }
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
before do
project.add_reporter(user)
project.add_reporter(another_user)
2018-05-09 12:01:36 +05:30
end
2021-04-17 20:07:23 +05:30
it 'renders private forks of the project' do
visit project_path(project)
2018-05-09 12:01:36 +05:30
2021-04-17 20:07:23 +05:30
another_project_fork = Projects::ForkService.new(project, another_user).execute
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
click_link 'Fork'
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
page.within '.fork-thumbnail-container' do
click_link 'Select'
end
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
visit project_forks_path(project)
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
page.within('.js-projects-list-holder') do
user_project_fork = user.fork_of(project.reload)
expect(page).to have_content("#{user_project_fork.namespace.human_name} / #{user_project_fork.name}")
end
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
expect(page).not_to have_content("#{another_project_fork.namespace.human_name} / #{another_project_fork.name}")
end
2018-03-17 18:26:18 +05:30
end
2021-04-17 20:07:23 +05:30
context 'when the user already forked the project' do
before do
create(:project, :repository, name: project.name, namespace: user.namespace)
end
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
it 'renders error' do
visit project_path(project)
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
click_link 'Fork'
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
page.within '.fork-thumbnail-container' do
click_link 'Select'
end
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
expect(page).to have_content "Name has already been taken"
end
2018-03-17 18:26:18 +05:30
end
2021-04-17 20:07:23 +05:30
context 'maintainer in group' do
let(:group) { create(:group) }
before do
group.add_maintainer(user)
end
it 'allows user to fork project to group or to user namespace', :js do
visit project_path(project)
wait_for_requests
expect(page).not_to have_css('a.disabled', text: 'Fork')
click_link 'Fork'
expect(page).to have_css('.fork-thumbnail')
expect(page).to have_css('.group-row')
expect(page).not_to have_css('.fork-thumbnail.disabled')
end
it 'allows user to fork project to group and not user when exceeded project limit', :js do
user.projects_limit = 0
user.save!
visit project_path(project)
wait_for_requests
expect(page).not_to have_css('a.disabled', text: 'Fork')
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
click_link 'Fork'
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
expect(page).to have_css('.fork-thumbnail.disabled')
expect(page).to have_css('.group-row')
end
it 'links to the fork if the project was already forked within that namespace', :sidekiq_might_not_need_inline, :js do
forked_project = fork_project(project, user, namespace: group, repository: true)
visit new_project_fork_path(project)
wait_for_requests
expect(page).to have_css('.group-row a.btn', text: 'Go to fork')
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
click_link 'Go to fork'
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
expect(current_path).to eq(project_path(forked_project))
end
2018-03-17 18:26:18 +05:30
end
end
end