Skip to content
This repository
Browse code

Revert "Fixes skipping object callback filters"

This reverts commit 8e1d3cd.

Conflicts:
	activesupport/CHANGELOG.md
	activesupport/lib/active_support/callbacks.rb
  • Loading branch information...
commit 19117ff392d34114c995d03c508ef650d1b9a76d 1 parent b880497
Aaron Patterson tenderlove authored
4 activesupport/CHANGELOG.md
Source Rendered
@@ -7,10 +7,6 @@
7 7
8 8 ## Rails 4.0.0.rc1 (April 29, 2013) ##
9 9
10   -* Fix skipping of filters defined by objects in `ActiveSupport::Callbacks::Callback`.
11   -
12   - *Ben McRedmond*
13   -
14 10 * An `ActiveSupport::Subscriber` class has been extracted from
15 11 `ActiveSupport::LogSubscriber`, allowing you to use the event attachment
16 12 API for other kinds of subscribers.
23 activesupport/lib/active_support/callbacks.rb
@@ -133,13 +133,7 @@ def next_id
133 133 end
134 134
135 135 def matches?(_kind, _filter)
136   - if @_is_object_filter
137   - _filter_matches = @filter.to_s.start_with?(_method_name_for_object_filter(_kind, _filter, false))
138   - else
139   - _filter_matches = (@filter == _filter)
140   - end
141   -
142   - @kind == _kind && _filter_matches
  136 + @kind == _kind && @filter == _filter
143 137 end
144 138
145 139 def duplicates?(other)
@@ -242,16 +236,6 @@ def recompile_options!
242 236 @compiled_options = conditions.flatten.join(" && ")
243 237 end
244 238
245   - def _method_name_for_object_filter(kind, filter, append_next_id = true)
246   - class_name = filter.kind_of?(Class) ? filter.to_s : filter.class.to_s
247   - class_name.gsub!(/<|>|#/, '')
248   - class_name.gsub!(/\/|:/, "_")
249   -
250   - method_name = "_callback_#{kind}_#{class_name}"
251   - method_name << "_#{next_id}" if append_next_id
252   - method_name
253   - end
254   -
255 239 # Filters support:
256 240 #
257 241 # Arrays:: Used in conditions. This is used to specify
@@ -273,8 +257,6 @@ def _method_name_for_object_filter(kind, filter, append_next_id = true)
273 257 # a method is created that calls the before_foo method
274 258 # on the object.
275 259 def _compile_filter(filter)
276   - @_is_object_filter = false
277   -
278 260 case filter
279 261 when Array
280 262 filter.map {|f| _compile_filter(f)}
@@ -289,8 +271,7 @@ def _compile_filter(filter)
289 271
290 272 method_name << (filter.arity == 1 ? "(self)" : " self, Proc.new ")
291 273 else
292   - method_name = _method_name_for_object_filter(kind, filter)
293   - @_is_object_filter = true
  274 + method_name = "_callback_#{@kind}_#{next_id}"
294 275 @klass.send(:define_method, "#{method_name}_object") { filter }
295 276
296 277 _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 comments on commit 19117ff

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