debian-mirror-gitlab/spec/features/projects/branches/user_creates_branch_spec.rb

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

128 lines
3.3 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'spec_helper'
2018-10-15 14:42:47 +05:30
2023-03-04 22:38:38 +05:30
RSpec.describe 'User creates branch', :js, feature_category: :projects do
2023-06-20 00:43:36 +05:30
include Features::BranchesHelpers
2018-10-15 14:42:47 +05:30
2022-10-11 01:57:18 +05:30
let_it_be(:group) { create(:group, :public) }
let_it_be(:user) { create(:user) }
2018-10-15 14:42:47 +05:30
2022-10-11 01:57:18 +05:30
shared_examples 'creates new branch' do
specify do
branch_name = "deploy_keys_#{SecureRandom.hex(4)}"
2018-10-15 14:42:47 +05:30
2022-10-11 01:57:18 +05:30
create_branch(branch_name)
expect(page).to have_content(branch_name)
end
end
shared_examples 'renders not found page' do
specify do
expect(page).to have_title('Not Found')
expect(page).to have_content('Page Not Found')
end
2018-10-15 14:42:47 +05:30
end
2022-10-11 01:57:18 +05:30
context 'when project is public with private repository' do
let_it_be(:project) { create(:project, :public, :repository, :repository_private, group: group) }
2018-10-15 14:42:47 +05:30
2022-10-11 01:57:18 +05:30
context 'when user is an inherited member from the group' do
context 'and user is a guest' do
before do
group.add_guest(user)
sign_in(user)
2018-10-15 14:42:47 +05:30
2022-10-11 01:57:18 +05:30
visit(new_project_branch_path(project))
end
2018-10-15 14:42:47 +05:30
2022-10-11 01:57:18 +05:30
it_behaves_like 'renders not found page'
end
2018-10-15 14:42:47 +05:30
2022-10-11 01:57:18 +05:30
context 'and user is a developer' do
before do
group.add_developer(user)
sign_in(user)
2018-10-15 14:42:47 +05:30
2022-10-11 01:57:18 +05:30
visit(new_project_branch_path(project))
end
2018-10-15 14:42:47 +05:30
2022-10-11 01:57:18 +05:30
it_behaves_like 'creates new branch'
end
2018-10-15 14:42:47 +05:30
end
end
2022-10-11 01:57:18 +05:30
context 'when project is private' do
let_it_be(:project) { create(:project, :private, :repository, group: group) }
context 'when user is a direct project member' do
context 'and user is a developer' do
before do
project.add_developer(user)
sign_in(user)
visit(new_project_branch_path(project))
end
context 'when on new branch page' do
it 'renders I18n supported text' do
page.within('#new-branch-form') do
expect(page).to have_content(_('Branch name'))
expect(page).to have_content(_('Create from'))
expect(page).to have_content(_('Existing branch name, tag, or commit SHA'))
end
end
end
it_behaves_like 'creates new branch'
context 'when branch name is invalid' do
it 'does not create new branch' do
invalid_branch_name = '1.0 stable'
2023-06-20 00:43:36 +05:30
fill_in("branch_name", with: invalid_branch_name)
find('body').click
click_button("Create branch")
2022-10-11 01:57:18 +05:30
expect(page).to have_content('Branch name is invalid')
expect(page).to have_content("can't contain spaces")
end
end
context 'when branch name already exists' do
it 'does not create new branch' do
create_branch('master')
expect(page).to have_content('Branch already exists')
end
end
end
end
context 'when user is an inherited member from the group' do
context 'and user is a guest' do
before do
group.add_guest(user)
sign_in(user)
visit(new_project_branch_path(project))
end
it_behaves_like 'renders not found page'
end
context 'and user is a developer' do
before do
group.add_developer(user)
sign_in(user)
visit(new_project_branch_path(project))
end
2018-10-15 14:42:47 +05:30
2022-10-11 01:57:18 +05:30
it_behaves_like 'creates new branch'
end
2018-10-15 14:42:47 +05:30
end
end
end