spec/mongoid/clients_spec.rb in mongoid-7.5.1 vs spec/mongoid/clients_spec.rb in mongoid-7.5.2

- old
+ new

@@ -1010,9 +1010,39 @@ }.to raise_error(Mongoid::Errors::Validations) end end end end + + context 'when requesting named client' do + let(:secondary_client) do + double(Mongo::Client).tap do |client| + allow(client).to receive(:cluster).and_return(double("cluster")) + end + end + + before do + expect(Mongoid::Clients::Factory).to receive(:create) + .with(:secondary) + .and_return(secondary_client) + end + + after do + Mongoid::Clients.clients.delete(:secondary) + end + + it 'does not close the client' do + expect(secondary_client).not_to receive(:close) + + Band.with(client: :default) do |klass| + klass.mongo_client + end + + Band.with(client: :secondary) do |klass| + klass.mongo_client + end + end + end end context "when overriding the default database" do let(:file) do