Skip to content

Commit

Permalink
Fix some bugs in the exclusion list matching algorithm and add some m…
Browse files Browse the repository at this point in the history
…ore tests.
  • Loading branch information
FooBarWidget committed Sep 3, 2008
1 parent d96a178 commit 2184dcf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/auto_redirection/controller_extensions.rb
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions lib/auto_redirection/redirection_information.rb
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions test/simple_redirections_test.rb
Expand Up @@ -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.