Integration test api call with xml body

I have implemented an API to be used like

curl -X POST -H ‘Content-type: application/xml’ -d ‘john</

and the above call works like charm. However, I can’t figure out how
to test this. The best I could come up with is using an integration
test like:

def test_user_registration

assert_difference(‘User.count’) do
xml = ’
[email protected]

post_via_redirect 'users/register', :user => xml, :content_type =>


This test actually calls the correct method on the users_controller,
however, the params[:user] yields unparsed XML instead of the usual
hash. Any idea how to do this?

(Yes, I do plan to use cucumber, rspec and webrat in the future, but
for now I have to do it the hard way…)

ok, solved it myself using an integration test like this:

assert_difference('User.count') do
  xml = "<user>
          <email>[email protected]</email>

  post 'api/users/register', xml, :content_type => 'application/


assert_response :created

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