Forum: RSpec Unable to post to an update action in a controller spec

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fernando P. (Guest)
on 2009-05-14 00:42
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.
BJ Clark (Guest)
on 2009-05-14 01:04
(Received via mailing list)
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
Fernando P. (Guest)
on 2009-05-14 14:23
> 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.
Zach D. (Guest)
on 2009-05-15 04:22
(Received via mailing list)
On Thu, May 14, 2009 at 6:23 AM, Fernando P. 
<removed_email_address@domain.invalid>
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:

http://guides.rubyonrails.org/routing.html#restful...

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
> removed_email_address@domain.invalid
> http://rubyforge.org/mailman/listinfo/rspec-users
>



--
Zach D.
http://www.continuousthinking.com (personal)
http://www.mutuallyhuman.com (hire me)
@zachdennis (twitter)
This topic is locked and can not be replied to.