07 June 2006

Testing REST in Rails

I've been working on a Rails app that has a REST API. This API uses the Atom syndication protocol, very similar to GData. It works, but there are issues, primarily in testing it, within Rails. This thread on the Rails mailing list describes it well. The problem is that Rails doesn't easily facilitate passing raw XML data in your POST, and it tries to turn that data into a hash. Unlike the call shown in the thread, I've gone and, prior to the POST call, done:

@request.env['RAW_POST_DATA'] = my_xml_post_data

to try to deposit the Atom XML directly. However, Rails seems to still try to hash this, and I get the same warnings as shown in the mailing list thread.

I will be digging in to the Rails source to see what can be done about this. But, if you've got a work around, please comment. The one other bit here, and I hope this will be an easy fix/change in the Rails code, is support for content type and accept headers of "application/atom+xml". If you use this today, it does not result in your xml request handler getting invoked. This is not a strict requirement, but following standards and so on, this would be good to have.

0 comments: