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:
parent
72725d7b7f
commit
65ce3d1297
2 changed files with 9 additions and 1 deletions
|
@ -102,7 +102,7 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def requirements
|
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]
|
requirements.reverse_merge!(@scope[:constraints]) if @scope[:constraints]
|
||||||
@options.each { |k, v| requirements[k] = v if v.is_a?(Regexp) }
|
@options.each { |k, v| requirements[k] = v if v.is_a?(Regexp) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -68,6 +68,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
|
||||||
get 'admin/accounts' => "queenbee#accounts"
|
get 'admin/accounts' => "queenbee#accounts"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get 'admin/passwords' => "queenbee#passwords", :constraints => ::TestRoutingMapper::IpRestrictor
|
||||||
|
|
||||||
scope 'pt', :name_prefix => 'pt' do
|
scope 'pt', :name_prefix => 'pt' do
|
||||||
resources :projects, :path_names => { :edit => 'editar', :new => 'novo' }, :path => 'projetos' do
|
resources :projects, :path_names => { :edit => 'editar', :new => 'novo' }, :path => 'projetos' do
|
||||||
post :preview, :on => :new
|
post :preview, :on => :new
|
||||||
|
@ -501,6 +503,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
|
||||||
|
|
||||||
get '/admin/accounts', {}, {'REMOTE_ADDR' => '10.0.0.100'}
|
get '/admin/accounts', {}, {'REMOTE_ADDR' => '10.0.0.100'}
|
||||||
assert_equal 'pass', @response.headers['X-Cascade']
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue