summaryrefslogtreecommitdiff
path: root/spec/features/users_spec.rb
blob: a4c3dfe9205fdc7ebe86979f64f478133210628d (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
require 'spec_helper'

feature 'Users' do
  scenario 'GET /users/sign_in creates a new user account' do
    visit new_user_session_path
    fill_in 'user_name', with: 'Name Surname'
    fill_in 'user_username', with: 'Great'
    fill_in 'user_email', with: 'name@mail.com'
    fill_in 'user_password_sign_up', with: 'password1234'
    expect { click_button 'Sign up' }.to change { User.count }.by(1)
  end

  scenario 'Successful user signin invalidates password reset token' do
    user = create(:user)
    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

    login_with(user)
    expect(current_path).to eq root_path

    user.reload
    expect(user.reset_password_token).to be_nil
  end

  let!(:user) { create(:user, username: 'user1', name: 'User 1', email: 'user1@gitlab.com') }
  scenario 'Should show one error if email is already taken' do
    visit new_user_session_path
    fill_in 'user_name', with: 'Another user name'
    fill_in 'user_username', with: 'anotheruser'
    fill_in 'user_email', with: user.email
    fill_in 'user_password_sign_up', with: '12341234'
    expect { click_button 'Sign up' }.to change { User.count }.by(0)
    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

  def errors_on_page(page)
    page.find('#error_explanation').find('ul').all('li').map{ |item| item.text }.join("\n")
  end

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

end