Guest User

Untitled

a guest
Jun 20th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. ## password_resets_controller_test.rb
  2.  
  3. require 'test_helper'
  4.  
  5. class PasswordResetsControllerTest < ActionController::TestCase
  6.  
  7. # Works using user fixture...
  8.  
  9. context "Logged out" do
  10. setup do
  11. @user = users(:ben)
  12. end
  13.  
  14. context "on GET to :edit" do
  15. context "with a valid perishable token" do
  16. setup { get :edit, :id => @user.perishable_token }
  17. should_respond_with :success
  18. should_render_template :edit
  19. should_not_set_the_flash
  20. end
  21.  
  22. context "without a valid perishable token" do
  23. setup { get :edit, :id => @user.username }
  24. should_not_assign_to :user
  25. should_respond_with :redirect
  26. should_set_the_flash_to /sorry/i
  27. end
  28. end
  29.  
  30. context "on PUT to :update" do
  31. setup { put :update, :id => @user.perishable_token, :user => { :password => "newpassword", :password_confirmation => "newpassword"} }
  32. should_respond_with :redirect
  33. should_set_the_flash_to /updated/i
  34. end
  35. end
  36.  
  37. # Doesn't work using Factory(:user
  38.  
  39. context "Logged out" do
  40. setup do
  41. @user = Factory(:user)
  42. @user_session = UserSession.find(@user)
  43. @user_session.destroy
  44. end
  45.  
  46. context "on GET to :edit" do
  47. context "with a valid perishable token" do
  48. setup { get :edit, :id => @user.perishable_token }
  49. should_respond_with :success
  50. should_render_template :edit
  51. should_not_set_the_flash
  52. end
  53.  
  54. context "without a valid perishable token" do
  55. setup { get :edit, :id => @user.username }
  56. should_not_assign_to :user
  57. should_respond_with :redirect
  58. should_set_the_flash_to /sorry/i
  59. end
  60. end
  61.  
  62. context "on PUT to :update" do
  63. setup { put :update, :id => @user.perishable_token, :user => { :password => "newpassword", :password_confirmation => "newpassword"} }
  64. should_respond_with :redirect
  65. should_set_the_flash_to /updated/i
  66. end
  67. end
  68. end
  69.  
  70. ## users.yml
  71.  
  72. ben:
  73. username: ben
  74. email: ben@example.com
  75. password_salt: <%= salt = Authlogic::Random.hex_token %>
  76. crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("password" + salt) %>
  77. persistence_token: <%= Authlogic::Random.hex_token %>
  78. single_access_token: <%= Authlogic::Random.friendly_token %>
  79. perishable_token: <%= Authlogic::Random.friendly_token %>
  80.  
  81.  
  82. ## factories.rb
  83.  
  84. Factory.define :user do |f|
  85. f.sequence(:username) { |n| "user#{n}" }
  86. f.password "password"
  87. f.password_confirmation { |u| u.password }
  88. f.sequence(:email) { |n| "user#{n}@example.com" }
  89. end
  90.  
  91. ## Errors
  92.  
  93.  
  94. 1) Failure:
  95. test: Logged out on GET to :edit with a valid perishable token should not set the flash. (PasswordResetsControllerTest)
  96. method __bind_1244363655_917834 in macros.rb at line 93
  97. method call in context.rb at line 254
  98. method test: Logged out on GET to :edit with a valid perishable token should not set the flash. in context.rb at line 254
  99. Flash was set to:
  100. {:notice=>"We're sorry, but we could not locate your account.If you are having issues try copying and pasting the URL from your email into your browser or restarting the reset password process."}.
  101. <{}> expected but was
  102. <{:notice=>
  103. "We're sorry, but we could not locate your account.If you are having issues try copying and pasting the URL from your email into your browser or restarting the reset password process."}>.
  104.  
  105. 2) Failure:
  106. test: Logged out on GET to :edit with a valid perishable token should render template :edit. (PasswordResetsControllerTest)
  107. method __bind_1244363655_938004 in macros.rb at line 220
  108. method call in context.rb at line 254
  109. method test: Logged out on GET to :edit with a valid perishable token should render template :edit. in context.rb at line 254
  110. expecting <"edit"> but rendering with <"">
  111.  
  112. 3) Failure:
  113. test: Logged out on GET to :edit with a valid perishable token should respond with success. (PasswordResetsControllerTest)
  114. method __bind_1244363655_954256 in macros.rb at line 177
  115. method call in context.rb at line 254
  116. method test: Logged out on GET to :edit with a valid perishable token should respond with success. in context.rb at line 254
  117. Expected response to be a <:success>, but was <302>
  118.  
  119. 4) Failure:
  120. test: Logged out on PUT to :update should have /updated/i in the flash. (PasswordResetsControllerTest)
  121. method assert_contains in assertions.rb at line 29
  122. method __bind_1244363656_269338 in macros.rb at line 89
  123. method call in context.rb at line 254
  124. method test: Logged out on PUT to :update should have /updated/i in the flash. in context.rb at line 254
  125. /updated/i not found in ["We're sorry, but we could not locate your account.If you are having issues try copying and pasting the URL from your email into your browser or restarting the reset password process."] , Flash: {:notice=>"We're sorry, but we could not locate your account.If you are having issues try copying and pasting the URL from your email into your browser or restarting the reset password process."}.
  126. <nil> is not true.
  127.  
  128. 25 tests, 26 assertions, 4 failures, 0 errors
Add Comment
Please, Sign In to add comment