如何在我的get请求中添加`headers`。

时间:2014-08-07 19:04:54

标签: ruby-on-rails ruby ruby-on-rails-4 rspec

如何将headers添加到我的获取request

it "can find an account" do 
    get "/accounts/#{@acc.id}/", headers # like the token or whatever your api needs
end

以下是我传递令牌的controller方法,现在我将如何append传递给get request

Account.find(id: @acc.id, authorization: @auth_token);

2 个答案:

答案 0 :(得分:1)

使用request.env设置标题

it "can find an account" do 
   request.env['AUTH_TOKEN'] = "token"
   get "/accounts/#{@acc.id}/"
end

答案 1 :(得分:1)

您可以将标题作为第三个参数发送到get

get "/accounts/#{@acc.id}/", nil, {'AUTH_TOKEN' => 'token'}.

有关详细信息,请参阅get的文档。