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

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 :wink:

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

Routing isn't used in a functional test - rails just whacks the specified action at the controller being tested

Fred