From 4243de6a04559dd5f02618b46f9f183e4e76a552 Mon Sep 17 00:00:00 2001 From: Maura Fitzgerald Date: Fri, 2 Nov 2012 23:19:05 +0000 Subject: Fixed issue where routes with globs caused constraints on that glob to be ignored. A regular expression constraint gets overwritten when the routes.rb file is processed. Changed the overwriting to an ||= instead of an = assignment. --- actionpack/test/dispatch/routing_test.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'actionpack/test/dispatch/routing_test.rb') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 4f5d8fdb7c..cb5299e8d3 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3065,6 +3065,35 @@ class TestConstraintsAccessingParameters < ActionDispatch::IntegrationTest end end +class TestGlobRoutingMapper < ActionDispatch::IntegrationTest + Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| + app.draw do + ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] } + + get "/*id" => redirect("/not_cars"), :constraints => {id: /dummy/} + get "/cars" => ok + end + end + + #include Routes.url_helpers + def app; Routes end + + def test_glob_constraint + get "/dummy" + assert_equal "301", @response.code + assert_equal "/not_cars", @response.header['Location'].match('/[^/]+$')[0] + end + + def test_glob_constraint_skip_route + get "/cars" + assert_equal "200", @response.code + end + def test_glob_constraint_skip_all + get "/missing" + assert_equal "404", @response.code + end +end + class TestOptimizedNamedRoutes < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do -- cgit v1.2.3