1
1
require "helper"
2
2
3
3
class TransactionCallbacksTest < ActiveSupport ::TestCase
4
- self . use_transactional_fixtures = false if Rails . version . start_with ?( '4.0' )
5
- self . use_transactional_tests = false if respond_to? ( :use_transactional_tests= )
4
+ self . use_transactional_fixtures = false if Rails . version_matches ?( '~> 4.0' )
5
+ self . use_transactional_tests = false if self . respond_to? ( :use_transactional_tests= )
6
6
fixtures :topics
7
7
8
8
class TopicWithCallbacks < ActiveRecord ::Base
@@ -228,14 +228,14 @@ def @first.last_after_transaction_error; @last_transaction_error; end
228
228
@second . after_commit_block { |r | r . history << :after_commit }
229
229
@second . after_rollback_block { |r | r . history << :after_rollback }
230
230
231
- action_without_rollback = -> do
231
+ action_without_rollback = Proc . new do
232
232
Topic . transaction do
233
233
@first . save!
234
234
@second . save!
235
235
end
236
236
end
237
237
238
- if Rails . version >= ' 4.2'
238
+ if Rails . version_matches? ( ' >= 4.2')
239
239
assert_raises RuntimeError , &action_without_rollback
240
240
else
241
241
action_without_rollback . call
@@ -244,15 +244,14 @@ def @first.last_after_transaction_error; @last_transaction_error; end
244
244
assert_equal [ :after_commit ] , @second . history
245
245
246
246
@second . history . clear
247
- action_with_rollback = -> do
247
+ action_with_rollback = Proc . new do
248
248
Topic . transaction do
249
249
@first . save!
250
250
@second . save!
251
251
raise ActiveRecord ::Rollback
252
252
end
253
253
end
254
-
255
- if Rails . version >= '4.2'
254
+ if Rails . version_matches? ( '>= 4.2' )
256
255
assert_raises RuntimeError , &action_with_rollback
257
256
assert_equal :rollback , @first . last_after_transaction_error
258
257
assert_equal [ ] , @second . history
0 commit comments