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"?> <building><building><static><name>new-home</name><description>new- description</description></static></building></building>)>
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.