Merge pull request #52005 from Shopify/transaction-blank

Fix `ActiveRecord::Transaction#blank?`
This commit is contained in:
Jean Boussier 2024-06-03 15:12:59 +02:00 committed by GitHub
commit 0f3dbe2f97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -111,12 +111,12 @@ module ActiveRecord
def open?
true
end
alias_method :blank?, :open?
# Returns true if no transaction is currently active.
def closed?
false
end
alias_method :blank?, :closed?
# Returns a UUID for this transaction.
def uuid

View File

@ -19,7 +19,14 @@ class TransactionTest < ActiveRecord::TestCase
@first, @second = Topic.find(1, 2).sort_by(&:id)
end
def test_after_all_transactions_committ
def test_blank?
assert_predicate Topic.current_transaction, :blank?
Topic.transaction do
assert_not_predicate Topic.current_transaction, :blank?
end
end
def test_after_all_transactions_commit
called = 0
ActiveRecord.after_all_transactions_commit { called += 1 }
assert_equal 1, called