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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

218 lines
5.7 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
2022-11-25 23:54:43 +05:30
shared_examples "increments the fork counter on the source project's page" do
specify :sidekiq_might_not_need_inline do
create_forks
visit project_path(project)
expect(page).to have_css('.fork-count', text: 2)
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) }
2022-11-25 23:54:43 +05:30
let(:group2) { create(:group) }
2021-04-29 21:17:54 +05:30
let(:user) { create(:group_member, :maintainer, user: create(:user), group: group ).user }
2022-11-25 23:54:43 +05:30
def submit_form(group_obj = group)
2022-10-11 01:57:18 +05:30
find('[data-testid="select_namespace_dropdown"]').click
2022-11-25 23:54:43 +05:30
find('[data-testid="select_namespace_dropdown_search_field"]').fill_in(with: group_obj.name)
click_button group_obj.name
2022-10-11 01:57:18 +05:30
2021-04-29 21:17:54 +05:30
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
2022-11-25 23:54:43 +05:30
context 'with cache_home_panel feature flag' do
before do
create(:group_member, :maintainer, user: user, group: group2 )
end
context 'when caching is enabled' do
before do
stub_feature_flags(cache_home_panel: project)
end
it_behaves_like "increments the fork counter on the source project's page"
end
context 'when caching is disabled' do
before do
stub_feature_flags(cache_home_panel: false)
end
it_behaves_like "increments the fork counter on the source project's page"
end
end
2021-04-29 21:17:54 +05:30
end
2018-03-17 18:26:18 +05:30
end
2022-11-25 23:54:43 +05:30
private
def create_fork(group_obj = group)
visit project_path(project)
find('.fork-btn').click
submit_form(group_obj)
wait_for_requests
end
def create_forks
create_fork
create_fork(group2)
end