未在RSpec请求响应中获取访问令牌

问题描述 投票:0回答:1

Rails 6.0.0

Ruby 2.6.3

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

gem'devise_token_auth','〜> 1.1.3'(默认设置)

除了我的rspec请求响应中不包含access-token之外,其他所有内容似乎都正常运行。

检查时得到

[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"=>"[email protected]",
 "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"}

注意,access-token标头仅包含一个空格(也有效)。在开发环境中不是这种情况,所有开发环境似乎都按预期工作。因此,我觉得我的RSpec配置或rails_helper中缺少某些内容。

这是一个副作用,我的API文档在生成时只是省略了auth-token键(和有效期)。

有什么想法吗?

样品规格

# 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
rspec-rails devise-token-auth
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.