Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@tenderlove tenderlove authored
View
4 activesupport/CHANGELOG.md
@@ -7,10 +7,6 @@
## Rails 4.0.0.rc1 (April 29, 2013) ##
-* Fix skipping of filters defined by objects in `ActiveSupport::Callbacks::Callback`.
-
- *Ben McRedmond*
-
* An `ActiveSupport::Subscriber` class has been extracted from
`ActiveSupport::LogSubscriber`, allowing you to use the event attachment
API for other kinds of subscribers.
View
23 activesupport/lib/active_support/callbacks.rb
@@ -133,13 +133,7 @@ def next_id
end
def matches?(_kind, _filter)
- if @_is_object_filter
- _filter_matches = @filter.to_s.start_with?(_method_name_for_object_filter(_kind, _filter, false))
- else
- _filter_matches = (@filter == _filter)
- end
-
- @kind == _kind && _filter_matches
+ @kind == _kind && @filter == _filter
end
def duplicates?(other)
@@ -242,16 +236,6 @@ def recompile_options!
@compiled_options = conditions.flatten.join(" && ")
end
- def _method_name_for_object_filter(kind, filter, append_next_id = true)
- class_name = filter.kind_of?(Class) ? filter.to_s : filter.class.to_s
- class_name.gsub!(/<|>|#/, '')
- class_name.gsub!(/\/|:/, "_")
-
- method_name = "_callback_#{kind}_#{class_name}"
- method_name << "_#{next_id}" if append_next_id
- method_name
- end
-
# Filters support:
#
# 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)
# a method is created that calls the before_foo method
# on the object.
def _compile_filter(filter)
- @_is_object_filter = false
-
case filter
when Array
filter.map {|f| _compile_filter(f)}
@@ -289,8 +271,7 @@ def _compile_filter(filter)
method_name << (filter.arity == 1 ? "(self)" : " self, Proc.new ")
else
- method_name = _method_name_for_object_filter(kind, filter)
- @_is_object_filter = true
+ method_name = "_callback_#{@kind}_#{next_id}"
@klass.send(:define_method, "#{method_name}_object") { filter }
_normalize_legacy_filter(kind, filter)
View
17 activesupport/test/callbacks_test.rb
@@ -66,16 +66,6 @@ def history
end
end
- class CallbackClass
- def self.before(model)
- model.history << [:before_save, :class]
- end
-
- def self.after(model)
- model.history << [:after_save, :class]
- end
- end
-
class Person < Record
[:before_save, :after_save].each do |callback_method|
callback_method_sym = callback_method.to_sym
@@ -83,7 +73,6 @@ class Person < Record
send(callback_method, callback_string(callback_method_sym))
send(callback_method, callback_proc(callback_method_sym))
send(callback_method, callback_object(callback_method_sym.to_s.gsub(/_save/, '')))
- send(callback_method, CallbackClass)
send(callback_method) { |model| model.history << [callback_method_sym, :block] }
end
@@ -97,7 +86,6 @@ class PersonSkipper < Person
skip_callback :save, :after, :before_save_method, :unless => :yes
skip_callback :save, :after, :before_save_method, :if => :no
skip_callback :save, :before, :before_save_method, :unless => :no
- skip_callback :save, :before, CallbackClass , :if => :yes
def yes; true; end
def no; false; end
end
@@ -442,7 +430,6 @@ def test_skip_person
[:before_save, :object],
[:before_save, :block],
[:after_save, :block],
- [:after_save, :class],
[:after_save, :object],
[:after_save, :proc],
[:after_save, :string],
@@ -462,10 +449,8 @@ def test_save_person
[:before_save, :string],
[:before_save, :proc],
[:before_save, :object],
- [:before_save, :class],
[:before_save, :block],
[:after_save, :block],
- [:after_save, :class],
[:after_save, :object],
[:after_save, :proc],
[:after_save, :string],
@@ -730,10 +715,8 @@ def test_skip_writer
[:before_save, :string],
[:before_save, :proc],
[:before_save, :object],
- [:before_save, :class],
[:before_save, :block],
[:after_save, :block],
- [:after_save, :class],
[:after_save, :object],
[:after_save, :proc],
[:after_save, :string],

0 comments on commit 19117ff

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