# Integration test api call with xml body

**URL:** <https://www.ruby-forum.com/t/integration-test-api-call-with-xml-body/176343>\
**Category:** Rails\
**Created:** [September 29, 2009, 10:47am UTC](https://www.ruby-forum.com/t/integration-test-api-call-with-xml-body/176343 "2009-09-29T10:47:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phibo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d6d6ee/32.png) [@phibo](https://www.ruby-forum.com/u/phibo)\
**Post date:** [September 29, 2009, 10:47am UTC](https://www.ruby-forum.com/t/integration-test-api-call-with-xml-body/176343/1 "2009-09-29T10:47:33Z")

</div>

I have implemented an API to be used like

curl -X POST -H ‘Content-type: application/xml’ -d ‘john\</  
login\>123456’  
[http://0.0.0.0:3000/users/register](http://0.0.0.0:3000/users/register)

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 = ‘  
phibo  
removed\_email\_address@domain.invalid  
somesecret  
’

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

```

‘application/xml’  
end  
end

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…)

---

<div class="post-metadata">

**Author:** ![phibo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d6d6ee/32.png) [@phibo](https://www.ruby-forum.com/u/phibo)\
**Post date:** [September 30, 2009, 11:43pm UTC](https://www.ruby-forum.com/t/integration-test-api-call-with-xml-body/176343/2 "2009-09-30T23:43:41Z")

</div>

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

```
assert_difference('User.count') do
  xml = "<user>
          <login>phibo</login>
          <email>removed_email_address@domain.invalid</email>
          <password>somesecret</password>
         </user>"

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

```

xml’  
end

```
assert_response :created
```
