Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. Index: test/functional/users_controller_test.rb
  2. ===================================================================
  3. --- test/functional/users_controller_test.rb (revision 2727)
  4. test/functional/users_controller_test.rb (working copy)
  5. @@ -117,7 117,33 @@
  6. put :update, :id => 1, :user => { }, :format => 'xml'
  7. assert_response :success
  8. end
  9.  
  10. def test_should_update_user_without_needing_password
  11. login_as :sam
  12. put :update, :id => users(:sam).id, :user => { :email => 'sam@newemail.com'}
  13. assert_redirected_to edit_user_path(assigns(:user))
  14. assert_not_equal users(:sam).email, assigns(:user).email
  15. end
  16.  
  17. def test_should_update_password_with_confirmation
  18. login_as :sam
  19. put :update, :id => users(:sam).id, :user => { :password => 'newpass', :password_confirmation => 'newpass'}
  20. assert_redirected_to edit_user_path(assigns(:user))
  21. assert flash.has_key?(:notice)
  22. end
  23.  
  24. def test_should_not_update_password_with_wrong_confirmation
  25. login_as :sam
  26. put :update, :id => users(:sam).id, :user => { :password => 'newpass', :password_confirmation => 'notnewpass'}
  27. assert !flash.has_key?(:notice)
  28. end
  29.  
  30. def test_should_not_update_password_with_blank_confirmation
  31. login_as :sam
  32. put :update, :id => users(:sam).id, :user => { :password => 'newpass', :password_confirmation => '' }
  33. assert !flash.has_key?(:notice)
  34. end
  35.  
  36. def test_should_only_update_safe_fields
  37. # non-admin should not be able to change all this stuff
  38. login_as :sam
  39. Index: app/models/user.rb
  40. ===================================================================
  41. --- app/models/user.rb (revision 2727)
  42. app/models/user.rb (working copy)
  43. @@ -13,6 13,7 @@
  44. validates_length_of :login, :minimum => 2
  45. validates_length_of :password, :minimum => 5, :allow_nil => true
  46. validates_confirmation_of :password, :on => :create
  47. validates_confirmation_of :password, :on => :update, :allow_nil => true
  48.  
  49. # names that start with #s really upset me for some reason
  50. validates_format_of :login, :with => /^[a-z]{2}(?:\w )?$/i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement