Browse files

added support for String, Proc, Method

git-svn-id: https://svn.thoughtbot.com/plugins/when/trunk@342 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information...
1 parent cfdaefa commit 4fd87e8f012b34379f455a47f146ab2ae049331a dcroak committed Feb 15, 2008
Showing with 8 additions and 4 deletions.
  1. +6 −2 lib/filters.rb
  2. +2 −2 test/filters_test.rb
View
8 lib/filters.rb
@@ -15,9 +15,13 @@ def #{filter}_with_conditions(*filters)
(! options[:unless].nil? && ActiveRecord::Base.evaluate_condition(options[:unless], controller))
if filter.class == Symbol
controller.send filter
+ elsif filter.class == String
+ eval(filter, binding)
+ elsif filter.class == Proc || filter.class == Method
+ filter.call(controller)
else
- raise ActionController::ActionControllerError,
- 'When only supports Symbol filters, refactor to use a Symbol or remove When'
+ raise ActiveRecord::ActiveRecordError,
+ "Filters must be a symbol denoting the method to call, a string to be evaluated, a block to be invoked, or an object responding to the callback method."
end
end
end
View
4 test/filters_test.rb
@@ -171,7 +171,7 @@ def rescue_action(exception)
assert_equal 'new name', @controller.name
end
- define_method "test_#{filter}_with_if_condition_#{condition.class}_which_returns_true_should_raise_an_exception_if_its_callback_is_not_a_symbol" do
+ define_method "test_#{filter}_with_if_condition_#{condition.class}_which_returns_true_should_raise_an_exception_if_its_callback_is_not_a_supported_type" do
CompaniesController.send filter.to_sym, CompaniesController, :if => condition
@controller.name = 'thoughtbot'
@@ -182,7 +182,7 @@ def rescue_action(exception)
end
end
- define_method "test_#{filter}_with_unless_condition_#{condition.class}_which_returns_true_should_raise_an_exception_if_its_callback_is_not_a_symbol" do
+ define_method "test_#{filter}_with_unless_condition_#{condition.class}_which_returns_true_should_raise_an_exception_if_its_callback_is_not_a_supported_type" do
CompaniesController.send filter.to_sym, CompaniesController, :unless => condition
@controller.name = 'thoughtbot'

0 comments on commit 4fd87e8

Please sign in to comment.