@@ -11,13 +11,17 @@ def test_transaction_instrumentation_on_commit
11
11
topic = topics ( :fifth )
12
12
13
13
notified = false
14
+ expected_transaction = nil
15
+
14
16
subscriber = ActiveSupport ::Notifications . subscribe ( "transaction.active_record" ) do |event |
15
17
assert event . payload [ :connection ]
18
+ assert_same expected_transaction , event . payload [ :transaction ]
16
19
assert_equal :commit , event . payload [ :outcome ]
17
20
notified = true
18
21
end
19
22
20
- ActiveRecord ::Base . transaction do
23
+ ActiveRecord ::Base . transaction do |transaction |
24
+ expected_transaction = transaction
21
25
topic . update ( title : "Ruby on Rails" )
22
26
end
23
27
@@ -30,13 +34,17 @@ def test_transaction_instrumentation_on_rollback
30
34
topic = topics ( :fifth )
31
35
32
36
notified = false
37
+ expected_transaction = nil
38
+
33
39
subscriber = ActiveSupport ::Notifications . subscribe ( "transaction.active_record" ) do |event |
34
40
assert event . payload [ :connection ]
41
+ assert_same expected_transaction , event . payload [ :transaction ]
35
42
assert_equal :rollback , event . payload [ :outcome ]
36
43
notified = true
37
44
end
38
45
39
- ActiveRecord ::Base . transaction do
46
+ ActiveRecord ::Base . transaction do |transaction |
47
+ expected_transaction = transaction
40
48
topic . update ( title : "Ruby on Rails" )
41
49
raise ActiveRecord ::Rollback
42
50
end
@@ -54,17 +62,24 @@ def test_transaction_instrumentation_with_savepoints
54
62
events << event
55
63
end
56
64
57
- ActiveRecord ::Base . transaction do
65
+ real_transaction = savepoint_transaction = nil
66
+ ActiveRecord ::Base . transaction do |transaction |
67
+ real_transaction = transaction
58
68
topic . update ( title : "Sinatra" )
59
- ActiveRecord ::Base . transaction ( requires_new : true ) do
69
+ ActiveRecord ::Base . transaction ( requires_new : true ) do |transaction |
70
+ savepoint_transaction = transaction
60
71
topic . update ( title : "Ruby on Rails" )
61
72
end
62
73
end
63
74
64
75
assert_equal 2 , events . count
65
- savepoint , real = events
66
- assert_equal :commit , savepoint . payload [ :outcome ]
67
- assert_equal :commit , real . payload [ :outcome ]
76
+ savepoint_event , real_event = events
77
+
78
+ assert_same savepoint_transaction , savepoint_event . payload [ :transaction ]
79
+ assert_equal :commit , savepoint_event . payload [ :outcome ]
80
+
81
+ assert_same real_transaction , real_event . payload [ :transaction ]
82
+ assert_equal :commit , real_event . payload [ :outcome ]
68
83
ensure
69
84
ActiveSupport ::Notifications . unsubscribe ( subscriber ) if subscriber
70
85
end
0 commit comments