Guest User

Untitled

a guest
Jul 22nd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. You start with this:
  2.  
  3. def update
  4. test do
  5. user_in_db = @user.reload
  6. user_in_db.password.should == params[:new_password]
  7. end
  8. end
  9.  
  10. Then add some code:
  11.  
  12. def update
  13. @user = User.find(params[:id])
  14. @user.password = params[:new_password]
  15. test do
  16. user_in_db = @user.reload
  17. user_in_db.password.should == params[:new_password]
  18. end
  19. end
  20.  
  21. Oops, it will fail next time it will be used, so we fix it:
  22.  
  23. def update
  24. @user = User.find(params[:id])
  25. @user.password = params[:new_password]
  26. @user.save
  27. test do
  28. user_in_db = @user.reload
  29. user_in_db.password.should == params[:new_password]
  30. end
  31. end
  32.  
  33. Now, lets imagine that somebody created a trigger on `users` updates that does something wrong with the password :) The above test will fail as soon as anybody will try to change the password!
Add Comment
Please, Sign In to add comment