Fix transaction extensions to handle failures correctly #25
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.
Overview
The
intercepting_failure
method was not handling the block's output correctly when it was a failure. It wasn't throwing:halt
with the failure as the given handlers were raising and therefore the throwing part was never reached.We modify the method to pass the failure to the handler and skip the throwing part, while extensions need to work in two phases:
1 - From within the transaction block, they intercept a failure a first time and assign it to a
result
variable available from the outer scope. After that, they raise to rollback the transaction but return theresult
variable after that.2 - From outside the transaction block, they throw again the failure when the
result
is actually a failure.We also make public the
throw_failure
method so that other extensions can create similar behavior.We also add a warning in the ActiveRecord extension to make it clear that the
:requires_new
option is not yet supported for this approach. We should find a way to make it work in the future.Closes #23
Screenshots/Screencasts
Details