public
Description: Conditional checks on Rails filters
Clone URL: git://github.com/thoughtbot/when.git
added support for String, Proc, Method

git-svn-id: https://svn.thoughtbot.com/plugins/when/trunk@342 
7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
dcroak (author)
Thu Feb 14 16:37:46 -0800 2008
commit  4fd87e8f012b34379f455a47f146ab2ae049331a
tree    7e1c2003a254c981b0eca7f0ae1e4895f14831cd
parent  cfdaefa7cb69b8e82bf1989591980b598d24f858
...
15
16
17
 
 
 
 
18
19
20
 
 
21
22
23
...
15
16
17
18
19
20
21
22
 
 
23
24
25
26
27
0
@@ -15,9 +15,13 @@ module When
0
                       (! options[:unless].nil? && ActiveRecord::Base.evaluate_condition(options[:unless], controller))
0
                     if filter.class == Symbol
0
                       controller.send filter
0
+ elsif filter.class == String
0
+ eval(filter, binding)
0
+ elsif filter.class == Proc || filter.class == Method
0
+ filter.call(controller)
0
                     else
0
- raise ActionController::ActionControllerError,
0
- 'When only supports Symbol filters, refactor to use a Symbol or remove When'
0
+ raise ActiveRecord::ActiveRecordError,
0
+ "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."
0
                     end
0
                   end
0
                 end
...
171
172
173
174
 
175
176
177
...
182
183
184
185
 
186
187
188
...
171
172
173
 
174
175
176
177
...
182
183
184
 
185
186
187
188
0
@@ -171,7 +171,7 @@ class FiltersTest < ActionController::TestCase
0
         assert_equal 'new name', @controller.name
0
       end
0
 
0
- define_method "test_#{filter}_with_if_condition_#{condition.class}_which_returns_true_should_raise_an_exception_if_its_callback_is_not_a_symbol" do
0
+ 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
0
         CompaniesController.send filter.to_sym, CompaniesController, :if => condition
0
 
0
         @controller.name = 'thoughtbot'
0
@@ -182,7 +182,7 @@ class FiltersTest < ActionController::TestCase
0
         end
0
       end
0
 
0
- define_method "test_#{filter}_with_unless_condition_#{condition.class}_which_returns_true_should_raise_an_exception_if_its_callback_is_not_a_symbol" do
0
+ 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
0
         CompaniesController.send filter.to_sym, CompaniesController, :unless => condition
0
 
0
         @controller.name = 'thoughtbot'

Comments

    No one has commented yet.