aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/routing_test.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2012-05-11 07:23:24 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2012-05-11 07:29:17 +0100
commit9b4514c3b8ecfbc40a44dbd4c2ebd4ce67f4a459 (patch)
tree2a463159668be3d0b47b730d87cd91e2b00c72db /actionpack/test/dispatch/routing_test.rb
parent0d48b12fc56df574bb81cfaf0f5fb4713e9230fc (diff)
downloadrails-9b4514c3b8ecfbc40a44dbd4c2ebd4ce67f4a459.tar.gz
rails-9b4514c3b8ecfbc40a44dbd4c2ebd4ce67f4a459.tar.bz2
rails-9b4514c3b8ecfbc40a44dbd4c2ebd4ce67f4a459.zip
Copy literal route constraints to defaults - fixes #3571 and #6224.
Diffstat (limited to 'actionpack/test/dispatch/routing_test.rb')
-rw-r--r--actionpack/test/dispatch/routing_test.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 6f22cb3ea8..3cec816f1c 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -2606,3 +2606,45 @@ class TestNamedRouteUrlHelpers < ActionDispatch::IntegrationTest
assert_raises(ActionController::RoutingError) { product_path(nil) }
end
end
+
+class TestUrlConstraints < ActionDispatch::IntegrationTest
+ Routes = ActionDispatch::Routing::RouteSet.new.tap do |app|
+ app.draw do
+ ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] }
+
+ constraints :subdomain => 'admin' do
+ get '/' => ok, :as => :admin_root
+ end
+
+ scope :constraints => { :protocol => 'https://' } do
+ get '/' => ok, :as => :secure_root
+ end
+
+ get '/' => ok, :as => :alternate_root, :constraints => { :port => 8080 }
+ end
+ end
+
+ include Routes.url_helpers
+ def app; Routes end
+
+ test "constraints are copied to defaults when using constraints method" do
+ assert_equal 'http://admin.example.com/', admin_root_url
+
+ get 'http://admin.example.com/'
+ assert_response :success
+ end
+
+ test "constraints are copied to defaults when using scope constraints hash" do
+ assert_equal 'https://www.example.com/', secure_root_url
+
+ get 'https://www.example.com/'
+ assert_response :success
+ end
+
+ test "constraints are copied to defaults when using route constraints hash" do
+ assert_equal 'http://www.example.com:8080/', alternate_root_url
+
+ get 'http://www.example.com:8080/'
+ assert_response :success
+ end
+end