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

Accept an object for :constraints option [#4904 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Andrew White 2010-06-19 20:52:55 +01:00 committed by José Valim
parent 72725d7b7f
commit 65ce3d1297
2 changed files with 9 additions and 1 deletions

View file

@ -102,7 +102,7 @@ module ActionDispatch
end
def requirements
@requirements ||= (@options[:constraints] || {}).tap do |requirements|
@requirements ||= (@options[:constraints].is_a?(Hash) ? @options[:constraints] : {}).tap do |requirements|
requirements.reverse_merge!(@scope[:constraints]) if @scope[:constraints]
@options.each { |k, v| requirements[k] = v if v.is_a?(Regexp) }
end

View file

@ -68,6 +68,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
get 'admin/accounts' => "queenbee#accounts"
end
get 'admin/passwords' => "queenbee#passwords", :constraints => ::TestRoutingMapper::IpRestrictor
scope 'pt', :name_prefix => 'pt' do
resources :projects, :path_names => { :edit => 'editar', :new => 'novo' }, :path => 'projetos' do
post :preview, :on => :new
@ -501,6 +503,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
get '/admin/accounts', {}, {'REMOTE_ADDR' => '10.0.0.100'}
assert_equal 'pass', @response.headers['X-Cascade']
get '/admin/passwords', {}, {'REMOTE_ADDR' => '192.168.1.100'}
assert_equal 'queenbee#passwords', @response.body
get '/admin/passwords', {}, {'REMOTE_ADDR' => '10.0.0.100'}
assert_equal 'pass', @response.headers['X-Cascade']
end
end