Browse files

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

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 72725d7 commit 65ce3d12971afd15de6ea22a2fc5af3ba1faf124 @pixeltrix pixeltrix committed with josevalim Jun 19, 2010
Showing with 9 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_dispatch/routing/mapper.rb
  2. +8 −0 actionpack/test/dispatch/routing_test.rb
View
2 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -102,7 +102,7 @@ def conditions
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
8 actionpack/test/dispatch/routing_test.rb
@@ -68,6 +68,8 @@ def self.matches?(request)
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 @@ def test_admin
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

0 comments on commit 65ce3d1

Please sign in to comment.