HTTP_ACCEPT header is missing in controller specs

15 views
Skip to first unread message

watcher...@gmail.com

unread,
Aug 22, 2015, 2:31:05 PM8/22/15
to rspec
Hi.

Recently I discovered a starange thing. ActionDispatch::TestRequest instance doesn't contain HTTP_ACCEPT header while been generated in controller specs:
RSpec.describe "Projects", :type => :controller do
    describe
FoosController do
        describe
"Get index" do
            context
"common" do
                before
do
                   
get :index, nil, {'HTTP_ACCEPT' => 'application/json'} #doesn't affect at all, nothing to affect
               
end
               
...
             
end
       
end
   
end
end

Hence it's impossible to set this header during requests. The only solution I found is setting the header with @request.env in before block before issuing the request:
before do
   
@request.env['HTTP_ACCEPT'] = 'application/json'
   
...
end
Can anyone explain me why this is happening in controller specs? And is there another (better) way to set the header? 




ActionDispatch::TestRequest

Reply all
Reply to author
Forward
0 new messages