Changeset 4677
- Timestamp:
- 08/05/06 22:12:50 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/routing.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/routing_test.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r4674 r4677 1 1 *SVN* 2 2 3 * Make Routing noisy when an anchor regexp is assigned to a segment. #5674 [francois.beausoleil@gmail.com] 4 3 5 * Added months and years to the resolution of DateHelper#distance_of_time_in_words, such that "60 days ago" becomes "2 months ago" #5611 [pjhyett@gmail.com] 4 6 7 >>>>>>> .r4676 5 8 * Short documentation to mention use of Mime::Type.register. #5710 [choonkeat@gmail.com] 6 9 trunk/actionpack/lib/action_controller/routing.rb
r4637 r4677 680 680 [defaults, requirements, conditions] 681 681 end 682 682 683 683 # Takes a hash of defaults and a hash of requirements, and assigns them to 684 684 # the segments. Any unused requirements (which do not correspond to a segment) … … 695 695 if segment 696 696 raise TypeError, "#{key}: requirements on a path segment must be regular expressions" unless requirement.is_a?(Regexp) 697 if requirement.source =~ %r{\\A|\\Z|\\z|\^|\$} 698 raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}" 699 end 697 700 segment.regexp = requirement 698 701 else trunk/actionpack/test/controller/routing_test.rb
r4518 r4677 151 151 rs.draw do |map| 152 152 map.article 'page/:year/:month/:day/:title', :controller => 'page', :action => 'show', 153 :year => / ^\d+$/, :month => /^\d+$/, :day => /^\d+$/153 :year => /\d+/, :month => /\d+/, :day => /\d+/ 154 154 map.connect ':controller/:action/:id' 155 155 end … … 1217 1217 controller.send(:multi_url, 7, "hello", 5) 1218 1218 end 1219 1219 1220 1220 def test_draw_default_route 1221 1221 ActionController::Routing.with_controllers(['users']) do … … 1223 1223 map.connect '/:controller/:action/:id' 1224 1224 end 1225 1225 1226 1226 assert_equal 1, set.routes.size 1227 1227 route = set.routes.first 1228 1228 1229 1229 assert route.segments.last.optional? 1230 1230 1231 1231 assert_equal '/users/show/10', set.generate(:controller => 'users', :action => 'show', :id => 10) 1232 1232 assert_equal '/users/index/10', set.generate(:controller => 'users', :id => 10) 1233 1233 1234 1234 assert_equal({:controller => 'users', :action => 'index', :id => '10'}, set.recognize_path('/users/index/10')) 1235 1235 assert_equal({:controller => 'users', :action => 'index', :id => '10'}, set.recognize_path('/users/index/10/')) 1236 1236 end 1237 1237 end 1238 1238 1239 1239 def test_route_with_parameter_shell 1240 1240 ActionController::Routing.with_controllers(['users', 'pages']) do … … 1243 1243 map.connect '/:controller/:action/:id' 1244 1244 end 1245 1245 1246 1246 assert_equal({:controller => 'pages', :action => 'index'}, set.recognize_path('/pages')) 1247 1247 assert_equal({:controller => 'pages', :action => 'index'}, set.recognize_path('/pages/index')) 1248 1248 assert_equal({:controller => 'pages', :action => 'list'}, set.recognize_path('/pages/list')) 1249 1249 1250 1250 assert_equal({:controller => 'pages', :action => 'show', :id => '10'}, set.recognize_path('/pages/show/10')) 1251 1251 assert_equal({:controller => 'pages', :action => 'show', :id => '10'}, set.recognize_path('/page/10')) … … 1253 1253 end 1254 1254 1255 def test_route_requirements_with_anchor_chars_are_invalid 1256 assert_raises ArgumentError do 1257 set.draw do |map| 1258 map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /^\d+/ 1259 end 1260 end 1261 assert_raises ArgumentError do 1262 set.draw do |map| 1263 map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\A\d+/ 1264 end 1265 end 1266 assert_raises ArgumentError do 1267 set.draw do |map| 1268 map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+$/ 1269 end 1270 end 1271 assert_raises ArgumentError do 1272 set.draw do |map| 1273 map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+\Z/ 1274 end 1275 end 1276 assert_raises ArgumentError do 1277 set.draw do |map| 1278 map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+\z/ 1279 end 1280 end 1281 assert_nothing_raised do 1282 set.draw do |map| 1283 map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+/, :name => /^(david|jamis)/ 1284 end 1285 assert_raises ActionController::RoutingError do 1286 set.generate :controller => 'pages', :action => 'show', :id => 10 1287 end 1288 end 1289 end 1290 1291 def test_non_path_route_requirements_match_all 1292 set.draw do |map| 1293 map.connect 'page/37s', :controller => 'pages', :action => 'show', :name => /(jamis|david)/ 1294 end 1295 assert_equal '/page/37s', set.generate(:controller => 'pages', :action => 'show', :name => 'jamis') 1296 assert_raises ActionController::RoutingError do 1297 set.generate(:controller => 'pages', :action => 'show', :name => 'not_jamis') 1298 end 1299 assert_raises ActionController::RoutingError do 1300 set.generate(:controller => 'pages', :action => 'show', :name => 'nor_jamis_and_david') 1301 end 1302 end 1303 1255 1304 def test_recognize_with_encoded_id_and_regex 1256 1305 set.draw do |map| 1257 1306 map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /[a-zA-Z0-9 ]+/ 1258 1307 end 1259 1308 1260 1309 assert_equal({:controller => 'pages', :action => 'show', :id => '10'}, set.recognize_path('/page/10')) 1261 1310 assert_equal({:controller => 'pages', :action => 'show', :id => 'hello world'}, set.recognize_path('/page/hello+world'))