Sha256: 145d191c60c6103d55ca2e6c61471d1384e5484c8d369b308174a5dbc0348436

Contents?: true

Size: 1002 Bytes

Versions: 2

Compression:

Stored size: 1002 Bytes

Contents

require 'test_helper'

class UsersControllerTest < ActionController::TestCase
  setup do
  end

  test 'returns 401 when not authorized' do
    get :index, format: :json
    assert_response 401
    assert_nil assigns(:current_user)
  end

  test 'returns success when authorized' do
    user = User.create
    @request.headers["Authorization"] = "Token token=#{user.id}.#{user.auth_token}"
    get :index
    assert_response :success
    assert_not_nil assigns(:current_user)
  end

  test 'returns 401 when invalid token' do
    user = User.create
    @request.headers["Authorization"] = "Token token=#{user.id}.invalidtoken"
    get :index
    assert_response 401
    assert_nil assigns(:current_user)
  end

  test 'returns 401 when token is expired' do
    user = User.create
    @request.headers["Authorization"] = "Token token=#{user.id}.#{user.auth_token}"
    Timecop.freeze(4.hours.since) do
      get :index
      assert_response 401
      assert_nil assigns(:current_user)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simple_token_auth-0.0.4 test/simple_token_auth/integration_test.rb
simple_token_auth-0.0.3 test/simple_token_auth/integration_test.rb