Created
May 25, 2011 20:51
-
-
Save kevn/991935 to your computer and use it in GitHub Desktop.
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
def fuck_my_transaction | |
begin | |
ActiveRecord::Base.connection.begin_db_transaction | |
# Raise any error except an AR::StatementInvalid, such as an ActiveRecord::Rollback, | |
# which is generally used to signal a rollback condition | |
raise ActiveRecord::Rollback.new("Fucking your transaction.") | |
rescue ActiveRecord::StatementInvalid | |
puts "Rescued, rolling back..." | |
ActiveRecord::Base.connection.rollback_db_transaction | |
end | |
ensure | |
puts "Outside block; the connection is still in a transaction if this is 1: #{ActiveRecord::Base.connection.instance_variable_get(:@nested_transaction_count)}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment