aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/routing_test.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-02-26 11:42:55 +0100
committerYves Senn <yves.senn@gmail.com>2013-02-26 21:09:49 +0100
commit09d9f04d08358dc2b49fbf6bc16b58f034161abb (patch)
treea1ce775d17b318dc19ef3b1501dac90d00178371 /actionpack/test/dispatch/routing_test.rb
parentffeb7ddcffa6509f03721ba29ebf16e9be255795 (diff)
downloadrails-09d9f04d08358dc2b49fbf6bc16b58f034161abb.tar.gz
rails-09d9f04d08358dc2b49fbf6bc16b58f034161abb.tar.bz2
rails-09d9f04d08358dc2b49fbf6bc16b58f034161abb.zip
the router allows String contraints.
Closes #9432.
Diffstat (limited to 'actionpack/test/dispatch/routing_test.rb')
-rw-r--r--actionpack/test/dispatch/routing_test.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 37ad9ddb6b..22c5cf71ce 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -3380,6 +3380,42 @@ class TestPortConstraints < ActionDispatch::IntegrationTest
end
end
+class TestFormatConstraints < ActionDispatch::IntegrationTest
+ Routes = ActionDispatch::Routing::RouteSet.new.tap do |app|
+ app.draw do
+ ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] }
+
+ get '/string', to: ok, constraints: { format: 'json' }
+ get '/regexp', to: ok, constraints: { format: /json/ }
+ end
+ end
+
+ include Routes.url_helpers
+ def app; Routes end
+
+ def test_string_format_constraints
+ get 'http://www.example.com/string'
+ assert_response :success
+
+ get 'http://www.example.com/string.json'
+ assert_response :success
+
+ get 'http://www.example.com/string.html'
+ assert_response :not_found
+ end
+
+ def test_regexp_format_constraints
+ get 'http://www.example.com/regexp'
+ assert_response :success
+
+ get 'http://www.example.com/regexp.json'
+ assert_response :success
+
+ get 'http://www.example.com/regexp.html'
+ assert_response :not_found
+ end
+end
+
class TestRouteDefaults < ActionDispatch::IntegrationTest
stub_controllers do |routes|
Routes = routes