我在 Rails 3 上使用 rack/test 和 rspec 通过设计验证用户 api 密钥。我发出的任何请求都会返回状态 302 和响应:“您正在被重定向。”。似乎无法弄清楚如何进行身份验证。
require 'spec_helper'
describe Api::V1::CollectController do
def app
Rails.application
end
context 'user' do
subject do
FactoryGirl.create :user
end
it 'allow valid api credentials' do
post '/api/collect', {}, { 'Authentication' => subject.authentication_token }
p last_response.body
end
end
end