spec/mongo/operation/write/command/insert_spec.rb in mongo-2.4.3 vs spec/mongo/operation/write/command/insert_spec.rb in mongo-2.5.0.beta

- old
+ new

@@ -84,22 +84,121 @@ end end describe '#message' do - let(:expected_selector) do - { :documents => documents, - :insert => authorized_collection.name, - :writeConcern => write_concern.options, - :ordered => true - } + context 'when the server supports OP_MSG', if: op_msg_enabled? do + + let(:documents) do + [ { foo: 1}, { bar: 2 }] + end + + let(:global_args) do + { + insert: TEST_COLL, + ordered: true, + writeConcern: write_concern.options, + '$db' => TEST_DB + } + end + + let(:expected_payload_1) do + { + type: 1, + payload: { identifier: 'documents', + sequence: documents + } + } + end + + context 'when the topology is sharded', if: sharded? && op_msg_enabled? do + + let(:expected_global_args) do + global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time) + end + + it 'creates the correct OP_MSG message' do + authorized_client.command(ping:1) + expect(Mongo::Protocol::Msg).to receive(:new).with([:none], + { validating_keys: true }, + expected_global_args, + expected_payload_1) + op.send(:message, authorized_primary) + end + end + + context 'when the topology is not sharded', if: !sharded? && op_msg_enabled? do + + let(:expected_global_args) do + global_args + end + + it 'creates the correct OP_MSG message' do + authorized_client.command(ping:1) + expect(Mongo::Protocol::Msg).to receive(:new).with([:none], + { validating_keys: true }, + expected_global_args, + expected_payload_1) + op.send(:message, authorized_primary) + end + end + + context 'when the write concern is 0' do + + let(:write_concern) do + Mongo::WriteConcern.get(w: 0) + end + + context 'when the topology is sharded', if: sharded? && op_msg_enabled? do + + let(:expected_global_args) do + global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time) + end + + it 'creates the correct OP_MSG message' do + authorized_client.command(ping:1) + expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], + { validating_keys: true }, + expected_global_args, + expected_payload_1) + op.send(:message, authorized_primary) + end + end + + context 'when the topology is not sharded', if: !sharded? && op_msg_enabled? do + + let(:expected_global_args) do + global_args + end + + it 'creates the correct OP_MSG message' do + authorized_client.command(ping:1) + expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], + { validating_keys: true }, + expected_global_args, + expected_payload_1) + op.send(:message, authorized_primary) + end + end + end end - it 'creates a query wire protocol message with correct specs' do - expect(Mongo::Protocol::Query).to receive(:new).with(authorized_collection.database.name, - '$cmd', - expected_selector, - { limit: -1, validating_keys: true }) - op.send(:message, double('server')) + context 'when the server does not support OP_MSG' do + + let(:expected_selector) do + { :documents => documents, + :insert => authorized_collection.name, + :writeConcern => write_concern.options, + :ordered => true + } + end + + it 'creates a query wire protocol message with correct specs', unless: op_msg_enabled? do + expect(Mongo::Protocol::Query).to receive(:new).with(authorized_collection.database.name, + '$cmd', + expected_selector, + { limit: -1, validating_keys: true }) + op.send(:message, authorized_primary) + end end end end