aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/routing_test.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-02-27 19:57:41 +0100
committerYves Senn <yves.senn@gmail.com>2013-02-27 19:57:41 +0100
commitafddc0409e53731c8f21328e83921fd234b5bf54 (patch)
treedece4dde896f888d42dd941dcd9f48b07f73d76a /actionpack/test/dispatch/routing_test.rb
parentafd4a14332c49fa0e236e6904a5f7e09ce33c407 (diff)
downloadrails-afddc0409e53731c8f21328e83921fd234b5bf54.tar.gz
rails-afddc0409e53731c8f21328e83921fd234b5bf54.tar.bz2
rails-afddc0409e53731c8f21328e83921fd234b5bf54.zip
`format: true` does not override existing format constraints.
Closes #9466. Passing `format: true` used to override the constraints: { format: /json/ } with `/.+/`. This patch only sets the format if there is no constraint present.
Diffstat (limited to 'actionpack/test/dispatch/routing_test.rb')
-rw-r--r--actionpack/test/dispatch/routing_test.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 4775324b43..89f406a3d0 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -3407,6 +3407,8 @@ class TestFormatConstraints < ActionDispatch::IntegrationTest
get '/string', to: ok, constraints: { format: 'json' }
get '/regexp', to: ok, constraints: { format: /json/ }
+ get '/json_only', to: ok, format: true, constraints: { format: /json/ }
+ get '/xml_only', to: ok, format: 'xml'
end
end
@@ -3434,6 +3436,28 @@ class TestFormatConstraints < ActionDispatch::IntegrationTest
get 'http://www.example.com/regexp.html'
assert_response :not_found
end
+
+ def test_enforce_with_format_true_with_constraint
+ get 'http://www.example.com/json_only.json'
+ assert_response :success
+
+ get 'http://www.example.com/json_only.html'
+ assert_response :not_found
+
+ get 'http://www.example.com/json_only'
+ assert_response :not_found
+ end
+
+ def test_enforce_with_string
+ get 'http://www.example.com/xml_only.xml'
+ assert_response :success
+
+ get 'http://www.example.com/xml_only'
+ assert_response :success
+
+ get 'http://www.example.com/xml_only.json'
+ assert_response :not_found
+ end
end
class TestRouteDefaults < ActionDispatch::IntegrationTest