diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-02-26 11:42:55 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-02-26 21:09:49 +0100 |
commit | 09d9f04d08358dc2b49fbf6bc16b58f034161abb (patch) | |
tree | a1ce775d17b318dc19ef3b1501dac90d00178371 /actionpack/test | |
parent | ffeb7ddcffa6509f03721ba29ebf16e9be255795 (diff) | |
download | rails-09d9f04d08358dc2b49fbf6bc16b58f034161abb.tar.gz rails-09d9f04d08358dc2b49fbf6bc16b58f034161abb.tar.bz2 rails-09d9f04d08358dc2b49fbf6bc16b58f034161abb.zip |
the router allows String contraints.
Closes #9432.
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 36 |
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 |