|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe 'Find operation options' do |
| 6 | + let(:subscriber) { Mrss::EventSubscriber.new } |
| 7 | + |
| 8 | + let(:seeds) do |
| 9 | + [ SpecConfig.instance.addresses.first ] |
| 10 | + end |
| 11 | + |
| 12 | + let(:client) do |
| 13 | + ClientRegistry.instance.new_local_client( |
| 14 | + seeds, |
| 15 | + SpecConfig.instance.test_options.merge(client_options) |
| 16 | + ).tap do |client| |
| 17 | + client.subscribe(Mongo::Monitoring::COMMAND, subscriber) |
| 18 | + end |
| 19 | + end |
| 20 | + |
| 21 | + let(:collection) do |
| 22 | + client['find_options', collection_options] |
| 23 | + end |
| 24 | + |
| 25 | + let(:find_command) do |
| 26 | + subscriber.started_events.find { |cmd| cmd.command_name == 'find' } |
| 27 | + end |
| 28 | + |
| 29 | + before do |
| 30 | + ClientRegistry.instance.global_client('authorized')['find_options'].drop |
| 31 | + collection.insert_many([ { a: 1 }, { a: 2 }, { a: 3 } ]) |
| 32 | + end |
| 33 | + |
| 34 | + describe 'collation' do |
| 35 | + let(:client_options) do |
| 36 | + {} |
| 37 | + end |
| 38 | + |
| 39 | + let(:collation) do |
| 40 | + { 'locale' => 'en_US' } |
| 41 | + end |
| 42 | + |
| 43 | + context 'when defined on the collection' do |
| 44 | + let(:collection_options) do |
| 45 | + { collation: collation } |
| 46 | + end |
| 47 | + |
| 48 | + it 'uses the collation defined on the collection' do |
| 49 | + collection.find.to_a |
| 50 | + expect(find_command.command['collation']).to be_nil |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + context 'when defined on the operation' do |
| 55 | + let(:collection_options) do |
| 56 | + {} |
| 57 | + end |
| 58 | + |
| 59 | + it 'uses the collation defined on the collection' do |
| 60 | + collection.find({}, collation: collation).to_a |
| 61 | + expect(find_command.command['collation']).to eq(collation) |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + context 'when defined on both collection and operation' do |
| 66 | + let(:collection_options) do |
| 67 | + { 'locale' => 'de_AT' } |
| 68 | + end |
| 69 | + |
| 70 | + it 'uses the collation defined on the collection' do |
| 71 | + collection.find({}, collation: collation).to_a |
| 72 | + expect(find_command.command['collation']).to eq(collation) |
| 73 | + end |
| 74 | + end |
| 75 | + end |
| 76 | +end |
0 commit comments