@@ -34,20 +34,21 @@ def test_raise_after_destroy
34
34
end
35
35
}
36
36
37
- assert @first . reload
38
37
assert_not_predicate @first , :frozen?
39
38
end
40
39
41
40
def test_successful
42
- Topic . transaction do
43
- @first . approved = true
44
- @second . approved = false
45
- @first . save
46
- @second . save
41
+ assert_not_called ( @first , :committed! ) do
42
+ Topic . transaction do
43
+ @first . approved = true
44
+ @second . approved = false
45
+ @first . save
46
+ @second . save
47
+ end
47
48
end
48
49
49
- assert Topic . find ( 1 ) . approved? , "First should have been approved"
50
- assert_not Topic . find ( 2 ) . approved? , "Second should have been unapproved"
50
+ assert_predicate Topic . find ( 1 ) , : approved?, "First should have been approved"
51
+ assert_not_predicate Topic . find ( 2 ) , : approved?, "Second should have been unapproved"
51
52
end
52
53
53
54
def transaction_with_return
@@ -76,11 +77,13 @@ def test_successful_with_return
76
77
end
77
78
end
78
79
79
- transaction_with_return
80
+ assert_not_called ( @first , :committed! ) do
81
+ transaction_with_return
82
+ end
80
83
assert committed
81
84
82
- assert Topic . find ( 1 ) . approved? , "First should have been approved"
83
- assert_not Topic . find ( 2 ) . approved? , "Second should have been unapproved"
85
+ assert_predicate Topic . find ( 1 ) , : approved?, "First should have been approved"
86
+ assert_not_predicate Topic . find ( 2 ) , : approved?, "Second should have been unapproved"
84
87
ensure
85
88
Topic . connection . class_eval do
86
89
remove_method :commit_db_transaction
@@ -99,9 +102,11 @@ def test_number_of_transactions_in_commit
99
102
end
100
103
end
101
104
102
- Topic . transaction do
103
- @first . approved = true
104
- @first . save!
105
+ assert_not_called ( @first , :committed! ) do
106
+ Topic . transaction do
107
+ @first . approved = true
108
+ @first . save!
109
+ end
105
110
end
106
111
107
112
assert_equal 0 , num
@@ -113,19 +118,21 @@ def test_number_of_transactions_in_commit
113
118
end
114
119
115
120
def test_successful_with_instance_method
116
- @first . transaction do
117
- @first . approved = true
118
- @second . approved = false
119
- @first . save
120
- @second . save
121
+ assert_not_called ( @first , :committed! ) do
122
+ @first . transaction do
123
+ @first . approved = true
124
+ @second . approved = false
125
+ @first . save
126
+ @second . save
127
+ end
121
128
end
122
129
123
- assert Topic . find ( 1 ) . approved? , "First should have been approved"
124
- assert_not Topic . find ( 2 ) . approved? , "Second should have been unapproved"
130
+ assert_predicate Topic . find ( 1 ) , : approved?, "First should have been approved"
131
+ assert_not_predicate Topic . find ( 2 ) , : approved?, "Second should have been unapproved"
125
132
end
126
133
127
134
def test_failing_on_exception
128
- begin
135
+ assert_not_called ( @first , :rolledback! ) do
129
136
Topic . transaction do
130
137
@first . approved = true
131
138
@second . approved = false
@@ -137,11 +144,11 @@ def test_failing_on_exception
137
144
# caught it
138
145
end
139
146
140
- assert @first . approved? , "First should still be changed in the objects"
141
- assert_not @second . approved? , "Second should still be changed in the objects"
147
+ assert_predicate @first , : approved?, "First should still be changed in the objects"
148
+ assert_not_predicate @second , : approved?, "Second should still be changed in the objects"
142
149
143
- assert_not Topic . find ( 1 ) . approved? , "First shouldn't have been approved"
144
- assert Topic . find ( 2 ) . approved? , "Second should still be approved"
150
+ assert_not_predicate Topic . find ( 1 ) , : approved?, "First shouldn't have been approved"
151
+ assert_predicate Topic . find ( 2 ) , : approved?, "Second should still be approved"
145
152
end
146
153
147
154
def test_raising_exception_in_callback_rollbacks_in_save
@@ -150,22 +157,26 @@ def @first.after_save_for_transaction
150
157
end
151
158
152
159
@first . approved = true
153
- e = assert_raises ( RuntimeError ) { @first . save }
154
- assert_equal "Make the transaction rollback" , e . message
160
+ assert_not_called ( @first , :rolledback! ) do
161
+ e = assert_raises ( RuntimeError ) { @first . save }
162
+ assert_equal "Make the transaction rollback" , e . message
163
+ end
155
164
assert_not_predicate Topic . find ( 1 ) , :approved?
156
165
end
157
166
158
167
def test_rolling_back_in_a_callback_rollbacks_before_save
159
168
def @first . before_save_for_transaction
160
169
raise ActiveRecord ::Rollback
161
170
end
162
- assert_not @first . approved
171
+ assert_not_predicate @first , : approved?
163
172
164
- Topic . transaction do
165
- @first . approved = true
166
- @first . save!
173
+ assert_not_called ( @first , :rolledback! ) do
174
+ Topic . transaction do
175
+ @first . approved = true
176
+ @first . save!
177
+ end
167
178
end
168
- assert_not Topic . find ( @first . id ) . approved? , "Should not commit the approved flag"
179
+ assert_not_predicate Topic . find ( @first . id ) , : approved?, "Should not commit the approved flag"
169
180
end
170
181
171
182
def test_raising_exception_in_nested_transaction_restore_state_in_save
@@ -175,11 +186,13 @@ def topic.after_save_for_transaction
175
186
raise "Make the transaction rollback"
176
187
end
177
188
178
- assert_raises ( RuntimeError ) do
179
- Topic . transaction { topic . save }
189
+ assert_not_called ( topic , :rolledback! ) do
190
+ assert_raises ( RuntimeError ) do
191
+ Topic . transaction { topic . save }
192
+ end
180
193
end
181
194
182
- assert topic . new_record? , "#{ topic . inspect } should be new record"
195
+ assert_predicate topic , : new_record?, "#{ topic . inspect } should be new record"
183
196
end
184
197
185
198
def test_transaction_state_is_cleared_when_record_is_persisted
0 commit comments