aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-08-28 10:33:40 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-08-28 10:33:40 -0700
commit6d86762fd8f83896a6932614e9ac9bdc42102805 (patch)
tree99c6b463c7b7c90a5a5ca36ab5cba623d4d49031 /actionpack/test
parent8c52480ba6071a12b97f124d9f21df2c39df3ed3 (diff)
parentd78f3f0ec33d57e78249d5b96f38401a1c239410 (diff)
downloadrails-6d86762fd8f83896a6932614e9ac9bdc42102805.tar.gz
rails-6d86762fd8f83896a6932614e9ac9bdc42102805.tar.bz2
rails-6d86762fd8f83896a6932614e9ac9bdc42102805.zip
Merge pull request #16637 from Agis-/redirect-with-constraint-route
Fix the router ignoring constraints when used together with a redirect route
Diffstat (limited to 'actionpack/test')
-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 b8e20c52a0..d141210ad9 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -14,6 +14,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ class GrumpyRestrictor
+ def self.matches?(request)
+ false
+ end
+ end
+
class YoutubeFavoritesRedirector
def self.call(params, request)
"http://www.youtube.com/watch?v=#{params[:youtube_id]}"
@@ -89,6 +95,24 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
verify_redirect 'http://www.example.com/private/index'
end
+ def test_redirect_with_failing_constraint
+ draw do
+ get 'hi', to: redirect("/foo"), constraints: ::TestRoutingMapper::GrumpyRestrictor
+ end
+
+ get '/hi'
+ assert_equal 404, status
+ end
+
+ def test_redirect_with_passing_constraint
+ draw do
+ get 'hi', to: redirect("/foo"), constraints: ->(req) { true }
+ end
+
+ get '/hi'
+ assert_equal 301, status
+ end
+
def test_namespace_with_controller_segment
assert_raise(ArgumentError) do
draw do