2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe 'Projects > Show > User sees Git instructions' do
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
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
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
shared_examples_for 'shows details of empty project with no repo' do
|
|
|
|
it 'shows Git command line instructions' do
|
|
|
|
click_link 'Create empty repository'
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
page.within '.empty-wrapper' do
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(page).to have_content('Command line instructions')
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
expect(page).to have_content("git push -u origin master")
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(page).to have_field('http_project_clone', with: project.http_url_to_repo) unless user_has_ssh_key
|
2018-03-17 18:26:18 +05:30
|
|
|
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
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(page).to have_field('http_project_clone', with: project.http_url_to_repo) unless user_has_ssh_key
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project is public' do
|
2018-10-15 14:42:47 +05:30
|
|
|
context 'when project has no repo' do
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:project) { create(:project, :public) }
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(project.owner)
|
|
|
|
visit project_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'shows details of empty project with no repo'
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
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.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
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when project is empty' do
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:project) { create(:project_empty_repo, :public) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
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
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:project) { create(:project, :public, :repository) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
context 'when not signed in' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab.config.gitlab).to receive(:host).and_return('www.example.com')
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
visit(project_path(project))
|
2018-03-17 18:26:18 +05:30
|
|
|
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
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:project) { create(:project, :internal, :repository) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
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
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:project) { create(:project, :private) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
visit(project_path(project))
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'redirects to the sign in page'
|
|
|
|
end
|
|
|
|
end
|