File tree Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ This release drops support for Ruby 2.7. [#453] @flavorjones
33
33
- ` Database#columns ` returns a list of internal frozen strings. [ #155 , #474 , #486 ] @tenderlove
34
34
- Freeze results that come from the database. [ #480 ] @tenderlove
35
35
- The encoding of a Database is no longer cached. [ #485 ] @tenderlove
36
+ - ` Database#transaction ` returns the result of the block when used with a block. @alexcwatt
36
37
37
38
38
39
### Removed
Original file line number Diff line number Diff line change @@ -644,16 +644,17 @@ def transaction(mode = nil)
644
644
if block_given?
645
645
abort = false
646
646
begin
647
- yield self
647
+ result = yield self
648
648
rescue
649
649
abort = true
650
650
raise
651
651
ensure
652
652
abort and rollback or commit
653
653
end
654
+ result
655
+ else
656
+ true
654
657
end
655
-
656
- true
657
658
end
658
659
659
660
# Commits the current transaction. If there is no current transaction,
Original file line number Diff line number Diff line change @@ -686,5 +686,15 @@ def test_default_transaction_mode
686
686
ensure
687
687
tf &.unlink
688
688
end
689
+
690
+ def test_transaction_returns_true_without_block
691
+ transaction = @db . transaction
692
+ assert_equal true , transaction
693
+ end
694
+
695
+ def test_transaction_returns_block_result
696
+ result = @db . transaction { :foo }
697
+ assert_equal :foo , result
698
+ end
689
699
end
690
700
end
You can’t perform that action at this time.
0 commit comments