Move into MiniSQLMultisiteConnection, and add test for rollback

This commit is contained in:
David Taylor
2018-07-24 09:41:55 +01:00
parent d7b5a374c2
commit 20a21b1240
5 changed files with 74 additions and 71 deletions

View File

@ -23,6 +23,27 @@ class MiniSqlMultisiteConnection < MiniSql::Connection
end
end
class AfterCommitWrapper
def initialize
@callback = Proc.new
end
def committed!(*)
@callback.call
end
def before_committed!(*); end
def rolledback!(*); end
end
# Allows running arbitrary code after the current transaction has been committed.
# Works even with nested transactions. Useful for scheduling sidekiq jobs.
def after_commit(&blk)
ActiveRecord::Base.connection.add_transaction_record(
AfterCommitWrapper.new(&blk)
)
end
def self.instance
new(nil, param_encoder: ParamEncoder.new)
end