foodsoft/spec/models/user_spec.rb

60 lines
2 KiB
Ruby
Raw Normal View History

2013-07-12 20:06:49 +02:00
require 'spec_helper'
describe User do
it 'is correctly created' do
user = FactoryGirl.create :user,
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
let(:user) { FactoryGirl.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
let(:user) { FactoryGirl.create :user, password: 'blahblah' }
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-07-24 22:46:25 +02:00
expect(FactoryGirl.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-07-24 22:46:25 +02:00
expect(FactoryGirl.build(:user, email: "#{user.email}")).to be_invalid
2013-07-12 20:06:49 +02:00
end
end
describe 'admin' do
let(:user) { FactoryGirl.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