Permalink
Browse files

Fix some bugs in the exclusion list matching algorithm and add some m…

…ore tests.
  • Loading branch information...
1 parent d96a178 commit 2184dcf0cdee5e17f21b5acc1f33b4f8bca0b2ec @FooBarWidget committed Sep 3, 2008
@@ -159,7 +159,7 @@ def redirection_information_for_current_request
def match_exclusion_list(redirection_info, exclusion_list)
case exclusion_list
when Array
- return exclusion_list.all? do |l|
+ return exclusion_list.any? do |l|
match_exclusion_list(redirection_info, l)
end
when Hash
@@ -89,15 +89,14 @@ def initialize(controller_path, action_name, params = {}, method = :get)
end
def path
- object = Object.new
- metaclass = class << object
- self
+ klass = Class.new do
+ include ActionController::UrlWriter
end
- metaclass.send(:include, ActionController::UrlWriter)
+ url_generator = klass.new
args = params.merge(:only_path => true,
:controller => controller,
:action => action)
- return metaclass.url_for(args)
+ return URI.parse(url_generator.url_for(args)).path
end
def marshal(encrypt = true, ascii7 = true)
@@ -162,4 +162,20 @@ class SimpleRedirectionTest < ActionController::TestCase
get(:action_auto_redirect)
assert_redirected_to '/'
end
+
+ test "match_exclusion_list with a Regexp" do
+ info = ControllerRedirectionInformation.new('users', 'create', { :id => 1 })
+ assert @controller.send(:match_exclusion_list, info, %r{^/users/create})
+ assert @controller.send(:match_exclusion_list, info, %r{^/users})
+ end
+
+ test "match_exclusion_list with a String" do
+ info = ControllerRedirectionInformation.new('users', 'create', { :id => 1 })
+ assert @controller.send(:match_exclusion_list, info, '/users/create')
+
+ info = ControllerRedirectionInformation.new('users', 'create', { :id => 1, :hello => 'world' })
+ assert @controller.send(:match_exclusion_list, info, '/users/create')
+
+ assert !@controller.send(:match_exclusion_list, info, '/users')
+ end
end

0 comments on commit 2184dcf

Please sign in to comment.