# ActiveResource testing

**URL:** <https://www.ruby-forum.com/t/activeresource-testing/147770>\
**Category:** Rails\
**Created:** [September 5, 2008, 9:00am UTC](https://www.ruby-forum.com/t/activeresource-testing/147770 "2008-09-05T09:00:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![reis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f1d935/32.png) [@reis](https://www.ruby-forum.com/u/reis)\
**Post date:** [September 5, 2008, 9:00am UTC](https://www.ruby-forum.com/t/activeresource-testing/147770/1 "2008-09-05T09:00:42Z")

</div>

Hi, I’m trying to make some good testing on active resources, but I’ve  
some trouble with the _post_ method.  
Basically this is my mock, where I set the POST verb and the expected  
URI.

ActiveResource::HttpMock.respond\_to do |mock|  
mock.post “/locations/buildings.xml?description=new-  
description&name=new-name”, {}, @variable, 201  
end

Now, if I call the post method with the following code (the one I use  
into the controller), it says correctly that doesn’t found the correct  
matching. This happen because in the mock my params are in the query  
string, but if I use the save method, the params will be serialized  
into an XML flow.

So this is the code.

Building.new({“name”=\>“new-name”, “description”=\>“new-  
description”}).save

and this the error I got is this.

ActiveResource::InvalidRequestError: No response recorded for  
\<POST: /locations/buildings.xml [Content-Typeapplication/xml]  
(\<?xml version="1.0" encoding="UTF-8"?\>  
new-homenew-  
description)\>

As I know is not possible to set the body in the mock, so I tried to  
use the custom methods, but nothing to do, because as I need to add  
the costum method (a mandatory symbol or string that will be added to  
the URI) I can’t recreate my URI.

For example.

Building.post(:name, {“name”=\>“new-home”, “description”=\>“new-  
description”})

Will give me back this.

/locations/buildings/name.xml?description=new-description&name=new-  
name # ladd the name string!

Also if I set nil it change the URI, and so this break my tests.  
Thanks a lot for your time.
