Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- test "login with valid information followed by logout" do
- get login_path
- post login_path, session: { email: @user.email, password: 'password' }
- assert is_logged_in?
- assert_redirected_to @user
- follow_redirect!
- assert_template 'users/show'
- assert_select "a[href=?]", login_path, count: 0
- assert_select "a[href=?]", logout_path
- assert_select "a[href=?]", user_path(@user)
- delete logout_path
- assert_redirected_to root_url
- assert_not is_logged_in? # <-- this line is the one that cocks up.
- follow_redirect!
- assert_select "a[href=?]", login_path
- assert_select "a[href=?]", logout_path, count: 0
- assert_select "a[href=?]", user_path(@user), count: 0
- end
- def destroy
- logout
- redirect_to root_url
- end
- def logout
- session.delete(:user_id)
- @current_user = nil
- end
- def is_logged_in?
- !current_user.nil?
- end
- test "login with invalid information" do
- get login_path
- assert_template 'sessions/new'
- post login_path, session: { email: "", password: "" }
- assert_template 'sessions/new'
- assert_not flash.empty?
- get root_path
- assert flash.empty?
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement