2016-07-25 23:28:08 -04:00
require 'spec_helper'
describe 'Edit Project Settings' , feature : true do
2017-04-21 17:05:19 -04:00
include Select2Helper
2016-07-25 23:28:08 -04:00
let ( :user ) { create ( :user ) }
2017-04-21 17:05:19 -04:00
let ( :project ) { create ( :empty_project , namespace : user . namespace , path : 'gitlab' , name : 'sample' ) }
2016-07-25 23:28:08 -04:00
before do
2017-06-21 19:44:10 -04:00
sign_in ( user )
2016-07-25 23:28:08 -04:00
end
2017-04-21 17:05:19 -04:00
describe 'Project settings section' , js : true do
2016-07-25 23:28:08 -04:00
it 'shows errors for invalid project name' do
2017-07-06 12:20:50 -04:00
visit edit_project_path ( project )
2016-07-25 23:28:08 -04:00
fill_in 'project_name_edit' , with : 'foo&bar'
click_button 'Save changes'
expect ( page ) . to have_field 'project_name_edit' , with : 'foo&bar'
2016-11-11 06:27:23 -05:00
expect ( page ) . to have_content " Name can contain only letters, digits, emojis, '_', '.', dash, space. It must start with letter, digit, emoji or '_'. "
2016-07-25 23:28:08 -04:00
expect ( page ) . to have_button 'Save changes'
end
2017-01-15 01:58:05 -05:00
2017-04-21 17:05:19 -04:00
it 'shows a successful notice when the project is updated' do
2017-07-06 12:20:50 -04:00
visit edit_project_path ( project )
2017-01-15 01:58:05 -05:00
fill_in 'project_name_edit' , with : 'hello world'
click_button 'Save changes'
expect ( page ) . to have_content " Project 'hello world' was successfully updated. "
end
2016-07-25 23:28:08 -04:00
end
2017-04-21 17:05:19 -04:00
describe 'Rename repository section' do
context 'with invalid characters' do
it 'shows errors for invalid project path/name' do
rename_project ( project , name : 'foo&bar' , path : 'foo&bar' )
expect ( page ) . to have_field 'Project name' , with : 'foo&bar'
expect ( page ) . to have_field 'Path' , with : 'foo&bar'
expect ( page ) . to have_content " Name can contain only letters, digits, emojis, '_', '.', dash, space. It must start with letter, digit, emoji or '_'. "
expect ( page ) . to have_content " Path can contain only letters, digits, '_', '-' and '.'. Cannot start with '-', end in '.git' or end in '.atom' "
end
end
2016-07-25 23:28:08 -04:00
2017-04-21 17:05:19 -04:00
context 'when changing project name' do
it 'renames the repository' do
rename_project ( project , name : 'bar' )
expect ( find ( 'h1.title' ) ) . to have_content ( project . name )
end
context 'with emojis' do
it 'shows error for invalid project name' do
rename_project ( project , name : '🚀 foo bar ☁️' )
expect ( page ) . to have_field 'Project name' , with : '🚀 foo bar ☁️'
expect ( page ) . not_to have_content " Name can contain only letters, digits, emojis '_', '.', dash and space. It must start with letter, digit, emoji or '_'. "
end
end
end
2016-07-25 23:28:08 -04:00
2017-04-21 17:05:19 -04:00
context 'when changing project path' do
# Not using empty project because we need a repo to exist
let ( :project ) { create ( :project , namespace : user . namespace , name : 'gitlabhq' ) }
2017-06-14 14:18:56 -04:00
before ( :context ) do
TestEnv . clean_test_path
end
after ( :example ) do
TestEnv . clean_test_path
end
2017-05-01 16:46:30 -04:00
2017-04-21 17:05:19 -04:00
specify 'the project is accessible via the new path' do
rename_project ( project , path : 'bar' )
new_path = namespace_project_path ( project . namespace , 'bar' )
visit new_path
expect ( current_path ) . to eq ( new_path )
expect ( find ( 'h1.title' ) ) . to have_content ( project . name )
end
specify 'the project is accessible via a redirect from the old path' do
2017-07-06 12:20:50 -04:00
old_path = project_path ( project )
2017-04-21 17:05:19 -04:00
rename_project ( project , path : 'bar' )
new_path = namespace_project_path ( project . namespace , 'bar' )
visit old_path
expect ( current_path ) . to eq ( new_path )
expect ( find ( 'h1.title' ) ) . to have_content ( project . name )
end
context 'and a new project is added with the same path' do
it 'overrides the redirect' do
2017-07-06 12:20:50 -04:00
old_path = project_path ( project )
2017-04-21 17:05:19 -04:00
rename_project ( project , path : 'bar' )
new_project = create ( :empty_project , namespace : user . namespace , path : 'gitlabhq' , name : 'quz' )
visit old_path
expect ( current_path ) . to eq ( old_path )
expect ( find ( 'h1.title' ) ) . to have_content ( new_project . name )
end
end
2016-07-25 23:28:08 -04:00
end
end
2016-11-11 06:27:23 -05:00
2017-04-21 17:05:19 -04:00
describe 'Transfer project section' , js : true do
# Not using empty project because we need a repo to exist
Fix or workaround spec failure
Not sure why this fixes this error:
```
ActiveRecord::RecordNotUnique:
PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_routes_on_source_type_and_source_id"
DETAIL: Key (source_type, source_id)=(Project, 1) already exists.
: INSERT INTO "routes" ("source_type", "path", "name", "source_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"
```
2017-05-03 13:54:06 -04:00
let! ( :project ) { create ( :project , namespace : user . namespace , name : 'gitlabhq' ) }
let! ( :group ) { create ( :group ) }
2017-05-01 16:46:30 -04:00
2017-06-14 14:18:56 -04:00
before ( :context ) do
TestEnv . clean_test_path
end
before ( :example ) do
group . add_owner ( user )
end
after ( :example ) do
TestEnv . clean_test_path
end
2016-11-11 06:27:23 -05:00
2017-04-21 17:05:19 -04:00
specify 'the project is accessible via the new path' do
transfer_project ( project , group )
new_path = namespace_project_path ( group , project )
visit new_path
expect ( current_path ) . to eq ( new_path )
expect ( find ( 'h1.title' ) ) . to have_content ( project . name )
end
2016-11-11 06:27:23 -05:00
2017-04-21 17:05:19 -04:00
specify 'the project is accessible via a redirect from the old path' do
2017-07-06 12:20:50 -04:00
old_path = project_path ( project )
2017-04-21 17:05:19 -04:00
transfer_project ( project , group )
new_path = namespace_project_path ( group , project )
visit old_path
expect ( current_path ) . to eq ( new_path )
expect ( find ( 'h1.title' ) ) . to have_content ( project . name )
end
2016-11-11 06:27:23 -05:00
2017-04-21 17:05:19 -04:00
context 'and a new project is added with the same path' do
it 'overrides the redirect' do
2017-07-06 12:20:50 -04:00
old_path = project_path ( project )
2017-04-21 17:05:19 -04:00
transfer_project ( project , group )
new_project = create ( :empty_project , namespace : user . namespace , path : 'gitlabhq' , name : 'quz' )
visit old_path
expect ( current_path ) . to eq ( old_path )
expect ( find ( 'h1.title' ) ) . to have_content ( new_project . name )
end
2016-11-11 06:27:23 -05:00
end
end
2016-07-25 23:28:08 -04:00
end
2017-04-21 17:05:19 -04:00
def rename_project ( project , name : nil , path : nil )
2017-07-06 12:20:50 -04:00
visit edit_project_path ( project )
2017-04-21 17:05:19 -04:00
fill_in ( 'project_name' , with : name ) if name
fill_in ( 'Path' , with : path ) if path
click_button ( 'Rename project' )
wait_for_edit_project_page_reload
project . reload
end
def transfer_project ( project , namespace )
2017-07-06 12:20:50 -04:00
visit edit_project_path ( project )
2017-04-21 17:05:19 -04:00
select2 ( namespace . id , from : '#new_namespace_id' )
click_button ( 'Transfer project' )
confirm_transfer_modal
wait_for_edit_project_page_reload
project . reload
end
def confirm_transfer_modal
fill_in ( 'confirm_name_input' , with : project . path )
click_button 'Confirm'
end
def wait_for_edit_project_page_reload
expect ( find ( '.project-edit-container' ) ) . to have_content ( 'Rename repository' )
end