blob: 52ce38484440c7c96223bfb2a1da056f37f70652 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
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
|