profile_spec.rb 2.21 KB
Newer Older
1 2
require 'spec_helper'

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
3
describe 'Profile account page', feature: true do
4 5 6
  let(:user) { create(:user) }

  before do
7
    sign_in(user)
8 9
  end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
10
  describe 'when signup is enabled' do
11
    before do
12
      stub_application_setting(signup_enabled: true)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
13
      visit profile_account_path
14
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
15

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
16
    it { expect(page).to have_content('Remove account') }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
17

18
    it 'deletes the account' do
19
      expect { click_link 'Delete account' }.to change { User.where(id: user.id).count }.by(-1)
20
      expect(current_path).to eq(new_user_session_path)
21 22 23
    end
  end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
24
  describe 'when signup is disabled' do
25
    before do
26
      stub_application_setting(signup_enabled: false)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
27
      visit profile_account_path
28 29
    end

30
    it 'does not have option to remove account' do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
31
      expect(page).not_to have_content('Remove account')
32
      expect(current_path).to eq(profile_account_path)
33 34
    end
  end
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

  describe 'when I reset private token' do
    before do
      visit profile_account_path
    end

    it 'resets private token' do
      previous_token = find("#private-token").value

      click_link('Reset private token')

      expect(find('#private-token').value).not_to eq(previous_token)
    end
  end

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  describe 'when I reset RSS token' do
    before do
      visit profile_account_path
    end

    it 'resets RSS token' do
      previous_token = find("#rss-token").value

      click_link('Reset RSS token')

      expect(page).to have_content 'RSS token was successfully reset'
      expect(find('#rss-token').value).not_to eq(previous_token)
    end
  end

65 66 67 68 69 70 71 72 73 74 75 76 77 78
  describe 'when I reset incoming email token' do
    before do
      allow(Gitlab.config.incoming_email).to receive(:enabled).and_return(true)
      visit profile_account_path
    end

    it 'resets incoming email token' do
      previous_token = find('#incoming-email-token').value

      click_link('Reset incoming email token')

      expect(find('#incoming-email-token').value).not_to eq(previous_token)
    end
  end
79 80 81 82 83 84 85 86 87 88 89 90 91 92

  describe 'when I change my username' do
    before do
      visit profile_account_path
    end

    it 'changes my username' do
      fill_in 'user_username', with: 'new-username'

      click_button('Update username')

      expect(page).to have_content('new-username')
    end
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
93
end