ruby on rails - Sending custom headers through RSpec -


given api consumers required send customer http header this:

# curl -h 'x-someheader: 123' http://127.0.0.1:3000/api/api_call.json 

then can read header in before_filter method this:

# app/controllers/api_controller.rb class apicontroller < applicationcontroller     before_filter :log_request  private     def log_request         logger.debug "header: #{request.env['http_x_someheader']}"         ...     end end 

so far great. test using rspec there change in behavior:

# spec/controllers/api_controller_spec.rb describe apicontroller     "should process header"         @request.env['http_x_someheader'] = '123'         :api_call         ...     end end 

however, request received in apicontroller not able find header variable.

when trying same code http_accept_language header, work. custom headers filtered somewhere?

ps: examples around web use request instead of @request. while i'm not 1 correct of current rails 3.2/rspec 2.14 combination - both methods not trigger right behavior, both work http_accept_language well.

well, maybe late people lined up:

it 'should profile when authorized'   user = factorygirl.create :user   request.headers[email_token] = user.email   request.headers[auth_token] = user.authentication_token   :profile   response.should success end 

just call request.headers appropriate settings.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -