Commit d4d34b16 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'rs-backport-ee-372' into 'master'

Backport changes from gitlab-org/gitlab-ee!372

Mostly replaces several Spinach tests with RSpec Feature tests.

See merge request !4043
parents bdfe6dc3 f18ec707
...@@ -205,7 +205,8 @@ module ProjectsHelper ...@@ -205,7 +205,8 @@ module ProjectsHelper
end end
def default_url_to_repo(project = @project) def default_url_to_repo(project = @project)
if default_clone_protocol == "ssh" case default_clone_protocol
when 'ssh'
project.ssh_url_to_repo project.ssh_url_to_repo
else else
project.http_url_to_repo project.http_url_to_repo
......
...@@ -6,21 +6,9 @@ Feature: Project Create ...@@ -6,21 +6,9 @@ Feature: Project Create
@javascript @javascript
Scenario: User create a project Scenario: User create a project
Given I sign in as a user
When I visit new project page
And I have an ssh key
And fill project form with valid data
Then I should see project page
And I should see empty project instuctions
@javascript
Scenario: Empty project instructions
Given I sign in as a user Given I sign in as a user
And I have an ssh key And I have an ssh key
When I visit new project page When I visit new project page
And fill project form with valid data And fill project form with valid data
Then I see empty project instuctions Then I should see project page
And I click on HTTP And I should see empty project instructions
Then Remote url should update to http link
And If I click on SSH
Then Remote url should update to ssh link
...@@ -13,33 +13,9 @@ class Spinach::Features::ProjectCreate < Spinach::FeatureSteps ...@@ -13,33 +13,9 @@ class Spinach::Features::ProjectCreate < Spinach::FeatureSteps
expect(current_path).to eq namespace_project_path(Project.last.namespace, Project.last) expect(current_path).to eq namespace_project_path(Project.last.namespace, Project.last)
end end
step 'I should see empty project instuctions' do step 'I should see empty project instructions' do
expect(page).to have_content "git init" expect(page).to have_content "git init"
expect(page).to have_content "git remote" expect(page).to have_content "git remote"
expect(page).to have_content Project.last.url_to_repo expect(page).to have_content Project.last.url_to_repo
end end
step 'I see empty project instuctions' do
expect(page).to have_content "git init"
expect(page).to have_content "git remote"
expect(page).to have_content Project.last.url_to_repo
end
step 'I click on HTTP' do
find('#clone-dropdown').click
find('.http-selector').click
end
step 'Remote url should update to http link' do
expect(page).to have_content "git remote add origin #{Project.last.http_url_to_repo}"
end
step 'If I click on SSH' do
find('#clone-dropdown').click
find('.ssh-selector').click
end
step 'Remote url should update to ssh link' do
expect(page).to have_content "git remote add origin #{Project.last.url_to_repo}"
end
end end
...@@ -60,6 +60,12 @@ FactoryGirl.define do ...@@ -60,6 +60,12 @@ FactoryGirl.define do
trait :private do trait :private do
visibility_level Gitlab::VisibilityLevel::PRIVATE visibility_level Gitlab::VisibilityLevel::PRIVATE
end end
trait :empty_repo do
after(:create) do |project|
project.create_repository
end
end
end end
# Project with empty repository # Project with empty repository
...@@ -67,9 +73,7 @@ FactoryGirl.define do ...@@ -67,9 +73,7 @@ FactoryGirl.define do
# This is a case when you just created a project # This is a case when you just created a project
# but not pushed any code there yet # but not pushed any code there yet
factory :project_empty_repo, parent: :empty_project do factory :project_empty_repo, parent: :empty_project do
after :create do |project| empty_repo
project.create_repository
end
end end
# Project with test repository # Project with test repository
......
require 'rails_helper'
feature 'Developer views empty project instructions', feature: true do
let(:project) { create(:empty_project, :empty_repo) }
let(:developer) { create(:user) }
background do
project.team << [developer, :developer]
login_as(developer)
end
context 'without an SSH key' do
scenario 'defaults to HTTP' do
visit_project
expect_instructions_for('http')
end
scenario 'switches to SSH', js: true do
visit_project
select_protocol('SSH')
expect_instructions_for('ssh')
end
end
context 'with an SSH key' do
background do
create(:personal_key, user: developer)
end
scenario 'defaults to SSH' do
visit_project
expect_instructions_for('ssh')
end
scenario 'switches to HTTP', js: true do
visit_project
select_protocol('HTTP')
expect_instructions_for('http')
end
end
def visit_project
visit namespace_project_path(project.namespace, project)
end
def select_protocol(protocol)
find('#clone-dropdown').click
find(".#{protocol.downcase}-selector").click
end
def expect_instructions_for(protocol)
msg = :"#{protocol.downcase}_url_to_repo"
expect(page).to have_content("git clone #{project.send(msg)}")
end
end
...@@ -88,18 +88,18 @@ describe ProjectsHelper do ...@@ -88,18 +88,18 @@ describe ProjectsHelper do
end end
describe 'default_clone_protocol' do describe 'default_clone_protocol' do
describe 'using HTTP' do context 'when user is not logged in and gitlab protocol is HTTP' do
it 'returns HTTP' do it 'returns HTTP' do
expect(helper).to receive(:current_user).and_return(nil) allow(helper).to receive(:current_user).and_return(nil)
expect(helper.send(:default_clone_protocol)).to eq('http') expect(helper.send(:default_clone_protocol)).to eq('http')
end end
end end
describe 'using HTTPS' do context 'when user is not logged in and gitlab protocol is HTTPS' do
it 'returns HTTPS' do it 'returns HTTPS' do
allow(Gitlab.config.gitlab).to receive(:protocol).and_return('https') stub_config_setting(protocol: 'https')
expect(helper).to receive(:current_user).and_return(nil) allow(helper).to receive(:current_user).and_return(nil)
expect(helper.send(:default_clone_protocol)).to eq('https') expect(helper.send(:default_clone_protocol)).to eq('https')
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment