[#8001] separate out routing specs
Reported by Chad Humphries | November 19th, 2007 @ 03:06 AM
Submitted By:
David Chelimsky (dchelimsky)
Routing happens outside of controllers and should be spec'able separately from controllers. This should be either part
of a higher level integration spec or Story Runner, OR should be a new component category parallel w/ models, views,
controllers and helpers.
Routing specs should support both route processing and route generation. For example:
route_for(:controller => "people", :action => "edit", :id => 1).should ==
"/people/1;edit"
AND
"/people/1;edit".should route_to(:controller => "people", :action => "edit", :id
=> 1)
The latter example would be extremely useful for custom mappings like this:
"/".should route_to(:controller => 'welcome')
Comments and changes to this ticket
-
Chad Humphries January 18th, 2008 @ 09:09 PM
Date: 2007-10-04 16:46
Sender: Rupert Voelcker
you can actually specify routes the other way round using params_from
with the following syntax:
params_from(:get, '/people/1/edit').should == {:controller =>
"people", :action => "edit", :id =>
"1"}
although route_to is a bit more suggestive of what it does. Then
perhaps route_from should be aliased to route_for so there's
a route_to and a route_from.
Date: 2007-10-04 13:00
Sender: Matt Scilipoti
+1. This looks like a good format to me.
Note: On edge, url format has changed from "/people/1;edit"
to "/people/1/edit"
Date: 2007-01-19 11:34
Sender: David Chelimsky
I'd LOVE to take credit for it, but it comes from a comment by
Eric Peden to [#6541]:
http://rubyforge.org/tracker/?fu...
541&group_id=797
Thanks for the idea Eric!
Date: 2007-01-19 10:00
Sender: Aslak Hellesøy
I LOVE that idea.
-
David Chelimsky December 18th, 2007 @ 01:17 PM
- → State changed from new to resolved
Done in r3143
-
-
David Chelimsky December 18th, 2007 @ 05:52 PM
@Scott: When you use script/generate rspec_scaffold, they get created in a separate file in spec/controllers. I think it makes sense to keep them there - we don't need a new directory - but to name them differently. WDYT?
-
Scott Taylor December 18th, 2007 @ 08:15 PM
Well, I'd think that this setup would be best:
/spec/routes/foo_bar_spec.rb
/spec/routes/foo_baz_spec.rb
Or, put them all in one file (spec/controllers/routes_spec.rb). But I would think a layout like this would be come a little too much, given enough controllers:
/spec/controllers/foo_bar_controller_spec.rb
/spec/controllers/foo_bar_controller_routes_spec.rb
/spec/controllers/foo_baz_spec.rb
/spec/controllers/foo_baz_routes_spec.rb
On my current project we have spec/controllers/routes_spec.rb which contains all the routes, and I think it's a little too cluttered for me.
So - it's really a matter more of taste than anything else. I prefer the spec/routes way, others will prefer other things.
-
David Chelimsky December 18th, 2007 @ 08:18 PM
I'm open to either. Go ahead and submit a patch if you want.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Behaviour Driven Development for Ruby.
