1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
# frozen_string_literal: true
# rubocop:todo all
require 'spec_helper'
describe 'read concern' do
min_server_version '3.2'
let(:subscriber) do
Mrss::EventSubscriber.new
end
let(:specified_read_concern) do
{ :level => :local }
end
let(:expected_read_concern) do
{ 'level' => 'local' }
end
let(:sent_read_concern) do
subscriber.clear_events!
collection.count_documents
subscriber.started_events.find { |c| c.command_name == 'aggregate' }.command[:readConcern]
end
shared_examples_for 'a read concern is specified' do
it 'sends a read concern to the server' do
expect(sent_read_concern).to eq(expected_read_concern)
end
end
shared_examples_for 'no read concern is specified' do
it 'does not send a read concern to the server' do
expect(sent_read_concern).to be_nil
end
end
context 'when the client has no read concern specified' do
let(:client) do
authorized_client.tap do |client|
client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end
end
context 'when the collection has no read concern specified' do
let(:collection) do
client[TEST_COLL]
end
it_behaves_like 'no read concern is specified'
end
context 'when the collection has a read concern specified' do
let(:collection) do
client[TEST_COLL].with(read_concern: specified_read_concern)
end
it_behaves_like 'a read concern is specified'
end
end
context 'when the client has a read concern specified' do
let(:client) do
authorized_client.with(read_concern: specified_read_concern).tap do |client|
client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end
end
context 'when the collection has no read concern specified' do
let(:collection) do
client[TEST_COLL]
end
it_behaves_like 'a read concern is specified'
end
context 'when the collection has a read concern specified' do
let(:collection) do
client[TEST_COLL].with(read_concern: specified_read_concern)
end
it_behaves_like 'a read concern is specified'
end
end
end
|