Skip to content
Browse files

Move regexps in options hash to :constraints hash so that they are pu…

…shed into the scope [#5208 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 0cc483a commit c019db8ca1c5639fdae80915cc7520eaad7dcd65 @pixeltrix pixeltrix committed with josevalim Aug 18, 2010
Showing with 26 additions and 0 deletions.
  1. +4 −0 actionpack/lib/action_dispatch/routing/mapper.rb
  2. +22 −0 actionpack/test/dispatch/routing_test.rb
View
4 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -774,6 +774,10 @@ def apply_common_behavior_for(method, resources, options, &block)
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
22 actionpack/test/dispatch/routing_test.rb
@@ -379,6 +379,12 @@ def self.matches?(request)
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 @@ def test_greedy_resource_id_regexp_doesnt_match_edit_and_custom_action
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

0 comments on commit c019db8

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