Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between 'env' and 'request.env' in Rails Controller?

I'm using rspec to write test for my application. In order to authorization I'm sending token in header:

request.headers['token'] = '000000099'
get :index

In controller side I can read this value by request.env["HTTP_TOKEN"] but env["HTTP_TOKEN"] is empty.

What is the difference between them and how can I set env instead of request.env?

like image 285
Ali Sepehri.Kh Avatar asked Oct 18 '15 07:10

Ali Sepehri.Kh


1 Answers

request.env is a ruby hash that contains information about a visiting user’s and server environments. request.env is the standard object that's being used in Rails app to extract important information such as path_info, request_uri etc.

env is empty for your test because rspec-rails bypasses the ActionController::Metal dispatch method.

like image 115
K M Rakibul Islam Avatar answered Oct 25 '22 21:10

K M Rakibul Islam