Than request.env['RAW_POST_DATA'] = json_body
?
3
-
Is this for a controller spec? It would help if you could include an example. – zetetic Feb 24 '11 at 21:46
-
Sorry, yes, it's for an rspec controller test. – avocade Feb 25 '11 at 23:07
-
1Not as far as I can tell. Thanks for showing me how to set the raw post data though :) – Kevin May 14 '13 at 18:48
Add a comment
|
I'm not sure if this is what you mean, but you can set the request headers to indicate JSON:
describe "POST 'create'" do
it "should be successful" do
request.env["HTTP_ACCEPT"] = "application/json"
post 'create', :article => { :title => "Foo" }.to_json
response.should be_success
end
end
-
Interesting, but we'll need to set the .json suffix for our API documentation but I guess we can do it this way as well. – avocade Feb 28 '11 at 13:39
-
1Why do you set the second
post
argument to be:article => <a hash>.to_json
rather than just a straight-up json string like<a hash>.to_json
? Does this require your handler to decode the contents of the article param rather than decoding the body? – Derek Dahmer Apr 4 '12 at 19:04