1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Move regexps in options hash to :constraints hash so that they are pushed into the scope [#5208 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Andrew White 2010-08-18 11:50:15 +01:00 committed by José Valim
parent 0cc483aa14
commit c019db8ca1
2 changed files with 26 additions and 0 deletions

View file

@ -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

View file

@ -379,6 +379,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
@ -1962,6 +1968,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