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

user_sees_git_instructions_spec.rb « show « projects « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5270939f681479a70efc002dcbf8816e54b4ff04 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Projects > Show > User sees Git instructions' do
  let_it_be(:user) { create(:user) }

  before do
    # Reset user notification settings between examples to prevent
    # validation failure on NotificationSetting.
    # See https://gitlab.com/gitlab-org/gitlab/-/issues/299822#note_492817174
    user.notification_settings.reset
  end

  shared_examples_for 'redirects to the sign in page' do
    it 'redirects to the sign in page' do
      expect(current_path).to eq(new_user_session_path)
    end
  end

  shared_examples_for 'shows details of empty project with no repo' do
    it 'shows Git command line instructions' do
      click_link 'Create empty repository'

      page.within '.empty-wrapper' do
        expect(page).to have_content('Command line instructions')
      end

      expect(page).to have_content("git push -u origin master")
    end
  end

  shared_examples_for 'shows details of empty project' do
    let(:user_has_ssh_key) { false }

    it 'shows details' do
      expect(page).not_to have_content('Git global setup')

      page.all(:css, '.git-empty .clone').each do |element|
        expect(element.text).to include(project.http_url_to_repo)
      end

      expect(page).to have_field('http_project_clone', with: project.http_url_to_repo) unless user_has_ssh_key
    end
  end

  shared_examples_for 'shows details of non empty project' do
    let(:user_has_ssh_key) { false }

    it 'shows details' do
      page.within('.breadcrumbs .breadcrumb-item-text') do
        expect(page).to have_content(project.title)
      end

      expect(page).to have_field('http_project_clone', with: project.http_url_to_repo) unless user_has_ssh_key
    end
  end

  context 'when project is public' do
    context 'when project has no repo' do
      let_it_be(:project) { create(:project, :public) }

      before do
        sign_in(project.first_owner)
        visit project_path(project)
      end

      include_examples 'shows details of empty project with no repo'
    end

    context ":default_branch_name is specified" do
      let_it_be(:project) { create(:project, :public) }

      before do
        expect(Gitlab::CurrentSettings)
          .to receive(:default_branch_name)
          .at_least(:once)
          .and_return('example_branch')

        sign_in(project.first_owner)
        visit project_path(project)
      end

      it "recommends default_branch_name instead of master" do
        click_link 'Create empty repository'

        expect(page).to have_content("git push -u origin example_branch")
      end
    end

    context 'when project is empty' do
      let_it_be(:project) { create(:project_empty_repo, :public) }

      context 'when not signed in' do
        before do
          visit(project_path(project))
        end

        include_examples 'shows details of empty project'
      end

      context 'when signed in' do
        before do
          sign_in(user)
        end

        context 'when user does not have ssh keys' do
          before do
            visit(project_path(project))
          end

          include_examples 'shows details of empty project'
        end

        context 'when user has ssh keys' do
          before do
            create(:personal_key, user: user)

            visit(project_path(project))
          end

          include_examples 'shows details of empty project' do
            let(:user_has_ssh_key) { true }
          end
        end
      end
    end

    context 'when project is not empty' do
      let_it_be(:project) { create(:project, :public, :repository) }

      context 'when not signed in' do
        before do
          allow(Gitlab.config.gitlab).to receive(:host).and_return('www.example.com')

          visit(project_path(project))
        end

        include_examples 'shows details of non empty project'
      end

      context 'when signed in' do
        before do
          sign_in(user)
        end

        context 'when user does not have ssh keys' do
          before do
            visit(project_path(project))
          end

          include_examples 'shows details of non empty project'
        end

        context 'when user has ssh keys' do
          before do
            create(:personal_key, user: user)

            visit(project_path(project))
          end

          include_examples 'shows details of non empty project' do
            let(:user_has_ssh_key) { true }
          end
        end
      end
    end
  end

  context 'when project is internal' do
    let_it_be(:project) { create(:project, :internal, :repository) }

    context 'when not signed in' do
      before do
        visit(project_path(project))
      end

      include_examples 'redirects to the sign in page'
    end

    context 'when signed in' do
      before do
        sign_in(user)

        visit(project_path(project))
      end

      include_examples 'shows details of non empty project'
    end
  end

  context 'when project is private' do
    let_it_be(:project) { create(:project, :private) }

    before do
      visit(project_path(project))
    end

    include_examples 'redirects to the sign in page'
  end
end