Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom request headers in rspec controller test being passed as rack.session

I tried following instructions on how to pass the custom headers but it's not working for me. Here's what I'm calling in my respec test

post :create, {name:profile.name}, {'X-API-KEY' => 'somekey'}

From my controller I don't see it in the header as X-API-KEY but instead seems to be in request.headers["rack.session"]["X-API-KEY"]

How do I get it to not pass it as "rack.session"

like image 386
MonkeyBonkey Avatar asked May 09 '14 20:05

MonkeyBonkey


1 Answers

I've been digging through the issue this morning as well. The problem comes from here http://apidock.com/rails/ActionController/TestProcess/process as the method signature looks like this (action, parameters = nil, session = nil, flash = nil, http_method = 'GET'). This was quite unexpected to me and I'll keep looking though I'm not quite sure why it happens like this.

To get it working you could do

before do request.headers['X-API-KEY'] = 'somekey' end

This works, although not exactly what I wanted/expected from the get method.

like image 57
Stefan Dorunga Avatar answered Sep 27 '22 21:09

Stefan Dorunga