Hi y'all -
I've put together a Sequel extension to support after_commit and
after_rollback hooks on savepoints. The most common use-case for this is in
transactional testing, so that you can do:
Pseudocode example:
# Test setup
def around
# hooks: :savepoint makes after_commit and after_rollback callbacks that
are declared in savepoints
# run immediately after their savepoints commit or rollback, rather than
waiting for the entire
# transaction to commit or rollback.
DB.transaction(auto_savepoint: true, hooks: :savepoint, rollback: :always)
{ super }
end
it "should do something in an after_commit callback" do
# App logic:
DB.transaction do
DB.after_commit { do_something }
end
# do_something happens here, so specs can easily cover it.
# The Sequel default would be for it to never happen, since it would
# wait for the top-level transaction to complete, but it
# would always be rolled back.
assert do_something_happened
end
# As opposed to here, which is the Sequel default.
The extension is here:
https://github.com/chanks/sequel-savepoint-hooks
It's dependent on some refactoring that I submitted to Sequel in PR #1198:
https://github.com/jeremyevans/sequel/pull/1198
My question is, who else thinks this is useful enough to be included in
Sequel core? I personally use transactional testing almost exclusively, and
I want to be able to spec my after_commit blocks, so I think it's pretty
essential, but I'd like to hear what other people think.
Chris
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.