mongoid 5.4.1 → 6.0.0.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/config/locales/en.yml +23 -16
- data/lib/mongoid.rb +4 -9
- data/lib/mongoid/atomic.rb +1 -1
- data/lib/mongoid/atomic/modifiers.rb +8 -12
- data/lib/mongoid/attributes.rb +9 -11
- data/lib/mongoid/attributes/dynamic.rb +5 -6
- data/lib/mongoid/attributes/nested.rb +1 -1
- data/lib/mongoid/attributes/processing.rb +4 -0
- data/lib/mongoid/attributes/readonly.rb +22 -0
- data/lib/mongoid/cacheable.rb +36 -0
- data/lib/mongoid/changeable.rb +37 -1
- data/lib/mongoid/clients.rb +0 -63
- data/lib/mongoid/clients/factory.rb +0 -2
- data/lib/mongoid/clients/options.rb +54 -249
- data/lib/mongoid/clients/storage_options.rb +1 -69
- data/lib/mongoid/composable.rb +26 -2
- data/lib/mongoid/config.rb +1 -1
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -0
- data/lib/mongoid/contextual/atomic.rb +6 -9
- data/lib/mongoid/contextual/geo_near.rb +2 -3
- data/lib/mongoid/contextual/map_reduce.rb +97 -24
- data/lib/mongoid/contextual/memory.rb +7 -4
- data/lib/mongoid/contextual/mongo.rb +63 -54
- data/lib/mongoid/contextual/none.rb +2 -2
- data/lib/mongoid/copyable.rb +19 -19
- data/lib/mongoid/criteria.rb +5 -4
- data/lib/mongoid/criteria/findable.rb +2 -3
- data/lib/mongoid/criteria/includable.rb +63 -16
- data/lib/mongoid/criteria/marshalable.rb +2 -2
- data/lib/mongoid/criteria/modifiable.rb +17 -1
- data/lib/mongoid/criteria/options.rb +25 -0
- data/lib/mongoid/criteria/queryable.rb +86 -0
- data/lib/mongoid/criteria/queryable/aggregable.rb +120 -0
- data/lib/mongoid/criteria/queryable/extensions.rb +28 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +185 -0
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +37 -0
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/date.rb +63 -0
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +53 -0
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +200 -0
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +86 -0
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +90 -0
- data/lib/mongoid/criteria/queryable/extensions/object.rb +206 -0
- data/lib/mongoid/criteria/queryable/extensions/range.rb +70 -0
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +45 -0
- data/lib/mongoid/criteria/queryable/extensions/set.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/string.rb +137 -0
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +79 -0
- data/lib/mongoid/criteria/queryable/extensions/time.rb +60 -0
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +54 -0
- data/lib/mongoid/criteria/queryable/forwardable.rb +65 -0
- data/lib/mongoid/criteria/queryable/key.rb +103 -0
- data/lib/mongoid/criteria/queryable/macroable.rb +27 -0
- data/lib/mongoid/criteria/queryable/mergeable.rb +271 -0
- data/lib/mongoid/criteria/queryable/optional.rb +411 -0
- data/lib/mongoid/criteria/queryable/options.rb +136 -0
- data/lib/mongoid/criteria/queryable/pipeline.rb +111 -0
- data/lib/mongoid/criteria/queryable/selectable.rb +662 -0
- data/lib/mongoid/criteria/queryable/selector.rb +196 -0
- data/lib/mongoid/criteria/queryable/smash.rb +103 -0
- data/lib/mongoid/document.rb +9 -23
- data/lib/mongoid/errors.rb +2 -1
- data/lib/mongoid/errors/ambiguous_relationship.rb +1 -1
- data/lib/mongoid/errors/delete_restriction.rb +2 -2
- data/lib/mongoid/errors/invalid_field.rb +2 -2
- data/lib/mongoid/errors/invalid_persistence_option.rb +29 -0
- data/lib/mongoid/errors/invalid_relation.rb +66 -0
- data/lib/mongoid/errors/inverse_not_found.rb +1 -1
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/evolvable.rb +1 -1
- data/lib/mongoid/extensions.rb +0 -5
- data/lib/mongoid/extensions/big_decimal.rb +17 -8
- data/lib/mongoid/extensions/date.rb +4 -1
- data/lib/mongoid/extensions/hash.rb +2 -3
- data/lib/mongoid/extensions/object.rb +2 -2
- data/lib/mongoid/extensions/string.rb +4 -3
- data/lib/mongoid/extensions/time.rb +5 -2
- data/lib/mongoid/factory.rb +1 -0
- data/lib/mongoid/fields/foreign_key.rb +2 -2
- data/lib/mongoid/fields/localized.rb +3 -8
- data/lib/mongoid/fields/validators/macro.rb +18 -0
- data/lib/mongoid/findable.rb +3 -3
- data/lib/mongoid/indexable.rb +17 -16
- data/lib/mongoid/indexable/specification.rb +1 -1
- data/lib/mongoid/indexable/validators/options.rb +1 -2
- data/lib/mongoid/interceptable.rb +6 -17
- data/lib/mongoid/loggable.rb +1 -1
- data/lib/mongoid/matchable.rb +3 -10
- data/lib/mongoid/matchable/gt.rb +2 -0
- data/lib/mongoid/matchable/gte.rb +2 -0
- data/lib/mongoid/matchable/lt.rb +2 -0
- data/lib/mongoid/matchable/lte.rb +2 -0
- data/lib/mongoid/persistable.rb +6 -5
- data/lib/mongoid/persistable/creatable.rb +2 -0
- data/lib/mongoid/persistable/deletable.rb +7 -3
- data/lib/mongoid/persistable/settable.rb +3 -16
- data/lib/mongoid/persistable/updatable.rb +10 -12
- data/lib/mongoid/persistence_context.rb +216 -0
- data/lib/mongoid/query_cache.rb +5 -30
- data/lib/mongoid/relations/accessors.rb +6 -2
- data/lib/mongoid/relations/auto_save.rb +12 -4
- data/lib/mongoid/relations/bindings/embedded/in.rb +4 -0
- data/lib/mongoid/relations/bindings/embedded/many.rb +8 -1
- data/lib/mongoid/relations/bindings/embedded/one.rb +10 -0
- data/lib/mongoid/relations/bindings/referenced/many.rb +4 -0
- data/lib/mongoid/relations/builders.rb +2 -2
- data/lib/mongoid/relations/builders/embedded/one.rb +1 -1
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +1 -1
- data/lib/mongoid/relations/conversions.rb +1 -1
- data/lib/mongoid/relations/counter_cache.rb +28 -18
- data/lib/mongoid/relations/eager.rb +19 -7
- data/lib/mongoid/relations/eager/base.rb +5 -5
- data/lib/mongoid/relations/embedded/batchable.rb +9 -33
- data/lib/mongoid/relations/embedded/in.rb +16 -2
- data/lib/mongoid/relations/embedded/many.rb +23 -8
- data/lib/mongoid/relations/embedded/one.rb +17 -2
- data/lib/mongoid/relations/macros.rb +9 -2
- data/lib/mongoid/relations/metadata.rb +3 -3
- data/lib/mongoid/relations/nested_builder.rb +1 -1
- data/lib/mongoid/relations/options.rb +2 -2
- data/lib/mongoid/relations/proxy.rb +2 -33
- data/lib/mongoid/relations/referenced/in.rb +23 -11
- data/lib/mongoid/relations/referenced/many.rb +24 -16
- data/lib/mongoid/relations/referenced/many_to_many.rb +20 -13
- data/lib/mongoid/relations/referenced/one.rb +17 -1
- data/lib/mongoid/relations/reflections.rb +3 -5
- data/lib/mongoid/relations/touchable.rb +1 -1
- data/lib/mongoid/reloadable.rb +1 -1
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +2 -3
- data/lib/mongoid/tasks/database.rb +1 -2
- data/lib/mongoid/threaded.rb +4 -4
- data/lib/mongoid/traversable.rb +1 -1
- data/lib/mongoid/validatable.rb +1 -1
- data/lib/mongoid/validatable/macros.rb +2 -4
- data/lib/mongoid/validatable/uniqueness.rb +1 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +4 -7
- data/spec/app/models/album.rb +5 -1
- data/spec/app/models/artist.rb +21 -0
- data/spec/app/models/band.rb +0 -1
- data/spec/app/models/church.rb +0 -2
- data/spec/app/models/ordered_post.rb +5 -0
- data/spec/app/models/oscar.rb +1 -2
- data/spec/app/models/person.rb +3 -1
- data/spec/app/models/post.rb +0 -1
- data/spec/app/models/princess.rb +2 -0
- data/spec/app/models/record.rb +1 -0
- data/spec/app/models/thing.rb +1 -1
- data/spec/config/mongoid.yml +1 -5
- data/spec/mongoid/atomic/modifiers_spec.rb +17 -17
- data/spec/mongoid/atomic_spec.rb +17 -17
- data/spec/mongoid/attributes/nested_spec.rb +14 -14
- data/spec/mongoid/attributes/readonly_spec.rb +87 -44
- data/spec/mongoid/attributes_spec.rb +63 -0
- data/spec/mongoid/cacheable_spec.rb +112 -0
- data/spec/mongoid/changeable_spec.rb +58 -0
- data/spec/mongoid/clients/factory_spec.rb +3 -11
- data/spec/mongoid/clients/options_spec.rb +378 -96
- data/spec/mongoid/clients_spec.rb +207 -170
- data/spec/mongoid/composable_spec.rb +7 -0
- data/spec/mongoid/config_spec.rb +41 -21
- data/spec/mongoid/contextual/atomic_spec.rb +77 -343
- data/spec/mongoid/contextual/map_reduce_spec.rb +119 -111
- data/spec/mongoid/contextual/memory_spec.rb +56 -316
- data/spec/mongoid/contextual/mongo_spec.rb +104 -378
- data/spec/mongoid/copyable_spec.rb +8 -15
- data/spec/mongoid/criteria/modifiable_spec.rb +239 -7
- data/spec/mongoid/criteria/options_spec.rb +29 -0
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +370 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +523 -0
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +59 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +213 -0
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +330 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +405 -0
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +327 -0
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +77 -0
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +108 -0
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +309 -0
- data/spec/mongoid/{extensions/origin/regexp_raw_spec.rb → criteria/queryable/extensions/regexp_spec.rb} +21 -20
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +39 -0
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +302 -0
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +167 -0
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +376 -0
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +347 -0
- data/spec/mongoid/criteria/queryable/forwardable_spec.rb +87 -0
- data/spec/mongoid/criteria/queryable/key_spec.rb +52 -0
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +49 -0
- data/spec/mongoid/criteria/queryable/optional_spec.rb +1786 -0
- data/spec/mongoid/criteria/queryable/options_spec.rb +360 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +200 -0
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +137 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +4159 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +778 -0
- data/spec/mongoid/criteria/queryable/smash_spec.rb +30 -0
- data/spec/mongoid/criteria_spec.rb +45 -63
- data/spec/mongoid/document_spec.rb +21 -88
- data/spec/mongoid/errors/invalid_relation_spec.rb +37 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +6 -3
- data/spec/mongoid/extensions/big_decimal_spec.rb +320 -18
- data/spec/mongoid/extensions/date_spec.rb +2 -6
- data/spec/mongoid/extensions/date_time_spec.rb +2 -6
- data/spec/mongoid/extensions/float_spec.rb +8 -1
- data/spec/mongoid/extensions/integer_spec.rb +8 -1
- data/spec/mongoid/extensions/object_spec.rb +11 -0
- data/spec/mongoid/extensions/string_spec.rb +21 -0
- data/spec/mongoid/extensions/time_spec.rb +4 -8
- data/spec/mongoid/extensions/time_with_zone_spec.rb +2 -6
- data/spec/mongoid/fields/localized_spec.rb +0 -91
- data/spec/mongoid/findable_spec.rb +46 -1
- data/spec/mongoid/indexable_spec.rb +6 -46
- data/spec/mongoid/interceptable_spec.rb +49 -10
- data/spec/mongoid/matchable/gt_spec.rb +11 -0
- data/spec/mongoid/matchable/gte_spec.rb +10 -0
- data/spec/mongoid/matchable/lt_spec.rb +11 -0
- data/spec/mongoid/matchable/lte_spec.rb +11 -0
- data/spec/mongoid/matchable_spec.rb +1 -51
- data/spec/mongoid/persistable/creatable_spec.rb +2 -2
- data/spec/mongoid/persistable/deletable_spec.rb +1 -1
- data/spec/mongoid/persistable/destroyable_spec.rb +6 -2
- data/spec/mongoid/persistable/savable_spec.rb +30 -30
- data/spec/mongoid/persistable/settable_spec.rb +0 -185
- data/spec/mongoid/persistable/updatable_spec.rb +166 -5
- data/spec/mongoid/persistence_context_spec.rb +654 -0
- data/spec/mongoid/positional_spec.rb +10 -10
- data/spec/mongoid/query_cache_spec.rb +89 -65
- data/spec/mongoid/relations/accessors_spec.rb +1 -1
- data/spec/mongoid/relations/auto_save_spec.rb +39 -6
- data/spec/mongoid/relations/builders_spec.rb +37 -10
- data/spec/mongoid/relations/counter_cache_spec.rb +64 -15
- data/spec/mongoid/relations/cyclic_spec.rb +0 -22
- data/spec/mongoid/relations/embedded/many_spec.rb +9 -41
- data/spec/mongoid/relations/embedded/one_spec.rb +2 -1
- data/spec/mongoid/relations/macros_spec.rb +395 -7
- data/spec/mongoid/relations/proxy_spec.rb +3 -1
- data/spec/mongoid/relations/referenced/in_spec.rb +41 -1
- data/spec/mongoid/relations/referenced/many_spec.rb +6 -29
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +6 -29
- data/spec/mongoid/relations/reflections_spec.rb +9 -9
- data/spec/mongoid/reloadable_spec.rb +51 -0
- data/spec/mongoid/scopable_spec.rb +0 -12
- data/spec/mongoid/serializable_spec.rb +0 -50
- data/spec/mongoid/validatable/presence_spec.rb +1 -1
- data/spec/mongoid/validatable/uniqueness_spec.rb +16 -9
- data/spec/mongoid/validatable_spec.rb +16 -0
- data/spec/spec_helper.rb +10 -10
- metadata +536 -479
- metadata.gz.sig +0 -0
- data/lib/mongoid/clients/thread_options.rb +0 -19
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +0 -20
- data/lib/mongoid/extensions/decimal128.rb +0 -39
- data/lib/mongoid/extensions/origin/regexp_raw.rb +0 -43
- data/lib/mongoid/matchable/regexp.rb +0 -27
- data/spec/app/models/post_genre.rb +0 -6
- data/spec/mongoid/extensions/decimal128_spec.rb +0 -44
- data/spec/mongoid/matchable/regexp_spec.rb +0 -59
| @@ -32,15 +32,15 @@ describe Mongoid::Contextual::MapReduce do | |
| 32 32 | 
             
                Band.collection
         | 
