mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
2ea1d684d9
Signed-off-by: Joshua Peek <josh@joshpeek.com>
37 lines
783 B
Ruby
37 lines
783 B
Ruby
require "cases/helper"
|
|
|
|
class Comment < ActiveRecord::Base
|
|
attr_accessor :callers
|
|
|
|
before_validation :record_callers
|
|
|
|
after_validation do
|
|
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
|