Filter procs must take 1 or 2 arguments. Raise ArgumentError otherwise.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8583 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
2b326a7155
commit
3b13a09e89
@ -583,10 +583,12 @@ def class_for_filter(filter, filter_type) #:nodoc:
|
||||
when filter.respond_to?(:call)
|
||||
if filter.is_a?(Method)
|
||||
MethodFilter
|
||||
elsif filter.arity == 1
|
||||
ProcFilter
|
||||
else
|
||||
ProcWithCallFilter
|
||||
case filter.arity
|
||||
when 1; ProcFilter
|
||||
when 2; ProcWithCallFilter
|
||||
else raise ArgumentError, 'Filter blocks must take one or two arguments.'
|
||||
end
|
||||
end
|
||||
when filter.respond_to?(:filter)
|
||||
ClassFilter
|
||||
|
@ -696,10 +696,6 @@ class ControllerWithProcFilter < PostsController
|
||||
end
|
||||
end
|
||||
|
||||
class ControllerWithWrongFilterType < PostsController
|
||||
around_filter lambda { yield }, :only => :no_raise
|
||||
end
|
||||
|
||||
class ControllerWithNestedFilters < ControllerWithSymbolAsFilter
|
||||
around_filter :raise_before, :raise_after, :without_exception, :only => :raises_both
|
||||
end
|
||||
@ -746,14 +742,15 @@ def test_filters_registering
|
||||
assert_equal 1, ControllerWithFilterClass.filter_chain.size
|
||||
assert_equal 1, ControllerWithFilterInstance.filter_chain.size
|
||||
assert_equal 3, ControllerWithSymbolAsFilter.filter_chain.size
|
||||
assert_equal 1, ControllerWithWrongFilterType.filter_chain.size
|
||||
assert_equal 6, ControllerWithNestedFilters.filter_chain.size
|
||||
assert_equal 4, ControllerWithAllTypesOfFilters.filter_chain.size
|
||||
end
|
||||
|
||||
def test_wrong_filter_type
|
||||
assert_raise(ActionController::ActionControllerError) do
|
||||
test_process(ControllerWithWrongFilterType,'no_raise')
|
||||
assert_raise ArgumentError do
|
||||
Class.new PostsController do
|
||||
around_filter lambda { yield }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user