| 33 33 | 
             
              end
         | 
| 34 34 |  | 
| 35 | 
            -
               | 
| 36 | 
            -
                Band.all
         | 
| 37 | 
            -
              end
         | 
| 35 | 
            +
              describe "#command" do
         | 
| 38 36 |  | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 37 | 
            +
                let(:criteria) do
         | 
| 38 | 
            +
                  Band.all
         | 
| 39 | 
            +
                end
         | 
| 42 40 |  | 
| 43 | 
            -
             | 
| 41 | 
            +
                let(:map_reduce) do
         | 
| 42 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 43 | 
            +
                end
         | 
| 44 44 |  | 
| 45 45 | 
             
                let(:base_command) do
         | 
| 46 46 | 
             
                  {
         | 
| @@ -51,25 +51,27 @@ describe Mongoid::Contextual::MapReduce do | |
| 51 51 | 
             
                  }
         | 
| 52 52 | 
             
                end
         | 
| 53 53 |  | 
| 54 | 
            -
                 | 
| 54 | 
            +
                it "returns the db command" do
         | 
| 55 | 
            +
                  expect(map_reduce.command).to eq(base_command)
         | 
| 56 | 
            +
                end
         | 
| 55 57 |  | 
| 58 | 
            +
                context "with sort" do
         | 
