Guest User

Untitled

a guest
Jul 18th, 2018
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. context "POST create" do
  2. context "with just an email" do
  3. setup do
  4. post :create, :user_session => {:email => "josh.m.shgsdarpe@gmail.com"}
  5. end
  6. should_render_template :new
  7. should "have one error" do
  8. assert_select "div [class=errorExplanation]" do
  9. assert_select "li", {:count => 1, :text => "Password cannot be blank"}
  10. end
  11. end
  12. should_wrap_labels_correctly(["Password"], ["Email"])
  13. should "not define current_user" do
  14. assert_nil @response.session[:user_credentials_id]
  15. end
  16. end
  17. context "with just a password" do
  18. setup do
  19. post :create, :user_session => {:password => "asdf"}
  20. end
  21. should_render_template :new
  22. should "have one error" do
  23. assert_select "div [class=errorExplanation]" do
  24. assert_select "li", {:count => 1, :text => "Email cannot be blank"}
  25. end
  26. end
  27. should_wrap_labels_correctly(["Email"], ["Password"])
  28. should "not define current_user" do
  29. assert_nil @response.session[:user_credentials_id]
  30. end
  31. end
  32. context "with invalid credentials" do
  33. setup do
  34. post :create, :user_session => {:email => "josh.m.sharpe@gmail.com", :password => "asdf"}
  35. end
  36. should_render_template :new
  37. should "have one error" do
  38. assert_select "div [class=errorExplanation]" do
  39. assert_select "li", {:count => 1, :text => "Your email or password is incorrect. Please try again."}
  40. end
  41. end
  42. should_wrap_labels_correctly([], ["Password", "Email"])
  43. should "not define current_user" do
  44. assert_nil @response.session[:user_credentials_id]
  45. end
  46. end
  47. context "with an unconfirmed user" do
  48. setup do
  49. @user = users(:josh)
  50. assert @user.update_attribute(:confirmed_at, nil)
  51. post :create, :user_session => {:email => @user.email, :password => "asdf1234"}
  52. end
  53. should_render_template :new
  54. should "not define current_user" do
  55. assert_nil @response.session[:user_credentials_id]
  56. end
  57. should "have one error" do
  58. assert_select "div [class=errorExplanation]" do
  59. assert_select "li", {:count => 1}
  60. end
  61. end
  62. should_wrap_labels_correctly([], ["Password", "Email"])
  63. should "have the unconfirmed error" do
  64. # assert @response.body.include?("This account has not been confirmed.<br />Click <a href=\"/users/#{users(:josh).id}/send_repeat_confirmation_email\">here</a> to send another confirmation email.")
  65. end
  66. should "have the correct width for the error box" do
  67. assert_match (/<div class='errorWrapper' style='width:232px;'>/), @response.body
  68. end
  69. end
  70. context "with valid credentials" do
  71. setup do
  72. post :create, :user_session => {:email => "josh.m.sharpe@gmail.com", :password => "asdf1234"}
  73. end
  74. should "redirect_to root_path" do
  75. assert_redirected_to root_path
  76. end
  77. should "define current_user" do
  78. assert_equal users(:josh).id, @response.session[:user_credentials_id]
  79. end
  80. end
  81. end
Add Comment
Please, Sign In to add comment