Add before_commit hook to transaction provider#523
Open
erikrozendaal wants to merge 1 commit into
Open
Conversation
The `before_commit` hook is exposed in ActiveRecord using the underlying transaction adapter which can be accessed through the current database connection.
There was a problem hiding this comment.
Pull request overview
This PR exposes an ActiveRecord before_commit hook via Sequent’s transaction provider abstraction, implemented by delegating to the current ActiveRecord transaction on the active connection.
Changes:
- Add
before_commitsupport toActiveRecordTransactionProvider. - Delegate
before_committhroughReadOnlyActiveRecordTransactionProviderand implement it forNoTransactions. - Add RSpec coverage for
before_commitexecution and nested-transaction behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| spec/lib/sequent/core/transactions/active_record_transaction_provider_spec.rb | Adds specs asserting before_commit hooks are invoked and delayed until outermost transaction completion. |
| lib/sequent/core/transactions/active_record_transaction_provider.rb | Implements before_commit and routes commit/rollback hooks via ActiveRecord::Base.connection.current_transaction. |
| lib/sequent/core/transactions/read_only_active_record_transaction_provider.rb | Delegates before_commit to the wrapped transaction provider. |
| lib/sequent/core/transactions/no_transactions.rb | Adds a before_commit method consistent with the no-transaction behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+12
to
+18
| context 'with before_commit hooks' do | ||
| it 'calls the before_commit hooks' do | ||
| called = false | ||
| provider.transaction do | ||
| provider.before_commit { called = true } | ||
| end | ||
| expect(called).to be_truthy |
lvonk
approved these changes
May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
before_commithook is exposed in ActiveRecord using the underlying transaction adapter which can be accessed through the current database connection.