| 56 59 | 
             
                  let(:criteria) do
         | 
| 57 60 | 
             
                    Band.order_by(name: -1)
         | 
| 58 61 | 
             
                  end
         | 
| 59 62 |  | 
| 60 | 
            -
                  it " | 
| 61 | 
            -
                    expect(map_reduce.command | 
| 63 | 
            +
                  it "returns the db command with a sort option" do
         | 
| 64 | 
            +
                    expect(map_reduce.command).to eq(base_command.merge(sort: {'name' => -1}))
         | 
| 62 65 | 
             
                  end
         | 
| 63 66 | 
             
                end
         | 
| 64 67 |  | 
| 65 68 | 
             
                context "with limit" do
         | 
| 66 | 
            -
             | 
| 67 69 | 
             
                  let(:criteria) do
         | 
| 68 70 | 
             
                    Band.limit(10)
         | 
| 69 71 | 
             
                  end
         | 
| 70 72 |  | 
| 71 73 | 
             
                  it "returns the db command with a limit option" do
         | 
| 72 | 
            -
                    expect(map_reduce.command | 
| 74 | 
            +
                    expect(map_reduce.command).to eq(base_command.merge(limit: 10))
         | 
| 73 75 | 
             
                  end
         | 
| 74 76 | 
             
                end
         | 
| 75 77 | 
             
              end
         | 
| @@ -80,6 +82,10 @@ describe Mongoid::Contextual::MapReduce do | |
| 80 82 | 
             
                  Band.all
         | 
| 81 83 | 
             
                end
         | 
| 82 84 |  | 
| 85 | 
            +
                let(:map_reduce) do
         | 
| 86 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 87 | 
            +
                end
         | 
| 88 | 
            +
             | 
| 83 89 | 
             
                let(:counts) do
         | 
| 84 90 | 
             
                  map_reduce.out(inline: 1).counts
         | 
| 85 91 | 
             
                end
         | 
| @@ -96,6 +102,14 @@ describe Mongoid::Contextual::MapReduce do | |
| 96 102 |  | 
| 97 103 | 
             
              describe "#each" do
         | 
| 98 104 |  | 
| 105 | 
            +
                let(:criteria) do
         | 
| 106 | 
            +
                  Band.all
         | 
| 107 | 
            +
                end
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                let(:map_reduce) do
         | 
| 110 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 111 | 
            +
                end
         | 
| 112 | 
            +
             | 
| 99 113 | 
             
                context "when the map/reduce is inline" do
         | 
| 100 114 |  | 
| 101 115 | 
             
                  let(:results) do
         | 
| @@ -116,40 +130,20 @@ describe Mongoid::Contextual::MapReduce do | |
| 116 130 | 
             
                    map_reduce.out(replace: "mr-output")
         | 
| 117 131 | 
             
                  end
         | 
| 118 132 |  | 
| 119 | 
            -
                   | 
| 120 | 
            -
                    [
         | 
| 133 | 
            +
                  it "iterates over the results" do
         | 
| 134 | 
            +
                    expect(results.entries).to eq([
         | 
| 121 135 | 
             
                      { "_id" => "Depeche Mode", "value" => { "likes" => 200 }},
         | 
| 122 136 | 
             
                      { "_id" => "Tool", "value" => { "likes" => 100 }}
         | 
| 123 | 
            -
                    ]
         | 
| 124 | 
            -
                  end
         | 
| 125 | 
            -
             | 
| 126 | 
            -
                  it "iterates over the results" do
         | 
| 127 | 
            -
                    expect(results.entries).to eq(expected_results)
         | 
| 128 | 
            -
                  end
         | 
| 129 | 
            -
             | 
| 130 | 
            -
                  it 'outputs to the collection' do
         | 
| 131 | 
            -
                    expect(results.entries).to eq(map_reduce.criteria.view.database["mr-output"].find.to_a)
         | 
| 137 | 
            +
                    ])
         | 
| 132 138 | 
             
                  end
         | 
| 133 139 | 
             
                end
         | 
| 134 140 |  | 
| 135 141 | 
             
                context "when no output is provided" do
         | 
| 136 142 |  | 
| 137 | 
            -
                   | 
| 138 | 
            -
             | 
| 139 | 
            -
             | 
| 140 | 
            -
             | 
| 141 | 
            -
                        map_reduce.entries
         | 
| 142 | 
            -
                      }.to raise_error(Mongoid::Errors::NoMapReduceOutput)
         | 
| 143 | 
            -
                    end
         | 
| 144 | 
            -
                  end
         | 
| 145 | 
            -
             | 
| 146 | 
            -
                  context "when the statstics are requested" do
         | 
| 147 | 
            -
             | 
| 148 | 
            -
                    it "raises an error" do
         | 
| 149 | 
            -
                      expect {
         | 
| 150 | 
            -
                        map_reduce.counts
         | 
| 151 | 
            -
                      }.to raise_error(Mongoid::Errors::NoMapReduceOutput)
         | 
| 152 | 
            -
                    end
         | 
| 143 | 
            +
                  it "raises an error" do
         | 
| 144 | 
            +
                    expect {
         | 
| 145 | 
            +
                      map_reduce.entries
         | 
| 146 | 
            +
                    }.to raise_error(Mongoid::Errors::NoMapReduceOutput)
         | 
| 153 147 | 
             
                  end
         | 
| 154 148 | 
             
                end
         | 
| 155 149 |  | 
| @@ -167,46 +161,17 @@ describe Mongoid::Contextual::MapReduce do | |
| 167 161 | 
             
                    expect(results.entries).to be_empty
         | 
| 168 162 | 
             
                  end
         | 
| 169 163 | 
             
                end
         | 
| 164 | 
            +
              end
         | 
| 170 165 |  | 
| 171 | 
            -
             | 
| 172 | 
            -
             | 
| 173 | 
            -
                  let(:map) do
         | 
| 174 | 
            -
                    %Q{
         | 
| 175 | 
            -
                     function() {
         | 
| 176 | 
            -
                       emit(this.name, 1);
         | 
| 177 | 
            -
                    }}
         | 
| 178 | 
            -
                  end
         | 
| 179 | 
            -
             | 
| 180 | 
            -
                  let(:reduce) do
         | 
| 181 | 
            -
                    %Q{
         | 
| 182 | 
            -
                     function(key, values) {
         | 
| 183 | 
            -
                       return Array.sum(values);
         | 
| 184 | 
            -
                    }}
         | 
| 185 | 
            -
                  end
         | 
| 186 | 
            -
             | 
| 187 | 
            -
                  let(:criteria) do
         | 
| 188 | 
            -
                    Band.where(name: 'DEPECHE MODE').collation(locale: 'en_US', strength: 2)
         | 
| 189 | 
            -
                  end
         | 
| 190 | 
            -
             | 
| 191 | 
            -
                  context 'when the server supports collations', if: collation_supported? do
         | 
| 192 | 
            -
             | 
| 193 | 
            -
                    it 'applies the collation' do
         | 
| 194 | 
            -
                      expect(map_reduce.out(inline: 1).count).to eq(1)
         | 
| 195 | 
            -
                    end
         | 
| 196 | 
            -
                  end
         | 
| 197 | 
            -
             | 
| 198 | 
            -
                  context 'when the server does not support collations', unless: collation_supported? do
         | 
| 166 | 
            +
              describe "#emitted" do
         | 
| 199 167 |  | 
| 200 | 
            -
             | 
| 201 | 
            -
             | 
| 202 | 
            -
                        map_reduce.out(inline: 1).to_a
         | 
| 203 | 
            -
                      }.to raise_exception(Mongo::Error::UnsupportedCollation)
         | 
