Sha256: 38a3626df0fa2c764983f23fafdf1779f7a679f8c89b8274d57f97ef55c8090d

Contents?: true

Size: 1.68 KB

Versions: 7

Compression:

Stored size: 1.68 KB

Contents

require 'test_helper'

module Guts
  class SessionsControllerTest < ActionController::TestCase
    setup do
      @user   = guts_users :admin_user
      @routes = Engine.routes
    end

    test 'should get login' do
      get :new
      assert_response :success
    end

    test 'should show error for invalid user' do
      post :create, params: {
        session: { email: 'durkadurka@gmail.com' }
      }

      assert_response :success
      assert_equal 'Invalid login credentials', flash[:alert]
    end

    test 'should login the user' do
      post :create, params: {
        session: {
          email: @user.email,
          password: 'dingo'
        }
      }

      assert_redirected_to home_path
    end

    test 'should log the user out' do
      get :destroy
      assert_equal 'You have been logged out', flash[:notice]
      assert_redirected_to new_session_path
    end

    test 'should get forgot password page' do
      get :forgot
      assert_response :success
    end

    test 'should set a forgot password token' do
      post :forgot_token, params: {
        session: { email: @user.email }
      }

      assert_equal 'Your reset link has been sent to your inbox.', flash[:notice]
      assert_redirected_to new_session_path
    end

    test 'should not set a forgot password token for invalid user' do
      post :forgot_token, params: {
        session: { email: 'durkadurka@gmail.com' }
      }

      assert_equal 'Invalid email address', flash[:alert]
    end

    test 'should reset the users password' do
      get :reset_password, params: { token: 123456 }
      assert flash[:notice].include?('new password is now')
      assert_redirected_to new_session_path
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
guts-3.1.2 test/controllers/guts/sessions_controller_test.rb
guts-3.1.1 test/controllers/guts/sessions_controller_test.rb
guts-3.1.0 test/controllers/guts/sessions_controller_test.rb
guts-3.0.1 test/controllers/guts/sessions_controller_test.rb
guts-3.0.0 test/controllers/guts/sessions_controller_test.rb
guts-2.1.0 test/controllers/guts/sessions_controller_test.rb
guts-2.0.2 test/controllers/guts/sessions_controller_test.rb