Unable to post to an update action in a controller spec

Hi,

I use restful routes. In one of my views I have a form that looks like:

<%- form_tag ‘/items/update’, :method => :put do -%>

<%= submit_tag “Recalculate” %>
<%- end -%>

I know I cheated a bit, as I should be submitting to /items/1 instead.
Anyway, now how can I trigger the update action in my controller test?

I tried stuff like:
post :update, {:method => ‘put’, :item => {‘1’ => {:quantity => 5}}}

But the route recognition isn’t pleased, I guess it’s missing an :id. Is
it possible to test the way I coded it?

PS: please no comment about writing code before testing, I know it’s a
bad habit, and I am doing my best to change it.

On May 13, 2009, at 1:42 PM, Fernando P. wrote:

I know I cheated a bit, as I should be submitting to /items/1 instead.
Anyway, now how can I trigger the update action in my controller test?

I tried stuff like:
post :update, {:method => ‘put’, :item => {‘1’ => {:quantity => 5}}}

put :update, :item => 1 etc.

There are 4 methods for the 4 HTTP types. get, post, put, delete.


BJ Clark

put :update, :item => 1 etc.

I tried that but didn’t work. I managed to get it working by simply
doing:

post :update, {:id => ‘dummy’, :item => {‘1’ => …}}

For some reason, I previously tried with :id => ‘update’ but Rails
didn’t like it.

On Thu, May 14, 2009 at 6:23 AM, Fernando P. [email protected]
wrote:

put :update, :item => 1 etc.

I tried that but didn’t work. I managed to get it working by simply
doing:

post :update, {:id => ‘dummy’, :item => {‘1’ => …}}

For some reason, I previously tried with :id => ‘update’ but Rails
didn’t like it.

I don’t get the impression you’re very familiar with RESTful routing
in Rails. You may want to look read about it in the Agile Web
Development w/Rails book and/or Rails guides:

It should give you a better overview of when/where to use ids, puts,
posts, etc.


Posted via http://www.ruby-forum.com/.


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users


Zach D.
http://www.continuousthinking.com (personal)
http://www.mutuallyhuman.com (hire me)
@zachdennis (twitter)