我在这方面找不到任何东西。如何在我的 RSpec 请求测试中传递 API 密钥?
我的 API 密钥是在标头中发送的,所以我在网络上这样传递它:
Header: Authorization
Value: Token token="c32a29a71ca5953180c0a60c7d68ed9e"
如何在 RSpec 请求规范中传递它?
谢谢!!
编辑:
这是我的规格:
require 'spec_helper'
describe "sessions" do
before do
@program =FactoryGirl.create(:program)
@user = FactoryGirl.create(:user)
FactoryGirl.create(:api_key)
end
it "is authenticated with a token" do
put "/api/v1/users/#{@user.id}?user_email=#{@user.email}&auth_token=#{@user.authentication_token}", {user: {name: "New Name"}}, { 'Authorization' => "Token token='MyString'" }
response.status.should be(201)
end
it "fails without an API Token" do
put "/api/v1/users/#{@user.id}?user_email=#{@user.email}&auth_token=#{@user.authentication_token}", user: {name: "New Name"}
response.status.should be(401)
end
end