Skip to content

Commit

Permalink
Revert some ActiveSupport::Callbacks changes.
Browse files Browse the repository at this point in the history
This reverts commits 911a085 and
30b31f5.

Reason: these changes make the Active Model tests fail randomly.

Some examples:
http://travis-ci.org/#!/rails/rails/jobs/1498992
http://travis-ci.org/#!/rails/rails/jobs/1496948
http://travis-ci.org/#!/rails/rails/jobs/1489985

This script was used to reproduce these breaks:
https://gist.github.com/f6828a03ee4d40bffbc3

200 times, 0 failures
  • Loading branch information
rafaelfranca committed Jun 1, 2012
1 parent 60b4290 commit a769fe9
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions activesupport/lib/active_support/callbacks.rb
Expand Up @@ -328,17 +328,26 @@ module ClassMethods
# if it was not yet defined.
# This generated method plays caching role.
def __define_callbacks(kind, object) #:nodoc:
chain = object.send("_#{kind}_callbacks")
name = "_run_callbacks_#{chain.object_id.abs}"
name = __callback_runner_name(kind)
unless object.respond_to?(name, true)
str = object.send("_#{kind}_callbacks").compile
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def #{name}() #{chain.compile} end
def #{name}() #{str} end
protected :#{name}
RUBY_EVAL
end
name
end

def __reset_runner(symbol)
name = __callback_runner_name(symbol)
undef_method(name) if method_defined?(name)
end

def __callback_runner_name(kind)
"_run__#{self.name.hash.abs}__#{kind}__callbacks"
end

# This is used internally to append, prepend and skip callbacks to the
# CallbackChain.
#
Expand All @@ -350,6 +359,7 @@ def __update_callbacks(name, filters = [], block = nil) #:nodoc:
([self] + ActiveSupport::DescendantsTracker.descendants(self)).reverse.each do |target|
chain = target.send("_#{name}_callbacks")
yield target, chain.dup, type, filters, options
target.__reset_runner(name)
end
end

Expand Down Expand Up @@ -437,9 +447,12 @@ def reset_callbacks(symbol)
chain = target.send("_#{symbol}_callbacks").dup
callbacks.each { |c| chain.delete(c) }
target.send("_#{symbol}_callbacks=", chain)
target.__reset_runner(symbol)
end

self.send("_#{symbol}_callbacks=", callbacks.dup.clear)

__reset_runner(symbol)
end

# Define sets of events in the object lifecycle that support callbacks.
Expand Down

0 comments on commit a769fe9

Please sign in to comment.