Ruby on Rails: Functional Testing: POST does not send raw XML data

I have the following:

@request.env['RAW_POST_DATA'] = data @request.env['CONTENT_TYPE'] = 'application/xml' @request.env['HTTP_CONTENT_TYPE'] = 'application/xml' post "create", :api_key => api_key, :format => "xml" 

and test.log shows this:

 Processing ****Controller#create to xml (for 0.0.0.0 at 2011-07-08 15:40:20) [POST] Parameters: {"format"=>"xml", "action"=>"create", "api_key"=>"the_hatter_wants_to_have_tea1", "controller"=>"****"} 

Which ... I think it's good, but RAW_POST_DATA does not appear as a hash in the parameter list in the log .... now ... it works when I call an action from the terminal using curl

 curl -H 'Content-Type: application/xml' -d '<object><name>Das Object</name></object>' http://notAvailableDuringTesting.butWorksInDevelopmentMode.dev/object.xml?api_key=the_hatter_wants_to_have_tea1 

what am i doing wrong here?

+4
source share
1 answer

Is there a reason why you are not just passing parameters to the mail call itself? eg:

  post "create", :api_key => api_key, :format => "xml", :params => data 

Controller tests verify that the action of the controller does what it expects when you send parameters that you already know about. they usually do not check the xml parsing in params.

If you just want to test the first - then don't bother doing them in xml - just pass them as a hash.

If you really want to test the xml parsing on params, you may need to learn something that works outside the scope of the rails tests (e.g. selenium or watir)

0
source

All Articles