Skip to content
This repository
Browse code

Revert "Merge pull request #10034 from benofsky/fix_skipping_object_c…

…allback_filters"

This reverts commit c79c698, reversing
changes made to ba4c274.

This broke all the tests. See https://travis-ci.org/rails/rails/builds/6061839
  • Loading branch information...
commit 49a0f554a66ed427df2ab9942e64252b56b60c27 1 parent 02acd95
Rafael Mendonça França authored April 04, 2013
3  activesupport/CHANGELOG.md
Source Rendered
@@ -14,9 +14,6 @@
14 14
 
15 15
     *Charles Jones*
16 16
 
17  
-*   Fix skipping of filters defined by objects in `ActiveSupport::Callbacks::Callback`.
18  
-
19  
-    *Ben McRedmond*
20 17
 
21 18
 ## Rails 4.0.0.beta1 (February 25, 2013) ##
22 19
 
14  activesupport/lib/active_support/callbacks.rb
@@ -131,7 +131,6 @@ def next_id
131 131
       end
132 132
 
133 133
       def matches?(_kind, _filter)
134  
-        _filter = _method_name_for_object_filter(_kind, _filter) if @_is_object_filter
135 134
         @kind == _kind && @filter == _filter
136 135
       end
137 136
 
@@ -235,14 +234,6 @@ def recompile_options!
235 234
         @compiled_options = conditions.flatten.join(" && ")
236 235
       end
237 236
 
238  
-      def _method_name_for_object_filter(kind, filter)
239  
-        class_name = filter.kind_of?(Class) ? filter.to_s : filter.class.to_s
240  
-        class_name.gsub!(/<|>|#/, '')
241  
-        class_name.gsub!(/\/|:/, "_")
242  
-
243  
-        "_callback_#{kind}_#{class_name}"
244  
-      end
245  
-
246 237
       # Filters support:
247 238
       #
248 239
       #   Arrays::  Used in conditions. This is used to specify
@@ -264,8 +255,6 @@ def _method_name_for_object_filter(kind, filter)
264 255
       #     a method is created that calls the before_foo method
265 256
       #     on the object.
266 257
       def _compile_filter(filter)
267  
-        @_is_object_filter = false
268  
-
269 258
         case filter
270 259
         when Array
271 260
           filter.map {|f| _compile_filter(f)}
@@ -280,8 +269,7 @@ def _compile_filter(filter)
280 269
 
281 270
           method_name << (filter.arity == 1 ? "(self)" : " self, Proc.new ")
282 271
         else
283  
-          method_name = _method_name_for_object_filter(kind, filter)
284  
-          @_is_object_filter = true
  272
+          method_name = "_callback_#{@kind}_#{next_id}"
285 273
           @klass.send(:define_method, "#{method_name}_object") { filter }
286 274
 
287 275
           _normalize_legacy_filter(kind, filter)
17  activesupport/test/callbacks_test.rb
@@ -66,16 +66,6 @@ def history
66 66
     end
67 67
   end
68 68
 
69  
-  class CallbackClass
70  
-    def self.before(model)
71  
-      model.history << [:before_save, :class]
72  
-    end
73  
-    
74  
-    def self.after(model)
75  
-      model.history << [:after_save, :class]
76  
-    end
77  
-  end
78  
-
79 69
   class Person < Record
80 70
     [:before_save, :after_save].each do |callback_method|
81 71
       callback_method_sym = callback_method.to_sym
@@ -83,7 +73,6 @@ class Person < Record
83 73
       send(callback_method, callback_string(callback_method_sym))
84 74
       send(callback_method, callback_proc(callback_method_sym))
85 75
       send(callback_method, callback_object(callback_method_sym.to_s.gsub(/_save/, '')))
86  
-      send(callback_method, CallbackClass)
87 76
       send(callback_method) { |model| model.history << [callback_method_sym, :block] }
88 77
     end
89 78
 
@@ -97,7 +86,6 @@ class PersonSkipper < Person
97 86
     skip_callback :save, :after, :before_save_method, :unless => :yes
98 87
     skip_callback :save, :after, :before_save_method, :if => :no
99 88
     skip_callback :save, :before, :before_save_method, :unless => :no
100  
-    skip_callback :save, :before, CallbackClass , :if => :yes
101 89
     def yes; true; end
102 90
     def no; false; end
103 91
   end
@@ -442,7 +430,6 @@ def test_skip_person
442 430
         [:before_save, :object],
443 431
         [:before_save, :block],
444 432
         [:after_save, :block],
445  
-        [:after_save, :class],
446 433
         [:after_save, :object],
447 434
         [:after_save, :proc],
448 435
         [:after_save, :string],
@@ -462,10 +449,8 @@ def test_save_person
462 449
         [:before_save, :string],
463 450
         [:before_save, :proc],
464 451
         [:before_save, :object],
465  
-        [:before_save, :class],
466 452
         [:before_save, :block],
467 453
         [:after_save, :block],
468  
-        [:after_save, :class],
469 454
         [:after_save, :object],
470 455
         [:after_save, :proc],
471 456
         [:after_save, :string],
@@ -730,10 +715,8 @@ def test_skip_writer
730 715
         [:before_save, :string],
731 716
         [:before_save, :proc],
732 717
         [:before_save, :object],
733  
-        [:before_save, :class],
734 718
         [:before_save, :block],
735 719
         [:after_save, :block],
736  
-        [:after_save, :class],
737 720
         [:after_save, :object],
738 721
         [:after_save, :proc],
739 722
         [:after_save, :string],

0 notes on commit 49a0f55

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