summaryrefslogtreecommitdiff
path: root/spec/features/profiles/account_spec.rb
blob: 171e061e60e84afe506ff8bb19d9cf882e11eac1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'rails_helper'

feature 'Profile > Account' do
  given(:user) { create(:user, username: 'foo') }

  before do
    sign_in(user)
  end

  describe 'Change username' do
    given(:new_username) { 'bar' }
    given(:new_user_path) { "/#{new_username}" }
    given(:old_user_path) { "/#{user.username}" }

    scenario 'the user is accessible via the new path' do
      update_username(new_username)
      visit new_user_path
      expect(current_path).to eq(new_user_path)
      expect(find('.user-info')).to have_content(new_username)
    end

    scenario 'the old user path redirects to the new path' do
      update_username(new_username)
      visit old_user_path
      expect(current_path).to eq(new_user_path)
      expect(find('.user-info')).to have_content(new_username)
    end

    context 'with a project' do
      given!(:project) { create(:project, namespace: user.namespace) }
      given(:new_project_path) { "/#{new_username}/#{project.path}" }
      given(:old_project_path) { "/#{user.username}/#{project.path}" }

      before(:context) do
        TestEnv.clean_test_path
      end

      after do
        TestEnv.clean_test_path
      end

      scenario 'the project is accessible via the new path' do
        update_username(new_username)
        visit new_project_path
        expect(current_path).to eq(new_project_path)
        expect(find('.breadcrumbs-sub-title')).to have_content(project.path)
      end

      scenario 'the old project path redirects to the new path' do
        update_username(new_username)
        visit old_project_path
        expect(current_path).to eq(new_project_path)
        expect(find('.breadcrumbs-sub-title')).to have_content(project.path)
      end
    end
  end
end

def update_username(new_username)
  allow(user.namespace).to receive(:move_dir)
  visit profile_account_path
  fill_in 'user_username', with: new_username
  click_button 'Update username'
end