Created
December 4, 2009 17:20
-
-
Save deanrad/249177 to your computer and use it in GitHub Desktop.
This file contains 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
# MY FIRST (NON-WORKING) ATTEMPT - borrowing from rails/lib/console_sanbox.. | |
# I think it works only for console where a single connection can be counted on | |
# Allow for server to run in a mode where xactions are rolled back on exit, | |
# like script/console's --sandbox option. eg: > SANDBOX=1 script/server -p 3001 | |
if ENV['SANDBOX']=="1" | |
$stderr.puts "NOTE: YOU ARE RUNNING IN SANDBOX MODE, ALL XACTIONS WILL ABORT ON EXIT" | |
conf = YAML::load( File.open(RAILS_ROOT + '/config/database.yml'))[RAILS_ENV] | |
$stderr.puts conf.inspect | |
ActiveRecord::Base.establish_connection(conf) | |
ActiveRecord::Base.connection.begin_db_transaction | |
at_exit do | |
ActiveRecord::Base.connection.rollback_db_transaction | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment