mongoid 3.1.7 → 4.0.0.alpha1
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 +4 -4
- data/CHANGELOG.md +317 -11
- data/README.md +4 -5
- data/lib/config/locales/en.yml +9 -12
- data/lib/mongoid.rb +6 -75
- data/lib/mongoid/atomic.rb +0 -11
- data/lib/mongoid/atomic/paths/embedded.rb +0 -30
- data/lib/mongoid/atomic/paths/root.rb +0 -13
- data/lib/mongoid/attributes.rb +30 -108
- data/lib/mongoid/attributes/dynamic.rb +154 -0
- data/lib/mongoid/attributes/nested.rb +82 -0
- data/lib/mongoid/attributes/processing.rb +13 -66
- data/lib/mongoid/{dirty.rb → changeable.rb} +5 -2
- data/lib/mongoid/composable.rb +104 -0
- data/lib/mongoid/config.rb +3 -9
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/contextual/aggregable/mongo.rb +5 -9
- data/lib/mongoid/contextual/atomic.rb +53 -53
- data/lib/mongoid/contextual/command.rb +26 -0
- data/lib/mongoid/contextual/map_reduce.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +6 -5
- data/lib/mongoid/contextual/mongo.rb +59 -28
- data/lib/mongoid/contextual/text_search.rb +180 -0
- data/lib/mongoid/copyable.rb +2 -3
- data/lib/mongoid/criteria.rb +13 -33
- data/lib/mongoid/criteria/{#findable.rb# → findable.rb} +0 -2
- data/lib/mongoid/{criterion/inspection.rb → criteria/inspectable.rb} +2 -2
- data/lib/mongoid/{criterion → criteria}/marshalable.rb +3 -1
- data/lib/mongoid/{criterion → criteria}/modifiable.rb +1 -1
- data/lib/mongoid/{criterion/scoping.rb → criteria/scopable.rb} +2 -2
- data/lib/mongoid/document.rb +28 -12
- data/lib/mongoid/errors.rb +1 -1
- data/lib/mongoid/errors/document_not_found.rb +2 -1
- data/lib/mongoid/errors/invalid_value.rb +16 -0
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/extensions.rb +2 -7
- data/lib/mongoid/extensions/array.rb +2 -2
- data/lib/mongoid/extensions/boolean.rb +14 -17
- data/lib/mongoid/extensions/float.rb +1 -0
- data/lib/mongoid/extensions/hash.rb +1 -1
- data/lib/mongoid/extensions/object.rb +4 -4
- data/lib/mongoid/extensions/object_id.rb +5 -5
- data/lib/mongoid/extensions/range.rb +8 -2
- data/lib/mongoid/extensions/string.rb +5 -17
- data/lib/mongoid/extensions/time.rb +2 -2
- data/lib/mongoid/factory.rb +3 -3
- data/lib/mongoid/fields.rb +9 -8
- data/lib/mongoid/fields/foreign_key.rb +3 -3
- data/lib/mongoid/fields/standard.rb +4 -16
- data/lib/mongoid/fields/validators/macro.rb +11 -3
- data/lib/mongoid/{finders.rb → findable.rb} +6 -2
- data/lib/mongoid/{indexes.rb → indexable.rb} +50 -55
- data/lib/mongoid/indexable/specification.rb +104 -0
- data/lib/mongoid/{indexes → indexable}/validators/options.rb +2 -1
- data/lib/mongoid/{inspection.rb → inspectable.rb} +15 -11
- data/lib/mongoid/{callbacks.rb → interceptable.rb} +3 -52
- data/lib/mongoid/log_subscriber.rb +22 -0
- data/lib/mongoid/matchable.rb +152 -0
- data/lib/mongoid/{matchers → matchable}/all.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/and.rb +2 -2
- data/lib/mongoid/{matchers → matchable}/default.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/exists.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/gt.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/gte.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/in.rb +2 -2
- data/lib/mongoid/{matchers → matchable}/lt.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/lte.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/ne.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/nin.rb +3 -2
- data/lib/mongoid/{matchers → matchable}/or.rb +2 -2
- data/lib/mongoid/{matchers → matchable}/size.rb +1 -1
- data/lib/mongoid/persistable.rb +212 -0
- data/lib/mongoid/persistable/creatable.rb +188 -0
- data/lib/mongoid/persistable/deletable.rb +148 -0
- data/lib/mongoid/persistable/destroyable.rb +55 -0
- data/lib/mongoid/persistable/incrementable.rb +36 -0
- data/lib/mongoid/persistable/logical.rb +38 -0
- data/lib/mongoid/persistable/poppable.rb +39 -0
- data/lib/mongoid/persistable/pullable.rb +55 -0
- data/lib/mongoid/persistable/pushable.rb +62 -0
- data/lib/mongoid/persistable/renamable.rb +35 -0
- data/lib/mongoid/persistable/savable.rb +52 -0
- data/lib/mongoid/persistable/settable.rb +33 -0
- data/lib/mongoid/persistable/unsettable.rb +36 -0
- data/lib/mongoid/persistable/updatable.rb +151 -0
- data/lib/mongoid/persistable/upsertable.rb +55 -0
- data/lib/mongoid/positional.rb +71 -0
- data/lib/mongoid/railtie.rb +32 -45
- data/lib/mongoid/railties/database.rake +12 -6
- data/lib/mongoid/relations.rb +3 -3
- data/lib/mongoid/relations/accessors.rb +13 -46
- data/lib/mongoid/relations/auto_save.rb +15 -36
- data/lib/mongoid/relations/binding.rb +0 -23
- data/lib/mongoid/relations/bindings/embedded/many.rb +1 -3
- data/lib/mongoid/relations/bindings/referenced/in.rb +3 -8
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +3 -1
- data/lib/mongoid/relations/builder.rb +1 -1
- data/lib/mongoid/relations/builders.rb +2 -2
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +10 -13
- data/lib/mongoid/relations/builders/nested_attributes/one.rb +4 -5
- data/lib/mongoid/relations/builders/referenced/in.rb +1 -1
- data/lib/mongoid/relations/builders/referenced/many.rb +1 -2
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +1 -2
- data/lib/mongoid/relations/builders/referenced/one.rb +1 -1
- data/lib/mongoid/relations/cascading.rb +3 -5
- data/lib/mongoid/relations/constraint.rb +1 -1
- data/lib/mongoid/relations/conversions.rb +1 -1
- data/lib/mongoid/relations/counter_cache.rb +39 -15
- data/lib/mongoid/relations/eager.rb +47 -0
- data/lib/mongoid/relations/eager/base.rb +57 -0
- data/lib/mongoid/relations/eager/belongs_to.rb +30 -0
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +40 -0
- data/lib/mongoid/relations/eager/has_many.rb +37 -0
- data/lib/mongoid/relations/eager/has_one.rb +29 -0
- data/lib/mongoid/relations/embedded/batchable.rb +3 -4
- data/lib/mongoid/relations/embedded/many.rb +7 -27
- data/lib/mongoid/relations/macros.rb +2 -4
- data/lib/mongoid/relations/many.rb +30 -31
- data/lib/mongoid/relations/metadata.rb +6 -75
- data/lib/mongoid/relations/nested_builder.rb +2 -2
- data/lib/mongoid/relations/options.rb +1 -0
- data/lib/mongoid/relations/polymorphic.rb +0 -1
- data/lib/mongoid/relations/proxy.rb +10 -32
- data/lib/mongoid/relations/referenced/in.rb +2 -18
- data/lib/mongoid/relations/referenced/many.rb +9 -22
- data/lib/mongoid/relations/referenced/many_to_many.rb +10 -33
- data/lib/mongoid/relations/referenced/one.rb +2 -21
- data/lib/mongoid/relations/synchronization.rb +3 -3
- data/lib/mongoid/relations/touchable.rb +33 -0
- data/lib/mongoid/{reloading.rb → reloadable.rb} +6 -4
- data/lib/mongoid/{scoping.rb → scopable.rb} +26 -3
- data/lib/mongoid/selectable.rb +59 -0
- data/lib/mongoid/{serialization.rb → serializable.rb} +10 -1
- data/lib/mongoid/sessions.rb +37 -345
- data/lib/mongoid/sessions/factory.rb +2 -0
- data/lib/mongoid/sessions/options.rb +176 -0
- data/lib/mongoid/sessions/storage_options.rb +140 -0
- data/lib/mongoid/sessions/thread_options.rb +19 -0
- data/lib/mongoid/sessions/validators/storage.rb +15 -1
- data/lib/mongoid/{sharding.rb → shardable.rb} +5 -1
- data/lib/mongoid/support/query_counter.rb +23 -0
- data/lib/mongoid/threaded.rb +0 -110
- data/lib/mongoid/threaded/lifecycle.rb +0 -28
- data/lib/mongoid/timestamps/updated/short.rb +2 -2
- data/lib/mongoid/{hierarchy.rb → traversable.rb} +9 -5
- data/lib/mongoid/{validations.rb → validatable.rb} +23 -9
- data/lib/mongoid/{validations → validatable}/associated.rb +3 -1
- data/lib/mongoid/{validations → validatable}/format.rb +1 -1
- data/lib/mongoid/{validations → validatable}/length.rb +1 -1
- data/lib/mongoid/{validations → validatable}/localizable.rb +1 -1
- data/lib/mongoid/{validations → validatable}/macros.rb +4 -3
- data/lib/mongoid/{validations → validatable}/presence.rb +1 -1
- data/lib/mongoid/{validations → validatable}/queryable.rb +1 -2
- data/lib/mongoid/{validations → validatable}/uniqueness.rb +3 -3
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +9 -13
- data/lib/rails/generators/mongoid/model/model_generator.rb +0 -1
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +0 -3
- data/lib/rails/generators/mongoid_generator.rb +3 -40
- data/lib/rails/mongoid.rb +59 -57
- data/lib/support/ruby_version.rb +1 -1
- data/spec/app/models/account.rb +2 -6
- data/spec/app/models/acolyte.rb +1 -0
- data/spec/app/models/actor.rb +0 -1
- data/spec/app/models/address.rb +6 -1
- data/spec/app/models/animal.rb +1 -1
- data/spec/app/models/appointment.rb +2 -2
- data/spec/app/models/article.rb +1 -4
- data/spec/app/models/audio.rb +5 -0
- data/spec/app/models/author.rb +0 -2
- data/spec/app/models/band.rb +3 -2
- data/spec/app/models/bar.rb +1 -0
- data/spec/app/models/book.rb +1 -0
- data/spec/app/models/building.rb +0 -2
- data/spec/app/models/building_address.rb +0 -2
- data/spec/app/models/bus.rb +1 -1
- data/spec/app/models/canvas.rb +1 -1
- data/spec/app/models/contractor.rb +0 -2
- data/spec/app/models/country_code.rb +1 -1
- data/spec/app/models/definition.rb +2 -2
- data/spec/app/models/dragon.rb +4 -0
- data/spec/app/models/drug.rb +1 -3
- data/spec/app/models/dungeon.rb +4 -0
- data/spec/app/models/filesystem.rb +1 -0
- data/spec/app/models/fish.rb +0 -1
- data/spec/app/models/fruits.rb +6 -0
- data/spec/app/models/game.rb +0 -2
- data/spec/app/models/house.rb +0 -2
- data/spec/app/models/item.rb +1 -5
- data/spec/app/models/jar.rb +1 -1
- data/spec/app/models/label.rb +4 -4
- data/spec/app/models/login.rb +1 -1
- data/spec/app/models/movie.rb +1 -0
- data/spec/app/models/name.rb +3 -3
- data/spec/app/models/note.rb +1 -1
- data/spec/app/models/oscar.rb +1 -1
- data/spec/app/models/parent_doc.rb +1 -1
- data/spec/app/models/person.rb +13 -8
- data/spec/app/models/phone.rb +1 -3
- data/spec/app/models/player.rb +1 -1
- data/spec/app/models/post.rb +2 -1
- data/spec/app/models/quiz.rb +0 -3
- data/spec/app/models/record.rb +5 -5
- data/spec/app/models/registry.rb +1 -1
- data/spec/app/models/server.rb +1 -1
- data/spec/app/models/service.rb +3 -3
- data/spec/app/models/sound.rb +5 -0
- data/spec/app/models/template.rb +1 -1
- data/spec/app/models/title.rb +0 -1
- data/spec/app/models/track.rb +5 -5
- data/spec/app/models/tree.rb +1 -1
- data/spec/app/models/video.rb +0 -4
- data/spec/app/models/wiki_page.rb +1 -4
- data/spec/app/models/word.rb +3 -0
- data/spec/app/models/word_origin.rb +1 -1
- data/spec/config/mongoid.yml +7 -8
- data/spec/helpers.rb +18 -0
- data/spec/mongoid/atomic/modifiers_spec.rb +22 -22
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +8 -49
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +7 -49
- data/spec/mongoid/atomic/paths/root_spec.rb +3 -61
- data/spec/mongoid/atomic/paths_spec.rb +19 -19
- data/spec/mongoid/atomic_spec.rb +19 -19
- data/spec/mongoid/{nested_attributes_spec.rb → attributes/nested_spec.rb} +335 -448
- data/spec/mongoid/attributes/readonly_spec.rb +16 -16
- data/spec/mongoid/attributes_spec.rb +188 -434
- data/spec/mongoid/{dirty_spec.rb → changeable_spec.rb} +117 -148
- data/spec/mongoid/{components_spec.rb → composable_spec.rb} +3 -3
- data/spec/mongoid/config/environment_spec.rb +3 -3
- data/spec/mongoid/config/options_spec.rb +6 -6
- data/spec/mongoid/config_spec.rb +24 -48
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +12 -12
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +46 -38
- data/spec/mongoid/contextual/atomic_spec.rb +60 -56
- data/spec/mongoid/contextual/find_and_modify_spec.rb +14 -14
- data/spec/mongoid/contextual/geo_near_spec.rb +22 -22
- data/spec/mongoid/contextual/map_reduce_spec.rb +27 -27
- data/spec/mongoid/contextual/memory_spec.rb +94 -94
- data/spec/mongoid/contextual/mongo_spec.rb +225 -139
- data/spec/mongoid/contextual/text_search_spec.rb +207 -0
- data/spec/mongoid/copyable_spec.rb +56 -68
- data/spec/mongoid/criteria/findable_spec.rb +991 -0
- data/spec/mongoid/{criterion/inspection_spec.rb → criteria/inspectable_spec.rb} +5 -5
- data/spec/mongoid/{criterion → criteria}/marshalable_spec.rb +2 -2
- data/spec/mongoid/criteria/modifiable_spec.rb +1063 -0
- data/spec/mongoid/{criterion/scoping_spec.rb → criteria/scopable_spec.rb} +31 -31
- data/spec/mongoid/criteria_spec.rb +530 -2207
- data/spec/mongoid/document_spec.rb +166 -120
- data/spec/mongoid/equality_spec.rb +22 -22
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +3 -3
- data/spec/mongoid/errors/callback_spec.rb +3 -3
- data/spec/mongoid/errors/delete_restriction_spec.rb +3 -3
- data/spec/mongoid/errors/document_not_found_spec.rb +11 -11
- data/spec/mongoid/errors/eager_load_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_collection_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_config_option_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_field_option_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_field_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_find_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_includes_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_index_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_options_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_path_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_scope_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_time_spec.rb +3 -3
- data/spec/mongoid/errors/inverse_not_found_spec.rb +3 -3
- data/spec/mongoid/errors/mixed_relations_spec.rb +3 -3
- data/spec/mongoid/errors/mixed_session_configuration_spec.rb +3 -3
- data/spec/mongoid/errors/mongoid_error_spec.rb +7 -7
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +3 -3
- data/spec/mongoid/errors/no_environment_spec.rb +3 -3
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +3 -3
- data/spec/mongoid/errors/no_metadata_spec.rb +3 -3
- data/spec/mongoid/errors/no_parent_spec.rb +3 -3
- data/spec/mongoid/errors/no_session_config_spec.rb +3 -3
- data/spec/mongoid/errors/no_session_database_spec.rb +3 -3
- data/spec/mongoid/errors/no_session_hosts_spec.rb +3 -3
- data/spec/mongoid/errors/no_sessions_config_spec.rb +3 -3
- data/spec/mongoid/errors/readonly_attribute_spec.rb +3 -3
- data/spec/mongoid/errors/scope_overwrite_spec.rb +3 -3
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +3 -3
- data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -5
- data/spec/mongoid/errors/unsaved_document_spec.rb +3 -3
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +3 -3
- data/spec/mongoid/errors/validations_spec.rb +7 -7
- data/spec/mongoid/extensions/array_spec.rb +61 -61
- data/spec/mongoid/extensions/big_decimal_spec.rb +11 -11
- data/spec/mongoid/extensions/binary_spec.rb +12 -12
- data/spec/mongoid/extensions/boolean_spec.rb +18 -18
- data/spec/mongoid/extensions/date_spec.rb +13 -13
- data/spec/mongoid/extensions/date_time_spec.rb +9 -9
- data/spec/mongoid/extensions/false_class_spec.rb +5 -5
- data/spec/mongoid/extensions/float_spec.rb +29 -15
- data/spec/mongoid/extensions/hash_spec.rb +29 -29
- data/spec/mongoid/extensions/integer_spec.rb +15 -15
- data/spec/mongoid/extensions/module_spec.rb +2 -2
- data/spec/mongoid/extensions/nil_class_spec.rb +1 -1
- data/spec/mongoid/extensions/object_id_spec.rb +134 -134
- data/spec/mongoid/extensions/object_spec.rb +26 -26
- data/spec/mongoid/extensions/range_spec.rb +61 -12
- data/spec/mongoid/extensions/regexp_spec.rb +4 -4
- data/spec/mongoid/extensions/set_spec.rb +4 -4
- data/spec/mongoid/extensions/string_spec.rb +35 -46
- data/spec/mongoid/extensions/symbol_spec.rb +9 -9
- data/spec/mongoid/extensions/time_spec.rb +49 -49
- data/spec/mongoid/extensions/time_with_zone_spec.rb +34 -34
- data/spec/mongoid/extensions/true_class_spec.rb +5 -5
- data/spec/mongoid/extensions_spec.rb +15 -0
- data/spec/mongoid/factory_spec.rb +15 -15
- data/spec/mongoid/fields/foreign_key_spec.rb +73 -66
- data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +15 -15
- data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +22 -22
- data/spec/mongoid/fields/localized_spec.rb +23 -23
- data/spec/mongoid/fields/standard_spec.rb +12 -12
- data/spec/mongoid/fields_spec.rb +168 -209
- data/spec/mongoid/{finders_spec.rb → findable_spec.rb} +62 -27
- data/spec/mongoid/indexable/specification_spec.rb +102 -0
- data/spec/mongoid/{indexes_spec.rb → indexable_spec.rb} +171 -51
- data/spec/mongoid/{inspection_spec.rb → inspectable_spec.rb} +6 -14
- data/spec/mongoid/{callbacks_spec.rb → interceptable_spec.rb} +105 -105
- data/spec/mongoid/log_subscriber_spec.rb +74 -0
- data/spec/mongoid/loggable_spec.rb +1 -1
- data/spec/mongoid/{matchers → matchable}/all_spec.rb +4 -4
- data/spec/mongoid/{matchers → matchable}/and_spec.rb +11 -11
- data/spec/mongoid/{matchers → matchable}/default_spec.rb +15 -15
- data/spec/mongoid/{matchers → matchable}/exists_spec.rb +5 -5
- data/spec/mongoid/{matchers → matchable}/gt_spec.rb +9 -8
- data/spec/mongoid/{matchers → matchable}/gte_spec.rb +7 -7
- data/spec/mongoid/matchable/in_spec.rb +49 -0
- data/spec/mongoid/{matchers → matchable}/lt_spec.rb +7 -7
- data/spec/mongoid/{matchers → matchable}/lte_spec.rb +7 -7
- data/spec/mongoid/{matchers → matchable}/ne_spec.rb +3 -3
- data/spec/mongoid/matchable/nin_spec.rb +48 -0
- data/spec/mongoid/{matchers → matchable}/or_spec.rb +6 -6
- data/spec/mongoid/{matchers → matchable}/size_spec.rb +3 -3
- data/spec/mongoid/{matchers_spec.rb → matchable_spec.rb} +41 -41
- data/spec/mongoid/persistable/creatable_spec.rb +512 -0
- data/spec/mongoid/persistable/deletable_spec.rb +205 -0
- data/spec/mongoid/persistable/destroyable_spec.rb +148 -0
- data/spec/mongoid/persistable/incrementable_spec.rb +173 -0
- data/spec/mongoid/persistable/logical_spec.rb +143 -0
- data/spec/mongoid/persistable/poppable_spec.rb +115 -0
- data/spec/mongoid/persistable/pullable_spec.rb +228 -0
- data/spec/mongoid/persistable/pushable_spec.rb +258 -0
- data/spec/mongoid/persistable/renamable_spec.rb +135 -0
- data/spec/mongoid/persistable/savable_spec.rb +432 -0
- data/spec/mongoid/persistable/settable_spec.rb +139 -0
- data/spec/mongoid/persistable/unsettable_spec.rb +155 -0
- data/spec/mongoid/persistable/updatable_spec.rb +558 -0
- data/spec/mongoid/persistable/upsertable_spec.rb +106 -0
- data/spec/mongoid/persistable_spec.rb +206 -0
- data/spec/mongoid/{atomic/positionable_spec.rb → positional_spec.rb} +19 -14
- data/spec/mongoid/railties/document_spec.rb +2 -2
- data/spec/mongoid/relations/accessors_spec.rb +53 -145
- data/spec/mongoid/relations/auto_save_spec.rb +36 -16
- data/spec/mongoid/relations/bindings/embedded/in_spec.rb +6 -6
- data/spec/mongoid/relations/bindings/embedded/many_spec.rb +2 -2
- data/spec/mongoid/relations/bindings/embedded/one_spec.rb +3 -3
- data/spec/mongoid/relations/bindings/referenced/in_spec.rb +12 -12
- data/spec/mongoid/relations/bindings/referenced/many_spec.rb +6 -6
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +9 -9
- data/spec/mongoid/relations/bindings/referenced/one_spec.rb +6 -6
- data/spec/mongoid/relations/builders/embedded/in_spec.rb +4 -4
- data/spec/mongoid/relations/builders/embedded/many_spec.rb +18 -18
- data/spec/mongoid/relations/builders/embedded/one_spec.rb +11 -11
- data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +12 -13
- data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +14 -14
- data/spec/mongoid/relations/builders/referenced/in_spec.rb +22 -33
- data/spec/mongoid/relations/builders/referenced/many_spec.rb +15 -15
- data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +18 -18
- data/spec/mongoid/relations/builders/referenced/one_spec.rb +11 -24
- data/spec/mongoid/relations/builders_spec.rb +21 -21
- data/spec/mongoid/relations/cascading/delete_spec.rb +7 -7
- data/spec/mongoid/relations/cascading/destroy_spec.rb +2 -2
- data/spec/mongoid/relations/cascading/nullify_spec.rb +2 -2
- data/spec/mongoid/relations/cascading/restrict_spec.rb +3 -3
- data/spec/mongoid/relations/cascading_spec.rb +16 -16
- data/spec/mongoid/relations/constraint_spec.rb +8 -7
- data/spec/mongoid/relations/conversions_spec.rb +16 -14
- data/spec/mongoid/relations/counter_cache_spec.rb +85 -0
- data/spec/mongoid/relations/cyclic_spec.rb +18 -18
- data/spec/mongoid/relations/eager/belongs_to_spec.rb +154 -0
- data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +143 -0
- data/spec/mongoid/relations/eager/has_many_spec.rb +207 -0
- data/spec/mongoid/relations/eager/has_one_spec.rb +163 -0
- data/spec/mongoid/relations/eager_spec.rb +228 -0
- data/spec/mongoid/relations/embedded/dirty_spec.rb +8 -8
- data/spec/mongoid/relations/embedded/in_spec.rb +55 -56
- data/spec/mongoid/relations/embedded/many_spec.rb +357 -367
- data/spec/mongoid/relations/embedded/one_spec.rb +98 -139
- data/spec/mongoid/relations/macros_spec.rb +108 -102
- data/spec/mongoid/relations/metadata_spec.rb +147 -241
- data/spec/mongoid/relations/options_spec.rb +1 -1
- data/spec/mongoid/relations/polymorphic_spec.rb +13 -17
- data/spec/mongoid/relations/proxy_spec.rb +2 -2
- data/spec/mongoid/relations/referenced/in_spec.rb +128 -303
- data/spec/mongoid/relations/referenced/many_spec.rb +379 -522
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +345 -417
- data/spec/mongoid/relations/referenced/one_spec.rb +148 -263
- data/spec/mongoid/relations/reflections_spec.rb +6 -6
- data/spec/mongoid/relations/synchronization_spec.rb +46 -50
- data/spec/mongoid/relations/targets/enumerable_spec.rb +116 -116
- data/spec/mongoid/relations/touchable_spec.rb +296 -0
- data/spec/mongoid/relations_spec.rb +16 -15
- data/spec/mongoid/{reloading_spec.rb → reloadable_spec.rb} +20 -60
- data/spec/mongoid/{scoping_spec.rb → scopable_spec.rb} +74 -126
- data/spec/mongoid/selectable_spec.rb +134 -0
- data/spec/mongoid/{serialization_spec.rb → serializable_spec.rb} +111 -82
- data/spec/mongoid/sessions/factory_spec.rb +49 -28
- data/spec/mongoid/sessions/mongo_uri_spec.rb +7 -7
- data/spec/mongoid/sessions/options_spec.rb +92 -0
- data/spec/mongoid/sessions_spec.rb +288 -177
- data/spec/mongoid/{sharding_spec.rb → shardable_spec.rb} +8 -8
- data/spec/mongoid/state_spec.rb +10 -10
- data/spec/mongoid/threaded_spec.rb +17 -70
- data/spec/mongoid/timestamps/created/short_spec.rb +6 -6
- data/spec/mongoid/timestamps/created_spec.rb +5 -5
- data/spec/mongoid/timestamps/updated/short_spec.rb +10 -10
- data/spec/mongoid/timestamps/updated_spec.rb +8 -12
- data/spec/mongoid/timestamps_spec.rb +7 -11
- data/spec/mongoid/{hierarchy_spec.rb → traversable_spec.rb} +19 -19
- data/spec/mongoid/{validations → validatable}/associated_spec.rb +18 -18
- data/spec/mongoid/{validations → validatable}/format_spec.rb +6 -6
- data/spec/mongoid/{validations → validatable}/length_spec.rb +7 -7
- data/spec/mongoid/{validations → validatable}/numericality_spec.rb +1 -1
- data/spec/mongoid/{validations → validatable}/presence_spec.rb +31 -38
- data/spec/mongoid/{validations → validatable}/uniqueness_spec.rb +126 -183
- data/spec/mongoid/{validations_spec.rb → validatable_spec.rb} +28 -28
- data/spec/mongoid_spec.rb +8 -8
- data/spec/rails/mongoid_spec.rb +72 -87
- data/spec/spec_helper.rb +19 -17
- metadata +261 -283
- data/lib/mongoid/atomic/positionable.rb +0 -73
- data/lib/mongoid/components.rb +0 -92
- data/lib/mongoid/config/inflections.rb +0 -6
- data/lib/mongoid/contextual/eager.rb +0 -158
- data/lib/mongoid/criterion/findable.rb +0 -179
- data/lib/mongoid/errors/versioning_not_on_root.rb +0 -23
- data/lib/mongoid/identity_map.rb +0 -163
- data/lib/mongoid/json.rb +0 -16
- data/lib/mongoid/matchers.rb +0 -32
- data/lib/mongoid/matchers/strategies.rb +0 -97
- data/lib/mongoid/multi_parameter_attributes.rb +0 -105
- data/lib/mongoid/nested_attributes.rb +0 -78
- data/lib/mongoid/observer.rb +0 -192
- data/lib/mongoid/paranoia.rb +0 -136
- data/lib/mongoid/persistence.rb +0 -357
- data/lib/mongoid/persistence/atomic.rb +0 -231
- data/lib/mongoid/persistence/atomic/add_to_set.rb +0 -47
- data/lib/mongoid/persistence/atomic/bit.rb +0 -35
- data/lib/mongoid/persistence/atomic/inc.rb +0 -45
- data/lib/mongoid/persistence/atomic/operation.rb +0 -154
- data/lib/mongoid/persistence/atomic/pop.rb +0 -32
- data/lib/mongoid/persistence/atomic/pull.rb +0 -32
- data/lib/mongoid/persistence/atomic/pull_all.rb +0 -32
- data/lib/mongoid/persistence/atomic/push.rb +0 -25
- data/lib/mongoid/persistence/atomic/push_all.rb +0 -25
- data/lib/mongoid/persistence/atomic/rename.rb +0 -30
- data/lib/mongoid/persistence/atomic/sets.rb +0 -28
- data/lib/mongoid/persistence/atomic/unset.rb +0 -27
- data/lib/mongoid/persistence/deletion.rb +0 -31
- data/lib/mongoid/persistence/insertion.rb +0 -38
- data/lib/mongoid/persistence/modification.rb +0 -35
- data/lib/mongoid/persistence/operations.rb +0 -214
- data/lib/mongoid/persistence/operations/embedded/insert.rb +0 -46
- data/lib/mongoid/persistence/operations/embedded/remove.rb +0 -43
- data/lib/mongoid/persistence/operations/insert.rb +0 -34
- data/lib/mongoid/persistence/operations/remove.rb +0 -33
- data/lib/mongoid/persistence/operations/update.rb +0 -59
- data/lib/mongoid/persistence/operations/upsert.rb +0 -28
- data/lib/mongoid/persistence/upsertion.rb +0 -31
- data/lib/mongoid/unit_of_work.rb +0 -61
- data/lib/mongoid/versioning.rb +0 -217
- data/lib/rack/mongoid.rb +0 -2
- data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
- data/lib/rails/generators/mongoid/observer/observer_generator.rb +0 -17
- data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +0 -4
- data/spec/app/models/actor_observer.rb +0 -15
- data/spec/app/models/callback_recorder.rb +0 -25
- data/spec/app/models/draft.rb +0 -9
- data/spec/app/models/paranoid_phone.rb +0 -25
- data/spec/app/models/paranoid_post.rb +0 -36
- data/spec/app/models/phone_observer.rb +0 -6
- data/spec/mongoid/#atomic_spec.rb# +0 -365
- data/spec/mongoid/attributes/processing_spec.rb +0 -149
- data/spec/mongoid/criterion/destructive_spec.rb +0 -101
- data/spec/mongoid/criterion/modifiable_spec.rb +0 -409
- data/spec/mongoid/criterion/modification_spec.rb +0 -402
- data/spec/mongoid/errors/versioning_not_on_root_spec.rb +0 -29
- data/spec/mongoid/identity_map_spec.rb +0 -564
- data/spec/mongoid/json_spec.rb +0 -33
- data/spec/mongoid/matchers/in_spec.rb +0 -25
- data/spec/mongoid/matchers/nin_spec.rb +0 -25
- data/spec/mongoid/multi_parameter_attributes_spec.rb +0 -128
- data/spec/mongoid/observer_spec.rb +0 -290
- data/spec/mongoid/paranoia_spec.rb +0 -759
- data/spec/mongoid/persistence/atomic/add_to_set_spec.rb +0 -262
- data/spec/mongoid/persistence/atomic/bit_spec.rb +0 -88
- data/spec/mongoid/persistence/atomic/inc_spec.rb +0 -133
- data/spec/mongoid/persistence/atomic/pop_spec.rb +0 -111
- data/spec/mongoid/persistence/atomic/pull_all_spec.rb +0 -77
- data/spec/mongoid/persistence/atomic/pull_spec.rb +0 -80
- data/spec/mongoid/persistence/atomic/push_all_spec.rb +0 -77
- data/spec/mongoid/persistence/atomic/push_spec.rb +0 -77
- data/spec/mongoid/persistence/atomic/rename_spec.rb +0 -42
- data/spec/mongoid/persistence/atomic/sets_spec.rb +0 -154
- data/spec/mongoid/persistence/atomic/unset_spec.rb +0 -65
- data/spec/mongoid/persistence/atomic_spec.rb +0 -216
- data/spec/mongoid/persistence/operations/embedded/insert_spec.rb +0 -191
- data/spec/mongoid/persistence/operations/embedded/remove_spec.rb +0 -8
- data/spec/mongoid/persistence/operations/insert_spec.rb +0 -149
- data/spec/mongoid/persistence/operations/remove_spec.rb +0 -113
- data/spec/mongoid/persistence/operations/update_spec.rb +0 -141
- data/spec/mongoid/persistence/operations/upsert_spec.rb +0 -59
- data/spec/mongoid/persistence/operations_spec.rb +0 -313
- data/spec/mongoid/persistence_spec.rb +0 -2279
- data/spec/mongoid/unit_of_work_spec.rb +0 -196
- data/spec/mongoid/versioning_spec.rb +0 -540
- data/spec/rack/mongoid/middleware/identity_map_spec.rb +0 -72
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Mongoid::
|
3
|
+
describe Mongoid::Criteria::Scopable do
|
4
4
|
|
5
5
|
describe "#apply_default_scope" do
|
6
6
|
|
@@ -25,11 +25,11 @@ describe Mongoid::Criterion::Scoping do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "merges in the options" do
|
28
|
-
scoped.options.
|
28
|
+
expect(scoped.options).to eq({ skip: 20 })
|
29
29
|
end
|
30
30
|
|
31
31
|
it "sets scoped to true" do
|
32
|
-
scoped.
|
32
|
+
expect(scoped).to be_scoped
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -54,11 +54,11 @@ describe Mongoid::Criterion::Scoping do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it "merges in the options" do
|
57
|
-
scoped.selector.
|
57
|
+
expect(scoped.selector).to eq({ "name" => "Depeche Mode" })
|
58
58
|
end
|
59
59
|
|
60
60
|
it "sets scoped to true" do
|
61
|
-
scoped.
|
61
|
+
expect(scoped).to be_scoped
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -85,13 +85,13 @@ describe Mongoid::Criterion::Scoping do
|
|
85
85
|
end
|
86
86
|
|
87
87
|
it "merges in the inclusions" do
|
88
|
-
scoped.inclusions.
|
88
|
+
expect(scoped.inclusions).to eq(
|
89
89
|
[ Band.relations["records"] ]
|
90
90
|
)
|
91
91
|
end
|
92
92
|
|
93
93
|
it "sets scoped to true" do
|
94
|
-
scoped.
|
94
|
+
expect(scoped).to be_scoped
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -104,13 +104,13 @@ describe Mongoid::Criterion::Scoping do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
it "merges in the inclusions" do
|
107
|
-
scoped.inclusions.
|
107
|
+
expect(scoped.inclusions).to eq(
|
108
108
|
[ Band.relations["records"], Band.relations["label"] ]
|
109
109
|
)
|
110
110
|
end
|
111
111
|
|
112
112
|
it "sets scoped to true" do
|
113
|
-
scoped.
|
113
|
+
expect(scoped).to be_scoped
|
114
114
|
end
|
115
115
|
end
|
116
116
|
end
|
@@ -129,7 +129,7 @@ describe Mongoid::Criterion::Scoping do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
it "removes the selection" do
|
132
|
-
criteria.selector.
|
132
|
+
expect(criteria.selector).to be_empty
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
@@ -146,7 +146,7 @@ describe Mongoid::Criterion::Scoping do
|
|
146
146
|
end
|
147
147
|
|
148
148
|
it "removes the options" do
|
149
|
-
criteria.options.
|
149
|
+
expect(criteria.options).to be_empty
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -161,11 +161,11 @@ describe Mongoid::Criterion::Scoping do
|
|
161
161
|
end
|
162
162
|
|
163
163
|
it "removes the options" do
|
164
|
-
criteria.options.
|
164
|
+
expect(criteria.options).to be_empty
|
165
165
|
end
|
166
166
|
|
167
167
|
it "does not remove the selector" do
|
168
|
-
criteria.selector.
|
168
|
+
expect(criteria.selector).to eq({ "name" => nil })
|
169
169
|
end
|
170
170
|
end
|
171
171
|
end
|
@@ -185,7 +185,7 @@ describe Mongoid::Criterion::Scoping do
|
|
185
185
|
end
|
186
186
|
|
187
187
|
it "removes the matching inclusions" do
|
188
|
-
criteria.inclusions.
|
188
|
+
expect(criteria.inclusions).to eq([ Band.relations["records"] ])
|
189
189
|
end
|
190
190
|
end
|
191
191
|
end
|
@@ -203,15 +203,15 @@ describe Mongoid::Criterion::Scoping do
|
|
203
203
|
end
|
204
204
|
|
205
205
|
it "returns a criteria" do
|
206
|
-
scoped.
|
206
|
+
expect(scoped).to be_a(Mongoid::Criteria)
|
207
207
|
end
|
208
208
|
|
209
209
|
it "contains an empty selector" do
|
210
|
-
scoped.selector.
|
210
|
+
expect(scoped.selector).to be_empty
|
211
211
|
end
|
212
212
|
|
213
213
|
it "contains empty options" do
|
214
|
-
scoped.options.
|
214
|
+
expect(scoped.options).to be_empty
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
@@ -222,15 +222,15 @@ describe Mongoid::Criterion::Scoping do
|
|
222
222
|
end
|
223
223
|
|
224
224
|
it "returns a criteria" do
|
225
|
-
scoped.
|
225
|
+
expect(scoped).to be_a(Mongoid::Criteria)
|
226
226
|
end
|
227
227
|
|
228
228
|
it "contains an empty selector" do
|
229
|
-
scoped.selector.
|
229
|
+
expect(scoped.selector).to be_empty
|
230
230
|
end
|
231
231
|
|
232
232
|
it "contains the options" do
|
233
|
-
scoped.options.
|
233
|
+
expect(scoped.options).to eq({ skip: 10, limit: 10 })
|
234
234
|
end
|
235
235
|
end
|
236
236
|
|
@@ -253,11 +253,11 @@ describe Mongoid::Criterion::Scoping do
|
|
253
253
|
end
|
254
254
|
|
255
255
|
it "allows the default scope to be added" do
|
256
|
-
scoped.selector.
|
256
|
+
expect(scoped.selector).to eq({ "name" => "Depeche Mode" })
|
257
257
|
end
|
258
258
|
|
259
259
|
it "flags as scoped" do
|
260
|
-
scoped.
|
260
|
+
expect(scoped).to be_scoped
|
261
261
|
end
|
262
262
|
|
263
263
|
context "when chained after an unscoped criteria" do
|
@@ -267,7 +267,7 @@ describe Mongoid::Criterion::Scoping do
|
|
267
267
|
end
|
268
268
|
|
269
269
|
it "reapplies the default scope" do
|
270
|
-
scoped.selector.
|
270
|
+
expect(scoped.selector).to eq({ "name" => "Depeche Mode" })
|
271
271
|
end
|
272
272
|
end
|
273
273
|
end
|
@@ -284,7 +284,7 @@ describe Mongoid::Criterion::Scoping do
|
|
284
284
|
end
|
285
285
|
|
286
286
|
it "returns the scoping options" do
|
287
|
-
criteria.scoping_options.
|
287
|
+
expect(criteria.scoping_options).to eq([ true, false ])
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
@@ -299,11 +299,11 @@ describe Mongoid::Criterion::Scoping do
|
|
299
299
|
end
|
300
300
|
|
301
301
|
it "sets the scoped flag" do
|
302
|
-
criteria.
|
302
|
+
expect(criteria).to be_scoped
|
303
303
|
end
|
304
304
|
|
305
305
|
it "sets the unscoped flag" do
|
306
|
-
criteria.
|
306
|
+
expect(criteria).to be_unscoped
|
307
307
|
end
|
308
308
|
end
|
309
309
|
|
@@ -332,7 +332,7 @@ describe Mongoid::Criterion::Scoping do
|
|
332
332
|
end
|
333
333
|
|
334
334
|
it "removes the default scope from the criteria" do
|
335
|
-
unscoped.selector.
|
335
|
+
expect(unscoped.selector).to be_empty
|
336
336
|
end
|
337
337
|
|
338
338
|
context "when chained after a scoped criteria" do
|
@@ -342,7 +342,7 @@ describe Mongoid::Criterion::Scoping do
|
|
342
342
|
end
|
343
343
|
|
344
344
|
it "removes all scoping" do
|
345
|
-
unscoped.selector.
|
345
|
+
expect(unscoped.selector).to be_empty
|
346
346
|
end
|
347
347
|
end
|
348
348
|
end
|
@@ -353,7 +353,7 @@ describe Mongoid::Criterion::Scoping do
|
|
353
353
|
|
354
354
|
it "does not allow default scoping to be added in the block" do
|
355
355
|
Band.unscoped do
|
356
|
-
empty.skip(10).selector.
|
356
|
+
expect(empty.skip(10).selector).to be_empty
|
357
357
|
end
|
358
358
|
end
|
359
359
|
end
|
@@ -362,7 +362,7 @@ describe Mongoid::Criterion::Scoping do
|
|
362
362
|
|
363
363
|
it "does not allow default scoping to be added in the block" do
|
364
364
|
Band.unscoped do
|
365
|
-
empty.scoped.selector.
|
365
|
+
expect(empty.scoped.selector).to be_empty
|
366
366
|
end
|
367
367
|
end
|
368
368
|
end
|
@@ -382,7 +382,7 @@ describe Mongoid::Criterion::Scoping do
|
|
382
382
|
|
383
383
|
it "does not allow the default scope to be applied" do
|
384
384
|
Band.unscoped do
|
385
|
-
empty.skipped.selector.
|
385
|
+
expect(empty.skipped.selector).to be_empty
|
386
386
|
end
|
387
387
|
end
|
388
388
|
end
|
@@ -17,7 +17,7 @@ describe Mongoid::Criteria do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "returns true" do
|
20
|
-
criteria.
|
20
|
+
expect(criteria).to eq(other)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -28,7 +28,7 @@ describe Mongoid::Criteria do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "returns false" do
|
31
|
-
criteria.
|
31
|
+
expect(criteria).to_not eq(other)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -46,7 +46,7 @@ describe Mongoid::Criteria do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "returns true" do
|
49
|
-
criteria.
|
49
|
+
expect(criteria).to eq(other)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -65,7 +65,7 @@ describe Mongoid::Criteria do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
it "returns false" do
|
68
|
-
criteria.
|
68
|
+
expect(criteria).to_not eq(other)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -73,7 +73,7 @@ describe Mongoid::Criteria do
|
|
73
73
|
context "when the other is neither a criteria or enumerable" do
|
74
74
|
|
75
75
|
it "returns false" do
|
76
|
-
criteria.
|
76
|
+
expect(criteria).to_not eq("test")
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -87,14 +87,14 @@ describe Mongoid::Criteria do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
it "returns true" do
|
90
|
-
(described_class === other).
|
90
|
+
expect(described_class === other).to be true
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
94
|
context "when the other is not a criteria" do
|
95
95
|
|
96
96
|
it "returns false" do
|
97
|
-
(described_class === []).
|
97
|
+
expect(described_class === []).to be false
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|
@@ -124,7 +124,7 @@ describe Mongoid::Criteria do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
it "returns the sorted documents" do
|
127
|
-
criteria.
|
127
|
+
expect(criteria).to eq([ friedel, hobrecht, pfluger ])
|
128
128
|
end
|
129
129
|
end
|
130
130
|
end
|
@@ -140,11 +140,11 @@ describe Mongoid::Criteria do
|
|
140
140
|
end
|
141
141
|
|
142
142
|
it "adds the batch size option" do
|
143
|
-
criteria.options[:batch_size].
|
143
|
+
expect(criteria.options[:batch_size]).to eq(1000)
|
144
144
|
end
|
145
145
|
|
146
146
|
it "returns the correct documents" do
|
147
|
-
criteria.
|
147
|
+
expect(criteria).to eq([ person ])
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
@@ -169,23 +169,23 @@ describe Mongoid::Criteria do
|
|
169
169
|
end
|
170
170
|
|
171
171
|
it "returns an avg" do
|
172
|
-
aggregates["avg"].
|
172
|
+
expect(aggregates["avg"]).to eq(750)
|
173
173
|
end
|
174
174
|
|
175
175
|
it "returns a count" do
|
176
|
-
aggregates["count"].
|
176
|
+
expect(aggregates["count"]).to eq(2)
|
177
177
|
end
|
178
178
|
|
179
179
|
it "returns a max" do
|
180
|
-
aggregates["max"].
|
180
|
+
expect(aggregates["max"]).to eq(1000)
|
181
181
|
end
|
182
182
|
|
183
183
|
it "returns a min" do
|
184
|
-
aggregates["min"].
|
184
|
+
expect(aggregates["min"]).to eq(500)
|
185
185
|
end
|
186
186
|
|
187
187
|
it "returns a sum" do
|
188
|
-
aggregates["sum"].
|
188
|
+
expect(aggregates["sum"]).to eq(1500)
|
189
189
|
end
|
190
190
|
end
|
191
191
|
end
|
@@ -211,7 +211,7 @@ describe Mongoid::Criteria do
|
|
211
211
|
end
|
212
212
|
|
213
213
|
it "returns the avg of the provided field" do
|
214
|
-
avg.
|
214
|
+
expect(avg).to eq(750)
|
215
215
|
end
|
216
216
|
end
|
217
217
|
end
|
@@ -233,7 +233,7 @@ describe Mongoid::Criteria do
|
|
233
233
|
end
|
234
234
|
|
235
235
|
it "returns the matching documents" do
|
236
|
-
criteria.
|
236
|
+
expect(criteria).to eq([ match ])
|
237
237
|
end
|
238
238
|
end
|
239
239
|
end
|
@@ -255,7 +255,7 @@ describe Mongoid::Criteria do
|
|
255
255
|
end
|
256
256
|
|
257
257
|
it "returns the matching documents" do
|
258
|
-
criteria.
|
258
|
+
expect(criteria).to eq([ match ])
|
259
259
|
end
|
260
260
|
end
|
261
261
|
end
|
@@ -271,7 +271,7 @@ describe Mongoid::Criteria do
|
|
271
271
|
end
|
272
272
|
|
273
273
|
it "returns the criteria as a json hash" do
|
274
|
-
criteria.as_json.
|
274
|
+
expect(criteria.as_json).to eq([ band.serializable_hash ])
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
@@ -290,7 +290,7 @@ describe Mongoid::Criteria do
|
|
290
290
|
end
|
291
291
|
|
292
292
|
it "returns the matching documents" do
|
293
|
-
criteria.
|
293
|
+
expect(criteria).to eq([ match ])
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
@@ -309,15 +309,15 @@ describe Mongoid::Criteria do
|
|
309
309
|
end
|
310
310
|
|
311
311
|
it "returns the new document" do
|
312
|
-
band.
|
312
|
+
expect(band).to be_new_record
|
313
313
|
end
|
314
314
|
|
315
315
|
it "sets the criteria attributes" do
|
316
|
-
band.name.
|
316
|
+
expect(band.name).to eq("Depeche Mode")
|
317
317
|
end
|
318
318
|
|
319
319
|
it "sets the attributes passed to build" do
|
320
|
-
band.genres.
|
320
|
+
expect(band.genres).to eq([ "electro" ])
|
321
321
|
end
|
322
322
|
end
|
323
323
|
|
@@ -330,15 +330,15 @@ describe Mongoid::Criteria do
|
|
330
330
|
end
|
331
331
|
|
332
332
|
it "returns the new document" do
|
333
|
-
band.
|
333
|
+
expect(band).to be_new_record
|
334
334
|
end
|
335
335
|
|
336
336
|
it "sets the criteria attributes" do
|
337
|
-
band.name.
|
337
|
+
expect(band.name).to eq("Depeche Mode")
|
338
338
|
end
|
339
339
|
|
340
340
|
it "sets the attributes passed to build" do
|
341
|
-
band.genres.
|
341
|
+
expect(band.genres).to eq([ "electro" ])
|
342
342
|
end
|
343
343
|
end
|
344
344
|
end
|
@@ -364,7 +364,7 @@ describe Mongoid::Criteria do
|
|
364
364
|
it "does not hit the database after first iteration" do
|
365
365
|
criteria.context.query.should_receive(:each).never
|
366
366
|
criteria.each do |doc|
|
367
|
-
doc.
|
367
|
+
expect(doc).to eq(person)
|
368
368
|
end
|
369
369
|
end
|
370
370
|
end
|
@@ -382,7 +382,7 @@ describe Mongoid::Criteria do
|
|
382
382
|
it "does not hit the database after first iteration" do
|
383
383
|
criteria.context.query.should_receive(:each).never
|
384
384
|
criteria.each do |doc|
|
385
|
-
doc.
|
385
|
+
expect(doc).to eq(person)
|
386
386
|
end
|
387
387
|
end
|
388
388
|
end
|
@@ -410,47 +410,47 @@ describe Mongoid::Criteria do
|
|
410
410
|
end
|
411
411
|
|
412
412
|
it "contains an equal selector" do
|
413
|
-
clone.selector.
|
413
|
+
expect(clone.selector).to eq({ "name" => "Depeche Mode" })
|
414
414
|
end
|
415
415
|
|
416
416
|
it "clones the selector" do
|
417
|
-
clone.selector.
|
417
|
+
expect(clone.selector).to_not equal(criteria.selector)
|
418
418
|
end
|
419
419
|
|
420
420
|
it "contains equal options" do
|
421
|
-
clone.options.
|
421
|
+
expect(clone.options).to eq({ sort: { "name" => 1 }})
|
422
422
|
end
|
423
423
|
|
424
424
|
it "clones the options" do
|
425
|
-
clone.options.
|
425
|
+
expect(clone.options).to_not equal(criteria.options)
|
426
426
|
end
|
427
427
|
|
428
428
|
it "contains equal inclusions" do
|
429
|
-
clone.inclusions.
|
429
|
+
expect(clone.inclusions).to eq([ Band.relations["records"] ])
|
430
430
|
end
|
431
431
|
|
432
432
|
it "clones the inclusions" do
|
433
|
-
clone.inclusions.
|
433
|
+
expect(clone.inclusions).to_not equal(criteria.inclusions)
|
434
434
|
end
|
435
435
|
|
436
436
|
it "contains equal documents" do
|
437
|
-
clone.documents.
|
437
|
+
expect(clone.documents).to eq([ band ])
|
438
438
|
end
|
439
439
|
|
440
440
|
it "clones the documents" do
|
441
|
-
clone.documents.
|
441
|
+
expect(clone.documents).to_not equal(criteria.documents)
|
442
442
|
end
|
443
443
|
|
444
444
|
it "contains equal scoping options" do
|
445
|
-
clone.scoping_options.
|
445
|
+
expect(clone.scoping_options).to eq([ nil, nil ])
|
446
446
|
end
|
447
447
|
|
448
448
|
it "clones the scoping options" do
|
449
|
-
clone.scoping_options.
|
449
|
+
expect(clone.scoping_options).to_not equal(criteria.scoping_options)
|
450
450
|
end
|
451
451
|
|
452
452
|
it "sets the context to nil" do
|
453
|
-
clone.instance_variable_get(:@context).
|
453
|
+
expect(clone.instance_variable_get(:@context)).to be_nil
|
454
454
|
end
|
455
455
|
end
|
456
456
|
end
|
@@ -462,7 +462,7 @@ describe Mongoid::Criteria do
|
|
462
462
|
end
|
463
463
|
|
464
464
|
it "sets the cache option to true" do
|
465
|
-
criteria.cache.
|
465
|
+
expect(criteria.cache).to be_cached
|
466
466
|
end
|
467
467
|
end
|
468
468
|
|
@@ -477,7 +477,7 @@ describe Mongoid::Criteria do
|
|
477
477
|
end
|
478
478
|
|
479
479
|
it "returns the embedded context" do
|
480
|
-
criteria.context.
|
480
|
+
expect(criteria.context).to be_a(Mongoid::Contextual::Memory)
|
481
481
|
end
|
482
482
|
end
|
483
483
|
|
@@ -488,71 +488,7 @@ describe Mongoid::Criteria do
|
|
488
488
|
end
|
489
489
|
|
490
490
|
it "returns the mongo context" do
|
491
|
-
criteria.context.
|
492
|
-
end
|
493
|
-
end
|
494
|
-
end
|
495
|
-
|
496
|
-
describe "#create" do
|
497
|
-
|
498
|
-
let(:criteria) do
|
499
|
-
Band.where(name: "Depeche Mode")
|
500
|
-
end
|
501
|
-
|
502
|
-
context "when provided valid attributes" do
|
503
|
-
let(:band) do
|
504
|
-
criteria.create(genres: [ "electro" ])
|
505
|
-
end
|
506
|
-
|
507
|
-
it "returns the created document" do
|
508
|
-
band.should be_persisted
|
509
|
-
end
|
510
|
-
|
511
|
-
it "sets the criteria attributes" do
|
512
|
-
band.name.should eq("Depeche Mode")
|
513
|
-
end
|
514
|
-
|
515
|
-
it "sets the attributes passed to build" do
|
516
|
-
band.genres.should eq([ "electro" ])
|
517
|
-
end
|
518
|
-
end
|
519
|
-
|
520
|
-
context "when provided a block" do
|
521
|
-
context "when provided valid attributes & using block" do
|
522
|
-
let(:band) do
|
523
|
-
criteria.create do |c|
|
524
|
-
c.genres = [ "electro" ]
|
525
|
-
end
|
526
|
-
end
|
527
|
-
|
528
|
-
it "returns the created document" do
|
529
|
-
band.should be_persisted
|
530
|
-
end
|
531
|
-
|
532
|
-
it "sets the criteria attributes" do
|
533
|
-
band.name.should eq("Depeche Mode")
|
534
|
-
end
|
535
|
-
|
536
|
-
it "sets the attributes passed to build" do
|
537
|
-
band.genres.should eq([ "electro" ])
|
538
|
-
end
|
539
|
-
end
|
540
|
-
end
|
541
|
-
|
542
|
-
end
|
543
|
-
|
544
|
-
describe "#create!" do
|
545
|
-
|
546
|
-
let(:criteria) do
|
547
|
-
Account.where(number: "11123213")
|
548
|
-
end
|
549
|
-
|
550
|
-
context "when provided invalid attributes" do
|
551
|
-
|
552
|
-
it "raises an error" do
|
553
|
-
expect {
|
554
|
-
criteria.create!
|
555
|
-
}.to raise_error(Mongoid::Errors::Validations)
|
491
|
+
expect(criteria.context).to be_a(Mongoid::Contextual::Mongo)
|
556
492
|
end
|
557
493
|
end
|
558
494
|
end
|
@@ -574,7 +510,7 @@ describe Mongoid::Criteria do
|
|
574
510
|
end
|
575
511
|
|
576
512
|
it "deletes all the documents from the database" do
|
577
|
-
Band.count.
|
513
|
+
expect(Band.count).to eq(0)
|
578
514
|
end
|
579
515
|
end
|
580
516
|
end
|
@@ -592,7 +528,7 @@ describe Mongoid::Criteria do
|
|
592
528
|
end
|
593
529
|
|
594
530
|
it "returns the documents" do
|
595
|
-
criteria.documents.
|
531
|
+
expect(criteria.documents).to eq([ band ])
|
596
532
|
end
|
597
533
|
end
|
598
534
|
|
@@ -611,7 +547,7 @@ describe Mongoid::Criteria do
|
|
611
547
|
end
|
612
548
|
|
613
549
|
it "sets the documents" do
|
614
|
-
criteria.documents.
|
550
|
+
expect(criteria.documents).to eq([ band ])
|
615
551
|
end
|
616
552
|
end
|
617
553
|
|
@@ -629,7 +565,7 @@ describe Mongoid::Criteria do
|
|
629
565
|
|
630
566
|
it "iterates over the matching documents" do
|
631
567
|
criteria.each do |doc|
|
632
|
-
doc.
|
568
|
+
expect(doc).to eq(band)
|
633
569
|
end
|
634
570
|
end
|
635
571
|
end
|
@@ -652,7 +588,7 @@ describe Mongoid::Criteria do
|
|
652
588
|
end
|
653
589
|
|
654
590
|
it "returns the matching documents" do
|
655
|
-
criteria.
|
591
|
+
expect(criteria).to eq([ match ])
|
656
592
|
end
|
657
593
|
end
|
658
594
|
|
@@ -669,7 +605,7 @@ describe Mongoid::Criteria do
|
|
669
605
|
end
|
670
606
|
|
671
607
|
it "returns true" do
|
672
|
-
criteria.
|
608
|
+
expect(criteria).to be_embedded
|
673
609
|
end
|
674
610
|
end
|
675
611
|
|
@@ -680,7 +616,7 @@ describe Mongoid::Criteria do
|
|
680
616
|
end
|
681
617
|
|
682
618
|
it "returns false" do
|
683
|
-
criteria.
|
619
|
+
expect(criteria).to_not be_embedded
|
684
620
|
end
|
685
621
|
end
|
686
622
|
end
|
@@ -733,7 +669,7 @@ describe Mongoid::Criteria do
|
|
733
669
|
end
|
734
670
|
|
735
671
|
it "returns the matching documents" do
|
736
|
-
criteria.
|
672
|
+
expect(criteria).to eq([ match ])
|
737
673
|
end
|
738
674
|
end
|
739
675
|
|
@@ -750,7 +686,7 @@ describe Mongoid::Criteria do
|
|
750
686
|
end
|
751
687
|
|
752
688
|
it "returns true" do
|
753
|
-
criteria.exists
|
689
|
+
expect(criteria.exists?).to be true
|
754
690
|
end
|
755
691
|
end
|
756
692
|
|
@@ -761,7 +697,7 @@ describe Mongoid::Criteria do
|
|
761
697
|
end
|
762
698
|
|
763
699
|
it "returns false" do
|
764
|
-
criteria.exists
|
700
|
+
expect(criteria.exists?).to be false
|
765
701
|
end
|
766
702
|
end
|
767
703
|
end
|
@@ -773,14 +709,14 @@ describe Mongoid::Criteria do
|
|
773
709
|
end
|
774
710
|
|
775
711
|
it "returns the criteria explain path" do
|
776
|
-
criteria.explain["cursor"].
|
712
|
+
expect(criteria.explain["cursor"]).to eq("BasicCursor")
|
777
713
|
end
|
778
714
|
end
|
779
715
|
|
780
716
|
describe "#extract_id" do
|
781
717
|
|
782
718
|
let(:id) do
|
783
|
-
|
719
|
+
BSON::ObjectId.new
|
784
720
|
end
|
785
721
|
|
786
722
|
context "when an id exists" do
|
@@ -792,7 +728,7 @@ describe Mongoid::Criteria do
|
|
792
728
|
end
|
793
729
|
|
794
730
|
it "returns the id" do
|
795
|
-
criteria.extract_id.
|
731
|
+
expect(criteria.extract_id).to eq(id)
|
796
732
|
end
|
797
733
|
end
|
798
734
|
|
@@ -805,7 +741,7 @@ describe Mongoid::Criteria do
|
|
805
741
|
end
|
806
742
|
|
807
743
|
it "returns the _id" do
|
808
|
-
criteria.extract_id.
|
744
|
+
expect(criteria.extract_id).to eq(id)
|
809
745
|
end
|
810
746
|
end
|
811
747
|
end
|
@@ -817,1526 +753,198 @@ describe Mongoid::Criteria do
|
|
817
753
|
end
|
818
754
|
|
819
755
|
it "returns the fields minus type" do
|
820
|
-
criteria.field_list.
|
756
|
+
expect(criteria.field_list).to eq([ "name" ])
|
821
757
|
end
|
822
758
|
end
|
823
759
|
|
824
|
-
describe "#
|
825
|
-
|
826
|
-
context "when finding by a document" do
|
827
|
-
|
828
|
-
let(:band) do
|
829
|
-
Band.create(name: "Tool")
|
830
|
-
end
|
831
|
-
|
832
|
-
let!(:record) do
|
833
|
-
band.records.create(name: "Undertow")
|
834
|
-
end
|
835
|
-
|
836
|
-
context "when the document is the root" do
|
837
|
-
|
838
|
-
let(:found) do
|
839
|
-
Band.find(band)
|
840
|
-
end
|
841
|
-
|
842
|
-
it "returns the matching document" do
|
843
|
-
expect(found).to eq(band)
|
844
|
-
end
|
845
|
-
end
|
846
|
-
|
847
|
-
context "when the document is the proxy" do
|
848
|
-
|
849
|
-
let(:found) do
|
850
|
-
Band.find(band.records.first.band)
|
851
|
-
end
|
852
|
-
|
853
|
-
it "returns the matching document" do
|
854
|
-
expect(found).to eq(band)
|
855
|
-
end
|
856
|
-
end
|
857
|
-
end
|
858
|
-
|
859
|
-
context "when the identity map is enabled" do
|
860
|
-
|
861
|
-
before(:all) do
|
862
|
-
Mongoid.identity_map_enabled = true
|
863
|
-
end
|
864
|
-
|
865
|
-
after(:all) do
|
866
|
-
Mongoid.identity_map_enabled = false
|
867
|
-
end
|
868
|
-
|
869
|
-
let!(:depeche) do
|
870
|
-
Band.create(name: "Depeche Mode")
|
871
|
-
end
|
872
|
-
|
873
|
-
let!(:placebo) do
|
874
|
-
Band.create(name: "Placebo")
|
875
|
-
end
|
876
|
-
|
877
|
-
context "when a parent and a child are in the identity map" do
|
878
|
-
|
879
|
-
let!(:canvas) do
|
880
|
-
Canvas.create
|
881
|
-
end
|
882
|
-
|
883
|
-
let!(:browser) do
|
884
|
-
Browser.create
|
885
|
-
end
|
886
|
-
|
887
|
-
context "when fetching a child class by a parent id" do
|
888
|
-
|
889
|
-
it "raises a not found error" do
|
890
|
-
expect {
|
891
|
-
Browser.find(canvas.id)
|
892
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
893
|
-
end
|
894
|
-
end
|
895
|
-
end
|
896
|
-
|
897
|
-
context "when providing a single id" do
|
898
|
-
|
899
|
-
let(:from_map) do
|
900
|
-
Band.find(depeche.id)
|
901
|
-
end
|
902
|
-
|
903
|
-
it "returns the document from the map" do
|
904
|
-
from_map.should equal(depeche)
|
905
|
-
end
|
906
|
-
end
|
907
|
-
|
908
|
-
context "when providing a single id as a String" do
|
909
|
-
|
910
|
-
let(:from_map) do
|
911
|
-
Band.find(depeche.id.to_s)
|
912
|
-
end
|
913
|
-
|
914
|
-
it "returns the document from the map" do
|
915
|
-
from_map.should equal(depeche)
|
916
|
-
end
|
917
|
-
end
|
918
|
-
|
919
|
-
context "when providing multiple ids" do
|
920
|
-
|
921
|
-
let(:from_map) do
|
922
|
-
Band.find(depeche.id, placebo.id)
|
923
|
-
end
|
924
|
-
|
925
|
-
it "returns the first match from the map" do
|
926
|
-
from_map.first.should equal(depeche)
|
927
|
-
end
|
760
|
+
describe "#find_and_modify" do
|
928
761
|
|
929
|
-
|
930
|
-
|
931
|
-
end
|
932
|
-
end
|
762
|
+
let!(:depeche) do
|
763
|
+
Band.create(name: "Depeche Mode")
|
933
764
|
end
|
934
765
|
|
935
|
-
|
936
|
-
|
937
|
-
let!(:band) do
|
938
|
-
Band.create
|
939
|
-
end
|
940
|
-
|
941
|
-
context "when a parent and a child are in the identity map" do
|
942
|
-
|
943
|
-
let!(:canvas) do
|
944
|
-
Canvas.create
|
945
|
-
end
|
946
|
-
|
947
|
-
let!(:browser) do
|
948
|
-
Browser.create
|
949
|
-
end
|
950
|
-
|
951
|
-
context "when fetching a child class by a parent id" do
|
952
|
-
|
953
|
-
it "raises a not found error" do
|
954
|
-
expect {
|
955
|
-
Browser.find(canvas.id)
|
956
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
957
|
-
end
|
958
|
-
end
|
959
|
-
end
|
960
|
-
|
961
|
-
context "when providing a single id" do
|
962
|
-
|
963
|
-
context "when the id matches" do
|
964
|
-
|
965
|
-
let(:found) do
|
966
|
-
Band.find(band.id)
|
967
|
-
end
|
968
|
-
|
969
|
-
it "returns the matching document" do
|
970
|
-
found.should eq(band)
|
971
|
-
end
|
972
|
-
end
|
973
|
-
|
974
|
-
context "when the id does not match" do
|
975
|
-
|
976
|
-
context "when raising a not found error" do
|
977
|
-
|
978
|
-
before do
|
979
|
-
Mongoid.raise_not_found_error = true
|
980
|
-
end
|
981
|
-
|
982
|
-
let(:found) do
|
983
|
-
Band.find(Moped::BSON::ObjectId.new)
|
984
|
-
end
|
985
|
-
|
986
|
-
it "raises an error" do
|
987
|
-
expect {
|
988
|
-
found
|
989
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
990
|
-
end
|
991
|
-
end
|
992
|
-
|
993
|
-
context "when raising no error" do
|
994
|
-
|
995
|
-
before do
|
996
|
-
Mongoid.raise_not_found_error = false
|
997
|
-
end
|
998
|
-
|
999
|
-
after do
|
1000
|
-
Mongoid.raise_not_found_error = true
|
1001
|
-
end
|
1002
|
-
|
1003
|
-
let(:found) do
|
1004
|
-
Band.find(Moped::BSON::ObjectId.new)
|
1005
|
-
end
|
1006
|
-
|
1007
|
-
it "returns nil" do
|
1008
|
-
found.should be_nil
|
1009
|
-
end
|
1010
|
-
end
|
1011
|
-
end
|
1012
|
-
end
|
1013
|
-
|
1014
|
-
context "when providing a splat of ids" do
|
1015
|
-
|
1016
|
-
let!(:band_two) do
|
1017
|
-
Band.create(name: "Tool")
|
1018
|
-
end
|
1019
|
-
|
1020
|
-
context "when all ids match" do
|
1021
|
-
|
1022
|
-
let(:found) do
|
1023
|
-
Band.find(band.id, band_two.id)
|
1024
|
-
end
|
1025
|
-
|
1026
|
-
it "contains the first match" do
|
1027
|
-
found.should include(band)
|
1028
|
-
end
|
1029
|
-
|
1030
|
-
it "contains the second match" do
|
1031
|
-
found.should include(band_two)
|
1032
|
-
end
|
1033
|
-
|
1034
|
-
context "when ids are duplicates" do
|
1035
|
-
let(:found) do
|
1036
|
-
Band.find(band.id, band.id)
|
1037
|
-
end
|
1038
|
-
|
1039
|
-
it "contains only the first match" do
|
1040
|
-
found.should eq([band])
|
1041
|
-
end
|
1042
|
-
end
|
1043
|
-
end
|
1044
|
-
|
1045
|
-
context "when any id does not match" do
|
1046
|
-
|
1047
|
-
context "when raising a not found error" do
|
1048
|
-
|
1049
|
-
before do
|
1050
|
-
Mongoid.raise_not_found_error = true
|
1051
|
-
end
|
1052
|
-
|
1053
|
-
let(:found) do
|
1054
|
-
Band.find(band.id, Moped::BSON::ObjectId.new)
|
1055
|
-
end
|
1056
|
-
|
1057
|
-
it "raises an error" do
|
1058
|
-
expect {
|
1059
|
-
found
|
1060
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
1061
|
-
end
|
1062
|
-
end
|
1063
|
-
|
1064
|
-
context "when raising no error" do
|
1065
|
-
|
1066
|
-
before do
|
1067
|
-
Mongoid.raise_not_found_error = false
|
1068
|
-
end
|
1069
|
-
|
1070
|
-
after do
|
1071
|
-
Mongoid.raise_not_found_error = true
|
1072
|
-
end
|
1073
|
-
|
1074
|
-
let(:found) do
|
1075
|
-
Band.find(band.id, Moped::BSON::ObjectId.new)
|
1076
|
-
end
|
1077
|
-
|
1078
|
-
it "returns only the matching documents" do
|
1079
|
-
found.should eq([ band ])
|
1080
|
-
end
|
1081
|
-
end
|
1082
|
-
end
|
1083
|
-
end
|
1084
|
-
|
1085
|
-
context "when providing an array of ids" do
|
1086
|
-
|
1087
|
-
let!(:band_two) do
|
1088
|
-
Band.create(name: "Tool")
|
1089
|
-
end
|
1090
|
-
|
1091
|
-
context "when all ids match" do
|
1092
|
-
|
1093
|
-
let(:found) do
|
1094
|
-
Band.find([ band.id, band_two.id ])
|
1095
|
-
end
|
1096
|
-
|
1097
|
-
it "contains the first match" do
|
1098
|
-
found.should include(band)
|
1099
|
-
end
|
1100
|
-
|
1101
|
-
it "contains the second match" do
|
1102
|
-
found.should include(band_two)
|
1103
|
-
end
|
1104
|
-
|
1105
|
-
context "when ids are duplicates" do
|
1106
|
-
let(:found) do
|
1107
|
-
Band.find([ band.id, band.id ])
|
1108
|
-
end
|
1109
|
-
|
1110
|
-
it "contains only the first match" do
|
1111
|
-
found.should eq([band])
|
1112
|
-
end
|
1113
|
-
end
|
1114
|
-
end
|
1115
|
-
|
1116
|
-
context "when any id does not match" do
|
1117
|
-
|
1118
|
-
context "when raising a not found error" do
|
1119
|
-
|
1120
|
-
before do
|
1121
|
-
Mongoid.raise_not_found_error = true
|
1122
|
-
end
|
1123
|
-
|
1124
|
-
let(:found) do
|
1125
|
-
Band.find([ band.id, Moped::BSON::ObjectId.new ])
|
1126
|
-
end
|
1127
|
-
|
1128
|
-
it "raises an error" do
|
1129
|
-
expect {
|
1130
|
-
found
|
1131
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
1132
|
-
end
|
1133
|
-
end
|
1134
|
-
|
1135
|
-
context "when raising no error" do
|
1136
|
-
|
1137
|
-
before do
|
1138
|
-
Mongoid.raise_not_found_error = false
|
1139
|
-
end
|
1140
|
-
|
1141
|
-
after do
|
1142
|
-
Mongoid.raise_not_found_error = true
|
1143
|
-
end
|
1144
|
-
|
1145
|
-
let(:found) do
|
1146
|
-
Band.find([ band.id, Moped::BSON::ObjectId.new ])
|
1147
|
-
end
|
1148
|
-
|
1149
|
-
it "returns only the matching documents" do
|
1150
|
-
found.should eq([ band ])
|
1151
|
-
end
|
1152
|
-
end
|
1153
|
-
end
|
1154
|
-
end
|
766
|
+
let!(:tool) do
|
767
|
+
Band.create(name: "Tool")
|
1155
768
|
end
|
1156
769
|
|
1157
|
-
context "when
|
1158
|
-
|
1159
|
-
before(:all) do
|
1160
|
-
Band.field :_id, type: String
|
1161
|
-
end
|
1162
|
-
|
1163
|
-
after(:all) do
|
1164
|
-
Band.field :_id, type: Moped::BSON::ObjectId, default: ->{ Moped::BSON::ObjectId.new }
|
1165
|
-
end
|
1166
|
-
|
1167
|
-
let!(:band) do
|
1168
|
-
Band.create do |band|
|
1169
|
-
band.id = "tool"
|
1170
|
-
end
|
1171
|
-
end
|
1172
|
-
|
1173
|
-
context "when providing a single id" do
|
1174
|
-
|
1175
|
-
context "when the id matches" do
|
1176
|
-
|
1177
|
-
let(:found) do
|
1178
|
-
Band.find(band.id)
|
1179
|
-
end
|
1180
|
-
|
1181
|
-
it "returns the matching document" do
|
1182
|
-
found.should eq(band)
|
1183
|
-
end
|
1184
|
-
end
|
1185
|
-
|
1186
|
-
context "when the id does not match" do
|
1187
|
-
|
1188
|
-
context "when raising a not found error" do
|
770
|
+
context "when the selector matches" do
|
1189
771
|
|
1190
|
-
|
1191
|
-
Mongoid.raise_not_found_error = true
|
1192
|
-
end
|
772
|
+
context "when the identity map is enabled" do
|
1193
773
|
|
1194
|
-
|
1195
|
-
Band.find("depeche-mode")
|
1196
|
-
end
|
774
|
+
context "when returning the updated document" do
|
1197
775
|
|
1198
|
-
|
1199
|
-
|
1200
|
-
found
|
1201
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
1202
|
-
end
|
1203
|
-
end
|
1204
|
-
|
1205
|
-
context "when raising no error" do
|
1206
|
-
|
1207
|
-
before do
|
1208
|
-
Mongoid.raise_not_found_error = false
|
1209
|
-
end
|
1210
|
-
|
1211
|
-
after do
|
1212
|
-
Mongoid.raise_not_found_error = true
|
1213
|
-
end
|
1214
|
-
|
1215
|
-
let(:found) do
|
1216
|
-
Band.find("depeche-mode")
|
1217
|
-
end
|
1218
|
-
|
1219
|
-
it "returns nil" do
|
1220
|
-
found.should be_nil
|
1221
|
-
end
|
1222
|
-
end
|
1223
|
-
end
|
1224
|
-
end
|
1225
|
-
|
1226
|
-
context "when providing a splat of ids" do
|
1227
|
-
|
1228
|
-
let!(:band_two) do
|
1229
|
-
Band.create do |band|
|
1230
|
-
band.id = "depeche-mode"
|
1231
|
-
end
|
1232
|
-
end
|
1233
|
-
|
1234
|
-
context "when all ids match" do
|
1235
|
-
|
1236
|
-
let(:found) do
|
1237
|
-
Band.find(band.id, band_two.id)
|
1238
|
-
end
|
1239
|
-
|
1240
|
-
it "contains the first match" do
|
1241
|
-
found.should include(band)
|
1242
|
-
end
|
1243
|
-
|
1244
|
-
it "contains the second match" do
|
1245
|
-
found.should include(band_two)
|
1246
|
-
end
|
1247
|
-
end
|
1248
|
-
|
1249
|
-
context "when any id does not match" do
|
1250
|
-
|
1251
|
-
context "when raising a not found error" do
|
1252
|
-
|
1253
|
-
before do
|
1254
|
-
Mongoid.raise_not_found_error = true
|
1255
|
-
end
|
1256
|
-
|
1257
|
-
let(:found) do
|
1258
|
-
Band.find(band.id, "new-order")
|
1259
|
-
end
|
1260
|
-
|
1261
|
-
it "raises an error" do
|
1262
|
-
expect {
|
1263
|
-
found
|
1264
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
1265
|
-
end
|
1266
|
-
end
|
1267
|
-
|
1268
|
-
context "when raising no error" do
|
1269
|
-
|
1270
|
-
before do
|
1271
|
-
Mongoid.raise_not_found_error = false
|
1272
|
-
end
|
1273
|
-
|
1274
|
-
after do
|
1275
|
-
Mongoid.raise_not_found_error = true
|
1276
|
-
end
|
1277
|
-
|
1278
|
-
let(:found) do
|
1279
|
-
Band.find(band.id, "new-order")
|
1280
|
-
end
|
1281
|
-
|
1282
|
-
it "returns only the matching documents" do
|
1283
|
-
found.should eq([ band ])
|
1284
|
-
end
|
1285
|
-
end
|
1286
|
-
end
|
1287
|
-
end
|
1288
|
-
|
1289
|
-
context "when providing an array of ids" do
|
1290
|
-
|
1291
|
-
let!(:band_two) do
|
1292
|
-
Band.create do |band|
|
1293
|
-
band.id = "depeche-mode"
|
1294
|
-
end
|
1295
|
-
end
|
1296
|
-
|
1297
|
-
context "when all ids match" do
|
1298
|
-
|
1299
|
-
let(:found) do
|
1300
|
-
Band.find([ band.id, band_two.id ])
|
1301
|
-
end
|
1302
|
-
|
1303
|
-
it "contains the first match" do
|
1304
|
-
found.should include(band)
|
1305
|
-
end
|
1306
|
-
|
1307
|
-
it "contains the second match" do
|
1308
|
-
found.should include(band_two)
|
1309
|
-
end
|
1310
|
-
end
|
1311
|
-
|
1312
|
-
context "when any id does not match" do
|
1313
|
-
|
1314
|
-
context "when raising a not found error" do
|
1315
|
-
|
1316
|
-
before do
|
1317
|
-
Mongoid.raise_not_found_error = true
|
1318
|
-
end
|
1319
|
-
|
1320
|
-
let(:found) do
|
1321
|
-
Band.find([ band.id, "new-order" ])
|
1322
|
-
end
|
1323
|
-
|
1324
|
-
it "raises an error" do
|
1325
|
-
expect {
|
1326
|
-
found
|
1327
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
1328
|
-
end
|
1329
|
-
end
|
1330
|
-
|
1331
|
-
context "when raising no error" do
|
1332
|
-
|
1333
|
-
before do
|
1334
|
-
Mongoid.raise_not_found_error = false
|
1335
|
-
end
|
1336
|
-
|
1337
|
-
after do
|
1338
|
-
Mongoid.raise_not_found_error = true
|
1339
|
-
end
|
1340
|
-
|
1341
|
-
let(:found) do
|
1342
|
-
Band.find([ band.id, "new-order" ])
|
1343
|
-
end
|
1344
|
-
|
1345
|
-
it "returns only the matching documents" do
|
1346
|
-
found.should eq([ band ])
|
1347
|
-
end
|
1348
|
-
end
|
1349
|
-
end
|
1350
|
-
end
|
1351
|
-
end
|
1352
|
-
|
1353
|
-
context "when using hash ids" do
|
1354
|
-
|
1355
|
-
before(:all) do
|
1356
|
-
Band.field :_id, type: Hash
|
1357
|
-
end
|
1358
|
-
|
1359
|
-
after(:all) do
|
1360
|
-
Band.field :_id, type: Moped::BSON::ObjectId, default: ->{ Moped::BSON::ObjectId.new }
|
1361
|
-
end
|
1362
|
-
|
1363
|
-
let!(:band) do
|
1364
|
-
Band.create do |band|
|
1365
|
-
band.id = {"new-order" => true, "Depeche Mode" => false}
|
1366
|
-
end
|
1367
|
-
end
|
1368
|
-
|
1369
|
-
context "when providing a single id" do
|
1370
|
-
|
1371
|
-
context "when the id matches" do
|
1372
|
-
|
1373
|
-
let(:found) do
|
1374
|
-
Band.find(band.id)
|
1375
|
-
end
|
1376
|
-
|
1377
|
-
it "returns the matching document" do
|
1378
|
-
found.should eq(band)
|
1379
|
-
end
|
1380
|
-
end
|
1381
|
-
|
1382
|
-
context "when the id does not match" do
|
1383
|
-
|
1384
|
-
context "when raising a not found error" do
|
1385
|
-
|
1386
|
-
before do
|
1387
|
-
Mongoid.raise_not_found_error = true
|
1388
|
-
end
|
1389
|
-
|
1390
|
-
let(:found) do
|
1391
|
-
Band.find({"new-order" => false, "Faith no More" => true})
|
1392
|
-
end
|
1393
|
-
|
1394
|
-
it "raises an error" do
|
1395
|
-
expect {
|
1396
|
-
found
|
1397
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
1398
|
-
end
|
1399
|
-
end
|
1400
|
-
|
1401
|
-
context "when raising no error" do
|
1402
|
-
|
1403
|
-
before do
|
1404
|
-
Mongoid.raise_not_found_error = false
|
1405
|
-
end
|
1406
|
-
|
1407
|
-
after do
|
1408
|
-
Mongoid.raise_not_found_error = true
|
1409
|
-
end
|
1410
|
-
|
1411
|
-
let(:found) do
|
1412
|
-
Band.find({"new-order" => false, "Faith no More" => true})
|
1413
|
-
end
|
1414
|
-
|
1415
|
-
it "returns nil" do
|
1416
|
-
found.should be_nil
|
1417
|
-
end
|
1418
|
-
end
|
1419
|
-
end
|
1420
|
-
end
|
1421
|
-
|
1422
|
-
context "when providing a splat of ids" do
|
1423
|
-
|
1424
|
-
let!(:band_two) do
|
1425
|
-
Band.create do |band|
|
1426
|
-
band.id = {"Radiohead" => false, "Nirvana"=> true}
|
1427
|
-
end
|
1428
|
-
end
|
1429
|
-
|
1430
|
-
context "when all ids match" do
|
1431
|
-
|
1432
|
-
let(:found) do
|
1433
|
-
Band.find(band.id, band_two.id)
|
1434
|
-
end
|
1435
|
-
|
1436
|
-
it "contains the first match" do
|
1437
|
-
found.should include(band)
|
1438
|
-
end
|
1439
|
-
|
1440
|
-
it "contains the second match" do
|
1441
|
-
found.should include(band_two)
|
1442
|
-
end
|
1443
|
-
end
|
1444
|
-
|
1445
|
-
context "when any id does not match" do
|
1446
|
-
|
1447
|
-
context "when raising a not found error" do
|
1448
|
-
|
1449
|
-
before do
|
1450
|
-
Mongoid.raise_not_found_error = true
|
1451
|
-
end
|
1452
|
-
|
1453
|
-
let(:found) do
|
1454
|
-
Band.find(band.id, {"Radiohead" => true, "Nirvana"=> false})
|
1455
|
-
end
|
1456
|
-
|
1457
|
-
it "raises an error" do
|
1458
|
-
expect {
|
1459
|
-
found
|
1460
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
1461
|
-
end
|
1462
|
-
end
|
1463
|
-
|
1464
|
-
context "when raising no error" do
|
1465
|
-
|
1466
|
-
before do
|
1467
|
-
Mongoid.raise_not_found_error = false
|
1468
|
-
end
|
1469
|
-
|
1470
|
-
after do
|
1471
|
-
Mongoid.raise_not_found_error = true
|
1472
|
-
end
|
1473
|
-
|
1474
|
-
let(:found) do
|
1475
|
-
Band.find(band.id, {"Radiohead" => true, "Nirvana"=> false})
|
1476
|
-
end
|
1477
|
-
|
1478
|
-
it "returns only the matching documents" do
|
1479
|
-
found.should eq([ band ])
|
1480
|
-
end
|
1481
|
-
end
|
1482
|
-
end
|
1483
|
-
end
|
1484
|
-
|
1485
|
-
context "when providing an array of ids" do
|
1486
|
-
|
1487
|
-
let!(:band_two) do
|
1488
|
-
Band.create do |band|
|
1489
|
-
band.id = {"Radiohead" => false, "Nirvana"=> true}
|
1490
|
-
end
|
1491
|
-
end
|
1492
|
-
|
1493
|
-
context "when all ids match" do
|
1494
|
-
|
1495
|
-
let(:found) do
|
1496
|
-
Band.find([ band.id, band_two.id ])
|
1497
|
-
end
|
1498
|
-
|
1499
|
-
it "contains the first match" do
|
1500
|
-
found.should include(band)
|
1501
|
-
end
|
1502
|
-
|
1503
|
-
it "contains the second match" do
|
1504
|
-
found.should include(band_two)
|
1505
|
-
end
|
1506
|
-
end
|
1507
|
-
|
1508
|
-
context "when any id does not match" do
|
1509
|
-
|
1510
|
-
context "when raising a not found error" do
|
1511
|
-
|
1512
|
-
before do
|
1513
|
-
Mongoid.raise_not_found_error = true
|
1514
|
-
end
|
1515
|
-
|
1516
|
-
let(:found) do
|
1517
|
-
Band.find([ band.id, {"Radiohead" => true, "Nirvana"=> false} ])
|
1518
|
-
end
|
1519
|
-
|
1520
|
-
it "raises an error" do
|
1521
|
-
expect {
|
1522
|
-
found
|
1523
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
1524
|
-
end
|
1525
|
-
end
|
1526
|
-
|
1527
|
-
context "when raising no error" do
|
1528
|
-
|
1529
|
-
before do
|
1530
|
-
Mongoid.raise_not_found_error = false
|
1531
|
-
end
|
1532
|
-
|
1533
|
-
after do
|
1534
|
-
Mongoid.raise_not_found_error = true
|
1535
|
-
end
|
1536
|
-
|
1537
|
-
let(:found) do
|
1538
|
-
Band.find([ band.id, {"Radiohead" => true, "Nirvana"=> false} ])
|
1539
|
-
end
|
1540
|
-
|
1541
|
-
it "returns only the matching documents" do
|
1542
|
-
found.should eq([ band ])
|
1543
|
-
end
|
1544
|
-
end
|
1545
|
-
end
|
1546
|
-
end
|
1547
|
-
end
|
1548
|
-
|
1549
|
-
context "when using integer ids" do
|
1550
|
-
|
1551
|
-
before(:all) do
|
1552
|
-
Band.field :_id, type: Integer
|
1553
|
-
end
|
1554
|
-
|
1555
|
-
after(:all) do
|
1556
|
-
Band.field :_id, type: Moped::BSON::ObjectId, default: ->{ Moped::BSON::ObjectId.new }
|
1557
|
-
end
|
1558
|
-
|
1559
|
-
let!(:band) do
|
1560
|
-
Band.create do |band|
|
1561
|
-
band.id = 1
|
1562
|
-
end
|
1563
|
-
end
|
1564
|
-
|
1565
|
-
context "when providing a single id" do
|
1566
|
-
|
1567
|
-
context "when the id matches" do
|
1568
|
-
|
1569
|
-
let(:found) do
|
1570
|
-
Band.find(band.id)
|
1571
|
-
end
|
1572
|
-
|
1573
|
-
it "returns the matching document" do
|
1574
|
-
found.should eq(band)
|
1575
|
-
end
|
1576
|
-
end
|
1577
|
-
|
1578
|
-
context "when the id does not match" do
|
1579
|
-
|
1580
|
-
context "when raising a not found error" do
|
1581
|
-
|
1582
|
-
before do
|
1583
|
-
Mongoid.raise_not_found_error = true
|
1584
|
-
end
|
1585
|
-
|
1586
|
-
let(:found) do
|
1587
|
-
Band.find(3)
|
1588
|
-
end
|
1589
|
-
|
1590
|
-
it "raises an error" do
|
1591
|
-
expect {
|
1592
|
-
found
|
1593
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
1594
|
-
end
|
1595
|
-
end
|
1596
|
-
|
1597
|
-
context "when raising no error" do
|
1598
|
-
|
1599
|
-
before do
|
1600
|
-
Mongoid.raise_not_found_error = false
|
1601
|
-
end
|
1602
|
-
|
1603
|
-
after do
|
1604
|
-
Mongoid.raise_not_found_error = true
|
1605
|
-
end
|
1606
|
-
|
1607
|
-
let(:found) do
|
1608
|
-
Band.find(3)
|
1609
|
-
end
|
1610
|
-
|
1611
|
-
it "returns nil" do
|
1612
|
-
found.should be_nil
|
1613
|
-
end
|
1614
|
-
end
|
1615
|
-
end
|
1616
|
-
end
|
1617
|
-
|
1618
|
-
context "when providing a splat of ids" do
|
1619
|
-
|
1620
|
-
let!(:band_two) do
|
1621
|
-
Band.create do |band|
|
1622
|
-
band.id = 2
|
1623
|
-
end
|
1624
|
-
end
|
1625
|
-
|
1626
|
-
context "when all ids match" do
|
1627
|
-
|
1628
|
-
let(:found) do
|
1629
|
-
Band.find(band.id, band_two.id)
|
1630
|
-
end
|
1631
|
-
|
1632
|
-
it "contains the first match" do
|
1633
|
-
found.should include(band)
|
1634
|
-
end
|
1635
|
-
|
1636
|
-
it "contains the second match" do
|
1637
|
-
found.should include(band_two)
|
1638
|
-
end
|
1639
|
-
end
|
1640
|
-
|
1641
|
-
context "when any id does not match" do
|
1642
|
-
|
1643
|
-
context "when raising a not found error" do
|
1644
|
-
|
1645
|
-
before do
|
1646
|
-
Mongoid.raise_not_found_error = true
|
1647
|
-
end
|
1648
|
-
|
1649
|
-
let(:found) do
|
1650
|
-
Band.find(band.id, 3)
|
1651
|
-
end
|
1652
|
-
|
1653
|
-
it "raises an error" do
|
1654
|
-
expect {
|
1655
|
-
found
|
1656
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
1657
|
-
end
|
1658
|
-
end
|
1659
|
-
|
1660
|
-
context "when raising no error" do
|
1661
|
-
|
1662
|
-
before do
|
1663
|
-
Mongoid.raise_not_found_error = false
|
1664
|
-
end
|
1665
|
-
|
1666
|
-
after do
|
1667
|
-
Mongoid.raise_not_found_error = true
|
1668
|
-
end
|
1669
|
-
|
1670
|
-
let(:found) do
|
1671
|
-
Band.find(band.id, 3)
|
1672
|
-
end
|
1673
|
-
|
1674
|
-
it "returns only the matching documents" do
|
1675
|
-
found.should eq([ band ])
|
1676
|
-
end
|
1677
|
-
end
|
1678
|
-
end
|
1679
|
-
end
|
1680
|
-
|
1681
|
-
context "when providing an array of ids" do
|
1682
|
-
|
1683
|
-
let!(:band_two) do
|
1684
|
-
Band.create do |band|
|
1685
|
-
band.id = 2
|
1686
|
-
end
|
1687
|
-
end
|
1688
|
-
|
1689
|
-
context "when all ids match" do
|
1690
|
-
|
1691
|
-
let(:found) do
|
1692
|
-
Band.find([ band.id, band_two.id ])
|
1693
|
-
end
|
1694
|
-
|
1695
|
-
it "contains the first match" do
|
1696
|
-
found.should include(band)
|
1697
|
-
end
|
1698
|
-
|
1699
|
-
it "contains the second match" do
|
1700
|
-
found.should include(band_two)
|
1701
|
-
end
|
1702
|
-
end
|
1703
|
-
|
1704
|
-
context "when any id does not match" do
|
1705
|
-
|
1706
|
-
context "when raising a not found error" do
|
1707
|
-
|
1708
|
-
before do
|
1709
|
-
Mongoid.raise_not_found_error = true
|
1710
|
-
end
|
1711
|
-
|
1712
|
-
let(:found) do
|
1713
|
-
Band.find([ band.id, 3 ])
|
1714
|
-
end
|
1715
|
-
|
1716
|
-
it "raises an error" do
|
1717
|
-
expect {
|
1718
|
-
found
|
1719
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
1720
|
-
end
|
1721
|
-
end
|
1722
|
-
|
1723
|
-
context "when raising no error" do
|
1724
|
-
|
1725
|
-
before do
|
1726
|
-
Mongoid.raise_not_found_error = false
|
1727
|
-
end
|
1728
|
-
|
1729
|
-
after do
|
1730
|
-
Mongoid.raise_not_found_error = true
|
1731
|
-
end
|
1732
|
-
|
1733
|
-
let(:found) do
|
1734
|
-
Band.find([ band.id, 3 ])
|
1735
|
-
end
|
1736
|
-
|
1737
|
-
it "returns only the matching documents" do
|
1738
|
-
found.should eq([ band ])
|
1739
|
-
end
|
1740
|
-
end
|
1741
|
-
end
|
1742
|
-
end
|
1743
|
-
|
1744
|
-
context "when providing a range" do
|
1745
|
-
|
1746
|
-
let!(:band_two) do
|
1747
|
-
Band.create do |band|
|
1748
|
-
band.id = 2
|
1749
|
-
end
|
1750
|
-
end
|
1751
|
-
|
1752
|
-
context "when all ids match" do
|
1753
|
-
|
1754
|
-
let(:found) do
|
1755
|
-
Band.find(1..2)
|
1756
|
-
end
|
1757
|
-
|
1758
|
-
it "contains the first match" do
|
1759
|
-
found.should include(band)
|
1760
|
-
end
|
1761
|
-
|
1762
|
-
it "contains the second match" do
|
1763
|
-
found.should include(band_two)
|
1764
|
-
end
|
1765
|
-
end
|
1766
|
-
|
1767
|
-
context "when any id does not match" do
|
1768
|
-
|
1769
|
-
context "when raising a not found error" do
|
1770
|
-
|
1771
|
-
before do
|
1772
|
-
Mongoid.raise_not_found_error = true
|
1773
|
-
end
|
1774
|
-
|
1775
|
-
let(:found) do
|
1776
|
-
Band.find(1..3)
|
1777
|
-
end
|
1778
|
-
|
1779
|
-
it "raises an error" do
|
1780
|
-
expect {
|
1781
|
-
found
|
1782
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
1783
|
-
end
|
1784
|
-
end
|
1785
|
-
|
1786
|
-
context "when raising no error" do
|
1787
|
-
|
1788
|
-
before do
|
1789
|
-
Mongoid.raise_not_found_error = false
|
1790
|
-
end
|
1791
|
-
|
1792
|
-
after do
|
1793
|
-
Mongoid.raise_not_found_error = true
|
1794
|
-
end
|
1795
|
-
|
1796
|
-
let(:found) do
|
1797
|
-
Band.find(1..3)
|
1798
|
-
end
|
1799
|
-
|
1800
|
-
it "contains the first match" do
|
1801
|
-
found.should include(band)
|
1802
|
-
end
|
1803
|
-
|
1804
|
-
it "contains the second match" do
|
1805
|
-
found.should include(band_two)
|
1806
|
-
end
|
1807
|
-
|
1808
|
-
it "returns only the matches" do
|
1809
|
-
found.count.should eq(2)
|
1810
|
-
end
|
1811
|
-
end
|
1812
|
-
end
|
1813
|
-
end
|
1814
|
-
end
|
1815
|
-
|
1816
|
-
context "when using string and object ids" do
|
1817
|
-
|
1818
|
-
let!(:band) do
|
1819
|
-
Band.create
|
1820
|
-
end
|
1821
|
-
|
1822
|
-
context "when providing multiple ids" do
|
1823
|
-
|
1824
|
-
context "when ids are duplicates" do
|
1825
|
-
|
1826
|
-
let(:found) do
|
1827
|
-
Band.find([ band.id.to_s, band.id ])
|
1828
|
-
end
|
1829
|
-
|
1830
|
-
it "contains only the first match" do
|
1831
|
-
found.should eq([band])
|
1832
|
-
end
|
1833
|
-
end
|
1834
|
-
end
|
1835
|
-
end
|
1836
|
-
end
|
1837
|
-
|
1838
|
-
describe "#find_and_modify" do
|
1839
|
-
|
1840
|
-
let!(:depeche) do
|
1841
|
-
Band.create(name: "Depeche Mode")
|
1842
|
-
end
|
1843
|
-
|
1844
|
-
let!(:tool) do
|
1845
|
-
Band.create(name: "Tool")
|
1846
|
-
end
|
1847
|
-
|
1848
|
-
context "when the selector matches" do
|
1849
|
-
|
1850
|
-
context "when the identity map is enabled" do
|
1851
|
-
|
1852
|
-
before(:all) do
|
1853
|
-
Mongoid.identity_map_enabled = true
|
1854
|
-
end
|
1855
|
-
|
1856
|
-
after(:all) do
|
1857
|
-
Mongoid.identity_map_enabled = false
|
1858
|
-
end
|
1859
|
-
|
1860
|
-
context "when returning the updated document" do
|
1861
|
-
|
1862
|
-
let(:criteria) do
|
1863
|
-
Band.where(name: "Depeche Mode")
|
776
|
+
let(:criteria) do
|
777
|
+
Band.where(name: "Depeche Mode")
|
1864
778
|
end
|
1865
779
|
|
1866
780
|
let(:result) do
|
1867
781
|
criteria.find_and_modify({ "$inc" => { likes: 1 }}, new: true)
|
1868
|
-
end
|
1869
|
-
|
1870
|
-
it "returns the first matching document" do
|
1871
|
-
result.should eq(depeche)
|
1872
|
-
end
|
1873
|
-
|
1874
|
-
it "updates the document in the identity map" do
|
1875
|
-
Mongoid::IdentityMap.get(Band, result.id).likes.should eq(1)
|
1876
|
-
end
|
1877
|
-
end
|
1878
|
-
|
1879
|
-
context "when not returning the updated document" do
|
1880
|
-
|
1881
|
-
let(:criteria) do
|
1882
|
-
Band.where(name: "Depeche Mode")
|
1883
|
-
end
|
1884
|
-
|
1885
|
-
let!(:result) do
|
1886
|
-
criteria.find_and_modify("$inc" => { likes: 1 })
|
1887
|
-
end
|
1888
|
-
|
1889
|
-
before do
|
1890
|
-
depeche.reload
|
1891
|
-
end
|
1892
|
-
|
1893
|
-
it "returns the first matching document" do
|
1894
|
-
result.should eq(depeche)
|
1895
|
-
end
|
1896
|
-
|
1897
|
-
it "updates the document in the identity map" do
|
1898
|
-
Mongoid::IdentityMap.get(Band, depeche.id).likes.should eq(1)
|
1899
|
-
end
|
1900
|
-
end
|
1901
|
-
end
|
1902
|
-
|
1903
|
-
context "when not providing options" do
|
1904
|
-
|
1905
|
-
let(:criteria) do
|
1906
|
-
Band.where(name: "Depeche Mode")
|
1907
|
-
end
|
1908
|
-
|
1909
|
-
let!(:result) do
|
1910
|
-
criteria.find_and_modify("$inc" => { likes: 1 })
|
1911
|
-
end
|
1912
|
-
|
1913
|
-
it "returns the first matching document" do
|
1914
|
-
result.should eq(depeche)
|
1915
|
-
end
|
1916
|
-
|
1917
|
-
it "updates the document in the database" do
|
1918
|
-
depeche.reload.likes.should eq(1)
|
1919
|
-
end
|
1920
|
-
end
|
1921
|
-
|
1922
|
-
context "when sorting" do
|
1923
|
-
|
1924
|
-
let(:criteria) do
|
1925
|
-
Band.desc(:name)
|
1926
|
-
end
|
1927
|
-
|
1928
|
-
let!(:result) do
|
1929
|
-
criteria.find_and_modify("$inc" => { likes: 1 })
|
1930
|
-
end
|
1931
|
-
|
1932
|
-
it "returns the first matching document" do
|
1933
|
-
result.should eq(tool)
|
1934
|
-
end
|
1935
|
-
|
1936
|
-
it "updates the document in the database" do
|
1937
|
-
tool.reload.likes.should eq(1)
|
1938
|
-
end
|
1939
|
-
end
|
1940
|
-
|
1941
|
-
context "when limiting fields" do
|
1942
|
-
|
1943
|
-
let(:criteria) do
|
1944
|
-
Band.only(:_id)
|
1945
|
-
end
|
1946
|
-
|
1947
|
-
let!(:result) do
|
1948
|
-
criteria.find_and_modify("$inc" => { likes: 1 })
|
1949
|
-
end
|
1950
|
-
|
1951
|
-
it "returns the first matching document" do
|
1952
|
-
result.should eq(depeche)
|
1953
|
-
end
|
1954
|
-
|
1955
|
-
it "limits the returned fields" do
|
1956
|
-
result.name.should be_nil
|
1957
|
-
end
|
1958
|
-
|
1959
|
-
it "updates the document in the database" do
|
1960
|
-
depeche.reload.likes.should eq(1)
|
1961
|
-
end
|
1962
|
-
end
|
1963
|
-
|
1964
|
-
context "when returning new" do
|
1965
|
-
|
1966
|
-
let(:criteria) do
|
1967
|
-
Band.where(name: "Depeche Mode")
|
1968
|
-
end
|
1969
|
-
|
1970
|
-
let!(:result) do
|
1971
|
-
criteria.find_and_modify({ "$inc" => { likes: 1 }}, new: true)
|
1972
|
-
end
|
1973
|
-
|
1974
|
-
it "returns the first matching document" do
|
1975
|
-
result.should eq(depeche)
|
1976
|
-
end
|
1977
|
-
|
1978
|
-
it "returns the updated document" do
|
1979
|
-
result.likes.should eq(1)
|
1980
|
-
end
|
1981
|
-
end
|
1982
|
-
|
1983
|
-
context "when removing" do
|
1984
|
-
|
1985
|
-
let(:criteria) do
|
1986
|
-
Band.where(name: "Depeche Mode")
|
1987
|
-
end
|
1988
|
-
|
1989
|
-
let!(:result) do
|
1990
|
-
criteria.find_and_modify({}, remove: true)
|
1991
|
-
end
|
1992
|
-
|
1993
|
-
it "returns the first matching document" do
|
1994
|
-
result.should eq(depeche)
|
1995
|
-
end
|
1996
|
-
|
1997
|
-
it "deletes the document from the database" do
|
1998
|
-
expect {
|
1999
|
-
depeche.reload
|
2000
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2001
|
-
end
|
2002
|
-
end
|
2003
|
-
end
|
2004
|
-
|
2005
|
-
context "when the selector does not match" do
|
2006
|
-
|
2007
|
-
let(:criteria) do
|
2008
|
-
Band.where(name: "Placebo")
|
2009
|
-
end
|
2010
|
-
|
2011
|
-
let(:result) do
|
2012
|
-
criteria.find_and_modify("$inc" => { likes: 1 })
|
2013
|
-
end
|
2014
|
-
|
2015
|
-
it "returns nil" do
|
2016
|
-
result.should be_nil
|
2017
|
-
end
|
2018
|
-
end
|
2019
|
-
end
|
2020
|
-
|
2021
|
-
describe "first_or_initialize" do
|
2022
|
-
|
2023
|
-
let!(:band) do
|
2024
|
-
Band.create(name: "Depeche Mode")
|
2025
|
-
end
|
2026
|
-
|
2027
|
-
context "when the document is found" do
|
2028
|
-
|
2029
|
-
let(:found) do
|
2030
|
-
Band.where(name: "Depeche Mode").first_or_initialize
|
2031
|
-
end
|
2032
|
-
|
2033
|
-
it "returns the document" do
|
2034
|
-
found.should eq(band)
|
2035
|
-
end
|
2036
|
-
end
|
2037
|
-
|
2038
|
-
context "when the document is not found" do
|
2039
|
-
|
2040
|
-
context "when attributes are provided" do
|
2041
|
-
|
2042
|
-
let(:document) do
|
2043
|
-
Band.where(name: "Tool").first_or_initialize(origin: "Essex")
|
2044
|
-
end
|
2045
|
-
|
2046
|
-
it "returns a new document" do
|
2047
|
-
document.name.should eq("Tool")
|
2048
|
-
end
|
2049
|
-
|
2050
|
-
it "returns a non persisted document" do
|
2051
|
-
document.should_not be_persisted
|
2052
|
-
end
|
2053
|
-
|
2054
|
-
it "sets the additional attributes" do
|
2055
|
-
document.origin.should eq("Essex")
|
2056
|
-
end
|
2057
|
-
end
|
2058
|
-
|
2059
|
-
context "when attributes are not provided" do
|
2060
|
-
|
2061
|
-
let(:document) do
|
2062
|
-
Band.where(name: "Tool").first_or_initialize
|
2063
|
-
end
|
2064
|
-
|
2065
|
-
it "returns a new document" do
|
2066
|
-
document.name.should eq("Tool")
|
2067
|
-
end
|
2068
|
-
|
2069
|
-
it "returns a non persisted document" do
|
2070
|
-
document.should_not be_persisted
|
2071
|
-
end
|
2072
|
-
end
|
2073
|
-
|
2074
|
-
context "when a block is provided" do
|
2075
|
-
|
2076
|
-
let(:document) do
|
2077
|
-
Band.where(name: "Tool").first_or_initialize do |doc|
|
2078
|
-
doc.active = false
|
2079
|
-
end
|
2080
|
-
end
|
2081
|
-
|
2082
|
-
it "returns a new document" do
|
2083
|
-
document.name.should eq("Tool")
|
2084
|
-
end
|
2085
|
-
|
2086
|
-
it "returns a non persisted document" do
|
2087
|
-
document.should_not be_persisted
|
2088
|
-
end
|
2089
|
-
|
2090
|
-
it "yields to the block" do
|
2091
|
-
document.active.should be_false
|
2092
|
-
end
|
2093
|
-
end
|
2094
|
-
|
2095
|
-
context "when the criteria is complex" do
|
2096
|
-
|
2097
|
-
context "when the document is not found" do
|
2098
|
-
|
2099
|
-
let(:document) do
|
2100
|
-
Band.in(name: [ "New Order" ]).first_or_initialize(active: false)
|
2101
|
-
end
|
2102
|
-
|
2103
|
-
it "returns a new document" do
|
2104
|
-
document.active.should be_false
|
2105
|
-
end
|
2106
|
-
|
2107
|
-
it "returns a non persisted document" do
|
2108
|
-
document.should_not be_persisted
|
2109
|
-
end
|
2110
|
-
end
|
2111
|
-
end
|
2112
|
-
end
|
2113
|
-
end
|
2114
|
-
|
2115
|
-
describe "#freeze" do
|
2116
|
-
|
2117
|
-
let(:criteria) do
|
2118
|
-
Band.all
|
2119
|
-
end
|
2120
|
-
|
2121
|
-
before do
|
2122
|
-
criteria.freeze
|
2123
|
-
end
|
2124
|
-
|
2125
|
-
it "freezes the criteria" do
|
2126
|
-
criteria.should be_frozen
|
2127
|
-
end
|
2128
|
-
|
2129
|
-
it "initializes inclusions" do
|
2130
|
-
criteria.inclusions.should be_empty
|
2131
|
-
end
|
2132
|
-
|
2133
|
-
it "initializes the context" do
|
2134
|
-
criteria.context.should_not be_nil
|
2135
|
-
end
|
2136
|
-
end
|
2137
|
-
|
2138
|
-
describe "#for_ids" do
|
2139
|
-
|
2140
|
-
context "when only 1 id exists" do
|
2141
|
-
|
2142
|
-
let(:id) do
|
2143
|
-
Moped::BSON::ObjectId.new
|
2144
|
-
end
|
2145
|
-
|
2146
|
-
let(:criteria) do
|
2147
|
-
Band.queryable.for_ids([ id ])
|
2148
|
-
end
|
2149
|
-
|
2150
|
-
it "does not turn the selector into an $in" do
|
2151
|
-
criteria.selector.should eq({ "_id" => id })
|
2152
|
-
end
|
2153
|
-
end
|
2154
|
-
end
|
2155
|
-
|
2156
|
-
describe "#from_map_or_db" do
|
2157
|
-
|
2158
|
-
before(:all) do
|
2159
|
-
Mongoid.identity_map_enabled = true
|
2160
|
-
end
|
2161
|
-
|
2162
|
-
after(:all) do
|
2163
|
-
Mongoid.identity_map_enabled = false
|
2164
|
-
end
|
2165
|
-
|
2166
|
-
context "when the document is in the identity map" do
|
2167
|
-
|
2168
|
-
let!(:band) do
|
2169
|
-
Band.create(name: "Depeche Mode")
|
2170
|
-
end
|
2171
|
-
|
2172
|
-
let(:criteria) do
|
2173
|
-
Band.where(_id: band.id)
|
2174
|
-
end
|
2175
|
-
|
2176
|
-
let(:from_map) do
|
2177
|
-
criteria.from_map_or_db
|
2178
|
-
end
|
2179
|
-
|
2180
|
-
it "returns the document from the map" do
|
2181
|
-
from_map.should equal(band)
|
2182
|
-
end
|
2183
|
-
end
|
2184
|
-
|
2185
|
-
context "when the document is not in the identity map" do
|
2186
|
-
|
2187
|
-
let!(:band) do
|
2188
|
-
Band.create(name: "Depeche Mode")
|
2189
|
-
end
|
2190
|
-
|
2191
|
-
let(:criteria) do
|
2192
|
-
Band.where(_id: band.id)
|
2193
|
-
end
|
2194
|
-
|
2195
|
-
before do
|
2196
|
-
Mongoid::IdentityMap.clear
|
2197
|
-
end
|
2198
|
-
|
2199
|
-
let(:from_db) do
|
2200
|
-
criteria.from_map_or_db
|
2201
|
-
end
|
2202
|
-
|
2203
|
-
it "returns the document from the database" do
|
2204
|
-
from_db.should_not equal(band)
|
2205
|
-
end
|
2206
|
-
|
2207
|
-
it "returns the correct document" do
|
2208
|
-
from_db.should eq(band)
|
2209
|
-
end
|
2210
|
-
end
|
782
|
+
end
|
2211
783
|
|
2212
|
-
|
784
|
+
it "returns the first matching document" do
|
785
|
+
expect(result).to eq(depeche)
|
786
|
+
end
|
787
|
+
end
|
2213
788
|
|
2214
|
-
|
2215
|
-
Band.create(name: "Depeche Mode")
|
2216
|
-
end
|
789
|
+
context "when not returning the updated document" do
|
2217
790
|
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
791
|
+
let(:criteria) do
|
792
|
+
Band.where(name: "Depeche Mode")
|
793
|
+
end
|
2221
794
|
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
end
|
795
|
+
let!(:result) do
|
796
|
+
criteria.find_and_modify("$inc" => { likes: 1 })
|
797
|
+
end
|
2226
798
|
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
799
|
+
before do
|
800
|
+
depeche.reload
|
801
|
+
end
|
2230
802
|
|
2231
|
-
|
2232
|
-
|
803
|
+
it "returns the first matching document" do
|
804
|
+
expect(result).to eq(depeche)
|
805
|
+
end
|
806
|
+
end
|
2233
807
|
end
|
2234
|
-
end
|
2235
|
-
end
|
2236
808
|
|
2237
|
-
|
2238
|
-
|
2239
|
-
before(:all) do
|
2240
|
-
Mongoid.identity_map_enabled = true
|
2241
|
-
end
|
809
|
+
context "when not providing options" do
|
2242
810
|
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
811
|
+
let(:criteria) do
|
812
|
+
Band.where(name: "Depeche Mode")
|
813
|
+
end
|
2246
814
|
|
2247
|
-
|
815
|
+
let!(:result) do
|
816
|
+
criteria.find_and_modify("$inc" => { likes: 1 })
|
817
|
+
end
|
2248
818
|
|
2249
|
-
|
2250
|
-
|
2251
|
-
|
819
|
+
it "returns the first matching document" do
|
820
|
+
expect(result).to eq(depeche)
|
821
|
+
end
|
2252
822
|
|
2253
|
-
|
2254
|
-
|
823
|
+
it "updates the document in the database" do
|
824
|
+
expect(depeche.reload.likes).to eq(1)
|
825
|
+
end
|
2255
826
|
end
|
2256
827
|
|
2257
|
-
context "when
|
828
|
+
context "when sorting" do
|
2258
829
|
|
2259
830
|
let(:criteria) do
|
2260
|
-
Band.
|
831
|
+
Band.desc(:name)
|
2261
832
|
end
|
2262
833
|
|
2263
|
-
let(:
|
2264
|
-
criteria.
|
834
|
+
let!(:result) do
|
835
|
+
criteria.find_and_modify("$inc" => { likes: 1 })
|
836
|
+
end
|
837
|
+
|
838
|
+
it "returns the first matching document" do
|
839
|
+
expect(result).to eq(tool)
|
2265
840
|
end
|
2266
841
|
|
2267
|
-
it "
|
2268
|
-
|
842
|
+
it "updates the document in the database" do
|
843
|
+
expect(tool.reload.likes).to eq(1)
|
2269
844
|
end
|
2270
845
|
end
|
2271
846
|
|
2272
|
-
context "when
|
847
|
+
context "when limiting fields" do
|
2273
848
|
|
2274
849
|
let(:criteria) do
|
2275
|
-
Band.
|
850
|
+
Band.only(:_id)
|
2276
851
|
end
|
2277
852
|
|
2278
|
-
let(:
|
2279
|
-
criteria.
|
853
|
+
let!(:result) do
|
854
|
+
criteria.find_and_modify("$inc" => { likes: 1 })
|
2280
855
|
end
|
2281
856
|
|
2282
|
-
it "returns the
|
2283
|
-
|
857
|
+
it "returns the first matching document" do
|
858
|
+
expect(result).to eq(depeche)
|
2284
859
|
end
|
2285
|
-
end
|
2286
|
-
end
|
2287
|
-
|
2288
|
-
context "when the document is not in the identity map" do
|
2289
|
-
|
2290
|
-
let!(:band) do
|
2291
|
-
Band.create(name: "Depeche Mode")
|
2292
|
-
end
|
2293
860
|
|
2294
|
-
|
2295
|
-
|
2296
|
-
|
861
|
+
it "limits the returned fields" do
|
862
|
+
expect(result.name).to be_nil
|
863
|
+
end
|
2297
864
|
|
2298
|
-
|
2299
|
-
|
865
|
+
it "updates the document in the database" do
|
866
|
+
expect(depeche.reload.likes).to eq(1)
|
867
|
+
end
|
2300
868
|
end
|
2301
869
|
|
2302
|
-
context "when
|
870
|
+
context "when returning new" do
|
2303
871
|
|
2304
872
|
let(:criteria) do
|
2305
|
-
Band.where(
|
873
|
+
Band.where(name: "Depeche Mode")
|
2306
874
|
end
|
2307
875
|
|
2308
|
-
let(:
|
2309
|
-
criteria.
|
876
|
+
let!(:result) do
|
877
|
+
criteria.find_and_modify({ "$inc" => { likes: 1 }}, new: true)
|
2310
878
|
end
|
2311
879
|
|
2312
|
-
it "returns the
|
2313
|
-
|
880
|
+
it "returns the first matching document" do
|
881
|
+
expect(result).to eq(depeche)
|
2314
882
|
end
|
2315
883
|
|
2316
|
-
it "returns the
|
2317
|
-
|
884
|
+
it "returns the updated document" do
|
885
|
+
expect(result.likes).to eq(1)
|
2318
886
|
end
|
2319
887
|
end
|
2320
888
|
|
2321
|
-
context "when
|
889
|
+
context "when removing" do
|
2322
890
|
|
2323
891
|
let(:criteria) do
|
2324
|
-
Band.where(:
|
892
|
+
Band.where(name: "Depeche Mode")
|
2325
893
|
end
|
2326
894
|
|
2327
|
-
let(:
|
2328
|
-
criteria.
|
895
|
+
let!(:result) do
|
896
|
+
criteria.find_and_modify({}, remove: true)
|
2329
897
|
end
|
2330
898
|
|
2331
|
-
it "returns the
|
2332
|
-
|
899
|
+
it "returns the first matching document" do
|
900
|
+
expect(result).to eq(depeche)
|
2333
901
|
end
|
2334
902
|
|
2335
|
-
it "
|
2336
|
-
|
903
|
+
it "deletes the document from the database" do
|
904
|
+
expect {
|
905
|
+
depeche.reload
|
906
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2337
907
|
end
|
2338
908
|
end
|
2339
909
|
end
|
910
|
+
|
911
|
+
context "when the selector does not match" do
|
912
|
+
|
913
|
+
let(:criteria) do
|
914
|
+
Band.where(name: "Placebo")
|
915
|
+
end
|
916
|
+
|
917
|
+
let(:result) do
|
918
|
+
criteria.find_and_modify("$inc" => { likes: 1 })
|
919
|
+
end
|
920
|
+
|
921
|
+
it "returns nil" do
|
922
|
+
expect(result).to be_nil
|
923
|
+
end
|
924
|
+
end
|
925
|
+
end
|
926
|
+
|
927
|
+
describe "#freeze" do
|
928
|
+
|
929
|
+
let(:criteria) do
|
930
|
+
Band.all
|
931
|
+
end
|
932
|
+
|
933
|
+
before do
|
934
|
+
criteria.freeze
|
935
|
+
end
|
936
|
+
|
937
|
+
it "freezes the criteria" do
|
938
|
+
expect(criteria).to be_frozen
|
939
|
+
end
|
940
|
+
|
941
|
+
it "initializes inclusions" do
|
942
|
+
expect(criteria.inclusions).to be_empty
|
943
|
+
end
|
944
|
+
|
945
|
+
it "initializes the context" do
|
946
|
+
expect(criteria.context).to_not be_nil
|
947
|
+
end
|
2340
948
|
end
|
2341
949
|
|
2342
950
|
describe "#geo_near" do
|
@@ -2354,7 +962,7 @@ describe Mongoid::Criteria do
|
|
2354
962
|
end
|
2355
963
|
|
2356
964
|
it "returns the matching documents" do
|
2357
|
-
criteria.
|
965
|
+
expect(criteria).to eq([ match ])
|
2358
966
|
end
|
2359
967
|
end
|
2360
968
|
|
@@ -2373,7 +981,7 @@ describe Mongoid::Criteria do
|
|
2373
981
|
end
|
2374
982
|
|
2375
983
|
it "returns the matching documents" do
|
2376
|
-
criteria.
|
984
|
+
expect(criteria).to eq([ match ])
|
2377
985
|
end
|
2378
986
|
end
|
2379
987
|
|
@@ -2392,7 +1000,7 @@ describe Mongoid::Criteria do
|
|
2392
1000
|
end
|
2393
1001
|
|
2394
1002
|
it "returns the matching documents" do
|
2395
|
-
criteria.
|
1003
|
+
expect(criteria).to eq([ match ])
|
2396
1004
|
end
|
2397
1005
|
end
|
2398
1006
|
|
@@ -2415,14 +1023,14 @@ describe Mongoid::Criteria do
|
|
2415
1023
|
end
|
2416
1024
|
|
2417
1025
|
it "returns the matching documents" do
|
2418
|
-
criteria.
|
1026
|
+
expect(criteria).to eq([ match ])
|
2419
1027
|
end
|
2420
1028
|
end
|
2421
1029
|
|
2422
1030
|
context "when querying on a foreign key" do
|
2423
1031
|
|
2424
1032
|
let(:id) do
|
2425
|
-
|
1033
|
+
BSON::ObjectId.new
|
2426
1034
|
end
|
2427
1035
|
|
2428
1036
|
let!(:match_one) do
|
@@ -2436,7 +1044,7 @@ describe Mongoid::Criteria do
|
|
2436
1044
|
end
|
2437
1045
|
|
2438
1046
|
it "returns the matching documents" do
|
2439
|
-
criteria.
|
1047
|
+
expect(criteria).to eq([ match_one ])
|
2440
1048
|
end
|
2441
1049
|
end
|
2442
1050
|
|
@@ -2447,7 +1055,7 @@ describe Mongoid::Criteria do
|
|
2447
1055
|
end
|
2448
1056
|
|
2449
1057
|
it "returns the matching documents" do
|
2450
|
-
criteria.
|
1058
|
+
expect(criteria).to eq([ match_one ])
|
2451
1059
|
end
|
2452
1060
|
end
|
2453
1061
|
|
@@ -2460,7 +1068,7 @@ describe Mongoid::Criteria do
|
|
2460
1068
|
end
|
2461
1069
|
|
2462
1070
|
it "returns the matching documents" do
|
2463
|
-
criteria.
|
1071
|
+
expect(criteria).to eq([ match_one ])
|
2464
1072
|
end
|
2465
1073
|
end
|
2466
1074
|
|
@@ -2475,7 +1083,7 @@ describe Mongoid::Criteria do
|
|
2475
1083
|
end
|
2476
1084
|
|
2477
1085
|
it "returns the matching documents" do
|
2478
|
-
criteria.
|
1086
|
+
expect(criteria).to eq([ game ])
|
2479
1087
|
end
|
2480
1088
|
end
|
2481
1089
|
end
|
@@ -2490,30 +1098,22 @@ describe Mongoid::Criteria do
|
|
2490
1098
|
end
|
2491
1099
|
|
2492
1100
|
it "sets the class" do
|
2493
|
-
criteria.klass.
|
1101
|
+
expect(criteria.klass).to eq(Band)
|
2494
1102
|
end
|
2495
1103
|
|
2496
1104
|
it "sets the aliased fields" do
|
2497
|
-
criteria.aliased_fields.
|
1105
|
+
expect(criteria.aliased_fields).to eq(Band.aliased_fields)
|
2498
1106
|
end
|
2499
1107
|
|
2500
1108
|
it "sets the serializers" do
|
2501
|
-
criteria.serializers.
|
1109
|
+
expect(criteria.serializers).to eq(Band.fields)
|
2502
1110
|
end
|
2503
1111
|
end
|
2504
1112
|
|
2505
1113
|
describe "#includes" do
|
2506
1114
|
|
2507
|
-
before do
|
2508
|
-
Mongoid.identity_map_enabled = true
|
2509
|
-
end
|
2510
|
-
|
2511
|
-
after do
|
2512
|
-
Mongoid.identity_map_enabled = false
|
2513
|
-
end
|
2514
|
-
|
2515
1115
|
let!(:person) do
|
2516
|
-
Person.create
|
1116
|
+
Person.create(age: 1)
|
2517
1117
|
end
|
2518
1118
|
|
2519
1119
|
context "when providing a name that is not a relation" do
|
@@ -2571,30 +1171,20 @@ describe Mongoid::Criteria do
|
|
2571
1171
|
B.create(c: c_two)
|
2572
1172
|
end
|
2573
1173
|
|
2574
|
-
before do
|
2575
|
-
Mongoid::IdentityMap.clear
|
2576
|
-
end
|
2577
|
-
|
2578
1174
|
let!(:results) do
|
2579
|
-
C.includes(:b).
|
1175
|
+
C.includes(:b).to_a.detect do |c|
|
2580
1176
|
c.id == c_two.id
|
2581
1177
|
end
|
2582
1178
|
end
|
2583
1179
|
|
2584
|
-
let(:from_map) do
|
2585
|
-
Mongoid::IdentityMap[B.collection_name][b.id]
|
2586
|
-
end
|
2587
|
-
|
2588
1180
|
it "returns the correct documents" do
|
2589
|
-
results.
|
1181
|
+
expect(results).to eq(c_two)
|
2590
1182
|
end
|
2591
1183
|
|
2592
|
-
it "
|
2593
|
-
|
2594
|
-
|
2595
|
-
|
2596
|
-
it "retrieves the document from the identity map" do
|
2597
|
-
results.b.should equal(from_map)
|
1184
|
+
it "does not query the db" do
|
1185
|
+
expect_query(0) do
|
1186
|
+
results.b
|
1187
|
+
end
|
2598
1188
|
end
|
2599
1189
|
end
|
2600
1190
|
end
|
@@ -2648,42 +1238,26 @@ describe Mongoid::Criteria do
|
|
2648
1238
|
C.create(d: d_two)
|
2649
1239
|
end
|
2650
1240
|
|
2651
|
-
before do
|
2652
|
-
Mongoid::IdentityMap.clear
|
2653
|
-
end
|
2654
|
-
|
2655
1241
|
let!(:results) do
|
2656
1242
|
D.includes(:b, :c).entries.detect do |d|
|
2657
1243
|
d.id == d_two.id
|
2658
1244
|
end
|
2659
1245
|
end
|
2660
1246
|
|
2661
|
-
let(:from_map_b) do
|
2662
|
-
Mongoid::IdentityMap[B.collection_name][b.id]
|
2663
|
-
end
|
2664
|
-
|
2665
|
-
let(:from_map_c) do
|
2666
|
-
Mongoid::IdentityMap[C.collection_name][c.id]
|
2667
|
-
end
|
2668
|
-
|
2669
1247
|
it "returns the correct documents" do
|
2670
|
-
results.
|
2671
|
-
end
|
2672
|
-
|
2673
|
-
it "inserts the b document into the identity map" do
|
2674
|
-
from_map_b.should eq(b)
|
1248
|
+
expect(results).to eq(d_two)
|
2675
1249
|
end
|
2676
1250
|
|
2677
|
-
it "
|
2678
|
-
|
2679
|
-
|
2680
|
-
|
2681
|
-
it "retrieves the b document from the identity map" do
|
2682
|
-
results.b.should equal(from_map_b)
|
1251
|
+
it "does not query the db on b" do
|
1252
|
+
expect_query(0) do
|
1253
|
+
results.b
|
1254
|
+
end
|
2683
1255
|
end
|
2684
1256
|
|
2685
|
-
it "
|
2686
|
-
|
1257
|
+
it "does not query the db on c" do
|
1258
|
+
expect_query(0) do
|
1259
|
+
results.b
|
1260
|
+
end
|
2687
1261
|
end
|
2688
1262
|
end
|
2689
1263
|
end
|
@@ -2735,42 +1309,26 @@ describe Mongoid::Criteria do
|
|
2735
1309
|
2.times.map { C.create(d: d_two) }
|
2736
1310
|
end
|
2737
1311
|
|
2738
|
-
before do
|
2739
|
-
Mongoid::IdentityMap.clear
|
2740
|
-
end
|
2741
|
-
|
2742
1312
|
let!(:results) do
|
2743
1313
|
D.includes(:b, :c).entries.detect do |d|
|
2744
1314
|
d.id == d_two.id
|
2745
1315
|
end
|
2746
1316
|
end
|
2747
1317
|
|
2748
|
-
let(:from_map_bs) do
|
2749
|
-
bs.map { |b| Mongoid::IdentityMap[B.collection_name][b.id] }
|
2750
|
-
end
|
2751
|
-
|
2752
|
-
let(:from_map_cs) do
|
2753
|
-
cs.map { |c| Mongoid::IdentityMap[C.collection_name][c.id] }
|
2754
|
-
end
|
2755
|
-
|
2756
1318
|
it "returns the correct documents" do
|
2757
|
-
results.
|
2758
|
-
end
|
2759
|
-
|
2760
|
-
it "inserts the b documents into the identity map" do
|
2761
|
-
from_map_bs.should eq(bs)
|
2762
|
-
end
|
2763
|
-
|
2764
|
-
it "inserts the c documents into the identity map" do
|
2765
|
-
from_map_cs.should eq(cs)
|
1319
|
+
expect(results).to eq(d_two)
|
2766
1320
|
end
|
2767
1321
|
|
2768
|
-
it "
|
2769
|
-
|
1322
|
+
it "does not query the db on b" do
|
1323
|
+
expect_query(0) do
|
1324
|
+
results.b
|
1325
|
+
end
|
2770
1326
|
end
|
2771
1327
|
|
2772
|
-
it "
|
2773
|
-
|
1328
|
+
it "does not query the db on c" do
|
1329
|
+
expect_query(0) do
|
1330
|
+
results.b
|
1331
|
+
end
|
2774
1332
|
end
|
2775
1333
|
end
|
2776
1334
|
end
|
@@ -2787,16 +1345,12 @@ describe Mongoid::Criteria do
|
|
2787
1345
|
end
|
2788
1346
|
|
2789
1347
|
it "does not duplicate the metadata in the inclusions" do
|
2790
|
-
criteria.inclusions.
|
1348
|
+
expect(criteria.inclusions).to eq([ metadata ])
|
2791
1349
|
end
|
2792
1350
|
end
|
2793
1351
|
|
2794
1352
|
context "when mapping the results more than once" do
|
2795
1353
|
|
2796
|
-
before do
|
2797
|
-
Mongoid::IdentityMap.clear
|
2798
|
-
end
|
2799
|
-
|
2800
1354
|
let!(:post) do
|
2801
1355
|
person.posts.create(title: "one")
|
2802
1356
|
end
|
@@ -2811,7 +1365,7 @@ describe Mongoid::Criteria do
|
|
2811
1365
|
end
|
2812
1366
|
|
2813
1367
|
it "returns the proper results" do
|
2814
|
-
results.first.title.
|
1368
|
+
expect(results.first.title).to eq("one")
|
2815
1369
|
end
|
2816
1370
|
end
|
2817
1371
|
|
@@ -2848,10 +1402,6 @@ describe Mongoid::Criteria do
|
|
2848
1402
|
|
2849
1403
|
context "when calling first" do
|
2850
1404
|
|
2851
|
-
before do
|
2852
|
-
Mongoid::IdentityMap.clear
|
2853
|
-
end
|
2854
|
-
|
2855
1405
|
let(:criteria) do
|
2856
1406
|
peep.reload.addresses.includes(:band)
|
2857
1407
|
end
|
@@ -2860,37 +1410,30 @@ describe Mongoid::Criteria do
|
|
2860
1410
|
criteria.context
|
2861
1411
|
end
|
2862
1412
|
|
2863
|
-
before do
|
2864
|
-
context.should_receive(:eager_load_one).with(address_one).once.and_call_original
|
2865
|
-
end
|
2866
|
-
|
2867
1413
|
let!(:document) do
|
2868
1414
|
criteria.first
|
2869
1415
|
end
|
2870
1416
|
|
2871
|
-
let(:eager_loaded) do
|
2872
|
-
Mongoid::IdentityMap[Band.collection_name]
|
2873
|
-
end
|
2874
|
-
|
2875
1417
|
it "eager loads the first document" do
|
2876
|
-
|
1418
|
+
expect_query(0) do
|
1419
|
+
expect(document.band).to eq(depeche)
|
1420
|
+
end
|
2877
1421
|
end
|
2878
1422
|
|
2879
1423
|
it "does not eager load the last document" do
|
2880
|
-
|
1424
|
+
doc = criteria.last
|
1425
|
+
expect_query(1) do
|
1426
|
+
expect(doc.band).to eq(tool)
|
1427
|
+
end
|
2881
1428
|
end
|
2882
1429
|
|
2883
1430
|
it "returns the document" do
|
2884
|
-
document.
|
1431
|
+
expect(document).to eq(address_one)
|
2885
1432
|
end
|
2886
1433
|
end
|
2887
1434
|
|
2888
1435
|
context "when calling last" do
|
2889
1436
|
|
2890
|
-
before do
|
2891
|
-
Mongoid::IdentityMap.clear
|
2892
|
-
end
|
2893
|
-
|
2894
1437
|
let(:criteria) do
|
2895
1438
|
peep.reload.addresses.includes(:band)
|
2896
1439
|
end
|
@@ -2899,37 +1442,30 @@ describe Mongoid::Criteria do
|
|
2899
1442
|
criteria.context
|
2900
1443
|
end
|
2901
1444
|
|
2902
|
-
before do
|
2903
|
-
context.should_receive(:eager_load_one).with(address_two).once.and_call_original
|
2904
|
-
end
|
2905
|
-
|
2906
1445
|
let!(:document) do
|
2907
1446
|
criteria.last
|
2908
1447
|
end
|
2909
1448
|
|
2910
|
-
|
2911
|
-
|
1449
|
+
it "eager loads the last document" do
|
1450
|
+
expect_query(0) do
|
1451
|
+
expect(document.band).to eq(tool)
|
1452
|
+
end
|
2912
1453
|
end
|
2913
1454
|
|
2914
1455
|
it "does not eager load the first document" do
|
2915
|
-
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
2919
|
-
eager_loaded[tool.id].should eq(tool)
|
1456
|
+
doc = criteria.first
|
1457
|
+
expect_query(1) do
|
1458
|
+
expect(doc.band).to eq(depeche)
|
1459
|
+
end
|
2920
1460
|
end
|
2921
1461
|
|
2922
1462
|
it "returns the document" do
|
2923
|
-
document.
|
1463
|
+
expect(document).to eq(address_two)
|
2924
1464
|
end
|
2925
1465
|
end
|
2926
1466
|
|
2927
1467
|
context "when iterating all documents" do
|
2928
1468
|
|
2929
|
-
before do
|
2930
|
-
Mongoid::IdentityMap.clear
|
2931
|
-
end
|
2932
|
-
|
2933
1469
|
let(:criteria) do
|
2934
1470
|
peep.reload.addresses.includes(:band)
|
2935
1471
|
end
|
@@ -2938,32 +1474,24 @@ describe Mongoid::Criteria do
|
|
2938
1474
|
criteria.context
|
2939
1475
|
end
|
2940
1476
|
|
2941
|
-
before do
|
2942
|
-
context.
|
2943
|
-
should_receive(:eager_load).
|
2944
|
-
with([ address_one, address_two ]).
|
2945
|
-
once.
|
2946
|
-
and_call_original
|
2947
|
-
end
|
2948
|
-
|
2949
1477
|
let!(:documents) do
|
2950
1478
|
criteria.to_a
|
2951
1479
|
end
|
2952
1480
|
|
2953
|
-
let(:eager_loaded) do
|
2954
|
-
Mongoid::IdentityMap[Band.collection_name]
|
2955
|
-
end
|
2956
|
-
|
2957
1481
|
it "eager loads the first document" do
|
2958
|
-
|
1482
|
+
expect_query(0) do
|
1483
|
+
expect(documents.first.band).to eq(depeche)
|
1484
|
+
end
|
2959
1485
|
end
|
2960
1486
|
|
2961
1487
|
it "eager loads the last document" do
|
2962
|
-
|
1488
|
+
expect_query(0) do
|
1489
|
+
expect(documents.last.band).to eq(tool)
|
1490
|
+
end
|
2963
1491
|
end
|
2964
1492
|
|
2965
1493
|
it "returns the documents" do
|
2966
|
-
documents.
|
1494
|
+
expect(documents).to eq([ address_one, address_two ])
|
2967
1495
|
end
|
2968
1496
|
end
|
2969
1497
|
end
|
@@ -2971,7 +1499,7 @@ describe Mongoid::Criteria do
|
|
2971
1499
|
context "when the criteria is from the root" do
|
2972
1500
|
|
2973
1501
|
let!(:person_two) do
|
2974
|
-
Person.create
|
1502
|
+
Person.create(age: 2)
|
2975
1503
|
end
|
2976
1504
|
|
2977
1505
|
let!(:post_one) do
|
@@ -2982,38 +1510,31 @@ describe Mongoid::Criteria do
|
|
2982
1510
|
person_two.posts.create(title: "two")
|
2983
1511
|
end
|
2984
1512
|
|
2985
|
-
before do
|
2986
|
-
Mongoid::IdentityMap.clear
|
2987
|
-
end
|
2988
|
-
|
2989
1513
|
context "when calling first" do
|
2990
1514
|
|
2991
|
-
let
|
1515
|
+
let(:criteria) do
|
2992
1516
|
Post.includes(:person)
|
2993
1517
|
end
|
2994
1518
|
|
2995
|
-
let!(:context) do
|
2996
|
-
criteria.context
|
2997
|
-
end
|
2998
|
-
|
2999
|
-
before do
|
3000
|
-
context.should_receive(:eager_load_one).with(post_one).once.and_call_original
|
3001
|
-
end
|
3002
|
-
|
3003
1519
|
let!(:document) do
|
3004
1520
|
criteria.first
|
3005
1521
|
end
|
3006
1522
|
|
3007
|
-
it "eager loads
|
3008
|
-
|
1523
|
+
it "eager loads the first document" do
|
1524
|
+
expect_query(0) do
|
1525
|
+
expect(document.person).to eq(person)
|
1526
|
+
end
|
3009
1527
|
end
|
3010
1528
|
|
3011
|
-
it "does not eager
|
3012
|
-
|
1529
|
+
it "does not eager load the last document" do
|
1530
|
+
doc = criteria.last
|
1531
|
+
expect_query(1) do
|
1532
|
+
expect(doc.person).to eq(person_two)
|
1533
|
+
end
|
3013
1534
|
end
|
3014
1535
|
|
3015
1536
|
it "returns the first document" do
|
3016
|
-
document.
|
1537
|
+
expect(document).to eq(post_one)
|
3017
1538
|
end
|
3018
1539
|
end
|
3019
1540
|
|
@@ -3023,28 +1544,25 @@ describe Mongoid::Criteria do
|
|
3023
1544
|
Post.includes(:person)
|
3024
1545
|
end
|
3025
1546
|
|
3026
|
-
let!(:context) do
|
3027
|
-
criteria.context
|
3028
|
-
end
|
3029
|
-
|
3030
|
-
before do
|
3031
|
-
context.should_receive(:eager_load_one).with(post_two).once.and_call_original
|
3032
|
-
end
|
3033
|
-
|
3034
1547
|
let!(:document) do
|
3035
1548
|
criteria.last
|
3036
1549
|
end
|
3037
1550
|
|
3038
|
-
it "eager loads
|
3039
|
-
|
1551
|
+
it "eager loads the last document" do
|
1552
|
+
expect_query(0) do
|
1553
|
+
expect(document.person).to eq(person_two)
|
1554
|
+
end
|
3040
1555
|
end
|
3041
1556
|
|
3042
|
-
it "does not eager
|
3043
|
-
|
1557
|
+
it "does not eager load the first document" do
|
1558
|
+
doc = criteria.first
|
1559
|
+
expect_query(1) do
|
1560
|
+
expect(doc.person).to eq(person)
|
1561
|
+
end
|
3044
1562
|
end
|
3045
1563
|
|
3046
1564
|
it "returns the last document" do
|
3047
|
-
document.
|
1565
|
+
expect(document).to eq(post_two)
|
3048
1566
|
end
|
3049
1567
|
end
|
3050
1568
|
end
|
@@ -3070,20 +1588,8 @@ describe Mongoid::Criteria do
|
|
3070
1588
|
|
3071
1589
|
context "when the criteria has no options" do
|
3072
1590
|
|
3073
|
-
before do
|
3074
|
-
Mongoid::IdentityMap.clear
|
3075
|
-
end
|
3076
|
-
|
3077
1591
|
let!(:criteria) do
|
3078
|
-
Person.all
|
3079
|
-
end
|
3080
|
-
|
3081
|
-
let!(:context) do
|
3082
|
-
criteria.context
|
3083
|
-
end
|
3084
|
-
|
3085
|
-
before do
|
3086
|
-
context.should_receive(:eager_load).with([ person ]).once.and_call_original
|
1592
|
+
Person.asc(:age).all
|
3087
1593
|
end
|
3088
1594
|
|
3089
1595
|
let!(:documents) do
|
@@ -3091,15 +1597,19 @@ describe Mongoid::Criteria do
|
|
3091
1597
|
end
|
3092
1598
|
|
3093
1599
|
it "returns the correct documents" do
|
3094
|
-
documents.
|
1600
|
+
expect(documents).to eq([ person ])
|
3095
1601
|
end
|
3096
1602
|
|
3097
|
-
it "
|
3098
|
-
|
1603
|
+
it "eager loads the first document" do
|
1604
|
+
expect_query(0) do
|
1605
|
+
expect(documents.first.posts.first).to eq(post_one)
|
1606
|
+
end
|
3099
1607
|
end
|
3100
1608
|
|
3101
|
-
it "
|
3102
|
-
|
1609
|
+
it "eager loads the last document" do
|
1610
|
+
expect_query(0) do
|
1611
|
+
expect(documents.first.posts.last).to eq(post_two)
|
1612
|
+
end
|
3103
1613
|
end
|
3104
1614
|
|
3105
1615
|
context "when executing the query twice" do
|
@@ -3120,36 +1630,16 @@ describe Mongoid::Criteria do
|
|
3120
1630
|
new_criteria.first
|
3121
1631
|
end
|
3122
1632
|
|
3123
|
-
let(:mapped) do
|
3124
|
-
Mongoid::IdentityMap[Post.collection_name][{"person_id" => person.id}]
|
3125
|
-
end
|
3126
|
-
|
3127
1633
|
it "does not duplicate documents in the relation" do
|
3128
|
-
person.posts.size.
|
3129
|
-
end
|
3130
|
-
|
3131
|
-
it "does not duplicate documents in the map" do
|
3132
|
-
mapped.size.should eq(2)
|
1634
|
+
expect(person.posts.size).to eq(2)
|
3133
1635
|
end
|
3134
1636
|
end
|
3135
1637
|
end
|
3136
1638
|
|
3137
1639
|
context "when calling first on the criteria" do
|
3138
1640
|
|
3139
|
-
before do
|
3140
|
-
Mongoid::IdentityMap.clear
|
3141
|
-
end
|
3142
|
-
|
3143
1641
|
let(:criteria) do
|
3144
|
-
Person.all
|
3145
|
-
end
|
3146
|
-
|
3147
|
-
let!(:context) do
|
3148
|
-
criteria.context
|
3149
|
-
end
|
3150
|
-
|
3151
|
-
before do
|
3152
|
-
context.should_receive(:eager_load_one).with(person).once.and_call_original
|
1642
|
+
Person.asc(:age).all
|
3153
1643
|
end
|
3154
1644
|
|
3155
1645
|
let!(:from_db) do
|
@@ -3157,26 +1647,26 @@ describe Mongoid::Criteria do
|
|
3157
1647
|
end
|
3158
1648
|
|
3159
1649
|
it "returns the correct documents" do
|
3160
|
-
from_db.
|
1650
|
+
expect(from_db).to eq(person)
|
3161
1651
|
end
|
3162
1652
|
|
3163
|
-
it "
|
3164
|
-
|
1653
|
+
it "eager loads the first document" do
|
1654
|
+
expect_query(0) do
|
1655
|
+
expect(from_db.posts.first).to eq(post_one)
|
1656
|
+
end
|
3165
1657
|
end
|
3166
1658
|
|
3167
|
-
it "
|
3168
|
-
|
1659
|
+
it "eager loads the last document" do
|
1660
|
+
expect_query(0) do
|
1661
|
+
expect(from_db.posts.last).to eq(post_two)
|
1662
|
+
end
|
3169
1663
|
end
|
3170
1664
|
end
|
3171
1665
|
|
3172
1666
|
context "when calling last on the criteria" do
|
3173
1667
|
|
3174
|
-
before do
|
3175
|
-
Mongoid::IdentityMap.clear
|
3176
|
-
end
|
3177
|
-
|
3178
1668
|
let(:criteria) do
|
3179
|
-
Person.all
|
1669
|
+
Person.asc(:age).all
|
3180
1670
|
end
|
3181
1671
|
|
3182
1672
|
let!(:context) do
|
@@ -3192,15 +1682,19 @@ describe Mongoid::Criteria do
|
|
3192
1682
|
end
|
3193
1683
|
|
3194
1684
|
it "returns the correct documents" do
|
3195
|
-
from_db.
|
1685
|
+
expect(from_db).to eq(person)
|
3196
1686
|
end
|
3197
1687
|
|
3198
|
-
it "
|
3199
|
-
|
1688
|
+
it "eager loads the first document" do
|
1689
|
+
expect_query(0) do
|
1690
|
+
expect(from_db.posts.first).to eq(post_one)
|
1691
|
+
end
|
3200
1692
|
end
|
3201
1693
|
|
3202
|
-
it "
|
3203
|
-
|
1694
|
+
it "eager loads the last document" do
|
1695
|
+
expect_query(0) do
|
1696
|
+
expect(from_db.posts.last).to eq(post_two)
|
1697
|
+
end
|
3204
1698
|
end
|
3205
1699
|
end
|
3206
1700
|
|
@@ -3214,20 +1708,8 @@ describe Mongoid::Criteria do
|
|
3214
1708
|
person_two.posts.create(title: "three")
|
3215
1709
|
end
|
3216
1710
|
|
3217
|
-
before do
|
3218
|
-
Mongoid::IdentityMap.clear
|
3219
|
-
end
|
3220
|
-
|
3221
1711
|
let!(:criteria) do
|
3222
|
-
Person.asc(:
|
3223
|
-
end
|
3224
|
-
|
3225
|
-
let(:context) do
|
3226
|
-
criteria.context
|
3227
|
-
end
|
3228
|
-
|
3229
|
-
before do
|
3230
|
-
context.should_receive(:eager_load).with([ person ]).once.and_call_original
|
1712
|
+
Person.asc(:age).limit(1)
|
3231
1713
|
end
|
3232
1714
|
|
3233
1715
|
let!(:documents) do
|
@@ -3235,19 +1717,19 @@ describe Mongoid::Criteria do
|
|
3235
1717
|
end
|
3236
1718
|
|
3237
1719
|
it "returns the correct documents" do
|
3238
|
-
criteria.
|
1720
|
+
expect(criteria).to eq([ person ])
|
3239
1721
|
end
|
3240
1722
|
|
3241
|
-
it "
|
3242
|
-
|
3243
|
-
|
3244
|
-
|
3245
|
-
it "inserts the second document into the identity map" do
|
3246
|
-
Mongoid::IdentityMap[Post.collection_name][post_two.id].should eq(post_two)
|
1723
|
+
it "eager loads the first document" do
|
1724
|
+
expect_query(0) do
|
1725
|
+
expect(documents.first.posts.first).to eq(post_one)
|
1726
|
+
end
|
3247
1727
|
end
|
3248
1728
|
|
3249
|
-
it "
|
3250
|
-
|
1729
|
+
it "eager loads the second document" do
|
1730
|
+
expect_query(0) do
|
1731
|
+
expect(documents.first.posts.last).to eq(post_two)
|
1732
|
+
end
|
3251
1733
|
end
|
3252
1734
|
end
|
3253
1735
|
end
|
@@ -3264,20 +1746,8 @@ describe Mongoid::Criteria do
|
|
3264
1746
|
|
3265
1747
|
context "when the criteria has no options" do
|
3266
1748
|
|
3267
|
-
before do
|
3268
|
-
Mongoid::IdentityMap.clear
|
3269
|
-
end
|
3270
|
-
|
3271
1749
|
let!(:criteria) do
|
3272
|
-
Person.includes(:preferences)
|
3273
|
-
end
|
3274
|
-
|
3275
|
-
let(:context) do
|
3276
|
-
criteria.context
|
3277
|
-
end
|
3278
|
-
|
3279
|
-
before do
|
3280
|
-
context.should_receive(:eager_load).with([ person ]).once.and_call_original
|
1750
|
+
Person.asc(:age).includes(:preferences)
|
3281
1751
|
end
|
3282
1752
|
|
3283
1753
|
let!(:documents) do
|
@@ -3285,38 +1755,26 @@ describe Mongoid::Criteria do
|
|
3285
1755
|
end
|
3286
1756
|
|
3287
1757
|
it "returns the correct documents" do
|
3288
|
-
documents.
|
3289
|
-
end
|
3290
|
-
|
3291
|
-
let(:preference_map) do
|
3292
|
-
Mongoid::IdentityMap[Preference.collection_name]
|
1758
|
+
expect(documents).to eq([ person ])
|
3293
1759
|
end
|
3294
1760
|
|
3295
|
-
it "
|
3296
|
-
|
1761
|
+
it "eager loads the first document" do
|
1762
|
+
expect_query(0) do
|
1763
|
+
expect(documents.first.preferences.first).to eq(preference_one)
|
1764
|
+
end
|
3297
1765
|
end
|
3298
1766
|
|
3299
|
-
it "
|
3300
|
-
|
1767
|
+
it "eager loads the last document" do
|
1768
|
+
expect_query(0) do
|
1769
|
+
expect(documents.first.preferences.last).to eq(preference_two)
|
1770
|
+
end
|
3301
1771
|
end
|
3302
1772
|
end
|
3303
1773
|
|
3304
1774
|
context "when calling first on the criteria" do
|
3305
1775
|
|
3306
|
-
before do
|
3307
|
-
Mongoid::IdentityMap.clear
|
3308
|
-
end
|
3309
|
-
|
3310
1776
|
let!(:criteria) do
|
3311
|
-
Person.includes(:preferences)
|
3312
|
-
end
|
3313
|
-
|
3314
|
-
let(:context) do
|
3315
|
-
criteria.context
|
3316
|
-
end
|
3317
|
-
|
3318
|
-
before do
|
3319
|
-
context.should_receive(:eager_load_one).with(person).once.and_call_original
|
1777
|
+
Person.asc(:age).includes(:preferences)
|
3320
1778
|
end
|
3321
1779
|
|
3322
1780
|
let!(:from_db) do
|
@@ -3324,38 +1782,26 @@ describe Mongoid::Criteria do
|
|
3324
1782
|
end
|
3325
1783
|
|
3326
1784
|
it "returns the correct documents" do
|
3327
|
-
from_db.
|
3328
|
-
end
|
3329
|
-
|
3330
|
-
let(:preference_map) do
|
3331
|
-
Mongoid::IdentityMap[Preference.collection_name]
|
1785
|
+
expect(from_db).to eq(person)
|
3332
1786
|
end
|
3333
1787
|
|
3334
|
-
it "
|
3335
|
-
|
1788
|
+
it "eager loads the first document" do
|
1789
|
+
expect_query(0) do
|
1790
|
+
expect(from_db.preferences.first).to eq(preference_one)
|
1791
|
+
end
|
3336
1792
|
end
|
3337
1793
|
|
3338
|
-
it "
|
3339
|
-
|
1794
|
+
it "eager loads the last document" do
|
1795
|
+
expect_query(0) do
|
1796
|
+
expect(from_db.preferences.last).to eq(preference_two)
|
1797
|
+
end
|
3340
1798
|
end
|
3341
1799
|
end
|
3342
1800
|
|
3343
1801
|
context "when calling last on the criteria" do
|
3344
1802
|
|
3345
|
-
before do
|
3346
|
-
Mongoid::IdentityMap.clear
|
3347
|
-
end
|
3348
|
-
|
3349
1803
|
let!(:criteria) do
|
3350
|
-
Person.includes(:preferences)
|
3351
|
-
end
|
3352
|
-
|
3353
|
-
let(:context) do
|
3354
|
-
criteria.context
|
3355
|
-
end
|
3356
|
-
|
3357
|
-
before do
|
3358
|
-
context.should_receive(:eager_load_one).with(person).once.and_call_original
|
1804
|
+
Person.asc(:age).includes(:preferences)
|
3359
1805
|
end
|
3360
1806
|
|
3361
1807
|
let!(:from_db) do
|
@@ -3363,70 +1809,19 @@ describe Mongoid::Criteria do
|
|
3363
1809
|
end
|
3364
1810
|
|
3365
1811
|
it "returns the correct documents" do
|
3366
|
-
from_db.
|
3367
|
-
end
|
3368
|
-
|
3369
|
-
let(:preference_map) do
|
3370
|
-
Mongoid::IdentityMap[Preference.collection_name]
|
3371
|
-
end
|
3372
|
-
|
3373
|
-
it "inserts the first document into the identity map" do
|
3374
|
-
preference_map[preference_one.id].should eq(preference_one)
|
3375
|
-
end
|
3376
|
-
|
3377
|
-
it "inserts the second document into the identity map" do
|
3378
|
-
preference_map[preference_two.id].should eq(preference_two)
|
3379
|
-
end
|
3380
|
-
end
|
3381
|
-
|
3382
|
-
context "when the criteria has limiting options" do
|
3383
|
-
|
3384
|
-
let!(:person_two) do
|
3385
|
-
Person.create
|
3386
|
-
end
|
3387
|
-
|
3388
|
-
let!(:preference_three) do
|
3389
|
-
person_two.preferences.create(name: "three")
|
3390
|
-
end
|
3391
|
-
|
3392
|
-
before do
|
3393
|
-
Mongoid::IdentityMap.clear
|
3394
|
-
end
|
3395
|
-
|
3396
|
-
let!(:criteria) do
|
3397
|
-
Person.includes(:preferences).asc(:_id).limit(1)
|
3398
|
-
end
|
3399
|
-
|
3400
|
-
let(:context) do
|
3401
|
-
criteria.context
|
3402
|
-
end
|
3403
|
-
|
3404
|
-
before do
|
3405
|
-
context.should_receive(:eager_load).with([ person ]).once.and_call_original
|
3406
|
-
end
|
3407
|
-
|
3408
|
-
let!(:documents) do
|
3409
|
-
criteria.entries
|
3410
|
-
end
|
3411
|
-
|
3412
|
-
let(:preference_map) do
|
3413
|
-
Mongoid::IdentityMap[Preference.collection_name]
|
3414
|
-
end
|
3415
|
-
|
3416
|
-
it "returns the correct documents" do
|
3417
|
-
documents.should eq([ person ])
|
3418
|
-
end
|
3419
|
-
|
3420
|
-
it "inserts the first document into the identity map" do
|
3421
|
-
preference_map[preference_one.id].should eq(preference_one)
|
1812
|
+
expect(from_db).to eq(person)
|
3422
1813
|
end
|
3423
1814
|
|
3424
|
-
it "
|
3425
|
-
|
1815
|
+
it "eager loads the first document" do
|
1816
|
+
expect_query(0) do
|
1817
|
+
expect(from_db.preferences.first).to eq(preference_one)
|
1818
|
+
end
|
3426
1819
|
end
|
3427
1820
|
|
3428
|
-
it "
|
3429
|
-
|
1821
|
+
it "eager loads the last document" do
|
1822
|
+
expect_query(0) do
|
1823
|
+
expect(from_db.preferences.last).to eq(preference_two)
|
1824
|
+
end
|
3430
1825
|
end
|
3431
1826
|
end
|
3432
1827
|
end
|
@@ -3443,20 +1838,8 @@ describe Mongoid::Criteria do
|
|
3443
1838
|
|
3444
1839
|
context "when the criteria has no options" do
|
3445
1840
|
|
3446
|
-
before do
|
3447
|
-
Mongoid::IdentityMap.clear
|
3448
|
-
end
|
3449
|
-
|
3450
1841
|
let!(:criteria) do
|
3451
|
-
Person.includes(:posts)
|
3452
|
-
end
|
3453
|
-
|
3454
|
-
let(:context) do
|
3455
|
-
criteria.context
|
3456
|
-
end
|
3457
|
-
|
3458
|
-
before do
|
3459
|
-
context.should_receive(:eager_load).with([ person ]).once.and_call_original
|
1842
|
+
Person.asc(:age).includes(:posts)
|
3460
1843
|
end
|
3461
1844
|
|
3462
1845
|
let!(:documents) do
|
@@ -3464,34 +1847,26 @@ describe Mongoid::Criteria do
|
|
3464
1847
|
end
|
3465
1848
|
|
3466
1849
|
it "returns the correct documents" do
|
3467
|
-
documents.
|
1850
|
+
expect(documents).to eq([ person ])
|
3468
1851
|
end
|
3469
1852
|
|
3470
|
-
it "
|
3471
|
-
|
1853
|
+
it "eager loads the first document" do
|
1854
|
+
expect_query(0) do
|
1855
|
+
expect(documents.first.posts.first).to eq(post_one)
|
1856
|
+
end
|
3472
1857
|
end
|
3473
1858
|
|
3474
|
-
it "
|
3475
|
-
|
1859
|
+
it "eager loads the last document" do
|
1860
|
+
expect_query(0) do
|
1861
|
+
expect(documents.first.posts.last).to eq(post_two)
|
1862
|
+
end
|
3476
1863
|
end
|
3477
1864
|
end
|
3478
1865
|
|
3479
1866
|
context "when calling first on the criteria" do
|
3480
1867
|
|
3481
|
-
before do
|
3482
|
-
Mongoid::IdentityMap.clear
|
3483
|
-
end
|
3484
|
-
|
3485
1868
|
let!(:criteria) do
|
3486
|
-
Person.includes(:posts)
|
3487
|
-
end
|
3488
|
-
|
3489
|
-
let(:context) do
|
3490
|
-
criteria.context
|
3491
|
-
end
|
3492
|
-
|
3493
|
-
before do
|
3494
|
-
context.should_receive(:eager_load_one).with(person).once.and_call_original
|
1869
|
+
Person.asc(:age).includes(:posts)
|
3495
1870
|
end
|
3496
1871
|
|
3497
1872
|
let!(:from_db) do
|
@@ -3499,49 +1874,25 @@ describe Mongoid::Criteria do
|
|
3499
1874
|
end
|
3500
1875
|
|
3501
1876
|
it "returns the correct documents" do
|
3502
|
-
from_db.
|
3503
|
-
end
|
3504
|
-
|
3505
|
-
it "inserts the first document into the identity map" do
|
3506
|
-
Mongoid::IdentityMap[Post.collection_name][post_one.id].should eq(post_one)
|
3507
|
-
end
|
3508
|
-
|
3509
|
-
it "inserts the second document into the identity map" do
|
3510
|
-
Mongoid::IdentityMap[Post.collection_name][post_two.id].should eq(post_two)
|
1877
|
+
expect(from_db).to eq(person)
|
3511
1878
|
end
|
3512
1879
|
|
3513
1880
|
context "when subsequently getting all documents" do
|
3514
1881
|
|
3515
|
-
before do
|
3516
|
-
context.should_receive(:eager_load).with([ person ]).once.and_call_original
|
3517
|
-
end
|
3518
|
-
|
3519
1882
|
let!(:documents) do
|
3520
1883
|
criteria.entries
|
3521
1884
|
end
|
3522
1885
|
|
3523
1886
|
it "returns the correct documents" do
|
3524
|
-
documents.
|
1887
|
+
expect(documents).to eq([ person ])
|
3525
1888
|
end
|
3526
1889
|
end
|
3527
1890
|
end
|
3528
1891
|
|
3529
1892
|
context "when calling last on the criteria" do
|
3530
1893
|
|
3531
|
-
before do
|
3532
|
-
Mongoid::IdentityMap.clear
|
3533
|
-
end
|
3534
|
-
|
3535
1894
|
let!(:criteria) do
|
3536
|
-
Person.includes(:posts)
|
3537
|
-
end
|
3538
|
-
|
3539
|
-
let(:context) do
|
3540
|
-
criteria.context
|
3541
|
-
end
|
3542
|
-
|
3543
|
-
before do
|
3544
|
-
context.should_receive(:eager_load_one).with(person).once.and_call_original
|
1895
|
+
Person.asc(:age).includes(:posts)
|
3545
1896
|
end
|
3546
1897
|
|
3547
1898
|
let!(:from_db) do
|
@@ -3549,29 +1900,17 @@ describe Mongoid::Criteria do
|
|
3549
1900
|
end
|
3550
1901
|
|
3551
1902
|
it "returns the correct documents" do
|
3552
|
-
from_db.
|
3553
|
-
end
|
3554
|
-
|
3555
|
-
it "inserts the first document into the identity map" do
|
3556
|
-
Mongoid::IdentityMap[Post.collection_name][post_one.id].should eq(post_one)
|
3557
|
-
end
|
3558
|
-
|
3559
|
-
it "inserts the second document into the identity map" do
|
3560
|
-
Mongoid::IdentityMap[Post.collection_name][post_two.id].should eq(post_two)
|
1903
|
+
expect(from_db).to eq(person)
|
3561
1904
|
end
|
3562
1905
|
|
3563
1906
|
context "when subsequently getting all documents" do
|
3564
1907
|
|
3565
|
-
before do
|
3566
|
-
context.should_receive(:eager_load).with([ person ]).once.and_call_original
|
3567
|
-
end
|
3568
|
-
|
3569
1908
|
let!(:documents) do
|
3570
1909
|
criteria.entries
|
3571
1910
|
end
|
3572
1911
|
|
3573
1912
|
it "returns the correct documents" do
|
3574
|
-
documents.
|
1913
|
+
expect(documents).to eq([ person ])
|
3575
1914
|
end
|
3576
1915
|
end
|
3577
1916
|
end
|
@@ -3586,12 +1925,8 @@ describe Mongoid::Criteria do
|
|
3586
1925
|
person_two.posts.create(title: "three")
|
3587
1926
|
end
|
3588
1927
|
|
3589
|
-
before do
|
3590
|
-
Mongoid::IdentityMap.clear
|
3591
|
-
end
|
3592
|
-
|
3593
1928
|
let!(:criteria) do
|
3594
|
-
Person.includes(:posts).asc(:
|
1929
|
+
Person.includes(:posts).asc(:age).limit(1)
|
3595
1930
|
end
|
3596
1931
|
|
3597
1932
|
let(:context) do
|
@@ -3607,19 +1942,7 @@ describe Mongoid::Criteria do
|
|
3607
1942
|
end
|
3608
1943
|
|
3609
1944
|
it "returns the correct documents" do
|
3610
|
-
documents.
|
3611
|
-
end
|
3612
|
-
|
3613
|
-
it "inserts the first document into the identity map" do
|
3614
|
-
Mongoid::IdentityMap[Post.collection_name][post_one.id].should eq(post_one)
|
3615
|
-
end
|
3616
|
-
|
3617
|
-
it "inserts the second document into the identity map" do
|
3618
|
-
Mongoid::IdentityMap[Post.collection_name][post_two.id].should eq(post_two)
|
3619
|
-
end
|
3620
|
-
|
3621
|
-
it "does not insert the third post into the identity map" do
|
3622
|
-
Mongoid::IdentityMap[Post.collection_name][post_three.id].should be_nil
|
1945
|
+
expect(documents).to eq([ person ])
|
3623
1946
|
end
|
3624
1947
|
end
|
3625
1948
|
end
|
@@ -3636,12 +1959,8 @@ describe Mongoid::Criteria do
|
|
3636
1959
|
|
3637
1960
|
context "when the criteria has no options" do
|
3638
1961
|
|
3639
|
-
before do
|
3640
|
-
Mongoid::IdentityMap.clear
|
3641
|
-
end
|
3642
|
-
|
3643
1962
|
let!(:criteria) do
|
3644
|
-
Person.includes(:game)
|
1963
|
+
Person.asc(:age).includes(:game)
|
3645
1964
|
end
|
3646
1965
|
|
3647
1966
|
let(:context) do
|
@@ -3657,49 +1976,22 @@ describe Mongoid::Criteria do
|
|
3657
1976
|
end
|
3658
1977
|
|
3659
1978
|
it "returns the correct documents" do
|
3660
|
-
documents.
|
3661
|
-
end
|
3662
|
-
|
3663
|
-
it "deletes the replaced document from the identity map" do
|
3664
|
-
Mongoid::IdentityMap[Game.collection_name][game_one.id].should be_nil
|
3665
|
-
end
|
3666
|
-
|
3667
|
-
it "inserts the second document into the identity map" do
|
3668
|
-
Mongoid::IdentityMap[Game.collection_name][game_two.id].should eq(game_two)
|
3669
|
-
end
|
3670
|
-
|
3671
|
-
context "when asking from map or db" do
|
3672
|
-
|
3673
|
-
let(:in_map) do
|
3674
|
-
Mongoid::IdentityMap[Game.collection_name][game_two.id]
|
3675
|
-
end
|
3676
|
-
|
3677
|
-
let(:game) do
|
3678
|
-
Game.where("person_id" => person.id).from_map_or_db
|
3679
|
-
end
|
3680
|
-
|
3681
|
-
it "returns the document from the map" do
|
3682
|
-
game.should equal(in_map)
|
3683
|
-
end
|
1979
|
+
expect(documents).to eq([ person ])
|
3684
1980
|
end
|
3685
1981
|
end
|
3686
1982
|
|
3687
1983
|
context "when the criteria has limiting options" do
|
3688
1984
|
|
3689
1985
|
let!(:person_two) do
|
3690
|
-
Person.create
|
1986
|
+
Person.create(age: 2)
|
3691
1987
|
end
|
3692
1988
|
|
3693
1989
|
let!(:game_three) do
|
3694
1990
|
person_two.create_game(name: "Skyrim")
|
3695
1991
|
end
|
3696
1992
|
|
3697
|
-
before do
|
3698
|
-
Mongoid::IdentityMap.clear
|
3699
|
-
end
|
3700
|
-
|
3701
1993
|
let!(:criteria) do
|
3702
|
-
Person.where(id: person.id).includes(:game).asc(:
|
1994
|
+
Person.where(id: person.id).includes(:game).asc(:age).limit(1)
|
3703
1995
|
end
|
3704
1996
|
|
3705
1997
|
let(:context) do
|
@@ -3715,15 +2007,7 @@ describe Mongoid::Criteria do
|
|
3715
2007
|
end
|
3716
2008
|
|
3717
2009
|
it "returns the correct documents" do
|
3718
|
-
documents.
|
3719
|
-
end
|
3720
|
-
|
3721
|
-
it "inserts the second document into the identity map" do
|
3722
|
-
Mongoid::IdentityMap[Game.collection_name][game_two.id].should eq(game_two)
|
3723
|
-
end
|
3724
|
-
|
3725
|
-
it "does not load the extra child into the map" do
|
3726
|
-
Mongoid::IdentityMap[Game.collection_name][game_three.id].should be_nil
|
2010
|
+
expect(documents).to eq([ person ])
|
3727
2011
|
end
|
3728
2012
|
end
|
3729
2013
|
end
|
@@ -3731,7 +2015,7 @@ describe Mongoid::Criteria do
|
|
3731
2015
|
context "when including a belongs to" do
|
3732
2016
|
|
3733
2017
|
let(:person_two) do
|
3734
|
-
Person.create
|
2018
|
+
Person.create(age: 2)
|
3735
2019
|
end
|
3736
2020
|
|
3737
2021
|
let!(:game_one) do
|
@@ -3742,10 +2026,6 @@ describe Mongoid::Criteria do
|
|
3742
2026
|
person_two.create_game(name: "two")
|
3743
2027
|
end
|
3744
2028
|
|
3745
|
-
before do
|
3746
|
-
Mongoid::IdentityMap.clear
|
3747
|
-
end
|
3748
|
-
|
3749
2029
|
context "when providing no options" do
|
3750
2030
|
|
3751
2031
|
let!(:criteria) do
|
@@ -3769,15 +2049,7 @@ describe Mongoid::Criteria do
|
|
3769
2049
|
end
|
3770
2050
|
|
3771
2051
|
it "returns the correct documents" do
|
3772
|
-
criteria.
|
3773
|
-
end
|
3774
|
-
|
3775
|
-
it "inserts the first document into the identity map" do
|
3776
|
-
Mongoid::IdentityMap[Person.collection_name][person.id].should eq(person)
|
3777
|
-
end
|
3778
|
-
|
3779
|
-
it "inserts the second document into the identity map" do
|
3780
|
-
Mongoid::IdentityMap[Person.collection_name][person_two.id].should eq(person_two)
|
2052
|
+
expect(criteria).to eq([ game_one, game_two ])
|
3781
2053
|
end
|
3782
2054
|
end
|
3783
2055
|
|
@@ -3800,15 +2072,7 @@ describe Mongoid::Criteria do
|
|
3800
2072
|
end
|
3801
2073
|
|
3802
2074
|
it "returns the correct documents" do
|
3803
|
-
documents.
|
3804
|
-
end
|
3805
|
-
|
3806
|
-
it "inserts the first document into the identity map" do
|
3807
|
-
Mongoid::IdentityMap[Person.collection_name][person.id].should eq(person)
|
3808
|
-
end
|
3809
|
-
|
3810
|
-
it "does not load the documents outside of the limit" do
|
3811
|
-
Mongoid::IdentityMap[Person.collection_name][person_two.id].should be_nil
|
2075
|
+
expect(documents).to eq([ game_one ])
|
3812
2076
|
end
|
3813
2077
|
end
|
3814
2078
|
end
|
@@ -3831,12 +2095,8 @@ describe Mongoid::Criteria do
|
|
3831
2095
|
person.create_game(name: "two")
|
3832
2096
|
end
|
3833
2097
|
|
3834
|
-
before do
|
3835
|
-
Mongoid::IdentityMap.clear
|
3836
|
-
end
|
3837
|
-
|
3838
2098
|
let!(:criteria) do
|
3839
|
-
Person.includes(:posts, :game)
|
2099
|
+
Person.includes(:posts, :game).asc(:age)
|
3840
2100
|
end
|
3841
2101
|
|
3842
2102
|
let(:context) do
|
@@ -3852,23 +2112,7 @@ describe Mongoid::Criteria do
|
|
3852
2112
|
end
|
3853
2113
|
|
3854
2114
|
it "returns the correct documents" do
|
3855
|
-
criteria.
|
3856
|
-
end
|
3857
|
-
|
3858
|
-
it "inserts the first has many document into the identity map" do
|
3859
|
-
Mongoid::IdentityMap[Post.collection_name][post_one.id].should eq(post_one)
|
3860
|
-
end
|
3861
|
-
|
3862
|
-
it "inserts the second has many document into the identity map" do
|
3863
|
-
Mongoid::IdentityMap[Post.collection_name][post_two.id].should eq(post_two)
|
3864
|
-
end
|
3865
|
-
|
3866
|
-
it "removes the first has one document from the identity map" do
|
3867
|
-
Mongoid::IdentityMap[Game.collection_name][game_one.id].should be_nil
|
3868
|
-
end
|
3869
|
-
|
3870
|
-
it "inserts the second has one document into the identity map" do
|
3871
|
-
Mongoid::IdentityMap[Game.collection_name][game_two.id].should eq(game_two)
|
2115
|
+
expect(criteria).to eq([ person ])
|
3872
2116
|
end
|
3873
2117
|
end
|
3874
2118
|
end
|
@@ -3884,7 +2128,7 @@ describe Mongoid::Criteria do
|
|
3884
2128
|
end
|
3885
2129
|
|
3886
2130
|
it "returns the inclusions" do
|
3887
|
-
criteria.inclusions.
|
2131
|
+
expect(criteria.inclusions).to eq([ metadata ])
|
3888
2132
|
end
|
3889
2133
|
end
|
3890
2134
|
|
@@ -3903,7 +2147,7 @@ describe Mongoid::Criteria do
|
|
3903
2147
|
end
|
3904
2148
|
|
3905
2149
|
it "sets the inclusions" do
|
3906
|
-
criteria.inclusions.
|
2150
|
+
expect(criteria.inclusions).to eq([ metadata ])
|
3907
2151
|
end
|
3908
2152
|
end
|
3909
2153
|
|
@@ -3922,7 +2166,7 @@ describe Mongoid::Criteria do
|
|
3922
2166
|
end
|
3923
2167
|
|
3924
2168
|
it "returns the matching documents" do
|
3925
|
-
criteria.
|
2169
|
+
expect(criteria).to eq([ match ])
|
3926
2170
|
end
|
3927
2171
|
end
|
3928
2172
|
|
@@ -3941,7 +2185,7 @@ describe Mongoid::Criteria do
|
|
3941
2185
|
end
|
3942
2186
|
|
3943
2187
|
it "returns the matching documents" do
|
3944
|
-
criteria.
|
2188
|
+
expect(criteria).to eq([ match ])
|
3945
2189
|
end
|
3946
2190
|
end
|
3947
2191
|
|
@@ -3978,7 +2222,7 @@ describe Mongoid::Criteria do
|
|
3978
2222
|
end
|
3979
2223
|
|
3980
2224
|
it "returns the map/reduce results" do
|
3981
|
-
map_reduce.
|
2225
|
+
expect(map_reduce).to eq([
|
3982
2226
|
{ "_id" => "Depeche Mode", "value" => { "likes" => 200 }},
|
3983
2227
|
{ "_id" => "Tool", "value" => { "likes" => 100 }}
|
3984
2228
|
])
|
@@ -4008,7 +2252,7 @@ describe Mongoid::Criteria do
|
|
4008
2252
|
end
|
4009
2253
|
|
4010
2254
|
it "returns the max of the provided field" do
|
4011
|
-
max.
|
2255
|
+
expect(max).to eq(1000)
|
4012
2256
|
end
|
4013
2257
|
end
|
4014
2258
|
|
@@ -4021,7 +2265,7 @@ describe Mongoid::Criteria do
|
|
4021
2265
|
end
|
4022
2266
|
|
4023
2267
|
it "returns the document with the max value for the field" do
|
4024
|
-
max.
|
2268
|
+
expect(max).to eq(depeche)
|
4025
2269
|
end
|
4026
2270
|
end
|
4027
2271
|
end
|
@@ -4046,7 +2290,7 @@ describe Mongoid::Criteria do
|
|
4046
2290
|
end
|
4047
2291
|
|
4048
2292
|
it "returns the matching documents" do
|
4049
|
-
criteria.
|
2293
|
+
expect(criteria).to eq([ match ])
|
4050
2294
|
end
|
4051
2295
|
end
|
4052
2296
|
|
@@ -4077,27 +2321,27 @@ describe Mongoid::Criteria do
|
|
4077
2321
|
end
|
4078
2322
|
|
4079
2323
|
it "merges the selector" do
|
4080
|
-
merged.selector.
|
2324
|
+
expect(merged.selector).to eq({ "name" => "Depeche Mode" })
|
4081
2325
|
end
|
4082
2326
|
|
4083
2327
|
it "merges the options" do
|
4084
|
-
merged.options.
|
2328
|
+
expect(merged.options).to eq({ sort: { "name" => 1 }})
|
4085
2329
|
end
|
4086
2330
|
|
4087
2331
|
it "merges the documents" do
|
4088
|
-
merged.documents.
|
2332
|
+
expect(merged.documents).to eq([ band ])
|
4089
2333
|
end
|
4090
2334
|
|
4091
2335
|
it "merges the scoping options" do
|
4092
|
-
merged.scoping_options.
|
2336
|
+
expect(merged.scoping_options).to eq([ nil, nil ])
|
4093
2337
|
end
|
4094
2338
|
|
4095
2339
|
it "merges the inclusions" do
|
4096
|
-
merged.inclusions.
|
2340
|
+
expect(merged.inclusions).to eq([ metadata ])
|
4097
2341
|
end
|
4098
2342
|
|
4099
2343
|
it "returns a new criteria" do
|
4100
|
-
merged.
|
2344
|
+
expect(merged).to_not equal(criteria)
|
4101
2345
|
end
|
4102
2346
|
end
|
4103
2347
|
|
@@ -4116,23 +2360,23 @@ describe Mongoid::Criteria do
|
|
4116
2360
|
end
|
4117
2361
|
|
4118
2362
|
it "merges the selector" do
|
4119
|
-
merged.selector.
|
2363
|
+
expect(merged.selector).to eq({ "name" => "Depeche Mode" })
|
4120
2364
|
end
|
4121
2365
|
|
4122
2366
|
it "merges the options" do
|
4123
|
-
merged.options.
|
2367
|
+
expect(merged.options).to eq({ sort: { "name" => 1 }})
|
4124
2368
|
end
|
4125
2369
|
|
4126
2370
|
it "merges the scoping options" do
|
4127
|
-
merged.scoping_options.
|
2371
|
+
expect(merged.scoping_options).to eq([ nil, nil ])
|
4128
2372
|
end
|
4129
2373
|
|
4130
2374
|
it "merges the inclusions" do
|
4131
|
-
merged.inclusions.
|
2375
|
+
expect(merged.inclusions).to eq([ metadata ])
|
4132
2376
|
end
|
4133
2377
|
|
4134
2378
|
it "returns a new criteria" do
|
4135
|
-
merged.
|
2379
|
+
expect(merged).to_not equal(criteria)
|
4136
2380
|
end
|
4137
2381
|
end
|
4138
2382
|
end
|
@@ -4162,27 +2406,27 @@ describe Mongoid::Criteria do
|
|
4162
2406
|
end
|
4163
2407
|
|
4164
2408
|
it "merges the selector" do
|
4165
|
-
merged.selector.
|
2409
|
+
expect(merged.selector).to eq({ "name" => "Depeche Mode" })
|
4166
2410
|
end
|
4167
2411
|
|
4168
2412
|
it "merges the options" do
|
4169
|
-
merged.options.
|
2413
|
+
expect(merged.options).to eq({ sort: { "name" => 1 }})
|
4170
2414
|
end
|
4171
2415
|
|
4172
2416
|
it "merges the documents" do
|
4173
|
-
merged.documents.
|
2417
|
+
expect(merged.documents).to eq([ band ])
|
4174
2418
|
end
|
4175
2419
|
|
4176
2420
|
it "merges the scoping options" do
|
4177
|
-
merged.scoping_options.
|
2421
|
+
expect(merged.scoping_options).to eq([ nil, nil ])
|
4178
2422
|
end
|
4179
2423
|
|
4180
2424
|
it "merges the inclusions" do
|
4181
|
-
merged.inclusions.
|
2425
|
+
expect(merged.inclusions).to eq([ metadata ])
|
4182
2426
|
end
|
4183
2427
|
|
4184
2428
|
it "returns the same criteria" do
|
4185
|
-
merged.
|
2429
|
+
expect(merged).to equal(criteria)
|
4186
2430
|
end
|
4187
2431
|
end
|
4188
2432
|
|
@@ -4209,7 +2453,7 @@ describe Mongoid::Criteria do
|
|
4209
2453
|
end
|
4210
2454
|
|
4211
2455
|
it "returns the min of the provided field" do
|
4212
|
-
min.
|
2456
|
+
expect(min).to eq(500)
|
4213
2457
|
end
|
4214
2458
|
end
|
4215
2459
|
|
@@ -4222,7 +2466,7 @@ describe Mongoid::Criteria do
|
|
4222
2466
|
end
|
4223
2467
|
|
4224
2468
|
it "returns the document with the min value for the field" do
|
4225
|
-
min.
|
2469
|
+
expect(min).to eq(tool)
|
4226
2470
|
end
|
4227
2471
|
end
|
4228
2472
|
end
|
@@ -4243,7 +2487,7 @@ describe Mongoid::Criteria do
|
|
4243
2487
|
end
|
4244
2488
|
|
4245
2489
|
it "returns the matching documents" do
|
4246
|
-
criteria.
|
2490
|
+
expect(criteria).to eq([ match ])
|
4247
2491
|
end
|
4248
2492
|
end
|
4249
2493
|
|
@@ -4262,7 +2506,7 @@ describe Mongoid::Criteria do
|
|
4262
2506
|
end
|
4263
2507
|
|
4264
2508
|
it "returns the matching documents" do
|
4265
|
-
criteria.
|
2509
|
+
expect(criteria).to eq([ match ])
|
4266
2510
|
end
|
4267
2511
|
end
|
4268
2512
|
|
@@ -4281,7 +2525,7 @@ describe Mongoid::Criteria do
|
|
4281
2525
|
end
|
4282
2526
|
|
4283
2527
|
it "returns the matching documents" do
|
4284
|
-
criteria.
|
2528
|
+
expect(criteria).to eq([ match ])
|
4285
2529
|
end
|
4286
2530
|
end
|
4287
2531
|
|
@@ -4300,7 +2544,7 @@ describe Mongoid::Criteria do
|
|
4300
2544
|
end
|
4301
2545
|
|
4302
2546
|
it "returns the matching documents" do
|
4303
|
-
criteria.
|
2547
|
+
expect(criteria).to eq([ match ])
|
4304
2548
|
end
|
4305
2549
|
end
|
4306
2550
|
|
@@ -4319,7 +2563,7 @@ describe Mongoid::Criteria do
|
|
4319
2563
|
end
|
4320
2564
|
|
4321
2565
|
it "returns the matching documents" do
|
4322
|
-
criteria.
|
2566
|
+
expect(criteria).to eq([ match ])
|
4323
2567
|
end
|
4324
2568
|
end
|
4325
2569
|
|
@@ -4338,7 +2582,7 @@ describe Mongoid::Criteria do
|
|
4338
2582
|
end
|
4339
2583
|
|
4340
2584
|
it "returns the matching documents" do
|
4341
|
-
criteria.
|
2585
|
+
expect(criteria).to eq([ match ])
|
4342
2586
|
end
|
4343
2587
|
end
|
4344
2588
|
|
@@ -4357,11 +2601,11 @@ describe Mongoid::Criteria do
|
|
4357
2601
|
end
|
4358
2602
|
|
4359
2603
|
it "limits the returned fields" do
|
4360
|
-
criteria.first.name.
|
2604
|
+
expect(criteria.first.name).to be_nil
|
4361
2605
|
end
|
4362
2606
|
|
4363
2607
|
it "does not add _type to the fields" do
|
4364
|
-
criteria.options[:fields]["_type"].
|
2608
|
+
expect(criteria.options[:fields]["_type"]).to be_nil
|
4365
2609
|
end
|
4366
2610
|
end
|
4367
2611
|
|
@@ -4372,15 +2616,15 @@ describe Mongoid::Criteria do
|
|
4372
2616
|
end
|
4373
2617
|
|
4374
2618
|
it "includes the limited fields" do
|
4375
|
-
criteria.first.name.
|
2619
|
+
expect(criteria.first.name).to_not be_nil
|
4376
2620
|
end
|
4377
2621
|
|
4378
2622
|
it "excludes the non included fields" do
|
4379
|
-
criteria.first.active.
|
2623
|
+
expect(criteria.first.active).to be_nil
|
4380
2624
|
end
|
4381
2625
|
|
4382
2626
|
it "does not add _type to the fields" do
|
4383
|
-
criteria.options[:fields]["_type"].
|
2627
|
+
expect(criteria.options[:fields]["_type"]).to be_nil
|
4384
2628
|
end
|
4385
2629
|
end
|
4386
2630
|
|
@@ -4392,7 +2636,7 @@ describe Mongoid::Criteria do
|
|
4392
2636
|
|
4393
2637
|
it "only limits the fields on the correct model" do
|
4394
2638
|
criteria.each do |band|
|
4395
|
-
Person.new.age.
|
2639
|
+
expect(Person.new.age).to eq(100)
|
4396
2640
|
end
|
4397
2641
|
end
|
4398
2642
|
end
|
@@ -4405,7 +2649,7 @@ describe Mongoid::Criteria do
|
|
4405
2649
|
|
4406
2650
|
it "only limits the fields on the correct criteria" do
|
4407
2651
|
criteria.each do |band|
|
4408
|
-
Band.new.active.
|
2652
|
+
expect(Band.new.active).to be true
|
4409
2653
|
end
|
4410
2654
|
end
|
4411
2655
|
end
|
@@ -4419,7 +2663,7 @@ describe Mongoid::Criteria do
|
|
4419
2663
|
it "only limits the fields on the correct criteria" do
|
4420
2664
|
criteria.each do |band|
|
4421
2665
|
Band.all.each do |b|
|
4422
|
-
b.active.
|
2666
|
+
expect(b.active).to be true
|
4423
2667
|
end
|
4424
2668
|
end
|
4425
2669
|
end
|
@@ -4433,7 +2677,7 @@ describe Mongoid::Criteria do
|
|
4433
2677
|
end
|
4434
2678
|
|
4435
2679
|
it "adds _type to the fields" do
|
4436
|
-
criteria.options[:fields]["_type"].
|
2680
|
+
expect(criteria.options[:fields]["_type"]).to eq(1)
|
4437
2681
|
end
|
4438
2682
|
end
|
4439
2683
|
|
@@ -4446,7 +2690,7 @@ describe Mongoid::Criteria do
|
|
4446
2690
|
end
|
4447
2691
|
|
4448
2692
|
it "properly uses the database field name" do
|
4449
|
-
criteria.options.
|
2693
|
+
expect(criteria.options).to eq(fields: { "mobile_phones" => 1 })
|
4450
2694
|
end
|
4451
2695
|
end
|
4452
2696
|
end
|
@@ -4471,7 +2715,7 @@ describe Mongoid::Criteria do
|
|
4471
2715
|
end
|
4472
2716
|
|
4473
2717
|
it "returns the matching documents" do
|
4474
|
-
criteria.
|
2718
|
+
expect(criteria).to eq([ match ])
|
4475
2719
|
end
|
4476
2720
|
end
|
4477
2721
|
|
@@ -4482,7 +2726,7 @@ describe Mongoid::Criteria do
|
|
4482
2726
|
end
|
4483
2727
|
|
4484
2728
|
it "returns the matching documents" do
|
4485
|
-
criteria.
|
2729
|
+
expect(criteria).to eq([ match ])
|
4486
2730
|
end
|
4487
2731
|
end
|
4488
2732
|
end
|
@@ -4502,6 +2746,28 @@ describe Mongoid::Criteria do
|
|
4502
2746
|
Band.create(name: "Photek", likes: 1)
|
4503
2747
|
end
|
4504
2748
|
|
2749
|
+
context "when the field is aliased" do
|
2750
|
+
|
2751
|
+
let!(:expensive) do
|
2752
|
+
Product.create(price: 100000)
|
2753
|
+
end
|
2754
|
+
|
2755
|
+
let!(:cheap) do
|
2756
|
+
Product.create(price: 1)
|
2757
|
+
end
|
2758
|
+
|
2759
|
+
context "when using alias_attribute" do
|
2760
|
+
|
2761
|
+
let(:plucked) do
|
2762
|
+
Product.pluck(:price)
|
2763
|
+
end
|
2764
|
+
|
2765
|
+
it "uses the aliases" do
|
2766
|
+
expect(plucked).to eq([ 100000, 1 ])
|
2767
|
+
end
|
2768
|
+
end
|
2769
|
+
end
|
2770
|
+
|
4505
2771
|
context "when the criteria matches" do
|
4506
2772
|
|
4507
2773
|
context "when there are no duplicate values" do
|
@@ -4515,7 +2781,7 @@ describe Mongoid::Criteria do
|
|
4515
2781
|
end
|
4516
2782
|
|
4517
2783
|
it "returns the values" do
|
4518
|
-
plucked.
|
2784
|
+
expect(plucked).to eq([ "Depeche Mode", "Tool", "Photek" ])
|
4519
2785
|
end
|
4520
2786
|
|
4521
2787
|
context "when subsequently executing the criteria without a pluck" do
|
@@ -4526,6 +2792,17 @@ describe Mongoid::Criteria do
|
|
4526
2792
|
end
|
4527
2793
|
end
|
4528
2794
|
|
2795
|
+
context "when plucking mult-fields" do
|
2796
|
+
|
2797
|
+
let(:plucked) do
|
2798
|
+
Band.where(:name.exists => true).pluck(:name, :likes)
|
2799
|
+
end
|
2800
|
+
|
2801
|
+
it "returns the values" do
|
2802
|
+
expect(plucked).to eq([ ["Depeche Mode", 3], ["Tool", 3], ["Photek", 1] ])
|
2803
|
+
end
|
2804
|
+
end
|
2805
|
+
|
4529
2806
|
context "when there are duplicate values" do
|
4530
2807
|
|
4531
2808
|
let(:plucked) do
|
@@ -4533,7 +2810,7 @@ describe Mongoid::Criteria do
|
|
4533
2810
|
end
|
4534
2811
|
|
4535
2812
|
it "returns the duplicates" do
|
4536
|
-
plucked.
|
2813
|
+
expect(plucked).to eq([ 3, 3, 1 ])
|
4537
2814
|
end
|
4538
2815
|
end
|
4539
2816
|
end
|
@@ -4545,7 +2822,7 @@ describe Mongoid::Criteria do
|
|
4545
2822
|
end
|
4546
2823
|
|
4547
2824
|
it "returns an empty array" do
|
4548
|
-
plucked.
|
2825
|
+
expect(plucked).to be_empty
|
4549
2826
|
end
|
4550
2827
|
end
|
4551
2828
|
|
@@ -4556,7 +2833,32 @@ describe Mongoid::Criteria do
|
|
4556
2833
|
end
|
4557
2834
|
|
4558
2835
|
it "returns the field values" do
|
4559
|
-
plucked.
|
2836
|
+
expect(plucked).to eq([ depeche.id, tool.id, photek.id ])
|
2837
|
+
end
|
2838
|
+
end
|
2839
|
+
|
2840
|
+
context "when plucking a field that doesnt exist" do
|
2841
|
+
|
2842
|
+
context "when pluck one field" do
|
2843
|
+
|
2844
|
+
let(:plucked) do
|
2845
|
+
Band.all.pluck(:foo)
|
2846
|
+
end
|
2847
|
+
|
2848
|
+
it "returns a empty array" do
|
2849
|
+
expect(plucked).to eq([])
|
2850
|
+
end
|
2851
|
+
end
|
2852
|
+
|
2853
|
+
context "when pluck multiple fields" do
|
2854
|
+
|
2855
|
+
let(:plucked) do
|
2856
|
+
Band.all.pluck(:foo, :bar)
|
2857
|
+
end
|
2858
|
+
|
2859
|
+
it "returns a empty array" do
|
2860
|
+
expect(plucked).to eq([[], [], []])
|
2861
|
+
end
|
4560
2862
|
end
|
4561
2863
|
end
|
4562
2864
|
end
|
@@ -4576,7 +2878,7 @@ describe Mongoid::Criteria do
|
|
4576
2878
|
context "when asking about a model public class method" do
|
4577
2879
|
|
4578
2880
|
it "returns true" do
|
4579
|
-
criteria.
|
2881
|
+
expect(criteria).to respond_to(:ages)
|
4580
2882
|
end
|
4581
2883
|
end
|
4582
2884
|
|
@@ -4585,7 +2887,7 @@ describe Mongoid::Criteria do
|
|
4585
2887
|
context "when including private methods" do
|
4586
2888
|
|
4587
2889
|
it "returns true" do
|
4588
|
-
criteria.respond_to?(:for_ids, true).
|
2890
|
+
expect(criteria.respond_to?(:for_ids, true)).to be true
|
4589
2891
|
end
|
4590
2892
|
end
|
4591
2893
|
end
|
@@ -4593,7 +2895,7 @@ describe Mongoid::Criteria do
|
|
4593
2895
|
context "when asking about a model class public instance method" do
|
4594
2896
|
|
4595
2897
|
it "returns true" do
|
4596
|
-
criteria.respond_to?(:join).
|
2898
|
+
expect(criteria.respond_to?(:join)).to be true
|
4597
2899
|
end
|
4598
2900
|
end
|
4599
2901
|
|
@@ -4602,14 +2904,14 @@ describe Mongoid::Criteria do
|
|
4602
2904
|
context "when not including private methods" do
|
4603
2905
|
|
4604
2906
|
it "returns false" do
|
4605
|
-
criteria.
|
2907
|
+
expect(criteria).to_not respond_to(:fork)
|
4606
2908
|
end
|
4607
2909
|
end
|
4608
2910
|
|
4609
2911
|
context "when including private methods" do
|
4610
2912
|
|
4611
2913
|
it "returns true" do
|
4612
|
-
criteria.respond_to?(:fork, true).
|
2914
|
+
expect(criteria.respond_to?(:fork, true)).to be true
|
4613
2915
|
end
|
4614
2916
|
end
|
4615
2917
|
end
|
@@ -4617,7 +2919,7 @@ describe Mongoid::Criteria do
|
|
4617
2919
|
context "when asking about a criteria instance method" do
|
4618
2920
|
|
4619
2921
|
it "returns true" do
|
4620
|
-
criteria.
|
2922
|
+
expect(criteria).to respond_to(:context)
|
4621
2923
|
end
|
4622
2924
|
end
|
4623
2925
|
|
@@ -4626,14 +2928,14 @@ describe Mongoid::Criteria do
|
|
4626
2928
|
context "when not including private methods" do
|
4627
2929
|
|
4628
2930
|
it "returns false" do
|
4629
|
-
criteria.
|
2931
|
+
expect(criteria).to_not respond_to(:puts)
|
4630
2932
|
end
|
4631
2933
|
end
|
4632
2934
|
|
4633
2935
|
context "when including private methods" do
|
4634
2936
|
|
4635
2937
|
it "returns true" do
|
4636
|
-
criteria.respond_to?(:puts, true).
|
2938
|
+
expect(criteria.respond_to?(:puts, true)).to be true
|
4637
2939
|
end
|
4638
2940
|
end
|
4639
2941
|
end
|
@@ -4656,7 +2958,7 @@ describe Mongoid::Criteria do
|
|
4656
2958
|
end
|
4657
2959
|
|
4658
2960
|
it "sorts the results in memory" do
|
4659
|
-
sorted.
|
2961
|
+
expect(sorted).to eq([ tool, depeche ])
|
4660
2962
|
end
|
4661
2963
|
end
|
4662
2964
|
|
@@ -4683,7 +2985,7 @@ describe Mongoid::Criteria do
|
|
4683
2985
|
end
|
4684
2986
|
|
4685
2987
|
it "returns the sum of the provided field" do
|
4686
|
-
sum.
|
2988
|
+
expect(sum).to eq(1500)
|
4687
2989
|
end
|
4688
2990
|
end
|
4689
2991
|
|
@@ -4694,7 +2996,7 @@ describe Mongoid::Criteria do
|
|
4694
2996
|
end
|
4695
2997
|
|
4696
2998
|
it "returns the sum for the provided block" do
|
4697
|
-
sum.
|
2999
|
+
expect(sum).to eq(1500)
|
4698
3000
|
end
|
4699
3001
|
end
|
4700
3002
|
end
|
@@ -4711,7 +3013,7 @@ describe Mongoid::Criteria do
|
|
4711
3013
|
end
|
4712
3014
|
|
4713
3015
|
it "returns the executed criteria" do
|
4714
|
-
criteria.to_ary.
|
3016
|
+
expect(criteria.to_ary).to eq([ band ])
|
4715
3017
|
end
|
4716
3018
|
end
|
4717
3019
|
|
@@ -4726,7 +3028,7 @@ describe Mongoid::Criteria do
|
|
4726
3028
|
end
|
4727
3029
|
|
4728
3030
|
it "executes the criteria while properly giving the hint to Mongo" do
|
4729
|
-
expect { criteria.to_ary }.to raise_error(Moped::Errors::QueryFailure)
|
3031
|
+
expect { criteria.to_ary }.to raise_error(Moped::Errors::QueryFailure, %r{failed with error 10113: "bad hint"})
|
4730
3032
|
end
|
4731
3033
|
end
|
4732
3034
|
|
@@ -4741,7 +3043,7 @@ describe Mongoid::Criteria do
|
|
4741
3043
|
end
|
4742
3044
|
|
4743
3045
|
it "executes the criteria while properly giving the hint to Mongo" do
|
4744
|
-
expect { criteria.to_ary }.to raise_error(Moped::Errors::QueryFailure)
|
3046
|
+
expect { criteria.to_ary }.to raise_error(Moped::Errors::QueryFailure, %r{failed with error 10113: "bad hint"})
|
4745
3047
|
end
|
4746
3048
|
end
|
4747
3049
|
|
@@ -4759,7 +3061,32 @@ describe Mongoid::Criteria do
|
|
4759
3061
|
end
|
4760
3062
|
|
4761
3063
|
it "executes the criteria while properly giving the max scan to Mongo" do
|
4762
|
-
criteria.to_ary.
|
3064
|
+
expect(criteria.to_ary).to eq [band]
|
3065
|
+
end
|
3066
|
+
end
|
3067
|
+
|
3068
|
+
describe "#text_search" do
|
3069
|
+
|
3070
|
+
let(:criteria) do
|
3071
|
+
Word.all
|
3072
|
+
end
|
3073
|
+
|
3074
|
+
before do
|
3075
|
+
Word.with(database: "admin").mongo_session.command(setParameter: 1, textSearchEnabled: true)
|
3076
|
+
Word.create_indexes
|
3077
|
+
Word.create!(name: "phase", origin: "latin")
|
3078
|
+
end
|
3079
|
+
|
3080
|
+
after(:all) do
|
3081
|
+
Word.remove_indexes
|
3082
|
+
end
|
3083
|
+
|
3084
|
+
let(:search) do
|
3085
|
+
criteria.text_search("phase")
|
3086
|
+
end
|
3087
|
+
|
3088
|
+
it "returns all fields" do
|
3089
|
+
expect(search.first.origin).to eq("latin")
|
4763
3090
|
end
|
4764
3091
|
end
|
4765
3092
|
|
@@ -4770,7 +3097,7 @@ describe Mongoid::Criteria do
|
|
4770
3097
|
end
|
4771
3098
|
|
4772
3099
|
it "returns self" do
|
4773
|
-
criteria.to_criteria.
|
3100
|
+
expect(criteria.to_criteria).to eq(criteria)
|
4774
3101
|
end
|
4775
3102
|
end
|
4776
3103
|
|
@@ -4781,11 +3108,11 @@ describe Mongoid::Criteria do
|
|
4781
3108
|
end
|
4782
3109
|
|
4783
3110
|
it "returns a proc" do
|
4784
|
-
criteria.to_proc.
|
3111
|
+
expect(criteria.to_proc).to be_a(Proc)
|
4785
3112
|
end
|
4786
3113
|
|
4787
3114
|
it "wraps the criteria in the proc" do
|
4788
|
-
criteria.to_proc[].
|
3115
|
+
expect(criteria.to_proc[]).to eq(criteria)
|
4789
3116
|
end
|
4790
3117
|
end
|
4791
3118
|
|
@@ -4802,7 +3129,7 @@ describe Mongoid::Criteria do
|
|
4802
3129
|
end
|
4803
3130
|
|
4804
3131
|
it "returns documents with the provided type" do
|
4805
|
-
criteria.
|
3132
|
+
expect(criteria).to eq([ browser ])
|
4806
3133
|
end
|
4807
3134
|
end
|
4808
3135
|
|
@@ -4817,7 +3144,7 @@ describe Mongoid::Criteria do
|
|
4817
3144
|
end
|
4818
3145
|
|
4819
3146
|
it "returns documents with the provided types" do
|
4820
|
-
criteria.
|
3147
|
+
expect(criteria).to eq([ browser ])
|
4821
3148
|
end
|
4822
3149
|
end
|
4823
3150
|
end
|
@@ -4850,7 +3177,7 @@ describe Mongoid::Criteria do
|
|
4850
3177
|
end
|
4851
3178
|
|
4852
3179
|
it "returns the matching documents" do
|
4853
|
-
criteria.
|
3180
|
+
expect(criteria).to eq([ match ])
|
4854
3181
|
end
|
4855
3182
|
end
|
4856
3183
|
end
|
@@ -4864,18 +3191,18 @@ describe Mongoid::Criteria do
|
|
4864
3191
|
end
|
4865
3192
|
|
4866
3193
|
it "returns the matching documents" do
|
4867
|
-
criteria.
|
3194
|
+
expect(criteria).to eq([ match ])
|
4868
3195
|
end
|
4869
3196
|
end
|
4870
3197
|
|
4871
3198
|
context "when the criteria is an exact fk array match" do
|
4872
3199
|
|
4873
3200
|
let(:id_one) do
|
4874
|
-
|
3201
|
+
BSON::ObjectId.new
|
4875
3202
|
end
|
4876
3203
|
|
4877
3204
|
let(:id_two) do
|
4878
|
-
|
3205
|
+
BSON::ObjectId.new
|
4879
3206
|
end
|
4880
3207
|
|
4881
3208
|
let(:criteria) do
|
@@ -4883,7 +3210,7 @@ describe Mongoid::Criteria do
|
|
4883
3210
|
end
|
4884
3211
|
|
4885
3212
|
it "does not wrap the array in another array" do
|
4886
|
-
criteria.selector.
|
3213
|
+
expect(criteria.selector).to eq({ "agent_ids" => [ id_one, id_two ]})
|
4887
3214
|
end
|
4888
3215
|
end
|
4889
3216
|
end
|
@@ -4902,7 +3229,7 @@ describe Mongoid::Criteria do
|
|
4902
3229
|
end
|
4903
3230
|
|
4904
3231
|
it "returns the matching documents" do
|
4905
|
-
criteria.
|
3232
|
+
expect(criteria).to eq([ match ])
|
4906
3233
|
end
|
4907
3234
|
end
|
4908
3235
|
|
@@ -4913,7 +3240,7 @@ describe Mongoid::Criteria do
|
|
4913
3240
|
end
|
4914
3241
|
|
4915
3242
|
it "returns the matching documents" do
|
4916
|
-
criteria.
|
3243
|
+
expect(criteria).to eq([ match ])
|
4917
3244
|
end
|
4918
3245
|
end
|
4919
3246
|
end
|
@@ -4986,7 +3313,7 @@ describe Mongoid::Criteria do
|
|
4986
3313
|
end
|
4987
3314
|
|
4988
3315
|
it "passes the block through method_missing" do
|
4989
|
-
criteria.uniq(&:name).
|
3316
|
+
expect(criteria.uniq(&:name)).to eq([ band_one ])
|
4990
3317
|
end
|
4991
3318
|
end
|
4992
3319
|
|
@@ -4996,16 +3323,12 @@ describe Mongoid::Criteria do
|
|
4996
3323
|
Band.where(name: "Depeche Mode").with(collection: "artists")
|
4997
3324
|
end
|
4998
3325
|
|
4999
|
-
after do
|
5000
|
-
Band.persistence_options.clear
|
5001
|
-
end
|
5002
|
-
|
5003
3326
|
it "retains the criteria selection" do
|
5004
|
-
criteria.selector.
|
3327
|
+
expect(criteria.selector).to eq("name" => "Depeche Mode")
|
5005
3328
|
end
|
5006
3329
|
|
5007
3330
|
it "sets the persistence options" do
|
5008
|
-
|
3331
|
+
expect(criteria.persistence_options).to eq(collection: "artists")
|
5009
3332
|
end
|
5010
3333
|
end
|
5011
3334
|
|
@@ -5024,7 +3347,7 @@ describe Mongoid::Criteria do
|
|
5024
3347
|
end
|
5025
3348
|
|
5026
3349
|
it "returns the matching documents" do
|
5027
|
-
criteria.
|
3350
|
+
expect(criteria).to eq([ match ])
|
5028
3351
|
end
|
5029
3352
|
end
|
5030
3353
|
|
@@ -5043,7 +3366,7 @@ describe Mongoid::Criteria do
|
|
5043
3366
|
end
|
5044
3367
|
|
5045
3368
|
it "returns the matching documents" do
|
5046
|
-
criteria.
|
3369
|
+
expect(criteria).to eq([ match ])
|
5047
3370
|
end
|
5048
3371
|
end
|
5049
3372
|
|
@@ -5064,7 +3387,7 @@ describe Mongoid::Criteria do
|
|
5064
3387
|
end
|
5065
3388
|
|
5066
3389
|
it "returns the matching documents" do
|
5067
|
-
criteria.
|
3390
|
+
expect(criteria).to eq([ match ])
|
5068
3391
|
end
|
5069
3392
|
end
|
5070
3393
|
|
@@ -5083,7 +3406,7 @@ describe Mongoid::Criteria do
|
|
5083
3406
|
end
|
5084
3407
|
|
5085
3408
|
it "returns the matching documents" do
|
5086
|
-
criteria.
|
3409
|
+
expect(criteria).to eq([ match ])
|
5087
3410
|
end
|
5088
3411
|
end
|
5089
3412
|
|
@@ -5102,7 +3425,7 @@ describe Mongoid::Criteria do
|
|
5102
3425
|
end
|
5103
3426
|
|
5104
3427
|
it "returns the matching documents" do
|
5105
|
-
criteria.
|
3428
|
+
expect(criteria).to eq([ match ])
|
5106
3429
|
end
|
5107
3430
|
end
|
5108
3431
|
|
@@ -5117,7 +3440,7 @@ describe Mongoid::Criteria do
|
|
5117
3440
|
end
|
5118
3441
|
|
5119
3442
|
it "returns the matching documents" do
|
5120
|
-
criteria.
|
3443
|
+
expect(criteria).to eq([ match ])
|
5121
3444
|
end
|
5122
3445
|
end
|
5123
3446
|
|
@@ -5132,7 +3455,7 @@ describe Mongoid::Criteria do
|
|
5132
3455
|
end
|
5133
3456
|
|
5134
3457
|
it "properly uses the database field name" do
|
5135
|
-
criteria.options.
|
3458
|
+
expect(criteria.options).to eq(fields: { "mobile_phones" => 0 })
|
5136
3459
|
end
|
5137
3460
|
end
|
5138
3461
|
end
|