0

Rails 6.0.0

Ruby 2.6.3

gem 'rspec-rails', '~> 3.8.2'

gem 'devise_token_auth', '~> 1.1.3' (Default setup)

Everything appears to be working fine with the exception of, my rspec request responses don't contain an access-token.

When inspect, I get

[1] pry> response.headers
=> {"X-Frame-Options"=>"SAMEORIGIN",
 "X-XSS-Protection"=>"1; mode=block",
 "X-Content-Type-Options"=>"nosniff",
 "X-Download-Options"=>"noopen",
 "X-Permitted-Cross-Domain-Policies"=>"none",
 "Referrer-Policy"=>"strict-origin-when-cross-origin",
 "Content-Type"=>"application/json; charset=utf-8",
 "access-token"=>" ",
 "token-type"=>"Bearer",
 "client"=>"Vy7BgunZKjUcPq_Qe5IXRQ",
 "expiry"=>" ",
 "uid"=>"example1@example.com",
 "ETag"=>"W/\"1ecd5da9ea592fde4b83f7ae6b6906ff\"",
 "Cache-Control"=>"max-age=0, private, must-revalidate",
 "X-Request-Id"=>"6cbc675a-f50c-4bf7-be0f-07ebf120285b",
 "X-Runtime"=>"0.042266",
 "Vary"=>"Origin",
 "Content-Length"=>"28"}

Note, access-token header contains just a space (also expiry). This is NOT the case in the development environment, all appears to be working as expected there. So, I feel like I'm missing something in my RSpec config or rails_helper.

A side-effect of this is, my API docs are just omitting the auth-token key (and expiry) when generated.

Any ideas?

Sample spec

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Api::V1::Clients', type: :request do
  let(:user) { FactoryBot.create(:user) }
  let(:client) { FactoryBot.create(:client) }

  let(:headers) do
    {
      'Content-Type': 'application/json',
      'Accept': 'application/json'
    }
  end

  describe 'GET /api/v1/clients' do
    before { client }
    it 'returns a 200 status code', :dox do
      get api_v1_clients_path, headers: headers.merge!(user.create_new_auth_token)
      expect(response).to have_http_status(200)
    end
  end
end
Garrett Davis
  • 339
  • 2
  • 11

1 Answers1

0

Found it.

https://github.com/lynndylanhurley/devise_token_auth/blob/master/docs/conceptual.md#about-token-management

You don't get a new token in a response less than 5.seconds before the previous.

Garrett Davis
  • 339
  • 2
  • 11