From 90437667cca568e7077edf7b605ce4d7bb9de7b3 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 18 Aug 2010 11:50:15 +0100 Subject: [PATCH] Move regexps in options hash to :constraints hash so that they are pushed into the scope [#5208 state:resolved] --- actionpack/lib/action_dispatch/routing/mapper.rb | 4 ++++ actionpack/test/dispatch/routing_test.rb | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index c27f06c..86e7744 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -774,6 +774,10 @@ module ActionDispatch return true end + options.each do |k,v| + (options[:constraints] ||= {})[k] = options.delete(k) if options[k].is_a?(Regexp) + end + scope_options = options.slice!(*RESOURCE_OPTIONS) unless scope_options.empty? scope(scope_options) do diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 4dabe15..a39bf31 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -371,6 +371,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + namespace :wiki do + resources :articles, :id => /[^\/]+/ do + resources :comments, :only => [:create, :new] + end + end + scope :only => :show do namespace :only do resources :sectors, :only => :index do @@ -1884,6 +1890,22 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_resource_constraints_are_pushed_to_scope + with_test_routes do + get '/wiki/articles/Ruby_on_Rails_3.0' + assert_equal 'wiki/articles#show', @response.body + assert_equal '/wiki/articles/Ruby_on_Rails_3.0', wiki_article_path(:id => 'Ruby_on_Rails_3.0') + + get '/wiki/articles/Ruby_on_Rails_3.0/comments/new' + assert_equal 'wiki/comments#new', @response.body + assert_equal '/wiki/articles/Ruby_on_Rails_3.0/comments/new', new_wiki_article_comment_path(:article_id => 'Ruby_on_Rails_3.0') + + post '/wiki/articles/Ruby_on_Rails_3.0/comments' + assert_equal 'wiki/comments#create', @response.body + assert_equal '/wiki/articles/Ruby_on_Rails_3.0/comments', wiki_article_comments_path(:article_id => 'Ruby_on_Rails_3.0') + end + end + private def with_test_routes yield -- 1.7.1