5

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 guess is fine, but the RAW_POST_DATA doesn't show up as a hash in the parameters list in the log.... now... it works when I call the 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?

NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352

1 Answers1

0

Is there a reason why you aren't just passing the params to the post call itself? eg:

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

Controller tests are there to test that the controller action does what it expects when you send it params that you already know of. they generally aren't there to test parsing of xml into params.

If you just want to test the former - then don't bother making them into xml - just pass them as a hash.

If you really do want to test parsing of xml into params - you may need to look into something that operates outside of the scope of rails tests (eg selenium or watir)

Taryn East
  • 27,486
  • 9
  • 86
  • 108
  • 1
    because the controller doesn't parse the XML if you do it like that. or at least, mine doesn't. – NullVoxPopuli Aug 10 '11 at 18:05
  • yes - you shouldn't pass it as xml if you do it that way - just as a hash. Of course if the purpose is to pass xml specifically - then I'm not sure what you need to do. – Taryn East Aug 22 '11 at 17:40