簡體   English   中英

如何在 Rails 5 中設置 request.referer (ActionDispatch::IntegrationTest)

[英]How set request.referer in Rails 5 (ActionDispatch::IntegrationTest)

我正在使用 Rails 5,默認測試引擎 (ActionDispatch::IntegrationTest)

如何在測試環境中設置request.referer的內容。

它在開發環境中完美運行,但在我運行測試時為零

我在文檔中找到了回復( http://edgeguides.rubyonrails.org/testing.html#setting-headers-and-cgi-variables

您可以使用以下語法設置request.referer

get articles_url, headers: { "HTTP_REFERER": "http://example.com/home" }

在這種情況下request.referer將等於http://example.com/home

對於 RSPEC 3、導軌 5

let(:headers) { some: "header" }
#...
request.headers.merge! headers
post :endpoint, params: params

https://github.com/rspec/rspec-rails/issues/1655#issuecomment-250418438

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM