diff options
author | Craig Demyanovich <cdemyanovich@mutuallyhuman.com> | 2008-06-03 13:38:00 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-06-03 13:38:00 -0500 |
commit | aa1771668877f20ca044e8f45a9736fbb7c8402e (patch) | |
tree | 8144566f85fcff4c94e6ccd993ad35c6d4688a1c /activerecord | |
parent | a977f3e88e989cd7d795c46504451b4b1b4db79d (diff) | |
download | rails-aa1771668877f20ca044e8f45a9736fbb7c8402e.tar.gz rails-aa1771668877f20ca044e8f45a9736fbb7c8402e.tar.bz2 rails-aa1771668877f20ca044e8f45a9736fbb7c8402e.zip |
Callbacks fire before notifying observers [#230 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/callbacks.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/callbacks_observers_test.rb | 38 |
2 files changed, 40 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index 41ec5c5e61..4edc209c65 100755 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -293,14 +293,14 @@ module ActiveRecord private def callback(method) - notify(method) - result = run_callbacks(method) { |result, object| result == false } if result != false && respond_to_without_attributes?(method) result = send(method) end + notify(method) + return result end diff --git a/activerecord/test/cases/callbacks_observers_test.rb b/activerecord/test/cases/callbacks_observers_test.rb new file mode 100644 index 0000000000..87de524923 --- /dev/null +++ b/activerecord/test/cases/callbacks_observers_test.rb @@ -0,0 +1,38 @@ +require "cases/helper" + +class Comment < ActiveRecord::Base + attr_accessor :callers + + before_validation :record_callers + + def after_validation + record_callers + end + + def record_callers + callers << self.class if callers + end +end + +class CommentObserver < ActiveRecord::Observer + attr_accessor :callers + + def after_validation(model) + callers << self.class if callers + end +end + +class CallbacksObserversTest < ActiveRecord::TestCase + def test_model_callbacks_fire_before_observers_are_notified + callers = [] + + comment = Comment.new + comment.callers = callers + + CommentObserver.instance.callers = callers + + comment.valid? + + assert_equal [Comment, Comment, CommentObserver], callers, "model callbacks did not fire before observers were notified" + end +end |