Skip to content

Commit

Permalink
Merge pull request #508 from alexcwatt/transaction-return
Browse files Browse the repository at this point in the history
Database#transaction returns block result
  • Loading branch information
flavorjones committed Feb 28, 2024
2 parents 62dc6e7 + 557c8b2 commit cbdb345
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/sqlite3/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions test/test_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cbdb345

Please sign in to comment.