How I posted xml in a functional test

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

On 1/23/07, krat [email protected] wrote:

So, I came up with the, er, ‘technique’ described below. Please give me

post :post_storage_record

action.to_s, parameters)

Krat,

You might want to try integration testing. I have a doc patch open
(http://dev.rubyonrails.org/ticket/7039) with an example
(http://dev.rubyonrails.org/attachment/ticket/7039/additional_integration_testing_docs.diff)
on posting raw data.

Hope this helps,


Zack C.
http://depixelate.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs