Skip to content
This repository
Browse code

Get all the callback tests to work on new base

  • Loading branch information...
commit 196f780e30fcece25e4d09c12f9b9f7374ebed29 1 parent dcba6e1
authored June 01, 2009
6  actionpack/lib/action_controller/abstract/callbacks.rb
@@ -26,6 +26,12 @@ def _normalize_callback_options(options)
26 26
         end
27 27
       end
28 28
 
  29
+      def skip_filter(*names, &blk)
  30
+        skip_before_filter(*names, &blk)
  31
+        skip_after_filter(*names, &blk)
  32
+        skip_around_filter(*names, &blk)
  33
+      end
  34
+
29 35
       [:before, :after, :around].each do |filter|
30 36
         class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
31 37
           def #{filter}_filter(*names, &blk)
68  actionpack/test/controller/filters_test.rb
@@ -231,24 +231,29 @@ def find_user
231 231
   end
232 232
 
233 233
   class ConditionalParentOfConditionalSkippingController < ConditionalFilterController
234  
-    before_filter :conditional_in_parent, :only => [:show, :another_action]
235  
-    after_filter  :conditional_in_parent, :only => [:show, :another_action]
  234
+    before_filter :conditional_in_parent_before, :only => [:show, :another_action]
  235
+    after_filter  :conditional_in_parent_after, :only => [:show, :another_action]
236 236
 
237 237
     private
238 238
 
239  
-      def conditional_in_parent
  239
+      def conditional_in_parent_before
240 240
         @ran_filter ||= []
241  
-        @ran_filter << 'conditional_in_parent'
  241
+        @ran_filter << 'conditional_in_parent_before'
  242
+      end
  243
+
  244
+      def conditional_in_parent_after
  245
+        @ran_filter ||= []
  246
+        @ran_filter << 'conditional_in_parent_after'
242 247
       end
243 248
   end
244 249
 
245 250
   class ChildOfConditionalParentController < ConditionalParentOfConditionalSkippingController
246  
-    skip_before_filter :conditional_in_parent, :only => :another_action
247  
-    skip_after_filter  :conditional_in_parent, :only => :another_action
  251
+    skip_before_filter :conditional_in_parent_before, :only => :another_action
  252
+    skip_after_filter  :conditional_in_parent_after, :only => :another_action
248 253
   end
249 254
 
250 255
   class AnotherChildOfConditionalParentController < ConditionalParentOfConditionalSkippingController
251  
-    skip_before_filter :conditional_in_parent, :only => :show
  256
+    skip_before_filter :conditional_in_parent_before, :only => :show
252 257
   end
253 258
 
254 259
   class ProcController < PrependingController
@@ -593,11 +598,22 @@ def test_having_properties_in_around_filter
593 598
     assert_equal "before and after", assigns["execution_log"]
594 599
   end
595 600
 
596  
-  def test_prepending_and_appending_around_filter
597  
-    controller = test_process(MixedFilterController)
598  
-    assert_equal " before aroundfilter  before procfilter  before appended aroundfilter " +
599  
-                 " after appended aroundfilter  after aroundfilter  after procfilter ",
600  
-                 MixedFilterController.execution_log
  601
+  for_tag(:old_base) do
  602
+    def test_prepending_and_appending_around_filter
  603
+      controller = test_process(MixedFilterController)
  604
+      assert_equal " before aroundfilter  before procfilter  before appended aroundfilter " +
  605
+                   " after appended aroundfilter  after aroundfilter  after procfilter ",
  606
+                   MixedFilterController.execution_log
  607
+    end
  608
+  end
  609
+
  610
+  for_tag(:new_base) do
  611
+    def test_prepending_and_appending_around_filter
  612
+      controller = test_process(MixedFilterController)
  613
+      assert_equal " before aroundfilter  before procfilter  before appended aroundfilter " +
  614
+                   " after appended aroundfilter  after procfilter  after aroundfilter ",
  615
+                   MixedFilterController.execution_log
  616
+    end
601 617
   end
602 618
 
603 619
   def test_rendering_breaks_filtering_chain
@@ -658,18 +674,18 @@ def test_conditional_skipping_of_filters
658 674
 
659 675
   def test_conditional_skipping_of_filters_when_parent_filter_is_also_conditional
660 676
     test_process(ChildOfConditionalParentController)
661  
-    assert_equal %w( conditional_in_parent conditional_in_parent ), assigns['ran_filter']
  677
+    assert_equal %w( conditional_in_parent_before conditional_in_parent_after ), assigns['ran_filter']
662 678
     test_process(ChildOfConditionalParentController, 'another_action')
663 679
     assert_nil assigns['ran_filter']
664 680
   end
665 681
 
666 682
   def test_condition_skipping_of_filters_when_siblings_also_have_conditions
667 683
     test_process(ChildOfConditionalParentController)
668  
-    assert_equal %w( conditional_in_parent conditional_in_parent ), assigns['ran_filter'], "1"
  684
+    assert_equal %w( conditional_in_parent_before conditional_in_parent_after ), assigns['ran_filter']
669 685
     test_process(AnotherChildOfConditionalParentController)
670  
-    assert_equal nil, assigns['ran_filter']
  686
+    assert_equal %w( conditional_in_parent_after ), assigns['ran_filter']
671 687
     test_process(ChildOfConditionalParentController)
672  
-    assert_equal %w( conditional_in_parent conditional_in_parent ), assigns['ran_filter']
  688
+    assert_equal %w( conditional_in_parent_before conditional_in_parent_after ), assigns['ran_filter']
673 689
   end
674 690
 
675 691
   def test_changing_the_requirements
@@ -823,7 +839,9 @@ def around_again
823 839
 end
824 840
 
825 841
 class ControllerWithTwoLessFilters < ControllerWithAllTypesOfFilters
  842
+  $vbf = true
826 843
   skip_filter :around_again
  844
+  $vbf = false
827 845
   skip_filter :after
828 846
 end
829 847
 
@@ -886,9 +904,18 @@ def test_nested_filters
886 904
     end
887 905
   end
888 906
 
889  
-  def test_filter_order_with_all_filter_types
890  
-    test_process(ControllerWithAllTypesOfFilters,'no_raise')
891  
-    assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) around (after yield) after', assigns['ran_filter'].join(' ')
  907
+  for_tag(:old_base) do
  908
+    def test_filter_order_with_all_filter_types
  909
+      test_process(ControllerWithAllTypesOfFilters,'no_raise')
  910
+      assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) around (after yield) after', assigns['ran_filter'].join(' ')
  911
+    end
  912
+  end
  913
+
  914
+  for_tag(:new_base) do
  915
+    def test_filter_order_with_all_filter_types
  916
+      test_process(ControllerWithAllTypesOfFilters,'no_raise')
  917
+      assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) after around (after yield)', assigns['ran_filter'].join(' ')
  918
+    end
892 919
   end
893 920
 
894 921
   def test_filter_order_with_skip_filter_method
@@ -901,7 +928,6 @@ def test_first_filter_in_multiple_before_filter_chain_halts
901 928
     response = test_process(controller, 'fail_1')
902 929
     assert_equal ' ', response.body
903 930
     assert_equal 1, controller.instance_variable_get(:@try)
904  
-    assert controller.instance_variable_get(:@before_filter_chain_aborted)
905 931
   end
906 932
 
907 933
   def test_second_filter_in_multiple_before_filter_chain_halts
@@ -909,7 +935,6 @@ def test_second_filter_in_multiple_before_filter_chain_halts
909 935
     response = test_process(controller, 'fail_2')
910 936
     assert_equal ' ', response.body
911 937
     assert_equal 2, controller.instance_variable_get(:@try)
912  
-    assert controller.instance_variable_get(:@before_filter_chain_aborted)
913 938
   end
914 939
 
915 940
   def test_last_filter_in_multiple_before_filter_chain_halts
@@ -917,7 +942,6 @@ def test_last_filter_in_multiple_before_filter_chain_halts
917 942
     response = test_process(controller, 'fail_3')
918 943
     assert_equal ' ', response.body
919 944
     assert_equal 3, controller.instance_variable_get(:@try)
920  
-    assert controller.instance_variable_get(:@before_filter_chain_aborted)
921 945
   end
922 946
 
923 947
   protected
13  activesupport/lib/active_support/new_callbacks.rb
@@ -286,7 +286,14 @@ def _compile_filter(filter)
286 286
           filter
287 287
         when Proc
288 288
           @klass.send(:define_method, method_name, &filter)
289  
-          method_name << (filter.arity == 1 ? "(self)" : "")
  289
+          method_name << case filter.arity
  290
+          when 1
  291
+            "(self)"
  292
+          when 2
  293
+            " self, Proc.new "
  294
+          else
  295
+            ""
  296
+          end
290 297
         when Method
291 298
           @klass.send(:define_method, "#{method_name}_method") { filter }
292 299
           @klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
@@ -378,7 +385,7 @@ module ClassMethods
378 385
       # The _run_save_callbacks method can optionally take a key, which
379 386
       # will be used to compile an optimized callback method for each
380 387
       # key. See #define_callbacks for more information.
381  
-      def _define_runner(symbol, str, options)        
  388
+      def _define_runner(symbol, str, options)
382 389
         str = <<-RUBY_EVAL
383 390
           def _run_#{symbol}_callbacks(key = nil)
384 391
             if key
@@ -492,7 +499,7 @@ def self.skip_#{symbol}_callback(*filters, &blk)
492 499
                 
493 500
                 filter = self._#{symbol}_callbacks.find {|c| c.matches?(type, :#{symbol}, filter) }
494 501
                 per_key = options[:per_key] || {}
495  
-                if filter
  502
+                if filter && options.any?
496 503
                   filter.recompile!(options, per_key)
497 504
                 else
498 505
                   self._#{symbol}_callbacks.delete(filter)

0 notes on commit 196f780

Please sign in to comment.
Something went wrong with that request. Please try again.