views:

27

answers:

1

I'm trying to test a rails action that takes raw json in the POST body. If i curl with the Content-Type: application/json header set, rails parses the params correctly.

How do you set the request body and headers directly in an rspec controller test?

+1  A: 

In RSpec 1.3 you can operate on a "request" variable. Something like this should work for you:

request.env['CONTENT_TYPE'] = 'application/json'
post :method_name
Matt Shanley
This worked perfectly, combined with settings the params in the request.env['RAW_POST_DATA']. Thanks.
Christopher Foy