Nicholas Wieland
2008-May-20 08:06 UTC
REST and create action: why does it accept GET requests ?
Hi *, # TODO: why does this method accept get requests ? # it "should not login getting correct credentials" do # get :create, :login => ''quentin'', :password => ''test'' # session[ :user_id ].should be_nil # flash[ :notice ].should be_nil # end This spec fails, but AFAIK create actions that are routed as .resources should accept just POSTed data, not GETted. Here the session is setted to the user.id, and the Flash notice says I logged in successfully, this doesn''t really make sense to me. Rails 2.0.2 TIA, ngw
Rory McKinley
2008-May-20 08:46 UTC
Re: REST and create action: why does it accept GET requests ?
Nicholas Wieland wrote:> Hi *, > > # TODO: why does this method accept get requests ? > # it "should not login getting correct credentials" do > # get :create, :login => ''quentin'', :password => ''test'' > # session[ :user_id ].should be_nil > # flash[ :notice ].should be_nil > # end ><snip> I think the way that it works is Rails will route POST requests to the /users/ url to create. However, if you explicitly call the create method using a GET (as you are doing here), I don''t think Rails will stop you. I think if you want to check that the routing is working it is possible using Rspec. Disclaimer: The exuberant use of "think" in the answer means that I am also still learning ;) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nathan Esquenazi
2008-May-20 10:17 UTC
Re: REST and create action: why does it accept GET requests ?
That is what verify is for: http://rails.rubyonrails.org/classes/ActionController/Verification/ClassMethods.html verify :method => :post, :redirect_to => etc... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-May-20 10:56 UTC
Re: REST and create action: why does it accept GET requests ?
On 20 May 2008, at 09:06, Nicholas Wieland wrote:> Hi *, > > # TODO: why does this method accept get requests ? > # it "should not login getting correct credentials" do > # get :create, :login => ''quentin'', :password => ''test'' > # session[ :user_id ].should be_nil > # flash[ :notice ].should be_nil > # end > > This spec fails, but AFAIK create actions that are routed > as .resources should accept just POSTed data, not GETted. Here the > session is setted to the user.id, and the Flash notice says I logged > in successfully, this doesn''t really make sense to me. Rails 2.0.2Routing isn''t used in a functional test - rails just whacks the specified action at the controller being tested Fred> > > TIA, > ngw--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---