Replies: 1 comment 2 replies
-
I'm glad you found a way to make this work and it is working well for your app. However, I'm not comfortable adding documentation for an approach that uses private APIs and that I consider unsafe in the general case (even if works fine in your app). The issue you are currently having is because in a simplified form, def transaction
synchronize do
add_transaction
begin_transaction
yield
ensure
rollback_transaction
remove_transaction
end
end While the behavior you want is: def transaction
synchronize do
add_transaction
begin_transaction
end
yield
ensure
synchronize do
rollback_transaction
remove_transaction
end
end Maybe you can consider adding an external Database extension that supported an approach like that. I would recommend a different method name, and accept no transaction options (using your expected transaction options internally): DB.shared_rolled_back_transaction{} This extension would use the approach I indicated above. When it checks out the connection to do the rollback, it would make sure it is the same connection it started with (raising an error otherwise), and then rollback the transaction. The method would raise before doing anything if the pool was not limited to a single connection. I realize that's more code that what you are currently using. So I would understand if you didn't want to do that. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is a follow-up on a previous google group thread, where I wanted to setup browser tests when Capybara runs the web app in a background Puma thread. I've used the following RSpec setup in a decently-sized application for more than half a year, and it worked without problems:
I only needed to make sure it wraps Capybara hooks, to ensure any in-progress requests complete before the transaction rolls back. For me it would be worth adding to the documentation, and potentially making it easier by not needing to call private API. But I leave that up to you, I wanted to at least post this for other people to find 🙂
Beta Was this translation helpful? Give feedback.
All reactions