| 204 | 
            -
                    end
         | 
| 205 | 
            -
                  end
         | 
| 168 | 
            +
                let(:criteria) do
         | 
| 169 | 
            +
                  Band.all
         | 
| 206 170 | 
             
                end
         | 
| 207 | 
            -
              end
         | 
| 208 171 |  | 
| 209 | 
            -
             | 
| 172 | 
            +
                let(:map_reduce) do
         | 
| 173 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 174 | 
            +
                end
         | 
| 210 175 |  | 
| 211 176 | 
             
                let(:emitted) do
         | 
| 212 177 | 
             
                  map_reduce.out(inline: 1).emitted
         | 
| @@ -219,8 +184,16 @@ describe Mongoid::Contextual::MapReduce do | |
| 219 184 |  | 
| 220 185 | 
             
              describe "#empty?" do
         | 
| 221 186 |  | 
| 187 | 
            +
                let(:map_reduce) do
         | 
| 188 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 189 | 
            +
                end
         | 
| 190 | 
            +
             | 
| 222 191 | 
             
                context "when the map/reduce has results" do
         | 
| 223 192 |  | 
| 193 | 
            +
                  let(:criteria) do
         | 
| 194 | 
            +
                    Band.all
         | 
| 195 | 
            +
                  end
         | 
| 196 | 
            +
             | 
| 224 197 | 
             
                  let(:results) do
         | 
| 225 198 | 
             
                    map_reduce.out(inline: 1)
         | 
| 226 199 | 
             
                  end
         | 
| @@ -248,6 +221,14 @@ describe Mongoid::Contextual::MapReduce do | |
| 248 221 |  | 
| 249 222 | 
             
              describe "#finalize" do
         | 
| 250 223 |  | 
| 224 | 
            +
                let(:criteria) do
         | 
| 225 | 
            +
                  Band.all
         | 
| 226 | 
            +
                end
         | 
| 227 | 
            +
             | 
| 228 | 
            +
                let(:map_reduce) do
         | 
| 229 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 230 | 
            +
                end
         | 
| 231 | 
            +
             | 
| 251 232 | 
             
                let(:finalized) do
         | 
| 252 233 | 
             
                  map_reduce.finalize("testing")
         | 
| 253 234 | 
             
                end
         | 
| @@ -259,6 +240,14 @@ describe Mongoid::Contextual::MapReduce do | |
| 259 240 |  | 
| 260 241 | 
             
              describe "#input" do
         | 
| 261 242 |  | 
| 243 | 
            +
                let(:criteria) do
         | 
| 244 | 
            +
                  Band.all
         | 
| 245 | 
            +
                end
         | 
| 246 | 
            +
             | 
| 247 | 
            +
                let(:map_reduce) do
         | 
| 248 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 249 | 
            +
                end
         | 
| 250 | 
            +
             | 
| 262 251 | 
             
                let(:input) do
         | 
| 263 252 | 
             
                  map_reduce.out(inline: 1).input
         | 
| 264 253 | 
             
                end
         | 
| @@ -270,6 +259,14 @@ describe Mongoid::Contextual::MapReduce do | |
| 270 259 |  | 
| 271 260 | 
             
              describe "#js_mode" do
         | 
| 272 261 |  | 
| 262 | 
            +
                let(:criteria) do
         | 
| 263 | 
            +
                  Band.all
         | 
| 264 | 
            +
                end
         | 
| 265 | 
            +
             | 
| 266 | 
            +
                let(:map_reduce) do
         | 
| 267 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 268 | 
            +
                end
         | 
| 269 | 
            +
             | 
| 273 270 | 
             
                let(:results) do
         | 
| 274 271 | 
             
                  map_reduce.out(inline: 1).js_mode
         | 
| 275 272 | 
             
                end
         | 
| @@ -281,6 +278,14 @@ describe Mongoid::Contextual::MapReduce do | |
| 281 278 |  | 
| 282 279 | 
             
              describe "#out" do
         | 
| 283 280 |  | 
| 281 | 
            +
                let(:criteria) do
         | 
| 282 | 
            +
                  Band.all
         | 
| 283 | 
            +
                end
         | 
| 284 | 
            +
             | 
| 285 | 
            +
                let(:map_reduce) do
         | 
| 286 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 287 | 
            +
                end
         | 
| 288 | 
            +
             | 
| 284 289 | 
             
                context "when providing inline" do
         | 
| 285 290 |  | 
| 286 291 | 
             
                  let(:out) do
         | 
| @@ -288,7 +293,7 @@ describe Mongoid::Contextual::MapReduce do | |
| 288 293 | 
             
                  end
         | 
| 289 294 |  | 
| 290 295 | 
             
                  it "sets the out command" do
         | 
