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

StackOverflow https://stackoverflow.com/questions/23573007

  •  19-07-2023
  •  | 
  •  

Вопрос

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"

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top