2013-02-21 11:09:47 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-06-28 20:19:52 +00:00
|
|
|
feature 'Users', feature: true do
|
2015-09-28 14:00:53 +00:00
|
|
|
let(:user) { create(:user, username: 'user1', name: 'User 1', email: 'user1@gitlab.com') }
|
|
|
|
let(:user2) { create(:user, username: 'user2', name: 'User 2', email: 'user2@gitlab.com') }
|
|
|
|
|
2015-04-08 18:26:04 +00:00
|
|
|
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
|
|
|
|
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
|
2013-02-21 11:09:47 +00:00
|
|
|
end
|
2015-06-15 15:35:41 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-09-28 14:00:53 +00:00
|
|
|
context 'With a logged-in user' do
|
|
|
|
before do
|
|
|
|
login_as(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Abuse report button' do
|
|
|
|
context 'User has never been reported for abuse' do
|
|
|
|
it 'enables the "Report abuse" button / dropdown' do
|
|
|
|
visit user_path(user2)
|
|
|
|
|
|
|
|
expect(page.find('#report_abuse').find('ul.dropdown-menu').all('li').count).to be(1)
|
|
|
|
expect(page.find('#report_abuse').all('.btn-close').count).to be(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'User has already been reported for abuse' do
|
|
|
|
before do
|
|
|
|
@abuse_report = AbuseReport.new(user: user2, message: 'Foo bar')
|
|
|
|
@abuse_report.reporter = user
|
|
|
|
@abuse_report.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'disables the "Report abuse" button' do
|
|
|
|
visit user_path(user2)
|
|
|
|
|
|
|
|
expect(page.find('#report_abuse').all('ul.dropdown-menu').count).to be(0)
|
|
|
|
expect(page.find('#report_abuse').all('.btn-close').count).to be(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-02-21 11:09:47 +00:00
|
|
|
end
|