Welcome to mirror list, hosted at ThFree Co, Russian Federation.

user_creates_branch_spec.rb « branches « projects « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: be236b7ca7e027633a13f48c5f9fe98fc7db2cd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'User creates branch', :js do
  include Spec::Support::Helpers::Features::BranchesHelpers

  let_it_be(:group) { create(:group, :public) }
  let_it_be(:user) { create(:user) }

  shared_examples 'creates new branch' do
    specify do
      branch_name = "deploy_keys_#{SecureRandom.hex(4)}"

      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

  context 'when project is public with private repository' do
    let_it_be(:project) { create(:project, :public, :repository, :repository_private, group: group) }

    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

        it_behaves_like 'creates new branch'
      end
    end
  end

  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

        it_behaves_like 'creates new branch'
      end
    end
  end
end