Permalink
Browse files

only reconnect if there was already an active connection

If you're using an in-memory database for the test database,
reconnecting will lose all information that schema:load did for us.
  • Loading branch information...
tenderlove committed Aug 11, 2013
1 parent 443a1a2 commit 230c6060b6b403483bdc877be068c86a4161d4b0
Showing with 4 additions and 1 deletion.
  1. +4 −1 activerecord/lib/active_record/railties/databases.rake
@@ -322,11 +322,14 @@ db_namespace = namespace :db do
# desc "Recreate the test database from an existent schema.rb file"
task :load_schema => 'db:test:purge' do
begin
+ should_reconnect = ActiveRecord::Base.connection_pool.active_connection?
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
ActiveRecord::Schema.verbose = false
db_namespace["schema:load"].invoke
ensure
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ActiveRecord::Tasks::DatabaseTasks.env])
+ if should_reconnect
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ActiveRecord::Tasks::DatabaseTasks.env])
+ end
end
end

0 comments on commit 230c606

Please sign in to comment.