Fernando Perez
2009-May-13 20:42 UTC
[rspec-users] 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. -- Posted via http://www.ruby-forum.com/.
BJ Clark
2009-May-13 20:48 UTC
[rspec-users] Unable to post to an update action in a controller spec
On May 13, 2009, at 1:42 PM, Fernando Perez wrote:> 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}}}put :update, :item => 1 etc. There are 4 methods for the 4 HTTP types. get, post, put, delete. ----- BJ Clark> > 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. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Fernando Perez
2009-May-14 10:23 UTC
[rspec-users] Unable to post to an update action in a controller spec
> 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. -- Posted via http://www.ruby-forum.com/.
Zach Dennis
2009-May-15 00:19 UTC
[rspec-users] Unable to post to an update action in a controller spec
On Thu, May 14, 2009 at 6:23 AM, Fernando Perez <lists at 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-routing-the-rails-default 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 at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) @zachdennis (twitter)