Sha256: de5838ff08556687a1ee3fdf37b5871dc8b6bde0a65a3db13097b45a0d1e6c61

Contents?: true

Size: 661 Bytes

Versions: 4

Compression:

Stored size: 661 Bytes

Contents

require 'test_helper'

class ProtectedResourcesControllerTest < ActionController::TestCase
  def authenticate
    @user = users(:one)
    @token = Knock::AuthToken.new(payload: { user_id: @user.id }).token
    @request.env['HTTP_AUTHORIZATION'] = "Bearer #{@token}"
  end

  test "responds with unauthorized" do
    get :index
    assert_response :unauthorized
  end

  test "responds with success if authenticated" do
    authenticate
    get :index
    assert_response :success
  end

  test "has a current_user after authentication" do
    authenticate
    get :index
    assert_response :success
    assert @controller.current_user.id == @user.id
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
knock-1.1.0 test/dummy/test/controllers/protected_resources_controller_test.rb
knock-1.1.0.rc1 test/dummy/test/controllers/protected_resources_controller_test.rb
knock-1.0.0 test/dummy/test/controllers/protected_resources_controller_test.rb
knock-1.0.0.rc1 test/dummy/test/controllers/protected_resources_controller_test.rb