Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. require 'test_helper'
  2.  
  3. class UsersLoginTest < ActionDispatch::IntegrationTest
  4. def setup
  5. @user = users(:michael)
  6. end
  7.  
  8. test "login with invalid information" do
  9. get login_path
  10. assert_template 'sessions/new'
  11. post login_path, params: { session: { email: "", password: "" } }
  12. assert_template 'sessions/new'
  13. assert_not flash.empty?
  14. get root_path
  15. assert flash.empty?
  16. end
  17.  
  18. test "login with valid information" do
  19. get login_path
  20. post login_path, params: { session: { email: @user.email,
  21. password: 'password' } }
  22. assert_redirected_to @user
  23. follow_redirect!
  24. assert_template 'users/show'
  25. assert_select "a[href=?]", login_path, count: 0
  26. assert_select "a[href=?]", logout_path
  27. assert_select "a[href=?]", user_path(@user)
  28. end
  29.  
  30. test "login with valid information followed by logout" do
  31. get login_path
  32. post login_path, params: { session: { email: @user.email,
  33. password: 'password' } }
  34. assert is_logged_in?
  35. assert_redirected_to @user
  36. follow_redirect!
  37. assert_template 'users/show'
  38. assert_select "a[href=?]", login_path, count: 0
  39. assert_select "a[href=?]", logout_path
  40. assert_select "a[gref=?]", user_path(@user)
  41. delete logout_path
  42. assert_not is_logged_in?
  43. assert_redirected_to root_url
  44. follow_redirect!
  45. assert_select "a[href=?]", login_path
  46. assert_select "a[href=?]", logout_path, count = 0
  47. assert_select "a[href=?]", user_path(@user), count = 0
  48. end
  49. end
  50.  
  51. # i po rails test takie o
  52.  
  53. FAIL["test_login_with_valid_information", UsersLoginTest, 0.6958769999910146]
  54. test_login_with_valid_information#UsersLoginTest (0.70s)
  55. Expected at least 1 element matching "a[href="/logout"]", found 0..
  56. Expected 0 to be >= 1.
  57. test/integration/users_login_test.rb:26:in `block in <class:UsersLoginTest>'
  58.  
  59. FAIL["test_login_with_valid_information_followed_by_logout", UsersLoginTest, 0.7184420000121463]
  60. test_login_with_valid_information_followed_by_logout#UsersLoginTest (0.72s)
  61. Expected at least 1 element matching "a[href="/logout"]", found 0..
  62. Expected 0 to be >= 1.
  63. test/integration/users_login_test.rb:39:in `block in <class:UsersLoginTest>'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement