Permalink
Browse files

Loading new configuration clears old sessions.

[ fix #2961 ]
  • Loading branch information...
1 parent 5f8d60a commit f5c0b712be149508f2dd57d417b779144240cc1e @durran durran committed Apr 17, 2013
Showing with 24 additions and 1 deletion.
  1. +3 −0 CHANGELOG.md
  2. +5 −1 lib/mongoid/config.rb
  3. +16 −0 spec/mongoid/config_spec.rb
View
@@ -16,6 +16,9 @@ For instructions on upgrading to newer versions, visit
* Dont duplicate embedded documents when saving after calling becomes method.
+* \#2961 Reloading a mongoid.yml configuration now properly clears previously
+ configured sessions.
+
* \#2937 Counts can now take a `true` argument to factor in skip and limit.
(Arthur Neves)
@@ -87,7 +87,11 @@ def destructive_fields
# @since 2.0.1
def load!(path, environment = nil)
settings = Environment.load_yaml(path, environment)
- load_configuration(settings) if settings.present?
+ if settings.present?
+ Sessions.disconnect
+ Sessions.clear
+ load_configuration(settings)
+ end
settings
end
@@ -73,6 +73,22 @@
File.join(File.dirname(__FILE__), "..", "config", "mongoid.yml")
end
+ context "when existing sessions exist in the configuration" do
+
+ let(:session) do
+ Moped::Session.new([ "127.0.0.1:27017" ])
+ end
+
+ before do
+ Mongoid::Threaded.sessions[:test] = session
+ described_class.load!(file, :test)
+ end
+
+ it "clears the previous sessions" do
+ expect(Mongoid::Threaded.sessions[:test]).to be_nil
+ end
+ end
+
context "when provided an environment" do
before do

0 comments on commit f5c0b71

Please sign in to comment.