Advertisement
Guest User

Untitled

a guest
Mar 27th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. test "login with valid information followed by logout" do
  2. get login_path
  3. post login_path, session: { email: @user.email, password: 'password' }
  4. assert is_logged_in?
  5. assert_redirected_to @user
  6. follow_redirect!
  7. assert_template 'users/show'
  8. assert_select "a[href=?]", login_path, count: 0
  9. assert_select "a[href=?]", logout_path
  10. assert_select "a[href=?]", user_path(@user)
  11. delete logout_path
  12. assert_redirected_to root_url
  13. assert_not is_logged_in? # <-- this line is the one that cocks up.
  14. follow_redirect!
  15. assert_select "a[href=?]", login_path
  16. assert_select "a[href=?]", logout_path, count: 0
  17. assert_select "a[href=?]", user_path(@user), count: 0
  18. end
  19.  
  20. def destroy
  21. logout
  22. redirect_to root_url
  23. end
  24.  
  25. def logout
  26. session.delete(:user_id)
  27. @current_user = nil
  28. end
  29.  
  30. def is_logged_in?
  31. !current_user.nil?
  32. end
  33.  
  34. test "login with invalid information" do
  35. get login_path
  36. assert_template 'sessions/new'
  37. post login_path, session: { email: "", password: "" }
  38. assert_template 'sessions/new'
  39. assert_not flash.empty?
  40. get root_path
  41. assert flash.empty?
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement