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

git-svn-id: https://svn.thoughtbot.com/plugins/when/trunk@347 
7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
jcarroll (author)
Thu Feb 14 18:03:03 -0800 2008
commit  f8630086e8b81116b1b4d7772fc44a6e1b32f0c7
tree    a96dff22ee5fd178e2cd94c93702b74c341f1746
parent  06047c40968b6befca5871d3942ed1aae4ffd7ac
...
26
27
28
29
 
30
31
32
...
26
27
28
 
29
30
31
32
0
@@ -26,7 +26,7 @@ module When
0
                       callback.call(record)
0
                     else
0
                       raise ActiveRecord::ActiveRecordError,
0
- "Callbacks 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
+ 'Callbacks must be a symbol denoting the method to call, a string to be evaluated or a block to be invoked.'
0
                     end
0
                   end
0
                 end
...
18
19
20
21
22
23
24
25
26
27
 
28
29
30
...
18
19
20
 
 
21
22
23
24
 
25
26
27
28
0
@@ -18,13 +18,11 @@ 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
- "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
+ 'Filters must be a symbol denoting the method to call evaluated or a block to be invoked.'
0
                     end
0
                   end
0
                 end
...
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
...
197
198
199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
201
202
0
@@ -197,154 +197,6 @@ class FiltersTest < ActionController::TestCase
0
 
0
   conditions.each do |condition|
0
     basic_filters.each do |filter|
0
- define_method "test_#{filter}_with_if_condition_#{condition.class}_which_returns_true_should_change_company_bio" do
0
- CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :if => condition
0
-
0
- CompaniesController.bio = 'thoughtbot'
0
- @controller.flag = true
0
-
0
- get :index
0
- assert_equal 'new bio', CompaniesController.bio
0
- end
0
-
0
- define_method "test_#{filter}_with_if_condition_#{condition.class}_which_returns_false_should_not_change_company_bio" do
0
- CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :if => condition
0
-
0
- CompaniesController.bio = 'thoughtbot'
0
- @controller.flag = false
0
-
0
- get :index
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
- end
0
-
0
- define_method "test_#{filter}_with_unless_condition_#{condition.class}_which_returns_true_should_not_change_company_bio" do
0
- CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :unless => condition
0
-
0
- CompaniesController.bio = 'thoughtbot'
0
- @controller.flag = true
0
-
0
- get :index
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
- end
0
-
0
- define_method "test_#{filter}_with_unless_condition_#{condition.class}_which_returns_false_should_change_company_bio" do
0
- CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :unless => condition
0
-
0
- CompaniesController.bio = 'thoughtbot'
0
- @controller.flag = false
0
-
0
- get :index
0
- assert_equal 'new bio', CompaniesController.bio
0
- end
0
-
0
- define_method "test_#{filter}_with_only_option_with_if_condition_#{condition.class}_which_returns_true_should_change_company_bio" do
0
- CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :only => :show, :if => condition
0
-
0
- CompaniesController.bio = 'thoughtbot'
0
- @controller.flag = true
0
-
0
- get :index
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
-
0
- get :show
0
- assert_equal 'new bio', CompaniesController.bio
0
- end
0
-
0
- define_method "test_#{filter}_with_only_option_if_condition_#{condition.class}_which_returns_false_should_not_change_company_bio" do
0
- CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :only => :show, :if => condition
0
-
0
- CompaniesController.bio = 'thoughtbot'
0
- @controller.flag = false
0
-
0
- get :index
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
-
0
- get :show
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
- end
0
-
0
- define_method "test_#{filter}_with_only_option_unless_condition_#{condition.class}_which_returns_true_should_not_change_company_bio" do
0
- CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :only => :show, :unless => condition
0
-
0
- CompaniesController.bio = 'thoughtbot'
0
- @controller.flag = true
0
-
0
- get :index
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
-
0
- get :show
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
- end
0
-
0
- define_method "test_#{filter}_with_only_option_unless_condition_#{condition.class}_which_returns_false_should_change_company_bio" do
0
- CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :only => :show, :unless => condition
0
-
0
- CompaniesController.bio = 'thoughtbot'
0
- @controller.flag = false
0
-
0
- get :index
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
-
0
- get :show
0
- assert_equal 'new bio', CompaniesController.bio
0
- end
0
-
0
- define_method "test_#{filter}_with_except_option_with_if_condition_#{condition.class}_which_returns_true_should_change_company_bio" do
0
- CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :except => :show, :if => condition
0
-
0
- CompaniesController.bio = 'thoughtbot'
0
- @controller.flag = true
0
-
0
- get :show
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
-
0
- get :index
0
- assert_equal 'new bio', CompaniesController.bio
0
- end
0
-
0
- define_method "test_#{filter}_with_except_option_if_condition_#{condition.class}_which_returns_false_should_not_change_company_bio" do
0
- CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :except => :show, :if => condition
0
-
0
- CompaniesController.bio = 'thoughtbot'
0
- @controller.flag = false
0
-
0
- get :show
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
-
0
- get :index
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
- end
0
-
0
- define_method "test_#{filter}_with_except_option_unless_condition_#{condition.class}_which_returns_true_should_not_change_company_bio" do
0
- CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :except => :show, :unless => condition
0
-
0
- CompaniesController.bio = 'thoughtbot'
0
- @controller.flag = true
0
-
0
- get :show
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
-
0
- get :index
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
- end
0
-
0
- define_method "test_#{filter}_with_except_option_unless_condition_#{condition.class}_which_returns_false_should_change_company_bio" do
0
- CompaniesController.send filter.to_sym, 'self.bio = "new bio"', :except => :show, :unless => condition
0
-
0
- CompaniesController.bio = 'thoughtbot'
0
- @controller.flag = false
0
-
0
- get :show
0
- assert_equal 'thoughtbot', CompaniesController.bio
0
-
0
- get :index
0
- assert_equal 'new bio', CompaniesController.bio
0
- end
0
- end
0
- end
0
-
0
- conditions.each do |condition|
0
- basic_filters.each do |filter|
0
       define_method "test_#{filter}_with_block_callback_with_if_condition_#{condition.class}_which_returns_true_should_change_company_name" do
0
         CompaniesController.send filter.to_sym, :if => condition do |controller|
0
           controller.change_name

Comments

    No one has commented yet.