diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-06-03 22:38:27 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-06-03 22:38:27 -0700 |
commit | 53bcbfbdc1eed45cc6615e59d36baf018ab43d96 (patch) | |
tree | 691441d50ef7e49b5317ce279329bcaa1d135744 /activerecord/test/cases/callbacks_observers_test.rb | |
parent | f55ad960d22337d0d92a93724f1cc3ad45200836 (diff) | |
parent | 82e96eb294ae21528c3e05e91c05c7ee5222afbd (diff) | |
download | rails-53bcbfbdc1eed45cc6615e59d36baf018ab43d96.tar.gz rails-53bcbfbdc1eed45cc6615e59d36baf018ab43d96.tar.bz2 rails-53bcbfbdc1eed45cc6615e59d36baf018ab43d96.zip |
Merge branch 'master' into erbout
Diffstat (limited to 'activerecord/test/cases/callbacks_observers_test.rb')
-rw-r--r-- | activerecord/test/cases/callbacks_observers_test.rb | 38 |
1 files changed, 38 insertions, 0 deletions
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 |