Sha256: bce9975fd0957bd2e344e5a85482f4c6e1726da38034344cdc351a114a87c18f

Contents?: true

Size: 1022 Bytes

Versions: 2

Compression:

Stored size: 1022 Bytes

Contents

require 'spec_helper'

RSpec.describe 'Request integration', type: :request do
  let(:token) { Visa::Token.create tokenable: User.create }

  def get_root_with_token(token)
    if Rails::VERSION::MAJOR == 4
      get '/', access_token: token
    else
      get '/', params: {access_token: token}
    end
  end

  it 'accepts valid tokens' do
    get_root_with_token "#{token.client_id}#{token.secret}"

    expect(response.status).to eq(200)
  end

  it 'returns 401 when the token is invalid' do
    get_root_with_token "#{token.client_id}this-is-invalid"

    expect(response.status).to eq(401)
  end

  it 'returns 401 when the token has not been used in two weeks' do
    token.update_column :last_requested_at, 15.days.ago

    get_root_with_token "#{token.client_id}#{token.secret}"

    expect(response.status).to eq(401)
  end

  it 'updates the last_requested_at column' do
    get_root_with_token "#{token.client_id}#{token.secret}"

    token.reload

    expect(token.last_requested_at).to_not be_nil
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
visa-0.1.0 spec/requests/requests_spec.rb
visa-0.0.3 spec/requests/requests_spec.rb