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

- old
+ new

@@ -91,20 +91,103 @@ end end describe '#message' do - let(:expected_selector) do - { - :update => TEST_COLL, - :updates => updates, - :ordered => true, - :writeConcern => write_concern.options - } + context 'when the server supports OP_MSG', if: op_msg_enabled? do + + let(:global_args) do + { + update: TEST_COLL, + ordered: true, + writeConcern: write_concern.options, + '$db' => TEST_DB + } + end + + let(:expected_payload_1) do + { + type: 1, + payload: { identifier: 'updates', + sequence: updates + } + } + 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], {}, 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], {}, 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], {}, 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], {}, expected_global_args, expected_payload_1) + op.send(:message, authorized_primary) + end + end + end end - it 'creates the correct Command message' do - expect(Mongo::Protocol::Query).to receive(:new).with(TEST_DB, '$cmd', expected_selector, { limit: -1 }) - op.send(:message, double('server')) + context 'when the server does not support OP_MSG' do + + let(:expected_selector) do + { + :update => TEST_COLL, + :updates => updates, + :ordered => true, + :writeConcern => write_concern.options + } + end + + it 'creates the correct Command message', unless: op_msg_enabled? do + expect(Mongo::Protocol::Query).to receive(:new).with(TEST_DB, '$cmd', expected_selector, { limit: -1 }) + op.send(:message, authorized_primary) + end end end end