I am using the request routing plugin to route some stuff based on
subdomains.
In one particular case, I have http://www.mysite.com/specialaction/:id
route to :controller => “mycontroller”, :action => “myaction”. The
route checks the requirement that the subdomain is “www”
So, what I want to do is test that this specific route is handled
correctly. Once, while fiddling around, I rearranged the order of some
routes and my routing broke. I want to make sure this doesn’t happen
again.
Is this a functional test? Or is this an integration test?
Jake
Functional test only works within one controller and any attempt to go
between controls will cause Rails to throw an exception. My feeling on
this would be, it seems like, an integration test since you won’t be
working with raw URLs. In order to test your routes you’ll have to
translate raw URLs into calls on your controller so if you can’t specify
URLs then you can’t test it. I haven’t done integration tests yet so
take it with a grain of salt.
Charlie
Jake J. wrote:
I am using the request routing plugin to route some stuff based on
subdomains.
In one particular case, I have http://www.mysite.com/specialaction/:id
route to :controller => “mycontroller”, :action => “myaction”. The
route checks the requirement that the subdomain is “www”
So, what I want to do is test that this specific route is handled
correctly. Once, while fiddling around, I rearranged the order of some
routes and my routing broke. I want to make sure this doesn’t happen
again.
Is this a functional test? Or is this an integration test?
Jake
There is an assert_routing function for integration tests. What I’ve
been
doing is creating a seperate routing_test integration just to test the
routing. For your case:
assert_routing ‘/specialaction/4’, :controller => ‘mycontroller’,
:action =>
‘myaction’, :id => 4
and
assert_equal ‘/specialaction/4’, url_for(:only_path => true, :controller
=>
‘mycontroller’, :action => ‘myaction’, :id => 4)
I’m sure there’s a key to check for certain subdomains. Never done that
so I
would have to look it up.
I’ve learned that routing is easily the most fragile part of a rails
app,
and can be a PIA to debug. Make sure you’ve got integration tests for
it.
Jason
I ended up building the check into my integration tests. It works well
there and I can check all sorts of things like remote address, various
subdomains, protocol, etc.
Jason R. wrote:
I’ve learned that routing is easily the most fragile part of a rails
app,
and can be a PIA to debug. Make sure you’ve got integration tests for
it.
I, too, have found this to be the case. Integration tests certainly
help.
Jake