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"=>"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"}
请注意,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
答案 0 :(得分:0)