spec/mongo/collection_spec.rb in mongo-2.4.1 vs spec/mongo/collection_spec.rb in mongo-2.4.2

- old
+ new

@@ -5,11 +5,11 @@ after do authorized_collection.delete_many end let(:collection_invalid_write_concern) do - authorized_collection.client.with(write: { w: (WRITE_CONCERN[:w] + 1) })[authorized_collection.name] + authorized_collection.client.with(write: INVALID_WRITE_CONCERN)[authorized_collection.name] end let(:collection_with_validator) do authorized_client[:validating] end @@ -95,11 +95,11 @@ end describe '#with' do let(:client) do - Mongo::Client.new(ADDRESSES) + Mongo::Client.new(ADDRESSES, TEST_OPTIONS) end let(:database) do Mongo::Database.new(client, :test) end @@ -127,22 +127,22 @@ end context 'when the client has a server selection timeout setting' do let(:client) do - Mongo::Client.new(ADDRESSES, server_selection_timeout: 2) + Mongo::Client.new(ADDRESSES, TEST_OPTIONS.merge(server_selection_timeout: 2)) end it 'passes the the server_selection_timeout to the cluster' do expect(client.cluster.options[:server_selection_timeout]).to eq(client.options[:server_selection_timeout]) end end context 'when the client has a read preference set' do let(:client) do - Mongo::Client.new(ADDRESSES, read: { mode: :primary_preferred }) + Mongo::Client.new(ADDRESSES, TEST_OPTIONS.merge(read: { mode: :primary_preferred })) end it 'sets the new read options on the new collection' do expect(new_collection.read_preference).to eq(Mongo::ServerSelector.get(new_options[:read])) expect(new_collection.read_preference).not_to eq(client.read_preference) @@ -150,11 +150,11 @@ end context 'when the client has a read preference and server selection timeout set' do let(:client) do - Mongo::Client.new(ADDRESSES, read: { mode: :primary_preferred }, server_selection_timeout: 2) + Mongo::Client.new(ADDRESSES, TEST_OPTIONS.merge(read: { mode: :primary_preferred }, server_selection_timeout: 2)) end it 'sets the new read options on the new collection' do expect(new_collection.read_preference).to eq(Mongo::ServerSelector.get(new_options[:read])) end @@ -180,11 +180,11 @@ end context 'when the client has a write concern set' do let(:client) do - Mongo::Client.new(ADDRESSES, write: { w: 10 }) + Mongo::Client.new(ADDRESSES, TEST_OPTIONS.merge(write: { w: 10 })) end it 'sets the new write options on the new collection' do expect(new_collection.write_concern.options).to eq(Mongo::WriteConcern.get(new_options[:write]).options) end @@ -213,22 +213,22 @@ end context 'when the client has a server selection timeout setting' do let(:client) do - Mongo::Client.new(ADDRESSES, server_selection_timeout: 2) + Mongo::Client.new(ADDRESSES, TEST_OPTIONS.merge(server_selection_timeout: 2)) end it 'passes the server_selection_timeout setting to the cluster' do expect(client.cluster.options[:server_selection_timeout]).to eq(client.options[:server_selection_timeout]) end end context 'when the client has a read preference set' do let(:client) do - Mongo::Client.new(ADDRESSES, read: { mode: :primary_preferred }) + Mongo::Client.new(ADDRESSES, TEST_OPTIONS.merge(read: { mode: :primary_preferred })) end it 'sets the new read options on the new collection' do expect(new_collection.read_preference).to eq(Mongo::ServerSelector.get(new_options[:read])) expect(new_collection.read_preference).not_to be(client.read_preference) @@ -420,11 +420,11 @@ database[:specs].drop end let(:options) do { - write: { w: WRITE_CONCERN[:w] + 1} + write: INVALID_WRITE_CONCERN } end let(:collection) do described_class.new(database, :specs, options) @@ -567,11 +567,11 @@ context 'when the collection has a write concern' do let(:write_options) do { - write: { w: WRITE_CONCERN[:w] + 1} + write: INVALID_WRITE_CONCERN } end let(:collection_with_write_options) do collection.with(write_options) @@ -1817,14 +1817,18 @@ let(:updated) do authorized_collection.find(field: 'testing').first end - it 'updates the first matching document in the collection' do + it 'updates the first matching document in the collection', if: write_command_enabled? do expect(response.modified_count).to eq(1) end + it 'does not return modified count', unless: write_command_enabled? do + expect(response.modified_count).to eq(nil) + end + it 'updates the documents in the collection' do expect(updated[:field]).to eq('testing') end end @@ -1836,14 +1840,18 @@ let(:updated) do authorized_collection.find(field: 'test1').to_a end - it 'reports that no documents were written' do + it 'reports that no documents were written', if: write_command_enabled? do expect(response.modified_count).to eq(0) end + it 'does not return modified count', unless: write_command_enabled? do + expect(response.modified_count).to eq(nil) + end + it 'does not insert the document' do expect(updated).to be_empty end end @@ -1874,14 +1882,18 @@ let(:updated) do authorized_collection.find(field: 'test1').to_a end - it 'reports that no documents were written' do + it 'reports that no documents were written', if: write_command_enabled? do expect(response.modified_count).to eq(0) end + it 'does not return modified count', unless: write_command_enabled? do + expect(response.modified_count).to eq(nil) + end + it 'does not insert the document' do expect(updated).to be_empty end end @@ -2071,14 +2083,18 @@ let(:updated) do authorized_collection.find(field: 'testing').to_a.last end - it 'returns the number updated' do + it 'returns the number updated', if: write_command_enabled? do expect(response.modified_count).to eq(2) end + it 'does not return modified count', unless: write_command_enabled? do + expect(response.modified_count).to eq(nil) + end + it 'updates the documents in the collection' do expect(updated[:field]).to eq('testing') end end @@ -2091,14 +2107,18 @@ let(:updated) do authorized_collection.find.to_a end - it 'reports that no documents were updated' do + it 'reports that no documents were updated', if: write_command_enabled? do expect(response.modified_count).to eq(0) end + it 'does not return modified count', unless: write_command_enabled? do + expect(response.modified_count).to eq(nil) + end + it 'updates no documents in the collection' do expect(updated).to be_empty end end @@ -2130,14 +2150,18 @@ let(:updated) do authorized_collection.find.to_a end - it 'reports that no documents were updated' do + it 'reports that no documents were updated', if: write_command_enabled? do expect(response.modified_count).to eq(0) end + it 'does not return modified count', unless: write_command_enabled? do + expect(response.modified_count).to eq(nil) + end + it 'updates no documents in the collection' do expect(updated).to be_empty end end @@ -2331,14 +2355,18 @@ let(:updated) do authorized_collection.find(field: 'testing').first end - it 'updates the first matching document in the collection' do + it 'updates the first matching document in the collection', if: write_command_enabled? do expect(response.modified_count).to eq(1) end + it 'does not return modified count', unless: write_command_enabled? do + expect(response.modified_count).to eq(nil) + end + it 'updates the documents in the collection' do expect(updated[:field]).to eq('testing') end end @@ -2351,14 +2379,18 @@ let(:updated) do authorized_collection.find.to_a end - it 'reports that no documents were updated' do + it 'reports that no documents were updated', if: write_command_enabled? do expect(response.modified_count).to eq(0) end + it 'does not return modified count', unless: write_command_enabled? do + expect(response.modified_count).to eq(nil) + end + it 'updates no documents in the collection' do expect(updated).to be_empty end end @@ -2390,11 +2422,15 @@ let(:updated) do authorized_collection.find.to_a end - it 'reports that no documents were updated' do + it 'reports that no documents were updated', if: write_command_enabled? do expect(response.modified_count).to eq(0) + end + + it 'does not return modified count', unless: write_command_enabled? do + expect(response.modified_count).to eq(nil) end it 'updates no documents in the collection' do expect(updated).to be_empty end