views:

1468

answers:

4

I'd like to write a functional test of a RESTful web service I'm working on in a Ruby on Rails app.

The test is of a POST request where the body of the request is a plain XML doc and not a form. Any pointers on how to do this? The problem I'm encountering is how to specify the body XML in the call to the post method.

A: 

Check out shoulda's "should_be_restful" macro. This macro will soon be deprecated from shoulda and only available in the in woulda gem.

Mike Breen
A: 

You may be able to do it by setting @request.env['RAW_POST_BODY'] to the desired input stream.

Matt Burke
+5  A: 

The following worked for me:

@request.env['RAW_POST_DATA'] = MY_XML_STRING
post :create
A: 

I just wrote a test script using Net:HTTP to test the REST service.

Nils