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

I use rspec to write a test for my application. For authorization, I send token in the header:

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

On the controller side, I can read this request.env["HTTP_TOKEN"] value, but env["HTTP_TOKEN"] empty.

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

+5
source share
1 answer

request.env is a ruby ​​array containing information about visited users and server environments. request.env is a standard object used in a Rails application to retrieve important information such as path_info , request_uri , etc.

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

+6
source

Source: https://habr.com/ru/post/1233953/


All Articles