2013-09-18 12:44:41 +02:00
|
|
|
require_relative '../spec_helper'
|
2013-07-12 20:06:49 +02:00
|
|
|
|
|
|
|
describe User do
|
|
|
|
|
|
|
|
it 'is correctly created' do
|
2013-09-18 12:44:41 +02:00
|
|
|
user = create :user,
|
2013-07-12 20:06:49 +02:00
|
|
|
nick: 'johnnydoe', first_name: 'Johnny', last_name: 'DoeBar',
|
|
|
|
email: 'johnnydoe@foodcoop.test', phone: '+1234567890'
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(user.nick).to eq('johnnydoe')
|
|
|
|
expect(user.first_name).to eq('Johnny')
|
|
|
|
expect(user.last_name).to eq('DoeBar')
|
|
|
|
expect(user.name).to eq('Johnny DoeBar')
|
|
|
|
expect(user.email).to eq('johnnydoe@foodcoop.test')
|
|
|
|
expect(user.phone).to eq('+1234567890')
|
2013-07-12 20:06:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'does not have the role' do
|
2013-09-18 12:44:41 +02:00
|
|
|
let(:user) { create :user }
|
2013-07-24 22:46:25 +02:00
|
|
|
it 'admin' do expect(user.role_admin?).to be_false end
|
|
|
|
it 'finance' do expect(user.role_finance?).to be_false end
|
|
|
|
it 'article_meta' do expect(user.role_article_meta?).to be_false end
|
|
|
|
it 'suppliers' do expect(user.role_suppliers?).to be_false end
|
|
|
|
it 'orders' do expect(user.role_orders?).to be_false end
|
2013-07-12 20:06:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe do
|
2013-09-18 12:44:41 +02:00
|
|
|
let(:user) { create :user, password: 'blahblah' }
|
2013-07-12 20:06:49 +02:00
|
|
|
|
|
|
|
it 'can authenticate with correct password' do
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(User.authenticate(user.nick, 'blahblah')).to be_true
|
2013-07-12 20:06:49 +02:00
|
|
|
end
|
|
|
|
it 'can not authenticate with incorrect password' do
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(User.authenticate(user.nick, 'foobar')).to be_nil
|
2013-07-12 20:06:49 +02:00
|
|
|
end
|
|
|
|
it 'can not set a password without matching confirmation' do
|
|
|
|
user.password = 'abcdefghij'
|
|
|
|
user.password_confirmation = 'foobarxyz'
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(user).to be_invalid
|
2013-07-12 20:06:49 +02:00
|
|
|
end
|
|
|
|
it 'can set a password with matching confirmation' do
|
|
|
|
user.password = 'abcdefghij'
|
|
|
|
user.password_confirmation = 'abcdefghij'
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(user).to be_valid
|
2013-07-12 20:06:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a unique nick' do
|
2013-09-18 12:44:41 +02:00
|
|
|
expect(build(:user, nick: user.nick, email: "x-#{user.email}")).to be_invalid
|
2013-07-12 20:06:49 +02:00
|
|
|
end
|
|
|
|
it 'has a unique email' do
|
2013-09-18 12:44:41 +02:00
|
|
|
expect(build(:user, email: "#{user.email}")).to be_invalid
|
2013-07-12 20:06:49 +02:00
|
|
|
end
|
2013-09-20 22:39:19 +02:00
|
|
|
|
|
|
|
it 'can authenticate using email address' do
|
|
|
|
expect(User.authenticate(user.email, 'blahblah')).to be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can authenticate when there is no nick' do
|
|
|
|
user.nick = nil
|
|
|
|
expect(user).to be_valid
|
|
|
|
expect(User.authenticate(user.email, 'blahblah')).to be_true
|
|
|
|
end
|
2013-07-12 20:06:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'admin' do
|
2013-09-18 12:44:41 +02:00
|
|
|
let(:user) { create :admin }
|
2013-07-24 22:46:25 +02:00
|
|
|
it 'default admin role' do expect(user.role_admin?).to be_true end
|
2013-07-12 20:06:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|