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.
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-05-13 22: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.
B8c4bfb1b6002a5b43d87de3335401f5?d=identicon&s=25 BJ Clark (Guest)
on 2009-05-13 23:04
(Received via mailing list)
On May 13, 2009, at 1:42 PM, Fernando Perez 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
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-05-14 12: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.
F86901feca747abbb5c6c020362ef2e7?d=identicon&s=25 Zach Dennis (zdennis)
on 2009-05-15 02:22
(Received via mailing list)
On Thu, May 14, 2009 at 6:23 AM, Fernando Perez <lists@ruby-forum.com>
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
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>



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