| 291 | 
            -
                    expect(out.command[:out] | 
| 296 | 
            +
                    expect(out.command[:out]).to eq(inline: 1)
         | 
| 292 297 | 
             
                  end
         | 
| 293 298 | 
             
                end
         | 
| 294 299 |  | 
| @@ -301,7 +306,7 @@ describe Mongoid::Contextual::MapReduce do | |
| 301 306 | 
             
                    end
         | 
| 302 307 |  | 
| 303 308 | 
             
                    it "sets the out command value to a string" do
         | 
| 304 | 
            -
                      expect(out.command[:out] | 
| 309 | 
            +
                      expect(out.command[:out]).to eq(replace: "test")
         | 
| 305 310 | 
             
                    end
         | 
| 306 311 | 
             
                  end
         | 
| 307 312 | 
             
                end
         | 
| @@ -309,6 +314,14 @@ describe Mongoid::Contextual::MapReduce do | |
| 309 314 |  | 
| 310 315 | 
             
              describe "#output" do
         | 
| 311 316 |  | 
| 317 | 
            +
                let(:criteria) do
         | 
| 318 | 
            +
                  Band.all
         | 
| 319 | 
            +
                end
         | 
| 320 | 
            +
             | 
| 321 | 
            +
                let(:map_reduce) do
         | 
| 322 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 323 | 
            +
                end
         | 
| 324 | 
            +
             | 
| 312 325 | 
             
                let(:output) do
         | 
| 313 326 | 
             
                  map_reduce.out(inline: 1).output
         | 
| 314 327 | 
             
                end
         | 
| @@ -318,44 +331,15 @@ describe Mongoid::Contextual::MapReduce do | |
| 318 331 | 
             
                end
         | 
| 319 332 | 
             
              end
         | 
| 320 333 |  | 
| 321 | 
            -
              describe "# | 
| 322 | 
            -
             | 
| 323 | 
            -
                let(:client) do
         | 
| 324 | 
            -
                  collection.database.client
         | 
| 325 | 
            -
                end
         | 
| 326 | 
            -
             | 
| 327 | 
            -
                context "when not specifying an out" do
         | 
| 334 | 
            +
              describe "#reduced" do
         | 
| 328 335 |  | 
| 329 | 
            -
             | 
| 330 | 
            -
             | 
| 331 | 
            -
                      map_reduce.raw
         | 
| 332 | 
            -
                    }.to raise_error(Mongoid::Errors::NoMapReduceOutput)
         | 
| 333 | 
            -
                  end
         | 
| 336 | 
            +
                let(:criteria) do
         | 
| 337 | 
            +
                  Band.all
         | 
| 334 338 | 
             
                end
         | 
| 335 339 |  | 
| 336 | 
            -
                 | 
| 337 | 
            -
             | 
| 338 | 
            -
                  let(:replace_map_reduce) do
         | 
| 339 | 
            -
                    map_reduce.out(replace: 'output-collection')
         | 
| 340 | 
            -
                  end
         | 
| 341 | 
            -
             | 
| 342 | 
            -
                  context 'when a read preference is defined' do
         | 
| 343 | 
            -
             | 
| 344 | 
            -
                    let(:criteria) do
         | 
| 345 | 
            -
                      Band.all.read(mode: :secondary)
         | 
| 346 | 
            -
                    end
         | 
| 347 | 
            -
             | 
| 348 | 
            -
                    it "uses the read preference", if: testing_replica_set? do
         | 
| 349 | 
            -
             | 
| 350 | 
            -
                      expect {
         | 
| 351 | 
            -
                        replace_map_reduce.raw
         | 
| 352 | 
            -
                      }.to raise_exception(Mongo::Error::OperationFailure)
         | 
| 353 | 
            -
                    end
         | 
| 354 | 
            -
                  end
         | 
| 340 | 
            +
                let(:map_reduce) do
         | 
| 341 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 355 342 | 
             
                end
         | 
| 356 | 
            -
              end
         | 
| 357 | 
            -
             | 
| 358 | 
            -
              describe "#reduced" do
         | 
| 359 343 |  | 
| 360 344 | 
             
                let(:reduced) do
         | 
| 361 345 | 
             
                  map_reduce.out(inline: 1).reduced
         | 
| @@ -368,6 +352,14 @@ describe Mongoid::Contextual::MapReduce do | |
| 368 352 |  | 
| 369 353 | 
             
              describe "#scope" do
         | 
| 370 354 |  | 
| 355 | 
            +
                let(:criteria) do
         | 
| 356 | 
            +
                  Band.all
         | 
| 357 | 
            +
                end
         | 
| 358 | 
            +
             | 
| 359 | 
            +
                let(:map_reduce) do
         | 
| 360 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 361 | 
            +
                end
         | 
| 362 | 
            +
             | 
| 371 363 | 
             
                let(:finalize) do
         | 
| 372 364 | 
             
                  %Q{
         | 
| 373 365 | 
             
                  function(key, value) {
         | 
| @@ -387,6 +379,14 @@ describe Mongoid::Contextual::MapReduce do | |
| 387 379 |  | 
| 388 380 | 
             
              describe "#time" do
         | 
| 389 381 |  | 
| 382 | 
            +
                let(:criteria) do
         | 
| 383 | 
            +
                  Band.all
         | 
| 384 | 
            +
                end
         | 
| 385 | 
            +
             | 
| 386 | 
            +
                let(:map_reduce) do
         | 
| 387 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 388 | 
            +
                end
         | 
| 389 | 
            +
             | 
| 390 390 | 
             
                let(:time) do
         | 
| 391 391 | 
             
                  map_reduce.out(inline: 1).time
         | 
| 392 392 | 
             
                end
         | 
| @@ -398,6 +398,14 @@ describe Mongoid::Contextual::MapReduce do | |
| 398 398 |  | 
| 399 399 | 
             
              describe "#execute" do
         | 
| 400 400 |  | 
| 401 | 
            +
                let(:criteria) do
         | 
| 402 | 
            +
                  Band.all
         | 
| 403 | 
            +
                end
         | 
| 404 | 
            +
             | 
| 405 | 
            +
                let(:map_reduce) do
         | 
| 406 | 
            +
                  described_class.new(collection, criteria, map, reduce)
         | 
| 407 | 
            +
                end
         | 
| 408 | 
            +
             | 
| 401 409 | 
             
                let(:execution_results) do
         | 
| 402 410 | 
             
                  map_reduce.out(inline: 1).execute
         | 
| 403 411 | 
             
                end
         | 
| @@ -47,21 +47,6 @@ describe Mongoid::Contextual::Memory do | |
| 47 47 | 
             
                      expect(context.send(method)).to be true
         | 
| 48 48 | 
             
                    end
         | 
| 49 49 | 
             
                  end
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                  context 'when there is a collation on the criteria' do
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                    let(:criteria) do
         | 
| 54 | 
            -
                      Address.where(street: "hobrecht").tap do |crit|
         | 
| 55 | 
            -
                        crit.documents = [ hobrecht, friedel ]
         | 
| 56 | 
            -
                      end.collation(locale: 'en_US', strength: 2)
         | 
| 57 | 
            -
                    end
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                    it "raises an exception" do
         | 
| 60 | 
            -
                      expect {
         | 
| 61 | 
            -
                        context.send(method)
         | 
| 62 | 
            -
                      }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 63 | 
            -
                    end
         | 
| 64 | 
            -
                  end
         | 
| 65 50 | 
             
                end
         | 
| 66 51 | 
             
              end
         | 
| 67 52 |  | 
| @@ -92,21 +77,6 @@ describe Mongoid::Contextual::Memory do | |
| 92 77 | 
             
                  end
         | 
| 93 78 | 
             
                end
         | 
| 94 79 |  | 
| 95 | 
            -
                context 'when there is a collation on the criteria' do
         | 
| 96 | 
            -
             | 
| 97 | 
            -
                  let(:criteria) do
         | 
| 98 | 
            -
                    Address.where(street: "hobrecht").tap do |crit|
         | 
| 99 | 
            -
                      crit.documents = [ hobrecht, friedel ]
         | 
| 100 | 
            -
                    end.collation(locale: 'en_US', strength: 2)
         | 
| 101 | 
            -
                  end
         | 
| 102 | 
            -
             | 
| 103 | 
            -
                  it "raises an exception" do
         | 
| 104 | 
            -
                    expect {
         | 
| 105 | 
            -
                      context.count
         | 
| 106 | 
            -
                    }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 107 | 
            -
                  end
         | 
| 108 | 
            -
                end
         | 
| 109 | 
            -
             | 
| 110 80 | 
             
                context "when provided a document" do
         | 
| 111 81 |  | 
| 112 82 | 
             
                  context "when the document matches" do
         | 
| @@ -275,21 +245,6 @@ describe Mongoid::Contextual::Memory do | |
| 275 245 | 
             
                      expect(deleted).to eq(1)
         | 
| 276 246 | 
             
                    end
         | 
| 277 247 | 
             
                  end
         | 
| 278 | 
            -
             | 
| 279 | 
            -
                  context 'when there is a collation on the criteria' do
         | 
| 280 | 
            -
             | 
| 281 | 
            -
                    let(:criteria) do
         | 
| 282 | 
            -
                      Address.any_in(street: [ "hobrecht", "friedel" ]).tap do |crit|
         | 
| 283 | 
            -
                        crit.documents = [ hobrecht, friedel, pfluger ]
         | 
| 284 | 
            -
                      end.collation(locale: 'en_US', strength: 2)
         | 
| 285 | 
            -
                    end
         | 
| 286 | 
            -
             | 
| 287 | 
            -
                    it "raises an exception" do
         | 
| 288 | 
            -
                      expect {
         | 
| 289 | 
            -
                        context.send(method)
         | 
| 290 | 
            -
                      }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 291 | 
            -
                    end
         | 
| 292 | 
            -
                  end
         | 
| 293 248 | 
             
                end
         | 
| 294 249 | 
             
              end
         | 
| 295 250 |  | 
| @@ -323,54 +278,36 @@ describe Mongoid::Contextual::Memory do | |
| 323 278 |  | 
| 324 279 | 
             
                describe "##{method}" do
         | 
| 325 280 |  | 
| 326 | 
            -
                   | 
| 327 | 
            -
             | 
| 328 | 
            -
             | 
| 329 | 
            -
                      context.send(method)
         | 
| 330 | 
            -
                    end
         | 
| 331 | 
            -
             | 
| 332 | 
            -
                    it "deletes the first matching document" do
         | 
| 333 | 
            -
                      expect(hobrecht).to be_destroyed
         | 
| 334 | 
            -
                    end
         | 
| 335 | 
            -
             | 
| 336 | 
            -
                    it "deletes the last matching document" do
         | 
| 337 | 
            -
                      expect(friedel).to be_destroyed
         | 
| 338 | 
            -
                    end
         | 
| 339 | 
            -
             | 
| 340 | 
            -
                    it "does not delete non matching docs" do
         | 
| 341 | 
            -
                      expect(pfluger).to_not be_destroyed
         | 
| 342 | 
            -
                    end
         | 
| 281 | 
            +
                  let!(:destroyed) do
         | 
| 282 | 
            +
                    context.send(method)
         | 
| 283 | 
            +
                  end
         | 
| 343 284 |  | 
| 344 | 
            -
             | 
| 345 | 
            -
             | 
| 346 | 
            -
             | 
| 285 | 
            +
                  it "deletes the first matching document" do
         | 
| 286 | 
            +
                    expect(hobrecht).to be_destroyed
         | 
| 287 | 
            +
                  end
         | 
| 347 288 |  | 
| 348 | 
            -
             | 
| 349 | 
            -
             | 
| 350 | 
            -
             | 
| 289 | 
            +
                  it "deletes the last matching document" do
         | 
| 290 | 
            +
                    expect(friedel).to be_destroyed
         | 
| 291 | 
            +
                  end
         | 
| 351 292 |  | 
| 352 | 
            -
             | 
| 353 | 
            -
             | 
| 354 | 
            -
             | 
| 293 | 
            +
                  it "does not delete non matching docs" do
         | 
| 294 | 
            +
                    expect(pfluger).to_not be_destroyed
         | 
| 295 | 
            +
                  end
         | 
| 355 296 |  | 
| 356 | 
            -
             | 
| 357 | 
            -
             | 
| 358 | 
            -
                    end
         | 
| 297 | 
            +
                  it "removes the docs from the relation" do
         | 
| 298 | 
            +
                    expect(person.addresses).to eq([ pfluger ])
         | 
| 359 299 | 
             
                  end
         | 
| 360 300 |  | 
| 361 | 
            -
                   | 
| 301 | 
            +
                  it "removes the docs from the context" do
         | 
| 302 | 
            +
                    expect(context.entries).to be_empty
         | 
| 303 | 
            +
                  end
         | 
| 362 304 |  | 
| 363 | 
            -
             | 
| 364 | 
            -
             | 
| 365 | 
            -
             | 
| 366 | 
            -
                      end.collation(locale: 'en_US', strength: 2)
         | 
| 367 | 
            -
                    end
         | 
| 305 | 
            +
                  it "persists the changes to the database" do
         | 
| 306 | 
            +
                    expect(person.reload.addresses).to eq([ pfluger ])
         | 
| 307 | 
            +
                  end
         | 
| 368 308 |  | 
| 369 | 
            -
             | 
| 370 | 
            -
             | 
| 371 | 
            -
                        context.send(method)
         | 
| 372 | 
            -
                      }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 373 | 
            -
                    end
         | 
| 309 | 
            +
                  it "returns the number of destroyed documents" do
         | 
| 310 | 
            +
                    expect(destroyed).to eq(2)
         | 
| 374 311 | 
             
                  end
         | 
| 375 312 | 
             
                end
         | 
| 376 313 | 
             
              end
         | 
| @@ -418,21 +355,6 @@ describe Mongoid::Contextual::Memory do | |
| 418 355 | 
             
                    expect(context.distinct(:street)).to eq([ "hobrecht", "friedel" ])
         | 
| 419 356 | 
             
                  end
         | 
| 420 357 | 
             
                end
         | 
| 421 | 
            -
             | 
| 422 | 
            -
                context 'when there is a collation on the criteria' do
         | 
| 423 | 
            -
             | 
| 424 | 
            -
                  let(:criteria) do
         | 
| 425 | 
            -
                    Address.where(street: "hobrecht").tap do |crit|
         | 
| 426 | 
            -
                      crit.documents = [ hobrecht, hobrecht, friedel ]
         | 
| 427 | 
            -
                    end.collation(locale: 'en_US', strength: 2)
         | 
| 428 | 
            -
                  end
         | 
| 429 | 
            -
             | 
| 430 | 
            -
                  it "raises an exception" do
         | 
| 431 | 
            -
                    expect {
         | 
| 432 | 
            -
                      context.distinct(:street)
         | 
| 433 | 
            -
                    }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 434 | 
            -
                  end
         | 
| 435 | 
            -
                end
         | 
| 436 358 | 
             
              end
         | 
| 437 359 |  | 
| 438 360 | 
             
              describe "#each" do
         | 
| @@ -519,21 +441,6 @@ describe Mongoid::Contextual::Memory do | |
| 519 441 | 
             
                    end
         | 
| 520 442 | 
             
                  end
         | 
| 521 443 | 
             
                end
         | 
| 522 | 
            -
             | 
| 523 | 
            -
                context 'when there is a collation on the criteria' do
         | 
| 524 | 
            -
             | 
| 525 | 
            -
                  let(:criteria) do
         | 
| 526 | 
            -
                    Address.where(street: "hobrecht").tap do |crit|
         | 
| 527 | 
            -
                      crit.documents = [ hobrecht, friedel ]
         | 
| 528 | 
            -
                    end.collation(locale: 'en_US', strength: 2)
         | 
| 529 | 
            -
                  end
         | 
| 530 | 
            -
             | 
| 531 | 
            -
                  it "raises an exception" do
         | 
| 532 | 
            -
                    expect {
         | 
| 533 | 
            -
                      context.each
         | 
| 534 | 
            -
                    }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 535 | 
            -
                  end
         | 
| 536 | 
            -
                end
         | 
| 537 444 | 
             
              end
         | 
| 538 445 |  | 
| 539 446 | 
             
              describe "#exists?" do
         | 
| @@ -579,21 +486,6 @@ describe Mongoid::Contextual::Memory do | |
| 579 486 | 
             
                    expect(context).to_not be_exists
         | 
| 580 487 | 
             
                  end
         | 
| 581 488 | 
             
                end
         | 
| 582 | 
            -
             | 
| 583 | 
            -
                context 'when there is a collation on the criteria' do
         | 
| 584 | 
            -
             | 
| 585 | 
            -
                  let(:criteria) do
         | 
| 586 | 
            -
                    Address.where(street: "pfluger").tap do |crit|
         | 
| 587 | 
            -
                      crit.documents = [ hobrecht, friedel ]
         | 
| 588 | 
            -
                    end.collation(locale: 'en_US', strength: 2)
         | 
| 589 | 
            -
                  end
         | 
| 590 | 
            -
             | 
| 591 | 
            -
                  it "raises an exception" do
         | 
| 592 | 
            -
                    expect {
         | 
| 593 | 
            -
                      context
         | 
| 594 | 
            -
                    }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 595 | 
            -
                  end
         | 
| 596 | 
            -
                end
         | 
| 597 489 | 
             
              end
         | 
| 598 490 |  | 
| 599 491 | 
             
              [ :first, :one ].each do |method|
         | 
| @@ -621,21 +513,6 @@ describe Mongoid::Contextual::Memory do | |
| 621 513 | 
             
                  it "returns the first matching document" do
         | 
| 622 514 | 
             
                    expect(context.send(method)).to eq(hobrecht)
         | 
| 623 515 | 
             
                  end
         | 
| 624 | 
            -
             | 
| 625 | 
            -
                  context 'when there is a collation on the criteria' do
         | 
| 626 | 
            -
             | 
| 627 | 
            -
                    let(:criteria) do
         | 
| 628 | 
            -
                      Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
         | 
| 629 | 
            -
                        crit.documents = [ hobrecht, friedel ]
         | 
| 630 | 
            -
                      end.collation(locale: 'en_US', strength: 2)
         | 
| 631 | 
            -
                    end
         | 
| 632 | 
            -
             | 
| 633 | 
            -
                    it "raises an exception" do
         | 
| 634 | 
            -
                      expect {
         | 
| 635 | 
            -
                        context.send(method)
         | 
| 636 | 
            -
                      }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 637 | 
            -
                    end
         | 
| 638 | 
            -
                  end
         | 
| 639 516 | 
             
                end
         | 
| 640 517 | 
             
              end
         | 
| 641 518 |  | 
| @@ -723,21 +600,6 @@ describe Mongoid::Contextual::Memory do | |
| 723 600 | 
             
                    expect(context).to eq([ hobrecht ])
         | 
| 724 601 | 
             
                  end
         | 
| 725 602 | 
             
                end
         | 
| 726 | 
            -
             | 
| 727 | 
            -
                context 'when there is a collation on the criteria' do
         | 
| 728 | 
            -
             | 
| 729 | 
            -
                  let(:criteria) do
         | 
| 730 | 
            -
                    Address.all.limit(1).tap do |crit|
         | 
| 731 | 
            -
                      crit.documents = [ hobrecht, friedel ]
         | 
| 732 | 
            -
                    end.collation(locale: 'en_US', strength: 2)
         | 
| 733 | 
            -
                  end
         | 
| 734 | 
            -
             | 
| 735 | 
            -
                  it "raises an exception" do
         | 
| 736 | 
            -
                    expect {
         | 
| 737 | 
            -
                      context
         | 
| 738 | 
            -
                    }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 739 | 
            -
                  end
         | 
| 740 | 
            -
                end
         | 
| 741 603 | 
             
              end
         | 
| 742 604 |  | 
| 743 605 | 
             
              describe "#last" do
         | 
| @@ -763,21 +625,6 @@ describe Mongoid::Contextual::Memory do | |
| 763 625 | 
             
                it "returns the last matching document" do
         | 
| 764 626 | 
             
                  expect(context.last).to eq(friedel)
         | 
| 765 627 | 
             
                end
         | 
| 766 | 
            -
             | 
| 767 | 
            -
                context 'when there is a collation on the criteria' do
         | 
| 768 | 
            -
             | 
| 769 | 
            -
                  let(:criteria) do
         | 
| 770 | 
            -
                    Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
         | 
| 771 | 
            -
                      crit.documents = [ hobrecht, friedel ]
         | 
| 772 | 
            -
                    end.collation(locale: 'en_US', strength: 2)
         | 
| 773 | 
            -
                  end
         | 
| 774 | 
            -
             | 
| 775 | 
            -
                  it "raises an exception" do
         | 
| 776 | 
            -
                    expect {
         | 
| 777 | 
            -
                      context.last
         | 
| 778 | 
            -
                    }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 779 | 
            -
                  end
         | 
| 780 | 
            -
                end
         | 
| 781 628 | 
             
              end
         | 
| 782 629 |  | 
| 783 630 | 
             
              [ :length, :size ].each do |method|
         | 
| @@ -825,21 +672,6 @@ describe Mongoid::Contextual::Memory do | |
| 825 672 | 
             
                      expect(context.send(method)).to eq(0)
         | 
| 826 673 | 
             
                    end
         | 
| 827 674 | 
             
                  end
         | 
| 828 | 
            -
             | 
| 829 | 
            -
                  context 'when there is a collation on the criteria' do
         | 
| 830 | 
            -
             | 
| 831 | 
            -
                    let(:criteria) do
         | 
| 832 | 
            -
                      Address.where(street: "hobrecht").tap do |crit|
         | 
| 833 | 
            -
                        crit.documents = [ hobrecht, friedel ]
         | 
| 834 | 
            -
                      end.collation(locale: 'en_US', strength: 2)
         | 
| 835 | 
            -
                    end
         | 
| 836 | 
            -
             | 
| 837 | 
            -
                    it "raises an exception" do
         | 
| 838 | 
            -
                      expect {
         | 
| 839 | 
            -
                        context.send(method)
         | 
| 840 | 
            -
                      }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 841 | 
            -
                    end
         | 
| 842 | 
            -
                  end
         | 
| 843 675 | 
             
                end
         | 
| 844 676 | 
             
              end
         | 
| 845 677 |  | 
| @@ -867,50 +699,32 @@ describe Mongoid::Contextual::Memory do | |
| 867 699 | 
             
                  described_class.new(criteria)
         | 
| 868 700 | 
             
                end
         | 
| 869 701 |  | 
| 870 | 
            -
                 | 
| 871 | 
            -
             | 
| 872 | 
            -
             | 
| 873 | 
            -
                    context.limit(2)
         | 
| 874 | 
            -
                  end
         | 
| 875 | 
            -
             | 
| 876 | 
            -
                  it "returns the context" do
         | 
| 877 | 
            -
                    expect(limit).to eq(context)
         | 
| 878 | 
            -
                  end
         | 
| 879 | 
            -
             | 
| 880 | 
            -
                  context "when asking for all documents" do
         | 
| 881 | 
            -
             | 
| 882 | 
            -
                    context "when only a limit exists" do
         | 
| 702 | 
            +
                let!(:limit) do
         | 
| 703 | 
            +
                  context.limit(2)
         | 
| 704 | 
            +
                end
         | 
| 883 705 |  | 
| 884 | 
            -
             | 
| 885 | 
            -
             | 
| 886 | 
            -
             | 
| 887 | 
            -
                    end
         | 
| 706 | 
            +
                it "returns the context" do
         | 
| 707 | 
            +
                  expect(limit).to eq(context)
         | 
| 708 | 
            +
                end
         | 
| 888 709 |  | 
| 889 | 
            -
             | 
| 710 | 
            +
                context "when asking for all documents" do
         | 
| 890 711 |  | 
| 891 | 
            -
             | 
| 892 | 
            -
                        limit.skip(1)
         | 
| 893 | 
            -
                      end
         | 
| 712 | 
            +
                  context "when only a limit exists" do
         | 
| 894 713 |  | 
| 895 | 
            -
             | 
| 896 | 
            -
             | 
| 897 | 
            -
                      end
         | 
| 714 | 
            +
                    it "only returns the limited documents" do
         | 
| 715 | 
            +
                      expect(context.entries).to eq([ hobrecht, friedel ])
         | 
| 898 716 | 
             
                    end
         | 
| 899 717 | 
             
                  end
         | 
| 900 | 
            -
                end
         | 
| 901 718 |  | 
| 902 | 
            -
             | 
| 719 | 
            +
                  context "when a skip and limit exist" do
         | 
| 903 720 |  | 
| 904 | 
            -
             | 
| 905 | 
            -
             | 
| 906 | 
            -
             | 
| 907 | 
            -
                    end.collation(locale: 'en_US', strength: 2)
         | 
| 908 | 
            -
                  end
         | 
| 721 | 
            +
                    before do
         | 
| 722 | 
            +
                      limit.skip(1)
         | 
| 723 | 
            +
                    end
         | 
| 909 724 |  | 
| 910 | 
            -
             | 
| 911 | 
            -
             | 
| 912 | 
            -
             | 
| 913 | 
            -
                    }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 725 | 
            +
                    it "applies the skip before the limit" do
         | 
| 726 | 
            +
                      expect(context.entries).to eq([ friedel, pfluger ])
         | 
| 727 | 
            +
                    end
         | 
| 914 728 | 
             
                  end
         | 
| 915 729 | 
             
                end
         | 
| 916 730 | 
             
              end
         | 
| @@ -970,21 +784,6 @@ describe Mongoid::Contextual::Memory do | |
| 970 784 | 
             
                    end
         | 
| 971 785 | 
             
                  end
         | 
| 972 786 | 
             
                end
         | 
| 973 | 
            -
             | 
| 974 | 
            -
                context 'when there is a collation on the criteria' do
         | 
| 975 | 
            -
             | 
| 976 | 
            -
                  let(:criteria) do
         | 
| 977 | 
            -
                    Address.all.tap do |crit|
         | 
| 978 | 
            -
                      crit.documents = [ hobrecht, friedel ]
         | 
| 979 | 
            -
                    end.collation(locale: 'en_US', strength: 2)
         | 
| 980 | 
            -
                  end
         | 
| 981 | 
            -
             | 
| 982 | 
            -
                  it "raises an exception" do
         | 
| 983 | 
            -
                    expect {
         | 
| 984 | 
            -
                      context.pluck(:foo, :bar)
         | 
| 985 | 
            -
                    }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 986 | 
            -
                  end
         | 
| 987 | 
            -
                end
         | 
| 988 787 | 
             
              end
         | 
| 989 788 |  | 
| 990 789 | 
             
              describe "#skip" do
         | 
| @@ -1011,50 +810,32 @@ describe Mongoid::Contextual::Memory do | |
| 1011 810 | 
             
                  described_class.new(criteria)
         | 
| 1012 811 | 
             
                end
         | 
| 1013 812 |  | 
| 1014 | 
            -
                 | 
| 1015 | 
            -
             | 
| 1016 | 
            -
             | 
| 1017 | 
            -
                    context.skip(1)
         | 
| 1018 | 
            -
                  end
         | 
| 1019 | 
            -
             | 
| 1020 | 
            -
                  it "returns the context" do
         | 
| 1021 | 
            -
                    expect(skip).to eq(context)
         | 
| 1022 | 
            -
                  end
         | 
| 1023 | 
            -
             | 
| 1024 | 
            -
                  context "when asking for all documents" do
         | 
| 1025 | 
            -
             | 
| 1026 | 
            -
                    context "when only a skip exists" do
         | 
| 813 | 
            +
                let!(:skip) do
         | 
| 814 | 
            +
                  context.skip(1)
         | 
| 815 | 
            +
                end
         | 
| 1027 816 |  | 
| 1028 | 
            -
             | 
| 1029 | 
            -
             | 
| 1030 | 
            -
             | 
| 1031 | 
            -
                    end
         | 
| 817 | 
            +
                it "returns the context" do
         | 
| 818 | 
            +
                  expect(skip).to eq(context)
         | 
| 819 | 
            +
                end
         | 
| 1032 820 |  | 
| 1033 | 
            -
             | 
| 821 | 
            +
                context "when asking for all documents" do
         | 
| 1034 822 |  | 
| 1035 | 
            -
             | 
| 1036 | 
            -
                        skip.limit(1)
         | 
| 1037 | 
            -
                      end
         | 
| 823 | 
            +
                  context "when only a skip exists" do
         | 
| 1038 824 |  | 
| 1039 | 
            -
             | 
| 1040 | 
            -
             | 
| 1041 | 
            -
                      end
         | 
| 825 | 
            +
                    it "skips the correct number" do
         | 
| 826 | 
            +
                      expect(context.entries).to eq([ friedel, pfluger ])
         | 
| 1042 827 | 
             
                    end
         | 
| 1043 828 | 
             
                  end
         | 
| 1044 | 
            -
                end
         | 
| 1045 829 |  | 
| 1046 | 
            -
             | 
| 830 | 
            +
                  context "when a skip and limit exist" do
         | 
| 1047 831 |  | 
| 1048 | 
            -
             | 
| 1049 | 
            -
             | 
| 1050 | 
            -
             | 
| 1051 | 
            -
                    end.collation(locale: 'en_US', strength: 2)
         | 
| 1052 | 
            -
                  end
         | 
| 832 | 
            +
                    before do
         | 
| 833 | 
            +
                      skip.limit(1)
         | 
| 834 | 
            +
                    end
         | 
| 1053 835 |  | 
| 1054 | 
            -
             | 
| 1055 | 
            -
             | 
| 1056 | 
            -
             | 
| 1057 | 
            -
                    }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 836 | 
            +
                    it "applies the skip before the limit" do
         | 
