Guest User

Untitled

a guest
Oct 29th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. # my User model
  2.  
  3. before_validation :update_password
  4.  
  5. def update_password
  6. return unless self.password_changed?
  7. self.changed_attributes.delete(:password) if self.password.blank?
  8. end
  9.  
  10. # Tests
  11.  
  12. test "test updating empty password" do
  13. user = create_user # this method creates a user with random data
  14.  
  15. original_id = user.id
  16. original_password = user.password
  17.  
  18. user.password = nil
  19. assert user.valid?(:update), user.errors.inspect # this is passing
  20.  
  21. user.password = nil
  22. user.save
  23. saved_user = User.find(original_id)
  24. assert_equal original_password, saved_user.password # this is line 87
  25. end
  26.  
  27. # RESULTS
  28.  
  29. 1) Failure:
  30. test_test_updating_empty_password(UserTest) [test/unit/user_test.rb:87]:
  31. <"$2a$10$rU0at9jcjYRfr5f9NlBMKumSD/NtrCPcAlD5M/edIOgrs5DrLfkXu"> expected but was
  32. <nil>.
Add Comment
Please, Sign In to add comment