Skip to content
This repository
Browse code

refactoring routing tests

Conflicts:

	actionpack/test/controller/routing_test.rb
  • Loading branch information...
commit 3e00e1f6e31941dadd885a6844de997d7dc33a10 1 parent 040b794
Aaron Patterson authored December 22, 2011

Showing 1 changed file with 30 additions and 23 deletions. Show diff stats Hide diff stats

  1. 53  actionpack/test/controller/routing_test.rb
53  actionpack/test/controller/routing_test.rb
@@ -85,13 +85,38 @@ class LegacyRouteSetTests < Test::Unit::TestCase
85 85
   attr_reader :rs
86 86
 
87 87
   def setup
88  
-    @rs = ::ActionDispatch::Routing::RouteSet.new
  88
+    @rs       = ::ActionDispatch::Routing::RouteSet.new
  89
+    @response = nil
  90
+  end
  91
+
  92
+  def get(uri_or_host, path = nil, port = nil)
  93
+    host = uri_or_host.host unless path
  94
+    path ||= uri_or_host.path
  95
+
  96
+    params = {'PATH_INFO'      => path,
  97
+              'REQUEST_METHOD' => 'GET',
  98
+              'HTTP_HOST'      => host}
  99
+
  100
+    @rs.call(params)[2]
89 101
   end
90 102
 
91 103
   def teardown
92 104
     @rs.clear!
93 105
   end
94 106
 
  107
+  def test_regexp_precidence
  108
+    @rs.draw do
  109
+      match '/whois/:domain', :constraints => {
  110
+        :domain => /\w+\.[\w\.]+/ },
  111
+        :to     => lambda { |env| [200, {}, 'regexp'] }
  112
+
  113
+      match '/whois/:id', :to => lambda { |env| [200, {}, 'id'] }
  114
+    end
  115
+
  116
+    assert_equal 'regexp', get(URI('http://example.org/whois/example.org'))
  117
+    assert_equal 'id', get(URI('http://example.org/whois/123'))
  118
+  end
  119
+
95 120
   def test_class_and_lambda_constraints
96 121
     subdomain = Class.new {
97 122
       def matches? request
@@ -106,17 +131,8 @@ def matches? request
106 131
                  :to          => lambda { |env| [200, {}, 'clients'] }
107 132
     end
108 133
 
109  
-    body = @rs.call({'PATH_INFO'      => '/',
110  
-                     'REQUEST_METHOD' => 'GET',
111  
-                     'HTTP_HOST'      => 'www.example.org'})[2]
112  
-
113  
-    assert_equal 'default', body
114  
-
115  
-    body = @rs.call({'PATH_INFO'      => '/',
116  
-                     'REQUEST_METHOD' => 'GET',
117  
-                     'HTTP_HOST'      => 'clients.example.org'})[2]
118  
-
119  
-    assert_equal 'clients', body
  134
+    assert_equal 'default', get(URI('http://www.example.org/'))
  135
+    assert_equal 'clients', get(URI('http://clients.example.org/'))
120 136
   end
121 137
 
122 138
   def test_lambda_constraints
@@ -130,17 +146,8 @@ def test_lambda_constraints
130 146
                  :to          => lambda { |env| [200, {}, 'clients'] }
131 147
     end
132 148
 
133  
-    body = @rs.call({'PATH_INFO'      => '/',
134  
-                     'REQUEST_METHOD' => 'GET',
135  
-                     'HTTP_HOST'      => 'www.example.org'})[2]
136  
-
137  
-    assert_equal 'default', body
138  
-
139  
-    body = @rs.call({'PATH_INFO'      => '/',
140  
-                     'REQUEST_METHOD' => 'GET',
141  
-                     'HTTP_HOST'      => 'clients.example.org'})[2]
142  
-
143  
-    assert_equal 'clients', body
  149
+    assert_equal 'default', get(URI('http://www.example.org/'))
  150
+    assert_equal 'clients', get(URI('http://clients.example.org/'))
144 151
   end
145 152
 
146 153
   def test_draw_with_block_arity_one_raises

0 notes on commit 3e00e1f

Please sign in to comment.
Something went wrong with that request. Please try again.