Skip to content

Add before_commit hook to transaction provider#523

Open
erikrozendaal wants to merge 1 commit into
masterfrom
feature/add-before-commit-hook
Open

Add before_commit hook to transaction provider#523
erikrozendaal wants to merge 1 commit into
masterfrom
feature/add-before-commit-hook

Conversation

@erikrozendaal
Copy link
Copy Markdown
Member

The before_commit hook is exposed in ActiveRecord using the underlying transaction adapter which can be accessed through the current database connection.

The `before_commit` hook is exposed in ActiveRecord using the
underlying transaction adapter which can be accessed through the
current database connection.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_commit support to ActiveRecordTransactionProvider.
  • Delegate before_commit through ReadOnlyActiveRecordTransactionProvider and implement it for NoTransactions.
  • Add RSpec coverage for before_commit execution 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants