Changeset 3504
- Timestamp:
- 01/31/06 23:55:04 (3 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/filters.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/filters_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r3497 r3504 1 1 *SVN* 2 3 * Added :only and :except controls to skip_before/after_filter just like for when you add filters [DHH] 2 4 3 5 * Ensure that the instance variables are copied to the template when performing render :update. [Nicholas Seckar] trunk/actionpack/lib/action_controller/filters.rb
r2873 r3504 252 252 # filters, not procs. This is especially useful for managing the chain in inheritance hierarchies where only one out 253 253 # of many sub-controllers need a different hierarchy. 254 # 255 # You can control the actions to skip the filter for with the <tt>:only</tt> and <tt>:except</tt> options, 256 # just like when you apply the filters. 254 257 def skip_before_filter(*filters) 255 for filter in filters.flatten 256 write_inheritable_attribute("before_filters", read_inheritable_attribute("before_filters") - [ filter ]) 258 if conditions = extract_conditions!(filters) 259 conditions[:only], conditions[:except] = conditions[:except], conditions[:only] 260 add_action_conditions(filters, conditions) 261 else 262 for filter in filters.flatten 263 write_inheritable_attribute("before_filters", read_inheritable_attribute("before_filters") - [ filter ]) 264 end 257 265 end 258 266 end … … 261 269 # filters, not procs. This is especially useful for managing the chain in inheritance hierarchies where only one out 262 270 # of many sub-controllers need a different hierarchy. 271 # 272 # You can control the actions to skip the filter for with the <tt>:only</tt> and <tt>:except</tt> options, 273 # just like when you apply the filters. 263 274 def skip_after_filter(*filters) 264 for filter in filters.flatten 265 write_inheritable_attribute("after_filters", read_inheritable_attribute("after_filters") - [ filter ]) 275 if conditions = extract_conditions!(filters) 276 conditions[:only], conditions[:except] = conditions[:except], conditions[:only] 277 add_action_conditions(filters, conditions) 278 else 279 for filter in filters.flatten 280 write_inheritable_attribute("after_filters", read_inheritable_attribute("after_filters") - [ filter ]) 281 end 266 282 end 267 283 end trunk/actionpack/test/controller/filters_test.rb
r2873 r3504 4 4 class TestController < ActionController::Base 5 5 before_filter :ensure_login 6 after_filter :clean_up 6 7 7 8 def show … … 14 15 @ran_filter << "ensure_login" 15 16 end 17 18 def clean_up 19 @ran_after_filter ||= [] 20 @ran_after_filter << "clean_up" 21 end 16 22 end 17 23 … … 108 114 end 109 115 end 116 117 class ConditionalSkippingController < TestController 118 skip_before_filter :ensure_login, :only => [ :login ] 119 skip_after_filter :clean_up, :only => [ :login ] 120 121 def login 122 render :inline => "ran action" 123 end 124 125 def change_password 126 render :inline => "ran action" 127 end 128 end 129 110 130 111 131 class ProcController < PrependingController … … 344 364 end 345 365 366 def test_conditional_skipping_of_filters 367 assert_nil test_process(ConditionalSkippingController, "login").template.assigns["ran_filter"] 368 assert_equal %w( ensure_login ), test_process(ConditionalSkippingController, "change_password").template.assigns["ran_filter"] 369 370 assert_nil test_process(ConditionalSkippingController, "login").template.controller.instance_variable_get("@ran_after_filter") 371 assert_equal %w( clean_up ), test_process(ConditionalSkippingController, "change_password").template.controller.instance_variable_get("@ran_after_filter") 372 end 373 346 374 private 347 375 def test_process(controller, action = "show")