| 837 | 
            +
                      expect(context.entries).to eq([ friedel ])
         | 
| 838 | 
            +
                    end
         | 
| 1058 839 | 
             
                  end
         | 
| 1059 840 | 
             
                end
         | 
| 1060 841 | 
             
              end
         | 
| @@ -1210,21 +991,6 @@ describe Mongoid::Contextual::Memory do | |
| 1210 991 | 
             
                    expect(context.entries).to eq([ friedel, hobrecht, pfluger ])
         | 
| 1211 992 | 
             
                  end
         | 
| 1212 993 | 
             
                end
         | 
| 1213 | 
            -
             | 
| 1214 | 
            -
                context 'when there is a collation on the criteria' do
         | 
| 1215 | 
            -
             | 
| 1216 | 
            -
                  let(:criteria) do
         | 
| 1217 | 
            -
                    Address.all.tap do |crit|
         | 
| 1218 | 
            -
                      crit.documents = [ hobrecht, friedel, pfluger ]
         | 
| 1219 | 
            -
                    end.collation(locale: 'en_US', strength: 2)
         | 
| 1220 | 
            -
                  end
         | 
| 1221 | 
            -
             | 
| 1222 | 
            -
                  it "raises an exception" do
         | 
| 1223 | 
            -
                    expect {
         | 
| 1224 | 
            -
                      context.sort(state: 1)
         | 
| 1225 | 
            -
                    }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 1226 | 
            -
                  end
         | 
