PageRenderTime 28ms CodeModel.GetById 9ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

/spec/features/projects/show/user_sees_git_instructions_spec.rb

https://gitlab.com/tnir/gitlab-ce
Ruby | 174 lines | 130 code | 43 blank | 1 comment | 0 complexity | fca629393fa148c696a7fb0a40de9533 MD5 | raw file
  1# frozen_string_literal: true
  2
  3require 'spec_helper'
  4
  5describe 'Projects > Show > User sees Git instructions' do
  6  let_it_be(:user) { create(:user) }
  7
  8  shared_examples_for 'redirects to the sign in page' do
  9    it 'redirects to the sign in page' do
 10      expect(current_path).to eq(new_user_session_path)
 11    end
 12  end
 13
 14  shared_examples_for 'shows details of empty project with no repo' do
 15    it 'shows Git command line instructions' do
 16      click_link 'Create empty repository'
 17
 18      page.within '.empty-wrapper' do
 19        expect(page).to have_content('Command line instructions')
 20      end
 21    end
 22  end
 23
 24  shared_examples_for 'shows details of empty project' do
 25    let(:user_has_ssh_key) { false }
 26
 27    it 'shows details' do
 28      expect(page).not_to have_content('Git global setup')
 29
 30      page.all(:css, '.git-empty .clone').each do |element|
 31        expect(element.text).to include(project.http_url_to_repo)
 32      end
 33
 34      expect(page).to have_field('http_project_clone', with: project.http_url_to_repo) unless user_has_ssh_key
 35    end
 36  end
 37
 38  shared_examples_for 'shows details of non empty project' do
 39    let(:user_has_ssh_key) { false }
 40
 41    it 'shows details' do
 42      page.within('.breadcrumbs .breadcrumb-item-text') do
 43        expect(page).to have_content(project.title)
 44      end
 45
 46      expect(page).to have_field('http_project_clone', with: project.http_url_to_repo) unless user_has_ssh_key
 47    end
 48  end
 49
 50  context 'when project is public' do
 51    context 'when project has no repo' do
 52      let_it_be(:project) { create(:project, :public) }
 53
 54      before do
 55        sign_in(project.owner)
 56        visit project_path(project)
 57      end
 58
 59      include_examples 'shows details of empty project with no repo'
 60    end
 61
 62    context 'when project is empty' do
 63      let_it_be(:project) { create(:project_empty_repo, :public) }
 64
 65      context 'when not signed in' do
 66        before do
 67          visit(project_path(project))
 68        end
 69
 70        include_examples 'shows details of empty project'
 71      end
 72
 73      context 'when signed in' do
 74        before do
 75          sign_in(user)
 76        end
 77
 78        context 'when user does not have ssh keys' do
 79          before do
 80            visit(project_path(project))
 81          end
 82
 83          include_examples 'shows details of empty project'
 84        end
 85
 86        context 'when user has ssh keys' do
 87          before do
 88            create(:personal_key, user: user)
 89
 90            visit(project_path(project))
 91          end
 92
 93          include_examples 'shows details of empty project' do
 94            let(:user_has_ssh_key) { true }
 95          end
 96        end
 97      end
 98    end
 99
100    context 'when project is not empty' do
101      let_it_be(:project) { create(:project, :public, :repository) }
102
103      before do
104        visit(project_path(project))
105      end
106
107      context 'when not signed in' do
108        before do
109          allow(Gitlab.config.gitlab).to receive(:host).and_return('www.example.com')
110        end
111
112        include_examples 'shows details of non empty project'
113      end
114
115      context 'when signed in' do
116        before do
117          sign_in(user)
118        end
119
120        context 'when user does not have ssh keys' do
121          before do
122            visit(project_path(project))
123          end
124
125          include_examples 'shows details of non empty project'
126        end
127
128        context 'when user has ssh keys' do
129          before do
130            create(:personal_key, user: user)
131
132            visit(project_path(project))
133          end
134
135          include_examples 'shows details of non empty project' do
136            let(:user_has_ssh_key) { true }
137          end
138        end
139      end
140    end
141  end
142
143  context 'when project is internal' do
144    let_it_be(:project) { create(:project, :internal, :repository) }
145
146    context 'when not signed in' do
147      before do
148        visit(project_path(project))
149      end
150
151      include_examples 'redirects to the sign in page'
152    end
153
154    context 'when signed in' do
155      before do
156        sign_in(user)
157
158        visit(project_path(project))
159      end
160
161      include_examples 'shows details of non empty project'
162    end
163  end
164
165  context 'when project is private' do
166    let_it_be(:project) { create(:project, :private) }
167
168    before do
169      visit(project_path(project))
170    end
171
172    include_examples 'redirects to the sign in page'
173  end
174end