On 1/23/07, krat
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> 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'' =>
''<person><id>1</id><first-name>Fred</first-name></person>'')
> >@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
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
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 Chandler
http://depixelate.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---