| 1227 | 
            -
                end
         | 
| 1228 994 | 
             
              end
         | 
| 1229 995 |  | 
| 1230 996 | 
             
              describe "#update" do
         | 
| @@ -1352,19 +1118,6 @@ describe Mongoid::Contextual::Memory do | |
| 1352 1118 | 
             
                    end
         | 
| 1353 1119 | 
             
                  end
         | 
| 1354 1120 | 
             
                end
         | 
| 1355 | 
            -
             | 
| 1356 | 
            -
                context 'when there is a collation on the criteria' do
         | 
| 1357 | 
            -
             | 
| 1358 | 
            -
                  let(:criteria) do
         | 
| 1359 | 
            -
                    Address.all.collation(locale: 'en_US', strength: 2)
         | 
| 1360 | 
            -
                  end
         | 
| 1361 | 
            -
             | 
| 1362 | 
            -
                  it "raises an exception" do
         | 
| 1363 | 
            -
                    expect {
         | 
| 1364 | 
            -
                      context.update
         | 
| 1365 | 
            -
                    }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 1366 | 
            -
                  end
         | 
| 1367 | 
            -
                end
         | 
| 1368 1121 | 
             
              end
         | 
| 1369 1122 |  | 
| 1370 1123 | 
             
              describe "#update_all" do
         | 
| @@ -1385,19 +1138,6 @@ describe Mongoid::Contextual::Memory do | |
| 1385 1138 | 
             
                  person.addresses.create(street: "pfluger")
         | 
| 1386 1139 | 
             
                end
         | 
| 1387 1140 |  | 
| 1388 | 
            -
                context 'when there is a collation on the criteria' do
         | 
| 1389 | 
            -
             | 
| 1390 | 
            -
                  let(:criteria) do
         | 
| 1391 | 
            -
                    Address.all.collation(locale: 'en_US', strength: 2)
         | 
| 1392 | 
            -
                  end
         | 
| 1393 | 
            -
             | 
| 1394 | 
            -
                  it "raises an exception" do
         | 
| 1395 | 
            -
                    expect {
         | 
| 1396 | 
            -
                      context.update_all({})
         | 
| 1397 | 
            -
                    }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
         | 
| 1398 | 
            -
                  end
         | 
| 1399 | 
            -
                end
         | 
| 1400 | 
            -
             | 
| 1401 1141 | 
             
                context "when the documents are empty" do
         | 
| 1402 1142 |  | 
| 1403 1143 | 
             
                  let(:person_two) do
         |