I have a test that sets the Authorization header.
test "index should return a list of shifts at a given date" do
@request.env["Custom_authorization"] = "bar"
@request.env["Authorization"] = "bar"
get :index,
{ date: '2015/9/8' }
assert_response :success
end
For some reason, the 'Authorization' header is being set to nil, even though customer authorization headers are set:
(byebug) request.headers['Authorization']
nil
(byebug) request.headers['Custom_authorization']
"bar"
Where is the 'Authorization' header being set to nil?
get method prototype is,
get(path, parameters = nil, headers_or_env = nil)
Reff : http://api.rubyonrails.org/classes/ActionDispatch/Integration/RequestHelpers.html#method-i-get
So use it like,
get :index, { date: '2015/9/8' }, { "Authorization" => "bar" }
下面的代码应该可以工作(byebug)request.headers [:Authorization]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.