I have a route in which I use restrictions to verify the host, and then a route that is essentially the same, but without a host restriction (these are really namespaces, but to simplify this example):
match "/(:page_key)" => "namespace_one/pages#show", :constraints => proc {|env| env['SERVER_NAME'] == 'test.mysite.local' } match "/(:page_key)" => "namespace_two/pages#show"
They work exactly as expected when accessing through the browser and in integration tests when determining the host and executing get "/page_key" , etc.
However, I want to write tests that ensure that these routes still work. I was not very lucky since the following test (which is currently in ActionController::IntegrationTest so that I can set the host) matched one without limitation:
assert_routing '', { :controller => 'namespace_one/pages', :action => 'show' } => The recognized options <{"action"=>"show", "controller"=>"frontend/pages"}> did not match <{"action"=>"show", "controller"=>"namespace_two/pages"}>, difference: <{"controller"=>"namespace_one/pages"}>
If I try to reset env in the proc constraints, all I get is --- :controller .
If I get rid of assert_routing and just make a call to get :show and dump @controller , it will allow the correct controller (as expected, all these routes work fine through HTTP requests).
source share