/vendor/gems/devise/test/integration/registerable_test.rb

https://github.com/kenan-memis/university-web · Ruby · 153 lines · 136 code · 17 blank · 0 comment · 0 complexity · 908a0d5c29567beb01db16593984ec62 MD5 · raw file

  1. require 'test_helper'
  2. class RegistrationTest < ActionController::IntegrationTest
  3. test 'a guest admin should be able to sign in successfully' do
  4. get new_admin_session_path
  5. click_link 'Sign up'
  6. assert_template 'registrations/new'
  7. fill_in 'email', :with => 'new_user@test.com'
  8. fill_in 'password', :with => 'new_user123'
  9. fill_in 'password confirmation', :with => 'new_user123'
  10. click_button 'Sign up'
  11. assert_contain 'You have signed up successfully.'
  12. assert warden.authenticated?(:admin)
  13. admin = Admin.last :order => "id"
  14. assert_equal admin.email, 'new_user@test.com'
  15. end
  16. test 'a guest user should be able to sign up successfully and be blocked by confirmation' do
  17. get new_user_registration_path
  18. fill_in 'email', :with => 'new_user@test.com'
  19. fill_in 'password', :with => 'new_user123'
  20. fill_in 'password confirmation', :with => 'new_user123'
  21. click_button 'Sign up'
  22. assert_contain 'You have signed up successfully'
  23. assert_contain 'Sign in'
  24. assert_not_contain 'You have to confirm your account before continuing'
  25. assert_not warden.authenticated?(:user)
  26. user = User.last :order => "id"
  27. assert_equal user.email, 'new_user@test.com'
  28. assert_not user.confirmed?
  29. end
  30. test 'a guest user cannot sign up with invalid information' do
  31. get new_user_registration_path
  32. fill_in 'email', :with => 'invalid_email'
  33. fill_in 'password', :with => 'new_user123'
  34. fill_in 'password confirmation', :with => 'new_user321'
  35. click_button 'Sign up'
  36. assert_template 'registrations/new'
  37. assert_have_selector '#error_explanation'
  38. assert_contain "Email is invalid"
  39. assert_contain "Password doesn't match confirmation"
  40. assert_nil User.first
  41. assert_not warden.authenticated?(:user)
  42. end
  43. test 'a guest should not sign up with email/password that already exists' do
  44. user = create_user
  45. get new_user_registration_path
  46. fill_in 'email', :with => 'user@test.com'
  47. fill_in 'password', :with => '123456'
  48. fill_in 'password confirmation', :with => '123456'
  49. click_button 'Sign up'
  50. assert_current_url '/users'
  51. assert_contain(/Email .* already .* taken/)
  52. assert_not warden.authenticated?(:user)
  53. end
  54. test 'a guest should not be able to change account' do
  55. get edit_user_registration_path
  56. assert_redirected_to new_user_session_path
  57. follow_redirect!
  58. assert_contain 'You need to sign in or sign up before continuing.'
  59. end
  60. test 'a signed in user should not be able to access sign up' do
  61. sign_in_as_user
  62. get new_user_registration_path
  63. assert_redirected_to root_path
  64. end
  65. test 'a signed in user should be able to edit his account' do
  66. sign_in_as_user
  67. get edit_user_registration_path
  68. fill_in 'email', :with => 'user.new@email.com'
  69. fill_in 'current password', :with => '123456'
  70. click_button 'Update'
  71. assert_current_url '/'
  72. assert_contain 'You updated your account successfully.'
  73. assert_equal "user.new@email.com", User.first.email
  74. end
  75. test 'a signed in user should not change his current user with invalid password' do
  76. sign_in_as_user
  77. get edit_user_registration_path
  78. fill_in 'email', :with => 'user.new@email.com'
  79. fill_in 'current password', :with => 'invalid'
  80. click_button 'Update'
  81. assert_template 'registrations/edit'
  82. assert_contain 'user@test.com'
  83. assert_have_selector 'form input[value="user.new@email.com"]'
  84. assert_equal "user@test.com", User.first.email
  85. end
  86. test 'a signed in user should be able to edit his password' do
  87. sign_in_as_user
  88. get edit_user_registration_path
  89. fill_in 'password', :with => 'pas123'
  90. fill_in 'password confirmation', :with => 'pas123'
  91. fill_in 'current password', :with => '123456'
  92. click_button 'Update'
  93. assert_current_url '/'
  94. assert_contain 'You updated your account successfully.'
  95. assert User.first.valid_password?('pas123')
  96. end
  97. test 'a signed in user should not be able to edit his password with invalid confirmation' do
  98. sign_in_as_user
  99. get edit_user_registration_path
  100. fill_in 'password', :with => 'pas123'
  101. fill_in 'password confirmation', :with => ''
  102. fill_in 'current password', :with => '123456'
  103. click_button 'Update'
  104. assert_contain "Password doesn't match confirmation"
  105. assert_not User.first.valid_password?('pas123')
  106. end
  107. test 'a signed in user should be able to cancel his account' do
  108. sign_in_as_user
  109. get edit_user_registration_path
  110. click_link "Cancel my account", :method => :delete
  111. assert_contain "Bye! Your account was successfully cancelled. We hope to see you again soon."
  112. assert User.all.empty?
  113. end
  114. end