Given a couple of cities in the DB: City.first.attributes => {:id => 1, :name => 'nyc'} City.last.attributes => {:id => 2, :name => 'boston'}
And a route like:
match '/:city/*dest' => 'cities#do_something', :constraints => {:city => /#{City.all.map{|c| c.name}.join('|'}/}
(so the constraints should evaluate to: /nyc|boston/)
And a spec:
it "recognizes and generates a route for city specific paths" do
{ :put => '/bad-city/some/path' }.should route_to({:controller => "cities", :action => "do_something", :dest => 'some/path', :city => 'bad-city'})
end
I would expect a failure. But it passes.
Likewise:
it "doesn't route bad city names" do
{ :put => '/some-bad-city/some/path' }.should_not be_routable
end
Here I expect it to pass, but it fails.
It seems the constraint is being ignored in the specs, since the matching cities have the same behavior as the bad ones.
Is this a known issue, or am I missing something that I need to do?