0

我在 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    
4

1 回答 1

0

我找到了一个可行的解决方案。但我不满意为什么原来的方法不起作用。我取消了机架/测试并改变了我与控制器的接口方式。以下工作。我现在主要是好奇...

require 'spec_helper'

describe Api::V1::CollectController do
  context 'user' do
    subject do
      FactoryGirl.create :user
    end

    it 'allow valid api credentials' do
      post :create, {}, { 'Authentication' => subject.authentication_token }
      p response.body
    end
  end
end  
于 2012-10-04T05:41:22.323 回答