SHARE
TWEET

Untitled

a guest Mar 20th, 2016 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'rails_helper'
  2.  
  3. RSpec.describe User, type: :model do
  4.  
  5.   describe 'authenticate' do
  6.     let(:user) { create :user }
  7.     it { expect(nil).to eq(User.authenticate('test@example.net', 'password1234')) }
  8.     it { expect(nil).to eq(User.authenticate('test@example.com', 'password12345')) }
  9.     it { expect(user).to eq(User.authenticate('test@example.com', 'password1234')) }
  10.   end
  11.  
  12.   describe '#create' do
  13.     let(:user) { build :user }
  14.  
  15.     it { expect(user).to be_valid }
  16.  
  17.     it 'validates email is blank' do
  18.       user.email = ''
  19.       expect(user).to be_invalid
  20.     end
  21.  
  22.     it 'validates password is blank' do
  23.       user.password = ''
  24.       expect(user).to be_invalid
  25.     end
  26.  
  27.     it 'validates name is blank' do
  28.       user.name = ''
  29.       expect(user).to be_invalid
  30.     end
  31.  
  32.     it 'validates names length' do
  33.       user.name = '123456789012345678901'
  34.       expect(user).to be_invalid
  35.     end
  36.  
  37.     it 'validates email format' do
  38.       user.email = 'a'
  39.       expect(user).to be_invalid
  40.  
  41.       user.email = 'a@a'
  42.       expect(user).to be_invalid
  43.  
  44.       user.email = 'a@a.'
  45.       expect(user).to be_invalid
  46.  
  47.       user.email = 'a@a.com'
  48.       expect(user).to be_valid
  49.     end
  50.  
  51.     it 'validates input password' do
  52.       user.password = '1234567'
  53.       expect(user).to be_invalid
  54.  
  55.       user.password = '12345678'
  56.       expect(user).to be_invalid
  57.  
  58.       user.password = 'abcdefg'
  59.       expect(user).to be_invalid
  60.  
  61.       user.password = 'abcdefgh'
  62.       expect(user).to be_invalid
  63.  
  64.       user.password = 'abcdefg1'
  65.       expect(user).to be_valid
  66.     end
  67.  
  68.     it 'save with password hash/salt' do
  69.       created_user = User.create(
  70.         subdomain: 'ore',
  71.         email: 'ore@ore.com',
  72.         password: 'password1234',
  73.         name: 'ORE Taro'
  74.       )
  75.       expect(created_user.errors).to be_empty
  76.       expect(created_user.password_salt).to match /[0-9a-f]{40}/
  77.       expect(created_user.password_hash).to match /[0-9a-f]{40}/
  78.     end
  79.   end
  80.  
  81. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top