Add Micro::Case#rollback_on_failure alias for #transaction#150
Open
serradura wants to merge 1 commit into
Open
Add Micro::Case#rollback_on_failure alias for #transaction#150serradura wants to merge 1 commit into
Micro::Case#rollback_on_failure alias for #transaction#150serradura wants to merge 1 commit into
Conversation
The `#transaction` instance helper is shadowed by the attribute reader when a use case declares `attribute :transaction` (a domain object that has nothing to do with the database). `rollback_on_failure` is an `alias_method` of `#transaction` — same signature, same resolution order, same back-compat shim — verbose enough to never realistically clash with a user-defined attribute. The name matches the sibling gem `solid-process`'s `rollback_on_failure` so the two APIs read alike. Closes the issue at issue-1-rollback-on-failure.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Micro::Case#transactionis shadowed by the attribute reader when a use case declaresattribute :transaction(a domain object — e.g. aPaymentTransactionrecord — that has nothing to do with the database). Insidecall!,transaction { ... }then calls the reader and silently drops the block.alias_method :rollback_on_failure, :transactionas a verbose, unambiguous escape hatch. Same signature, same resolution order (call-sitewith:> class macro > global default), sametransaction(:activerecord)back-compat shim —alias_methodmakes the equivalence a property of the language, not two implementations to keep in sync.solid-process'srollback_on_failure, so the two APIs read alike.#transactionis byte-for-byte unchanged. No newMicro::Case::Checkmethod needed (the alias inheritstransaction_owner!/activerecord_loaded!for free).Test plan
test/micro/case/rollback_on_failure_test.rbcovers:instance_method(:transaction) == instance_method(:rollback_on_failure))with:/ class-macro fallback / global-default fallback resolutionrollback_on_failure(:activerecord) { ... }back-compat shim flows through the aliasrollback_on_failure(:other) { ... }raises the sameArgumentErrorMicro::Casewithattribute :transactioncallingrollback_on_failure { ... }rolls back correctly; thetransactionattribute reader is untouched#transactiontests continue to pass unchanged.bundle exec rake test(bare bundle): 795 runs / 0 failures.bundle exec appraisal rails-8-1 rake test(with ActiveRecord): 1054 runs / 0 failures, both with and withoutENABLE_TRANSITIONS=true.Docs
CHANGELOG.md— entry under## [Unreleased](no version cut in this PR).README.md+README.pt-BR.md— lockstep, alias note + example appended to the inlinetransaction { ... }section. No TOC or Documentation-table changes.🤖 Generated with Claude Code