diff options
author | Matthew Draper <matthew@trebex.net> | 2017-04-04 04:12:56 +0930 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-04 04:12:56 +0930 |
commit | 3ecffab324fc03df76eba91e4c2a7cb89a0580b9 (patch) | |
tree | bdd0c432bcccc6e1aff60d7d3b9efa476a6bc7ba | |
parent | 67d210f7d76a2fa96ff41560fed2910147787ad4 (diff) | |
parent | b66b5378baf3804e9985a7cb9630f6d5a3ddcf97 (diff) | |
download | rails-3ecffab324fc03df76eba91e4c2a7cb89a0580b9.tar.gz rails-3ecffab324fc03df76eba91e4c2a7cb89a0580b9.tar.bz2 rails-3ecffab324fc03df76eba91e4c2a7cb89a0580b9.zip |
Merge pull request #28057 from eugeneius/clear_active_connections
Clear active connections after initialization
-rw-r--r-- | activerecord/lib/active_record/railtie.rb | 8 | ||||
-rw-r--r-- | railties/test/application/initializers/frameworks_test.rb | 8 |
2 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb index 0276d41494..73518ca144 100644 --- a/activerecord/lib/active_record/railtie.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -166,5 +166,13 @@ end_warning path = app.paths["db"].first config.watchable_files.concat ["#{path}/schema.rb", "#{path}/structure.sql"] end + + initializer "active_record.clear_active_connections" do + config.after_initialize do + ActiveSupport.on_load(:active_record) do + clear_active_connections! + end + end + end end end diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 90927159dd..eb2c578f91 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -262,5 +262,13 @@ module ApplicationTests Rails.env = orig_rails_env if orig_rails_env end end + + test "connections checked out during initialization are returned to the pool" do + app_file "config/initializers/active_record.rb", <<-RUBY + ActiveRecord::Base.connection + RUBY + require "#{app_path}/config/environment" + assert !ActiveRecord::Base.connection_pool.active_connection? + end end end |