project_settings_spec.rb 5.82 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Edit Project Settings' do
4 5
  include Select2Helper

6
  let(:user) { create(:user) }
7
  let(:project) { create(:project, namespace: user.namespace, path: 'gitlab', name: 'sample') }
8 9

  before do
10
    sign_in(user)
11 12
  end

13
  describe 'Project settings section', js: true do
14
    it 'shows errors for invalid project name' do
15
      visit edit_project_path(project)
16 17 18
      fill_in 'project_name_edit', with: 'foo&bar'
      click_button 'Save changes'
      expect(page).to have_field 'project_name_edit', with: 'foo&bar'
19
      expect(page).to have_content "Name can contain only letters, digits, emojis, '_', '.', dash, space. It must start with letter, digit, emoji or '_'."
20 21
      expect(page).to have_button 'Save changes'
    end
22

23
    it 'shows a successful notice when the project is updated' do
24
      visit edit_project_path(project)
25 26 27 28
      fill_in 'project_name_edit', with: 'hello world'
      click_button 'Save changes'
      expect(page).to have_content "Project 'hello world' was successfully updated."
    end
29 30
  end

31 32 33 34 35 36 37 38 39 40
  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
41

42 43 44 45 46 47 48 49 50 51 52 53 54 55
    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
56

57
    context 'when changing project path' do
58
      let(:project) { create(:project, :repository, namespace: user.namespace, name: 'gitlabhq') }
59

60 61 62 63 64 65 66
      before(:context) do
        TestEnv.clean_test_path
      end

      after(:example) do
        TestEnv.clean_test_path
      end
67 68 69 70 71 72 73 74 75 76

      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
77
        old_path = project_path(project)
78 79 80 81 82 83 84 85 86
        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
87
          old_path = project_path(project)
88
          rename_project(project, path: 'bar')
89
          new_project = create(:project, namespace: user.namespace, path: 'gitlabhq', name: 'quz')
90 91 92 93 94
          visit old_path
          expect(current_path).to eq(old_path)
          expect(find('h1.title')).to have_content(new_project.name)
        end
      end
95 96
    end
  end
97

98
  describe 'Transfer project section', js: true do
99
    let!(:project) { create(:project, :repository, namespace: user.namespace, name: 'gitlabhq') }
100 101
    let!(:group) { create(:group) }

102 103 104 105 106 107 108 109 110 111 112
    before(:context) do
      TestEnv.clean_test_path
    end

    before(:example) do
      group.add_owner(user)
    end

    after(:example) do
      TestEnv.clean_test_path
    end
113 114 115 116 117 118 119 120

    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
121

122
    specify 'the project is accessible via a redirect from the old path' do
123
      old_path = project_path(project)
124 125 126 127 128 129
      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
130

131 132
    context 'and a new project is added with the same path' do
      it 'overrides the redirect' do
133
        old_path = project_path(project)
134
        transfer_project(project, group)
135
        new_project = create(:project, namespace: user.namespace, path: 'gitlabhq', name: 'quz')
136 137 138 139
        visit old_path
        expect(current_path).to eq(old_path)
        expect(find('h1.title')).to have_content(new_project.name)
      end
140 141
    end
  end
142
end
143 144

def rename_project(project, name: nil, path: nil)
145
  visit edit_project_path(project)
146 147 148 149 150 151 152 153
  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)
154
  visit edit_project_path(project)
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
  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