diff options
Diffstat (limited to 'spec/features/projects/branches/user_creates_branch_spec.rb')
-rw-r--r-- | spec/features/projects/branches/user_creates_branch_spec.rb | 133 |
1 files changed, 107 insertions, 26 deletions
diff --git a/spec/features/projects/branches/user_creates_branch_spec.rb b/spec/features/projects/branches/user_creates_branch_spec.rb index 18d083f7d88..be236b7ca7e 100644 --- a/spec/features/projects/branches/user_creates_branch_spec.rb +++ b/spec/features/projects/branches/user_creates_branch_spec.rb @@ -1,48 +1,129 @@ # frozen_string_literal: true -require "spec_helper" +require 'spec_helper' -RSpec.describe "User creates branch", :js do +RSpec.describe 'User creates branch', :js do include Spec::Support::Helpers::Features::BranchesHelpers - let(:user) { create(:user) } - let(:project) { create(:project, :repository) } + let_it_be(:group) { create(:group, :public) } + let_it_be(:user) { create(:user) } - before do - project.add_developer(user) - sign_in(user) + shared_examples 'creates new branch' do + specify do + branch_name = "deploy_keys_#{SecureRandom.hex(4)}" - visit(new_project_branch_path(project)) + 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 end - it "creates new branch" do - branch_name = "deploy_keys" + context 'when project is public with private repository' do + let_it_be(:project) { create(:project, :public, :repository, :repository_private, group: group) } - create_branch(branch_name) + 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) - expect(page).to have_content(branch_name) - end + visit(new_project_branch_path(project)) + end - context "when branch name is invalid" do - it "does not create new branch" do - invalid_branch_name = "1.0 stable" + it_behaves_like 'renders not found page' + end - fill_in("branch_name", with: invalid_branch_name) - page.find("body").click # defocus the branch_name input + context 'and user is a developer' do + before do + group.add_developer(user) + sign_in(user) - select_branch("master") - click_button("Create branch") + visit(new_project_branch_path(project)) + end - expect(page).to have_content("Branch name is invalid") - expect(page).to have_content("can't contain spaces") + it_behaves_like 'creates new branch' + end end end - context "when branch name already exists" do - it "does not create new branch" do - create_branch("master") + 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' + + fill_in('branch_name', with: invalid_branch_name) + page.find('body').click # defocus the branch_name input + + select_branch('master') + click_button('Create branch') + + 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 - expect(page).to have_content("Branch already exists") + it_behaves_like 'creates new branch' + end end end end |