Testing Routes With RSpec and Subdomain Fu
11/25/2009 7:06:31 PMTesting subdomain fu based routes has really been causing me pain. Hope to wrap this up into a nice little patch package but maybe this will help others until time permits.
Example Route
1: map.foo_bar '/foo/bar', :controller => 'foo', :action => 'bar',
2: :conditions => { :subdomain => 'subdomain' }
Example Spec
1: it "should generate route for http://subdomain.test.com/foo/bar" do
2: controller.request.host = 'subdomain.test.com'
3: "/foo/bar".should route_to({ :controller => "foo", :action => 'bar' })
4: end Overriding recognized_request_for in ControllerExampleGroup
The method recognized_request_for in ActionController::Assertions::RoutingAssertions uses a new controller for testing the routes. This fix leverages the controller for the spec instead.
1: module Spec 2: module Rails 3: module Example 4: class ControllerExampleGroup < FunctionalExampleGroup
5: def recognized_request_for(path, request_method = nil) 6: path = "/#{path}" unless path.first == '/'
7: 8: # Assume given controller 9: request = controller.request #ActionController::TestRequest.new
10: request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method
11: request.path = path 12: 13: ActionController::Routing::Routes.recognize(request) 14: request 15: end 16: end 17: end 18: end 19: end Comments
Works a charm - thanks!
dotemacs
6/17/2010 10:30:07 AMNice, thank you for this
thanks! hope I can try this code. I'm using java and visual basic dot net as my language.
hasen kostüme
http://www.karneval-karnevalkostuem-karnevalskostueme.de/karneval-kostuem-karnevalkostuem-kostueme-hase-hasenkostuem-st5.html1/17/2012 10:19:00 AM
I enjoy reading articles that are so quite well-written.This really is great content. You have loaded this with helpful, informative content that any reader can realize.
Term life insurance prices
http://www.everydaylifeinsurance.org/term-life-insurance-rate1/23/2012 7:07:48 PM
This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It’s the old what goes around comes around routine. Big thanks for the useful info......
Affordable term life insurance
http://www.everydaylifeinsurance.org/affordable-life-insurance1/24/2012 12:30:53 PM
I discovered your blogs link put up by a friend on Facebook. Thank you for putting useful information on the internet. Its tough to get these things nowadays.
I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the latest stuff you post.
great post, very informative. I wonder why the other specialists of this sector do not notice this. You must continue your writing. I am confident, you have a huge readers' base already!
Another interesting one! When you and I would love for this to see when people need this type of site. It has great information on this topic. Ideal for new generation.
Thank you.
Pretty insightful post.Never thought that it was this simple after all. I had spent a good deal of my time looking for someone to explain this subject clearly and you’re the only one that ever did that. Keep it up
Many thanks for this code sample, it works and help me!
Hochwertige und diverse Werbeartikel für alle Branchen Qualitativ hochwertige personalisierte Werbeartikel
in der Schweiz Werbeartikel, Werbemittel und viel mehr Werbegeschenke, Werbeartikel und viel mehr
Werbemittel
Great post. its a need of today’s generation, but i think it need more information about this topic, really not a bad but i wish it looks more complete..
Bundle of Thanks…