users_spec.rb 3.7 KB
Newer Older
1 2
require 'spec_helper'

3
feature 'Users', js: true do
4
  let(:user) { create(:user, username: 'user1', name: 'User 1', email: 'user1@gitlab.com') }
5

6 7
  scenario 'GET /users/sign_in creates a new user account' do
    visit new_user_session_path
8
    click_link 'Register'
9 10 11 12 13
    fill_in 'new_user_name',                with: 'Name Surname'
    fill_in 'new_user_username',            with: 'Great'
    fill_in 'new_user_email',               with: 'name@mail.com'
    fill_in 'new_user_email_confirmation',  with: 'name@mail.com'
    fill_in 'new_user_password',            with: 'password1234'
14
    expect { click_button 'Register' }.to change { User.count }.by(1)
15 16 17 18 19 20 21 22 23 24 25 26
  end

  scenario 'Successful user signin invalidates password reset token' do
    expect(user.reset_password_token).to be_nil

    visit new_user_password_path
    fill_in 'user_email', with: user.email
    click_button 'Reset password'

    user.reload
    expect(user.reset_password_token).not_to be_nil

27
    gitlab_sign_in(user)
28 29 30 31
    expect(current_path).to eq root_path

    user.reload
    expect(user.reset_password_token).to be_nil
32
  end
33 34 35

  scenario 'Should show one error if email is already taken' do
    visit new_user_session_path
36
    click_link 'Register'
37 38 39 40 41
    fill_in 'new_user_name',                with: 'Another user name'
    fill_in 'new_user_username',            with: 'anotheruser'
    fill_in 'new_user_email',               with: user.email
    fill_in 'new_user_email_confirmation',  with: user.email
    fill_in 'new_user_password',            with: '12341234'
42
    expect { click_button 'Register' }.to change { User.count }.by(0)
43 44 45 46
    expect(page).to have_text('Email has already been taken')
    expect(number_of_errors_on_page(page)).to be(1), 'errors on page:\n #{errors_on_page page}'
  end

47
  describe 'redirect alias routes' do
48 49 50
    before do
      expect(user).to be_persisted
    end
51 52 53 54

    scenario '/u/user1 redirects to user page' do
      visit '/u/user1'

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
55 56
      expect(current_path).to eq user_path(user)
      expect(page).to have_text(user.name)
57
    end
58 59 60 61 62 63 64 65 66 67 68 69

    scenario '/u/user1/groups redirects to user groups page' do
      visit '/u/user1/groups'

      expect(current_path).to eq user_groups_path(user)
    end

    scenario '/u/user1/projects redirects to user projects page' do
      visit '/u/user1/projects'

      expect(current_path).to eq user_projects_path(user)
    end
70 71
  end

72 73 74 75 76 77 78 79
  feature 'username validation' do
    let(:loading_icon) { '.fa.fa-spinner' }
    let(:username_input) { 'new_user_username' }

    before(:each) do
      visit new_user_session_path
      click_link 'Register'
    end
80 81 82

    scenario 'doesn\'t show an error border if the username is available' do
      fill_in username_input, with: 'new-user'
83
      wait_for_requests
84 85 86 87 88
      expect(find('.username')).not_to have_css '.gl-field-error-outline'
    end

    scenario 'does not show an error border if the username contains dots (.)' do
      fill_in username_input, with: 'new.user.username'
89
      wait_for_requests
90 91 92
      expect(find('.username')).not_to have_css '.gl-field-error-outline'
    end

Bryce Johnson's avatar
Bryce Johnson committed
93
    scenario 'shows an error border if the username already exists' do
94
      fill_in username_input, with: user.username
95
      wait_for_requests
96
      expect(find('.username')).to have_css '.gl-field-error-outline'
97 98
    end

99 100
    scenario 'shows an  error border if the username contains special characters' do
      fill_in username_input, with: 'new$user!username'
101
      wait_for_requests
102
      expect(find('.username')).to have_css '.gl-field-error-outline'
103 104 105
    end
  end

106
  def errors_on_page(page)
107
    page.find('#error_explanation').find('ul').all('li').map { |item| item.text }.join("\n")
108 109 110 111 112
  end

  def number_of_errors_on_page(page)
    page.find('#error_explanation').find('ul').all('li').count
  end
113
end