diff --git a/CHANGELOG.md b/CHANGELOG.md index fba081a9..f2ca5fd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ This release drops support for Ruby 2.7. [#453] @flavorjones - `Database#columns` returns a list of internal frozen strings. [#155, #474, #486] @tenderlove - Freeze results that come from the database. [#480] @tenderlove - The encoding of a Database is no longer cached. [#485] @tenderlove +- `Database#transaction` returns the result of the block when used with a block. @alexcwatt ### Removed diff --git a/lib/sqlite3/database.rb b/lib/sqlite3/database.rb index e72c0ef1..b7f78016 100644 --- a/lib/sqlite3/database.rb +++ b/lib/sqlite3/database.rb @@ -651,9 +651,9 @@ def transaction(mode = nil) ensure abort and rollback or commit end + else + true end - - true end # Commits the current transaction. If there is no current transaction, diff --git a/test/test_database.rb b/test/test_database.rb index 5c902eed..14a2b653 100644 --- a/test/test_database.rb +++ b/test/test_database.rb @@ -686,5 +686,14 @@ def test_default_transaction_mode ensure tf&.unlink end + + def test_transaction_returns_true_without_block + assert @db.transaction + end + + def test_transaction_returns_block_result + result = @db.transaction { :foo } + assert_equal :foo, result + end end end