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 W. 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

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:

That is what verify is for:

http://rails.rubyonrails.org/classes/ActionController/Verification/ClassMethods.html

verify :method => :post, :redirect_to => etc…

On 20 May 2008, at 09:06, Nicholas W. wrote:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs