At the risk of looking stupid by doing things the hard way…
I could not find a way to post xml data in a functional test. This
thread http://www.ruby-forum.com/topic/64789#73740 just ends with no
solutions, and I could not find any good examples/solutions after
searching the usual blogs/etc. I found lots of examples using curl or
other command line functions, but I want to do it with regular old
functional test methods.
So, I came up with the, er, ‘technique’ described below. Please give me
some feedback! Is there an easier/right way to do this?
-krat
In your test:
@request.env.merge!(‘RAW_POST_DATA’ => ‘1Fred’)
@request.env.merge!(‘CONTENT_TYPE’ => ‘application/xml’)
post :post_storage_record
And, the magic hack inside action_controller\test_process.rb. Add one
line to grab the params out of the post and put them into the parameters
hash:
execute the request and set/volley the response
def process(action, parameters = nil, session = nil, flash = nil)
[…]
parameters ||= {}
############ KRAT HACK!! ###########
parameters.merge!(Hash.from_xml(@request.env[‘RAW_POST_DATA’])) if
@request.env[‘RAW_POST_DATA’] &&
@request.env[‘CONTENT_TYPE’]==‘application/xml’
#####################################
@request.assign_parameters(@controller.class.controller_path,
action.to_s, parameters)
[…]
end