spec/mongoid/clients_spec.rb in mongoid-5.1.6 vs spec/mongoid/clients_spec.rb in mongoid-5.2.0.rc0

- old
+ new

@@ -406,28 +406,97 @@ end it "returns the default client" do expect(mongo_client.options[:database].to_s).to eq(database_id) end + + it "sets the platform to Mongoid's platform constant" do + expect(mongo_client.options[:platform]).to eq(Mongoid::PLATFORM_DETAILS) + end + + it "sets the app_name to the config value" do + expect(mongo_client.options[:app_name]).to eq('testing') + end end context "when no client exists with the key" do before(:all) do Band.store_in(client: :nonexistent) end + after do + Band.reset_storage_options! + end + let(:band) do Band.new end it "raises an error" do expect { band.mongo_client }.to raise_error(Mongoid::Errors::NoClientConfig) end end + + context "when getting a client by name", if: testing_locally? do + + let(:file) do + File.join(File.dirname(__FILE__), "..", "config", "mongoid.yml") + end + + before do + described_class.clear + Mongoid.load!(file, :test) + Band.store_in(client: :reports) + end + + after do + mongo_client.close + Mongoid::Config.reset + Band.reset_storage_options! + end + + let!(:band) do + Band.store_in(client: :reports) + end + + let!(:mongo_client) do + Band.new.mongo_client + end + + it "uses the reports client" do + expect(mongo_client.options[:database].to_s).to eq('reports') + end + + it "sets the platform to Mongoid's platform constant" do + expect(mongo_client.options[:platform]).to eq(Mongoid::PLATFORM_DETAILS) + end + + it "sets the app_name to the config value" do + expect(mongo_client.options[:app_name]).to eq('testing') + end + end + + context 'when the app_name is not set in the config' do + + before do + Mongoid::Config.reset + Mongoid.configure do |config| + config.load_configuration(CONFIG) + end + end + + let(:mongo_client) do + Band.new.mongo_client + end + + it 'does not set the Mongoid.app_name option' do + expect(mongo_client.options.has_key?(:app_name)).to be(false) + end + end end describe ".mongo_client", if: non_legacy_server? do let(:file) do @@ -455,15 +524,23 @@ described_class.clear Mongoid.load!(file, :test) Mongoid.clients[:default][:database] = database_id end - let!(:mongo_client) do + let(:mongo_client) do Band.mongo_client end it "returns the default client" do expect(mongo_client.options[:database].to_s).to eq(database_id) + end + + it "sets the platform to Mongoid's platform constant" do + expect(mongo_client.options[:platform]).to eq(Mongoid::PLATFORM_DETAILS) + end + + it "sets the app_name to the config value" do + expect(mongo_client.options[:app_name]).to eq('testing') end end context "when no client exists with the key" do