SHARE
TWEET

Untitled

a guest Apr 21st, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
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