我正在嘗試爲我的API編寫請求規範,但需要傳遞API密鑰。 API密鑰作爲標題傳遞。在Web從我通過這樣的:如何在需要API密鑰時測試請求規範
Header: Authorization
Value: Token token="MyString"
在我的天賦,我想這樣的:
describe "sessions" do
before do
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"}}, { 'HTTP_AUTHORIZATION' => "Token token=\"MyString\"" }
response.status.should be(201)
end
end
這並不引發異常,但它也不起作用。我的測試只是失敗,錯誤代碼401
我將它改爲:'put「/api/v1/users/#{@user.id}?user_email=#{@user.email}&auth_token=#{@user.authenti cation_token}」,{user :{name:「New Name」}},{'HTTP_AUTHORIZATION'=>「Token token ='MyString'」}'但我在測試中仍然收到了'401'響應。 – Arel