rails/rails — pull request #10424 by markevich (2013-05-02 15:29:13+00:00)
Title: Restore ActiveRecord connection to original environment after rake:db:test:prepare task.

I have a simple application with User model and following rake task:

``` Ruby
task :setup => :environment do
Rake::Task['db:drop'].invoke
Rake::Task['db:create'].invoke
Rake::Task['db:migrate'].invoke
Rake::Task['db:seed'].invoke
Rake::Task['db:test:prepare'].invoke

User.create(email: 'example@example.com')
end
```
When i run ```rake setup ``` - user created in test database.

But if i comment out ```Rake::Task['db:test:prepare'].invoke``` task - user created in development database

PR ensures that ActiveRecord will establish connection back to original environment after execution of this task.