[rspec-users] Testing RESTful routes

Andrew WC Brown omen.king at gmail.com
Sun Sep 23 00:08:36 EDT 2007

I'm currently in a simliar situation as you.
I have an application that doesn't use the default routing.

When I try to write my stories.

And "user logged in successfully" do
  post "/session/create", :login => "Jon", :password => "your_momma"
  response.should redirect_to(home_path)

The post fails unless I include this back into my routes file
   map.connect ':controller/:action/:id.:format'

> map.connect ':controller/:action/:id'

and even then when I add them back in they'll conflict with my other routes
and I have to comment out all my other routes.
But then it will pass.

On 9/22/07, Ben Mabey <ben at benmabey.com> wrote:
> Hi all,
> The app I am making right now uses restful routing entirely.  I want to
> prevent people from accessing my actions without the proper HTTP verb so
> I commented out the :controller/:action/:id catch all routes that were
> used in pre-RESTful Rails apps.  Like so:
>    #map.connect ':controller/:action/:id.:format'
>    #map.connect ':controller/:action/:id'
> When I did this however all of my routing specs broke.  I have been
> testing my routes like the rspec-scaffold generator tests them:
> it "{ :controller => 'users', :action => 'new' } to /users/new" do
>     route_for(:controller => "users", :action => "new").should ==
> "/users/new"
> end
> To get around this the easiest thing I could think of was to add this to
> my routes.rb:
> if RAILS_ENV=="test"
>     map.connect ':controller/:action/:id.:format'
>     map.connect ':controller/:action/:id'
> end
> Are there better solutions?
> This is a workaround for the problem, but I'm wondering if there is a
> better way to test restful routes without relying on the old routing
> convention of controller/action/id.  Ideally, the routing specs should
> also verify the HTTP verb as well.  Is there any way to do this?
> Thanks,
> Ben
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070923/4de370f1/attachment.html 

More information about the rspec-users mailing list