Guest User

Untitled

a guest
Apr 21st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. # user.rb
  2. validates_each :password do |record, attr, value|
  3. record.errors.add(attr, 'cannot be the same as original password.') if User::encrypt(value, record.salt) == record.crypted_password
  4. end
  5.  
  6. # user_spec.rb
  7. it 'are the same as the original password' do
  8. # pending
  9. @admin.password_confirmation = @admin.password = 'currentPassword1'
  10. # @admin.send(:validate) # @admin.save doesn't work for some reason
  11. @admin.save!
  12. # puts @admin.errors.inspect.gsub( /</, "<" )
  13. p @admin.errors
  14. @admin.should be_valid
  15.  
  16. @admin.password_confirmation = @admin.password = 'currentPassword1'
  17. @admin.save!
  18. p @admin.errors
  19. # @user.should have(1).error_on(:password)
  20. @admin.should_not be_valid
  21. end
Add Comment
Please, Sign In to add comment