Skip to content

Commit

Permalink
Merge pull request rails#52005 from Shopify/transaction-blank
Browse files Browse the repository at this point in the history
Fix `ActiveRecord::Transaction#blank?`
  • Loading branch information
byroot authored Jun 3, 2024
2 parents 9cafa55 + 5705309 commit 0f3dbe2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ def after_rollback(&block)
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
Expand Down
9 changes: 8 additions & 1 deletion activerecord/test/cases/transactions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ def setup
@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
Expand Down

0 comments on commit 0f3dbe2

Please sign in to comment.