mongoid 3.1.6 → 4.0.0
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 +432 -8
- data/README.md +5 -6
- data/lib/config/locales/en.yml +32 -18
- data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded.rb +0 -30
- data/lib/mongoid/atomic/paths/root.rb +0 -13
- data/lib/mongoid/atomic.rb +1 -12
- 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/attributes.rb +63 -101
- data/lib/mongoid/{dirty.rb → changeable.rb} +32 -2
- data/lib/mongoid/composable.rb +105 -0
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/config.rb +3 -9
- data/lib/mongoid/contextual/aggregable/mongo.rb +7 -9
- data/lib/mongoid/contextual/atomic.rb +53 -53
- data/lib/mongoid/contextual/geo_near.rb +1 -1
- data/lib/mongoid/contextual/map_reduce.rb +4 -2
- data/lib/mongoid/contextual/memory.rb +18 -6
- data/lib/mongoid/contextual/mongo.rb +64 -56
- data/lib/mongoid/contextual/none.rb +90 -0
- data/lib/mongoid/contextual/text_search.rb +178 -0
- data/lib/mongoid/contextual.rb +2 -0
- data/lib/mongoid/copyable.rb +2 -3
- data/lib/mongoid/{criterion → criteria}/findable.rb +7 -47
- 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 +28 -8
- data/lib/mongoid/criteria/permission.rb +70 -0
- data/lib/mongoid/{criterion/scoping.rb → criteria/scopable.rb} +2 -2
- data/lib/mongoid/criteria.rb +39 -34
- data/lib/mongoid/document.rb +32 -17
- data/lib/mongoid/errors/document_not_destroyed.rb +25 -0
- data/lib/mongoid/errors/document_not_found.rb +2 -1
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
- data/lib/mongoid/errors/invalid_storage_parent.rb +26 -0
- data/lib/mongoid/errors/invalid_value.rb +16 -0
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/errors/readonly_document.rb +24 -0
- data/lib/mongoid/errors.rb +4 -1
- data/lib/mongoid/extensions/array.rb +3 -3
- data/lib/mongoid/extensions/big_decimal.rb +1 -1
- data/lib/mongoid/extensions/boolean.rb +15 -17
- data/lib/mongoid/extensions/date.rb +1 -1
- data/lib/mongoid/extensions/date_time.rb +3 -3
- data/lib/mongoid/extensions/float.rb +2 -1
- data/lib/mongoid/extensions/hash.rb +3 -3
- data/lib/mongoid/extensions/integer.rb +1 -1
- data/lib/mongoid/extensions/object.rb +7 -7
- data/lib/mongoid/extensions/object_id.rb +5 -5
- data/lib/mongoid/extensions/range.rb +9 -3
- data/lib/mongoid/extensions/regexp.rb +1 -1
- data/lib/mongoid/extensions/set.rb +1 -1
- data/lib/mongoid/extensions/string.rb +6 -18
- data/lib/mongoid/extensions/symbol.rb +1 -1
- data/lib/mongoid/extensions/time.rb +3 -3
- data/lib/mongoid/extensions/time_with_zone.rb +1 -1
- data/lib/mongoid/extensions.rb +2 -7
- data/lib/mongoid/factory.rb +8 -6
- data/lib/mongoid/fields/foreign_key.rb +3 -3
- data/lib/mongoid/fields/localized.rb +1 -1
- data/lib/mongoid/fields/standard.rb +5 -17
- data/lib/mongoid/fields/validators/macro.rb +15 -5
- data/lib/mongoid/fields.rb +41 -8
- data/lib/mongoid/{finders.rb → findable.rb} +8 -2
- data/lib/mongoid/indexable/specification.rb +104 -0
- data/lib/mongoid/{indexes → indexable}/validators/options.rb +2 -1
- data/lib/mongoid/{indexes.rb → indexable.rb} +50 -55
- data/lib/mongoid/{inspection.rb → inspectable.rb} +15 -11
- data/lib/mongoid/{callbacks.rb → interceptable.rb} +30 -62
- data/lib/mongoid/log_subscriber.rb +55 -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 +2 -2
- 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/matchable.rb +152 -0
- data/lib/mongoid/persistable/creatable.rb +188 -0
- data/lib/mongoid/persistable/deletable.rb +149 -0
- data/lib/mongoid/persistable/destroyable.rb +60 -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 +152 -0
- data/lib/mongoid/persistable/upsertable.rb +55 -0
- data/lib/mongoid/persistable.rb +216 -0
- data/lib/mongoid/positional.rb +71 -0
- data/lib/mongoid/query_cache.rb +247 -0
- data/lib/mongoid/railtie.rb +32 -45
- data/lib/mongoid/railties/database.rake +9 -25
- data/lib/mongoid/relations/accessors.rb +13 -49
- data/lib/mongoid/relations/auto_save.rb +15 -36
- data/lib/mongoid/relations/binding.rb +1 -24
- data/lib/mongoid/relations/bindings/embedded/in.rb +1 -1
- 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/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/builders.rb +2 -2
- 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/base.rb +149 -0
- data/lib/mongoid/relations/eager/belongs_to.rb +31 -0
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +47 -0
- data/lib/mongoid/relations/eager/has_many.rb +38 -0
- data/lib/mongoid/relations/eager/has_one.rb +30 -0
- data/lib/mongoid/relations/eager.rb +46 -0
- data/lib/mongoid/relations/embedded/batchable.rb +4 -5
- data/lib/mongoid/relations/embedded/in.rb +4 -4
- data/lib/mongoid/relations/embedded/many.rb +14 -32
- data/lib/mongoid/relations/embedded/one.rb +1 -1
- data/lib/mongoid/relations/macros.rb +3 -4
- data/lib/mongoid/relations/many.rb +30 -31
- data/lib/mongoid/relations/marshalable.rb +3 -3
- data/lib/mongoid/relations/metadata.rb +14 -79
- 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 +21 -41
- data/lib/mongoid/relations/referenced/in.rb +4 -20
- data/lib/mongoid/relations/referenced/many.rb +19 -32
- data/lib/mongoid/relations/referenced/many_to_many.rb +15 -38
- data/lib/mongoid/relations/referenced/one.rb +6 -25
- data/lib/mongoid/relations/synchronization.rb +3 -3
- data/lib/mongoid/relations/touchable.rb +34 -1
- data/lib/mongoid/relations.rb +11 -25
- data/lib/mongoid/{reloading.rb → reloadable.rb} +6 -4
- data/lib/mongoid/{scoping.rb → scopable.rb} +36 -36
- data/lib/mongoid/selectable.rb +59 -0
- data/lib/mongoid/{serialization.rb → serializable.rb} +11 -2
- data/lib/mongoid/sessions/factory.rb +2 -0
- data/lib/mongoid/sessions/options.rb +180 -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 +16 -3
- data/lib/mongoid/sessions.rb +37 -345
- data/lib/mongoid/{sharding.rb → shardable.rb} +5 -1
- data/lib/mongoid/{state.rb → stateful.rb} +13 -1
- data/lib/mongoid/support/query_counter.rb +23 -0
- data/lib/mongoid/tasks/database.rake +31 -0
- data/lib/mongoid/tasks/database.rb +107 -0
- data/lib/mongoid/threaded/lifecycle.rb +0 -28
- data/lib/mongoid/threaded.rb +0 -157
- data/lib/mongoid/timestamps/updated/short.rb +2 -2
- data/lib/mongoid/{hierarchy.rb → traversable.rb} +9 -5
- data/lib/mongoid/{validations → validatable}/associated.rb +4 -2
- 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 +23 -19
- data/lib/mongoid/{validations.rb → validatable.rb} +23 -10
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid.rb +10 -76
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +13 -24
- 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 +0 -122
- data/lib/support/ruby_version.rb +1 -1
- data/spec/app/models/account.rb +2 -6
- data/spec/app/models/acolyte.rb +2 -1
- data/spec/app/models/actor.rb +0 -1
- data/spec/app/models/address.rb +8 -3
- data/spec/app/models/animal.rb +1 -1
- data/spec/app/models/appointment.rb +3 -3
- 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/dog.rb +1 -1
- data/spec/app/models/draft.rb +9 -0
- 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/edit.rb +5 -0
- data/spec/app/models/even.rb +7 -0
- data/spec/app/models/event.rb +1 -1
- 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 +1 -3
- 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/line_item.rb +1 -1
- data/spec/app/models/login.rb +1 -1
- data/spec/app/models/message.rb +8 -0
- data/spec/app/models/movie.rb +1 -0
- data/spec/app/models/name.rb +3 -3
- data/spec/app/models/note.rb +3 -1
- data/spec/app/models/odd.rb +7 -0
- data/spec/app/models/oscar.rb +1 -1
- data/spec/app/models/parent_doc.rb +1 -1
- data/spec/app/models/person.rb +16 -10
- data/spec/app/models/phone.rb +1 -3
- data/spec/app/models/player.rb +3 -3
- data/spec/app/models/post.rb +5 -3
- data/spec/app/models/preference.rb +1 -1
- data/spec/app/models/quiz.rb +0 -3
- data/spec/app/models/record.rb +10 -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/symptom.rb +1 -1
- 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 +3 -3
- data/spec/app/models/video.rb +1 -5
- data/spec/app/models/wiki_page.rb +2 -5
- 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 +58 -18
- data/spec/mongoid/attributes_spec.rb +315 -436
- data/spec/mongoid/{dirty_spec.rb → changeable_spec.rb} +203 -153
- 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 +78 -38
- data/spec/mongoid/contextual/atomic_spec.rb +68 -58
- 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 +151 -94
- data/spec/mongoid/contextual/mongo_spec.rb +238 -150
- data/spec/mongoid/contextual/none_spec.rb +127 -0
- data/spec/mongoid/contextual/text_search_spec.rb +209 -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 +1255 -0
- data/spec/mongoid/{criterion/scoping_spec.rb → criteria/scopable_spec.rb} +37 -37
- data/spec/mongoid/criteria_spec.rb +578 -2295
- 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_destroyed_spec.rb +33 -0
- 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 +5 -5
- 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 +8 -8
- 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/readonly_document_spec.rb +29 -0
- 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 +8 -8
- 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 +38 -23
- data/spec/mongoid/fields/standard_spec.rb +12 -12
- data/spec/mongoid/fields_spec.rb +263 -217
- data/spec/mongoid/{finders_spec.rb → findable_spec.rb} +127 -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} +117 -116
- data/spec/mongoid/log_subscriber_spec.rb +75 -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/matchable/ne_spec.rb +46 -0
- 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 +218 -0
- data/spec/mongoid/persistable/destroyable_spec.rb +192 -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 +461 -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} +9 -9
- data/spec/mongoid/query_cache_spec.rb +231 -0
- 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 +37 -17
- data/spec/mongoid/relations/bindings/embedded/in_spec.rb +12 -12
- data/spec/mongoid/relations/bindings/embedded/many_spec.rb +3 -3
- data/spec/mongoid/relations/bindings/embedded/one_spec.rb +5 -5
- data/spec/mongoid/relations/bindings/referenced/in_spec.rb +26 -26
- data/spec/mongoid/relations/bindings/referenced/many_spec.rb +10 -10
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +19 -19
- data/spec/mongoid/relations/bindings/referenced/one_spec.rb +12 -12
- 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 +24 -35
- 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 +12 -25
- data/spec/mongoid/relations/builders_spec.rb +21 -21
- data/spec/mongoid/relations/cascading/delete_spec.rb +9 -9
- data/spec/mongoid/relations/cascading/destroy_spec.rb +6 -6
- data/spec/mongoid/relations/cascading/nullify_spec.rb +4 -4
- data/spec/mongoid/relations/cascading/restrict_spec.rb +7 -7
- 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 +117 -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 +56 -57
- data/spec/mongoid/relations/embedded/many_spec.rb +393 -372
- data/spec/mongoid/relations/embedded/one_spec.rb +108 -141
- data/spec/mongoid/relations/macros_spec.rb +108 -102
- data/spec/mongoid/relations/metadata_spec.rb +180 -255
- 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 +434 -527
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +352 -424
- data/spec/mongoid/relations/referenced/one_spec.rb +149 -264
- 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 +118 -118
- data/spec/mongoid/relations/touchable_spec.rb +333 -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} +89 -164
- data/spec/mongoid/selectable_spec.rb +134 -0
- data/spec/mongoid/{serialization_spec.rb → serializable_spec.rb} +129 -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 +107 -0
- data/spec/mongoid/sessions_spec.rb +289 -178
- data/spec/mongoid/{sharding_spec.rb → shardable_spec.rb} +8 -8
- data/spec/mongoid/{state_spec.rb → stateful_spec.rb} +36 -11
- data/spec/mongoid/tasks/database_rake_spec.rb +285 -0
- data/spec/mongoid/tasks/database_spec.rb +160 -0
- 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/timeless_spec.rb +6 -6
- data/spec/mongoid/timestamps/updated/short_spec.rb +11 -11
- data/spec/mongoid/timestamps/updated_spec.rb +9 -13
- data/spec/mongoid/timestamps_spec.rb +9 -13
- data/spec/mongoid/{hierarchy_spec.rb → traversable_spec.rb} +19 -19
- data/spec/mongoid/{validations → validatable}/associated_spec.rb +45 -22
- data/spec/mongoid/{validations → validatable}/format_spec.rb +6 -6
- data/spec/mongoid/{validations → validatable}/length_spec.rb +14 -14
- data/spec/mongoid/{validations → validatable}/numericality_spec.rb +1 -1
- data/spec/mongoid/{validations → validatable}/presence_spec.rb +37 -44
- data/spec/mongoid/{validations → validatable}/uniqueness_spec.rb +184 -192
- data/spec/mongoid/{validations_spec.rb → validatable_spec.rb} +28 -28
- data/spec/mongoid_spec.rb +8 -8
- data/spec/rails/mongoid_spec.rb +19 -335
- data/spec/spec_helper.rb +29 -13
- metadata +296 -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/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/strategies.rb +0 -97
- data/lib/mongoid/matchers.rb +0 -32
- 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/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/atomic.rb +0 -231
- 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/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/operations.rb +0 -214
- data/lib/mongoid/persistence/upsertion.rb +0 -31
- data/lib/mongoid/persistence.rb +0 -357
- data/lib/mongoid/unit_of_work.rb +0 -61
- data/lib/mongoid/versioning.rb +0 -217
- data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
- data/lib/rack/mongoid.rb +0 -2
- 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/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/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/ne_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
|
@@ -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
|
|
@@ -362,9 +362,9 @@ describe Mongoid::Criteria do
|
|
|
362
362
|
end
|
|
363
363
|
|
|
364
364
|
it "does not hit the database after first iteration" do
|
|
365
|
-
criteria.context.query.
|
|
365
|
+
expect(criteria.context.query).to 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
|
|
@@ -380,9 +380,9 @@ describe Mongoid::Criteria do
|
|
|
380
380
|
end
|
|
381
381
|
|
|
382
382
|
it "does not hit the database after first iteration" do
|
|
383
|
-
criteria.context.query.
|
|
383
|
+
expect(criteria.context.query).to 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,1525 +753,197 @@ 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
|
|
760
|
+
describe "#find_and_modify" do
|
|
852
761
|
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
end
|
|
856
|
-
end
|
|
762
|
+
let!(:depeche) do
|
|
763
|
+
Band.create(name: "Depeche Mode")
|
|
857
764
|
end
|
|
858
765
|
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
Mongoid.identity_map_enabled = true
|
|
863
|
-
end
|
|
766
|
+
let!(:tool) do
|
|
767
|
+
Band.create(name: "Tool")
|
|
768
|
+
end
|
|
864
769
|
|
|
865
|
-
|
|
866
|
-
Mongoid.identity_map_enabled = false
|
|
867
|
-
end
|
|
770
|
+
context "when the selector matches" do
|
|
868
771
|
|
|
869
|
-
|
|
870
|
-
Band.create(name: "Depeche Mode")
|
|
871
|
-
end
|
|
772
|
+
context "when the identity map is enabled" do
|
|
872
773
|
|
|
873
|
-
|
|
874
|
-
Band.create(name: "Placebo")
|
|
875
|
-
end
|
|
774
|
+
context "when returning the updated document" do
|
|
876
775
|
|
|
877
|
-
|
|
776
|
+
let(:criteria) do
|
|
777
|
+
Band.where(name: "Depeche Mode")
|
|
778
|
+
end
|
|
878
779
|
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
780
|
+
let(:result) do
|
|
781
|
+
criteria.find_and_modify({ "$inc" => { likes: 1 }}, new: true)
|
|
782
|
+
end
|
|
882
783
|
|
|
883
|
-
|
|
884
|
-
|
|
784
|
+
it "returns the first matching document" do
|
|
785
|
+
expect(result).to eq(depeche)
|
|
786
|
+
end
|
|
885
787
|
end
|
|
886
788
|
|
|
887
|
-
context "when
|
|
789
|
+
context "when not returning the updated document" do
|
|
888
790
|
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
Browser.find(canvas.id)
|
|
892
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
|
791
|
+
let(:criteria) do
|
|
792
|
+
Band.where(name: "Depeche Mode")
|
|
893
793
|
end
|
|
894
|
-
end
|
|
895
|
-
end
|
|
896
794
|
|
|
897
|
-
|
|
795
|
+
let!(:result) do
|
|
796
|
+
criteria.find_and_modify("$inc" => { likes: 1 })
|
|
797
|
+
end
|
|
898
798
|
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
799
|
+
before do
|
|
800
|
+
depeche.reload
|
|
801
|
+
end
|
|
902
802
|
|
|
903
|
-
|
|
904
|
-
|
|
803
|
+
it "returns the first matching document" do
|
|
804
|
+
expect(result).to eq(depeche)
|
|
805
|
+
end
|
|
905
806
|
end
|
|
906
807
|
end
|
|
907
808
|
|
|
908
|
-
context "when providing
|
|
909
|
-
|
|
910
|
-
let(:from_map) do
|
|
911
|
-
Band.find(depeche.id.to_s)
|
|
912
|
-
end
|
|
809
|
+
context "when not providing options" do
|
|
913
810
|
|
|
914
|
-
|
|
915
|
-
|
|
811
|
+
let(:criteria) do
|
|
812
|
+
Band.where(name: "Depeche Mode")
|
|
916
813
|
end
|
|
917
|
-
end
|
|
918
814
|
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
let(:from_map) do
|
|
922
|
-
Band.find(depeche.id, placebo.id)
|
|
815
|
+
let!(:result) do
|
|
816
|
+
criteria.find_and_modify("$inc" => { likes: 1 })
|
|
923
817
|
end
|
|
924
818
|
|
|
925
|
-
it "returns the first
|
|
926
|
-
|
|
819
|
+
it "returns the first matching document" do
|
|
820
|
+
expect(result).to eq(depeche)
|
|
927
821
|
end
|
|
928
822
|
|
|
929
|
-
it "
|
|
930
|
-
|
|
823
|
+
it "updates the document in the database" do
|
|
824
|
+
expect(depeche.reload.likes).to eq(1)
|
|
931
825
|
end
|
|
932
826
|
end
|
|
933
|
-
end
|
|
934
|
-
|
|
935
|
-
context "when using object ids" do
|
|
936
|
-
|
|
937
|
-
let!(:band) do
|
|
938
|
-
Band.create
|
|
939
|
-
end
|
|
940
827
|
|
|
941
|
-
context "when
|
|
828
|
+
context "when sorting" do
|
|
942
829
|
|
|
943
|
-
let
|
|
944
|
-
|
|
830
|
+
let(:criteria) do
|
|
831
|
+
Band.desc(:name)
|
|
945
832
|
end
|
|
946
833
|
|
|
947
|
-
let!(:
|
|
948
|
-
|
|
834
|
+
let!(:result) do
|
|
835
|
+
criteria.find_and_modify("$inc" => { likes: 1 })
|
|
949
836
|
end
|
|
950
837
|
|
|
951
|
-
|
|
838
|
+
it "returns the first matching document" do
|
|
839
|
+
expect(result).to eq(tool)
|
|
840
|
+
end
|
|
952
841
|
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
Browser.find(canvas.id)
|
|
956
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
|
957
|
-
end
|
|
842
|
+
it "updates the document in the database" do
|
|
843
|
+
expect(tool.reload.likes).to eq(1)
|
|
958
844
|
end
|
|
959
845
|
end
|
|
960
846
|
|
|
961
|
-
context "when
|
|
962
|
-
|
|
963
|
-
context "when the id matches" do
|
|
964
|
-
|
|
965
|
-
let(:found) do
|
|
966
|
-
Band.find(band.id)
|
|
967
|
-
end
|
|
847
|
+
context "when limiting fields" do
|
|
968
848
|
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
end
|
|
849
|
+
let(:criteria) do
|
|
850
|
+
Band.only(:_id)
|
|
972
851
|
end
|
|
973
852
|
|
|
974
|
-
|
|
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
|
|
853
|
+
let!(:result) do
|
|
854
|
+
criteria.find_and_modify("$inc" => { likes: 1 })
|
|
1011
855
|
end
|
|
1012
|
-
end
|
|
1013
856
|
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
let!(:band_two) do
|
|
1017
|
-
Band.create(name: "Tool")
|
|
857
|
+
it "returns the first matching document" do
|
|
858
|
+
expect(result).to eq(depeche)
|
|
1018
859
|
end
|
|
1019
860
|
|
|
1020
|
-
|
|
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
|
|
861
|
+
it "limits the returned fields" do
|
|
862
|
+
expect(result.name).to be_nil
|
|
1043
863
|
end
|
|
1044
864
|
|
|
1045
|
-
|
|
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
|
|
865
|
+
it "updates the document in the database" do
|
|
866
|
+
expect(depeche.reload.likes).to eq(1)
|
|
1082
867
|
end
|
|
1083
868
|
end
|
|
1084
869
|
|
|
1085
|
-
context "when
|
|
870
|
+
context "when returning new" do
|
|
1086
871
|
|
|
1087
|
-
let
|
|
1088
|
-
Band.
|
|
872
|
+
let(:criteria) do
|
|
873
|
+
Band.where(name: "Depeche Mode")
|
|
1089
874
|
end
|
|
1090
875
|
|
|
1091
|
-
|
|
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
|
|
876
|
+
let!(:result) do
|
|
877
|
+
criteria.find_and_modify({ "$inc" => { likes: 1 }}, new: true)
|
|
1114
878
|
end
|
|
1115
879
|
|
|
1116
|
-
|
|
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
|
|
880
|
+
it "returns the first matching document" do
|
|
881
|
+
expect(result).to eq(depeche)
|
|
1153
882
|
end
|
|
1154
|
-
end
|
|
1155
|
-
end
|
|
1156
|
-
|
|
1157
|
-
context "when using string ids" do
|
|
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
883
|
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
band.id = "tool"
|
|
884
|
+
it "returns the updated document" do
|
|
885
|
+
expect(result.likes).to eq(1)
|
|
1170
886
|
end
|
|
1171
887
|
end
|
|
1172
888
|
|
|
1173
|
-
context "when
|
|
1174
|
-
|
|
1175
|
-
context "when the id matches" do
|
|
1176
|
-
|
|
1177
|
-
let(:found) do
|
|
1178
|
-
Band.find(band.id)
|
|
1179
|
-
end
|
|
889
|
+
context "when removing" do
|
|
1180
890
|
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
end
|
|
891
|
+
let(:criteria) do
|
|
892
|
+
Band.where(name: "Depeche Mode")
|
|
1184
893
|
end
|
|
1185
894
|
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
before do
|
|
1191
|
-
Mongoid.raise_not_found_error = true
|
|
1192
|
-
end
|
|
1193
|
-
|
|
1194
|
-
let(:found) do
|
|
1195
|
-
Band.find("depeche-mode")
|
|
1196
|
-
end
|
|
1197
|
-
|
|
1198
|
-
it "raises an error" do
|
|
1199
|
-
expect {
|
|
1200
|
-
found
|
|
1201
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
|
1202
|
-
end
|
|
1203
|
-
end
|
|
1204
|
-
|
|
1205
|
-
context "when raising no error" do
|
|
895
|
+
let!(:result) do
|
|
896
|
+
criteria.find_and_modify({}, remove: true)
|
|
897
|
+
end
|
|
1206
898
|
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
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")
|
|
1864
|
-
end
|
|
1865
|
-
|
|
1866
|
-
let(:result) do
|
|
1867
|
-
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
|
|
899
|
+
it "returns the first matching document" do
|
|
900
|
+
expect(result).to eq(depeche)
|
|
901
|
+
end
|
|
1996
902
|
|
|
1997
903
|
it "deletes the document from the database" do
|
|
1998
904
|
expect {
|
|
1999
905
|
depeche.reload
|
|
2000
906
|
}.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
|
|
2211
|
-
|
|
2212
|
-
context "when the selector is cleared in the identity map" do
|
|
2213
|
-
|
|
2214
|
-
let!(:band) do
|
|
2215
|
-
Band.create(name: "Depeche Mode")
|
|
2216
|
-
end
|
|
2217
|
-
|
|
2218
|
-
let(:criteria) do
|
|
2219
|
-
Band.where(name: "Depeche Mode")
|
|
2220
|
-
end
|
|
2221
|
-
|
|
2222
|
-
before do
|
|
2223
|
-
Mongoid::IdentityMap.clear
|
|
2224
|
-
Mongoid::IdentityMap.clear_many(Band, { "name" => "Depeche Mode" })
|
|
2225
|
-
end
|
|
2226
|
-
|
|
2227
|
-
let(:from_db) do
|
|
2228
|
-
criteria.from_map_or_db
|
|
2229
|
-
end
|
|
2230
|
-
|
|
2231
|
-
it "returns nil" do
|
|
2232
|
-
from_db.should be_nil
|
|
2233
|
-
end
|
|
2234
|
-
end
|
|
2235
|
-
end
|
|
2236
|
-
|
|
2237
|
-
describe "#multiple_from_map_or_db" do
|
|
2238
|
-
|
|
2239
|
-
before(:all) do
|
|
2240
|
-
Mongoid.identity_map_enabled = true
|
|
2241
|
-
end
|
|
2242
|
-
|
|
2243
|
-
after(:all) do
|
|
2244
|
-
Mongoid.identity_map_enabled = false
|
|
2245
|
-
end
|
|
2246
|
-
|
|
2247
|
-
context "when the document is in the identity map" do
|
|
2248
|
-
|
|
2249
|
-
let!(:band) do
|
|
2250
|
-
Band.create(name: "Depeche Mode")
|
|
2251
|
-
end
|
|
2252
|
-
|
|
2253
|
-
let!(:band_two) do
|
|
2254
|
-
Band.create(name: "Tool")
|
|
2255
|
-
end
|
|
2256
|
-
|
|
2257
|
-
context "when providing a single id" do
|
|
2258
|
-
|
|
2259
|
-
let(:criteria) do
|
|
2260
|
-
Band.where(_id: band.id)
|
|
2261
|
-
end
|
|
2262
|
-
|
|
2263
|
-
let(:from_map) do
|
|
2264
|
-
criteria.multiple_from_map_or_db([ band.id ])
|
|
2265
|
-
end
|
|
2266
|
-
|
|
2267
|
-
it "returns the document from the map" do
|
|
2268
|
-
from_map.should include(band)
|
|
2269
|
-
end
|
|
2270
|
-
end
|
|
2271
|
-
|
|
2272
|
-
context "when providing multiple ids" do
|
|
2273
|
-
|
|
2274
|
-
let(:criteria) do
|
|
2275
|
-
Band.where(:_id.in => [ band.id, band_two.id ])
|
|
2276
|
-
end
|
|
2277
|
-
|
|
2278
|
-
let(:from_map) do
|
|
2279
|
-
criteria.multiple_from_map_or_db([ band.id, band_two.id ])
|
|
2280
|
-
end
|
|
2281
|
-
|
|
2282
|
-
it "returns the documents from the map" do
|
|
2283
|
-
from_map.should include(band, band_two)
|
|
2284
|
-
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
|
-
|
|
2294
|
-
let!(:band_two) do
|
|
2295
|
-
Band.create(name: "Tool")
|
|
2296
|
-
end
|
|
2297
|
-
|
|
2298
|
-
before do
|
|
2299
|
-
Mongoid::IdentityMap.clear
|
|
907
|
+
end
|
|
2300
908
|
end
|
|
909
|
+
end
|
|
2301
910
|
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
let(:criteria) do
|
|
2305
|
-
Band.where(_id: band.id)
|
|
2306
|
-
end
|
|
911
|
+
context "when the selector does not match" do
|
|
2307
912
|
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
913
|
+
let(:criteria) do
|
|
914
|
+
Band.where(name: "Placebo")
|
|
915
|
+
end
|
|
2311
916
|
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
917
|
+
let(:result) do
|
|
918
|
+
criteria.find_and_modify("$inc" => { likes: 1 })
|
|
919
|
+
end
|
|
2315
920
|
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
end
|
|
921
|
+
it "returns nil" do
|
|
922
|
+
expect(result).to be_nil
|
|
2319
923
|
end
|
|
924
|
+
end
|
|
925
|
+
end
|
|
2320
926
|
|
|
2321
|
-
|
|
927
|
+
describe "#freeze" do
|
|
2322
928
|
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
929
|
+
let(:criteria) do
|
|
930
|
+
Band.all
|
|
931
|
+
end
|
|
2326
932
|
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
933
|
+
before do
|
|
934
|
+
criteria.freeze
|
|
935
|
+
end
|
|
2330
936
|
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
937
|
+
it "freezes the criteria" do
|
|
938
|
+
expect(criteria).to be_frozen
|
|
939
|
+
end
|
|
2334
940
|
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
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
|
|
2339
947
|
end
|
|
2340
948
|
end
|
|
2341
949
|
|
|
@@ -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
|
|
@@ -3053,7 +1571,7 @@ describe Mongoid::Criteria do
|
|
|
3053
1571
|
context "when providing inclusions to the default scope" do
|
|
3054
1572
|
|
|
3055
1573
|
before do
|
|
3056
|
-
Person.default_scope(Person.includes(:posts))
|
|
1574
|
+
Person.default_scope(->{ Person.includes(:posts) })
|
|
3057
1575
|
end
|
|
3058
1576
|
|
|
3059
1577
|
after do
|
|
@@ -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
|
|
@@ -3113,43 +1623,23 @@ describe Mongoid::Criteria do
|
|
|
3113
1623
|
end
|
|
3114
1624
|
|
|
3115
1625
|
before do
|
|
3116
|
-
new_context.
|
|
1626
|
+
expect(new_context).to receive(:eager_load_one).with(person).once.and_call_original
|
|
3117
1627
|
end
|
|
3118
1628
|
|
|
3119
1629
|
let!(:from_db) 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
|
|
@@ -3184,7 +1674,7 @@ describe Mongoid::Criteria do
|
|
|
3184
1674
|
end
|
|
3185
1675
|
|
|
3186
1676
|
before do
|
|
3187
|
-
context.
|
|
1677
|
+
expect(context).to receive(:eager_load_one).with(person).once.and_call_original
|
|
3188
1678
|
end
|
|
3189
1679
|
|
|
3190
1680
|
let!(:from_db) 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.
|
|
3239
|
-
end
|
|
3240
|
-
|
|
3241
|
-
it "inserts the first document into the identity map" do
|
|
3242
|
-
Mongoid::IdentityMap[Post.collection_name][post_one.id].should eq(post_one)
|
|
1720
|
+
expect(criteria).to eq([ person ])
|
|
3243
1721
|
end
|
|
3244
1722
|
|
|
3245
|
-
it "
|
|
3246
|
-
|
|
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,148 +1755,73 @@ 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]
|
|
3293
|
-
end
|
|
3294
|
-
|
|
3295
|
-
it "inserts the first document into the identity map" do
|
|
3296
|
-
preference_map[preference_one.id].should eq(preference_one)
|
|
3297
|
-
end
|
|
3298
|
-
|
|
3299
|
-
it "inserts the second document into the identity map" do
|
|
3300
|
-
preference_map[preference_two.id].should eq(preference_two)
|
|
3301
|
-
end
|
|
3302
|
-
end
|
|
3303
|
-
|
|
3304
|
-
context "when calling first on the criteria" do
|
|
3305
|
-
|
|
3306
|
-
before do
|
|
3307
|
-
Mongoid::IdentityMap.clear
|
|
3308
|
-
end
|
|
3309
|
-
|
|
3310
|
-
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
|
|
3320
|
-
end
|
|
3321
|
-
|
|
3322
|
-
let!(:from_db) do
|
|
3323
|
-
criteria.first
|
|
3324
|
-
end
|
|
3325
|
-
|
|
3326
|
-
it "returns the correct documents" do
|
|
3327
|
-
from_db.should eq(person)
|
|
1758
|
+
expect(documents).to eq([ person ])
|
|
3328
1759
|
end
|
|
3329
1760
|
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
it "inserts the first document into the identity map" do
|
|
3335
|
-
preference_map[preference_one.id].should eq(preference_one)
|
|
3336
|
-
end
|
|
3337
|
-
|
|
3338
|
-
it "inserts the second document into the identity map" do
|
|
3339
|
-
preference_map[preference_two.id].should eq(preference_two)
|
|
3340
|
-
end
|
|
3341
|
-
end
|
|
3342
|
-
|
|
3343
|
-
context "when calling last on the criteria" do
|
|
3344
|
-
|
|
3345
|
-
before do
|
|
3346
|
-
Mongoid::IdentityMap.clear
|
|
3347
|
-
end
|
|
3348
|
-
|
|
3349
|
-
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
|
|
3359
|
-
end
|
|
3360
|
-
|
|
3361
|
-
let!(:from_db) do
|
|
3362
|
-
criteria.last
|
|
3363
|
-
end
|
|
3364
|
-
|
|
3365
|
-
it "returns the correct documents" do
|
|
3366
|
-
from_db.should eq(person)
|
|
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)
|
|
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
|
|
3375
1765
|
end
|
|
3376
1766
|
|
|
3377
|
-
it "
|
|
3378
|
-
|
|
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
|
|
3379
1771
|
end
|
|
3380
1772
|
end
|
|
3381
1773
|
|
|
3382
|
-
context "when
|
|
1774
|
+
context "when calling first on the criteria" do
|
|
3383
1775
|
|
|
3384
|
-
let!(:
|
|
3385
|
-
Person.
|
|
1776
|
+
let!(:criteria) do
|
|
1777
|
+
Person.asc(:age).includes(:preferences)
|
|
3386
1778
|
end
|
|
3387
1779
|
|
|
3388
|
-
let!(:
|
|
3389
|
-
|
|
1780
|
+
let!(:from_db) do
|
|
1781
|
+
criteria.first
|
|
3390
1782
|
end
|
|
3391
1783
|
|
|
3392
|
-
|
|
3393
|
-
|
|
1784
|
+
it "returns the correct documents" do
|
|
1785
|
+
expect(from_db).to eq(person)
|
|
3394
1786
|
end
|
|
3395
1787
|
|
|
3396
|
-
|
|
3397
|
-
|
|
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
|
|
3398
1792
|
end
|
|
3399
1793
|
|
|
3400
|
-
|
|
3401
|
-
|
|
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
|
|
3402
1798
|
end
|
|
1799
|
+
end
|
|
3403
1800
|
|
|
3404
|
-
|
|
3405
|
-
context.should_receive(:eager_load).with([ person ]).once.and_call_original
|
|
3406
|
-
end
|
|
1801
|
+
context "when calling last on the criteria" do
|
|
3407
1802
|
|
|
3408
|
-
let!(:
|
|
3409
|
-
|
|
1803
|
+
let!(:criteria) do
|
|
1804
|
+
Person.asc(:age).includes(:preferences)
|
|
3410
1805
|
end
|
|
3411
1806
|
|
|
3412
|
-
let(:
|
|
3413
|
-
|
|
1807
|
+
let!(:from_db) do
|
|
1808
|
+
criteria.last
|
|
3414
1809
|
end
|
|
3415
1810
|
|
|
3416
1811
|
it "returns the correct documents" do
|
|
3417
|
-
|
|
1812
|
+
expect(from_db).to eq(person)
|
|
3418
1813
|
end
|
|
3419
1814
|
|
|
3420
|
-
it "
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
it "inserts the second document into the identity map" do
|
|
3425
|
-
preference_map[preference_two.id].should eq(preference_two)
|
|
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
|
|
@@ -3599,7 +1934,7 @@ describe Mongoid::Criteria do
|
|
|
3599
1934
|
end
|
|
3600
1935
|
|
|
3601
1936
|
before do
|
|
3602
|
-
context.
|
|
1937
|
+
expect(context).to receive(:eager_load).with([ person ]).once.and_call_original
|
|
3603
1938
|
end
|
|
3604
1939
|
|
|
3605
1940
|
let!(:documents) 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
|
|
@@ -3649,7 +1968,7 @@ describe Mongoid::Criteria do
|
|
|
3649
1968
|
end
|
|
3650
1969
|
|
|
3651
1970
|
before do
|
|
3652
|
-
context.
|
|
1971
|
+
expect(context).to receive(:eager_load).with([ person ]).once.and_call_original
|
|
3653
1972
|
end
|
|
3654
1973
|
|
|
3655
1974
|
let!(:documents) 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
|
|
@@ -3707,7 +1999,7 @@ describe Mongoid::Criteria do
|
|
|
3707
1999
|
end
|
|
3708
2000
|
|
|
3709
2001
|
before do
|
|
3710
|
-
context.
|
|
2002
|
+
expect(context).to receive(:eager_load).with([ person ]).once.and_call_original
|
|
3711
2003
|
end
|
|
3712
2004
|
|
|
3713
2005
|
let!(:documents) 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
|
|
@@ -3757,11 +2037,7 @@ describe Mongoid::Criteria do
|
|
|
3757
2037
|
end
|
|
3758
2038
|
|
|
3759
2039
|
before do
|
|
3760
|
-
context.
|
|
3761
|
-
should_receive(:eager_load).
|
|
3762
|
-
with([ game_one, game_two ]).
|
|
3763
|
-
once.
|
|
3764
|
-
and_call_original
|
|
2040
|
+
expect(context).to receive(:eager_load).with([ game_one, game_two ]).once.and_call_original
|
|
3765
2041
|
end
|
|
3766
2042
|
|
|
3767
2043
|
let!(:documents) do
|
|
@@ -3769,15 +2045,7 @@ describe Mongoid::Criteria do
|
|
|
3769
2045
|
end
|
|
3770
2046
|
|
|
3771
2047
|
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)
|
|
2048
|
+
expect(criteria).to eq([ game_one, game_two ])
|
|
3781
2049
|
end
|
|
3782
2050
|
end
|
|
3783
2051
|
|
|
@@ -3792,7 +2060,7 @@ describe Mongoid::Criteria do
|
|
|
3792
2060
|
end
|
|
3793
2061
|
|
|
3794
2062
|
before do
|
|
3795
|
-
context.
|
|
2063
|
+
expect(context).to receive(:eager_load).with([ game_one ]).once.and_call_original
|
|
3796
2064
|
end
|
|
3797
2065
|
|
|
3798
2066
|
let!(:documents) do
|
|
@@ -3800,15 +2068,7 @@ describe Mongoid::Criteria do
|
|
|
3800
2068
|
end
|
|
3801
2069
|
|
|
3802
2070
|
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
|
|
2071
|
+
expect(documents).to eq([ game_one ])
|
|
3812
2072
|
end
|
|
3813
2073
|
end
|
|
3814
2074
|
end
|
|
@@ -3831,12 +2091,8 @@ describe Mongoid::Criteria do
|
|
|
3831
2091
|
person.create_game(name: "two")
|
|
3832
2092
|
end
|
|
3833
2093
|
|
|
3834
|
-
before do
|
|
3835
|
-
Mongoid::IdentityMap.clear
|
|
3836
|
-
end
|
|
3837
|
-
|
|
3838
2094
|
let!(:criteria) do
|
|
3839
|
-
Person.includes(:posts, :game)
|
|
2095
|
+
Person.includes(:posts, :game).asc(:age)
|
|
3840
2096
|
end
|
|
3841
2097
|
|
|
3842
2098
|
let(:context) do
|
|
@@ -3844,7 +2100,7 @@ describe Mongoid::Criteria do
|
|
|
3844
2100
|
end
|
|
3845
2101
|
|
|
3846
2102
|
before do
|
|
3847
|
-
context.
|
|
2103
|
+
expect(context).to receive(:eager_load).with([ person ]).once.and_call_original
|
|
3848
2104
|
end
|
|
3849
2105
|
|
|
3850
2106
|
let!(:documents) do
|
|
@@ -3852,23 +2108,7 @@ describe Mongoid::Criteria do
|
|
|
3852
2108
|
end
|
|
3853
2109
|
|
|
3854
2110
|
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)
|
|
2111
|
+
expect(criteria).to eq([ person ])
|
|
3872
2112
|
end
|
|
3873
2113
|
end
|
|
3874
2114
|
end
|
|
@@ -3884,7 +2124,7 @@ describe Mongoid::Criteria do
|
|
|
3884
2124
|
end
|
|
3885
2125
|
|
|
3886
2126
|
it "returns the inclusions" do
|
|
3887
|
-
criteria.inclusions.
|
|
2127
|
+
expect(criteria.inclusions).to eq([ metadata ])
|
|
3888
2128
|
end
|
|
3889
2129
|
end
|
|
3890
2130
|
|
|
@@ -3903,7 +2143,7 @@ describe Mongoid::Criteria do
|
|
|
3903
2143
|
end
|
|
3904
2144
|
|
|
3905
2145
|
it "sets the inclusions" do
|
|
3906
|
-
criteria.inclusions.
|
|
2146
|
+
expect(criteria.inclusions).to eq([ metadata ])
|
|
3907
2147
|
end
|
|
3908
2148
|
end
|
|
3909
2149
|
|
|
@@ -3922,7 +2162,7 @@ describe Mongoid::Criteria do
|
|
|
3922
2162
|
end
|
|
3923
2163
|
|
|
3924
2164
|
it "returns the matching documents" do
|
|
3925
|
-
criteria.
|
|
2165
|
+
expect(criteria).to eq([ match ])
|
|
3926
2166
|
end
|
|
3927
2167
|
end
|
|
3928
2168
|
|
|
@@ -3941,7 +2181,7 @@ describe Mongoid::Criteria do
|
|
|
3941
2181
|
end
|
|
3942
2182
|
|
|
3943
2183
|
it "returns the matching documents" do
|
|
3944
|
-
criteria.
|
|
2184
|
+
expect(criteria).to eq([ match ])
|
|
3945
2185
|
end
|
|
3946
2186
|
end
|
|
3947
2187
|
|
|
@@ -3973,15 +2213,29 @@ describe Mongoid::Criteria do
|
|
|
3973
2213
|
Band.create(name: "Tool", likes: 100)
|
|
3974
2214
|
end
|
|
3975
2215
|
|
|
3976
|
-
|
|
3977
|
-
|
|
2216
|
+
context "when no timeout options are provided" do
|
|
2217
|
+
|
|
2218
|
+
let(:map_reduce) do
|
|
2219
|
+
Band.limit(2).map_reduce(map, reduce).out(inline: 1)
|
|
2220
|
+
end
|
|
2221
|
+
|
|
2222
|
+
it "returns the map/reduce results" do
|
|
2223
|
+
expect(map_reduce).to eq([
|
|
2224
|
+
{ "_id" => "Depeche Mode", "value" => { "likes" => 200 }},
|
|
2225
|
+
{ "_id" => "Tool", "value" => { "likes" => 100 }}
|
|
2226
|
+
])
|
|
2227
|
+
end
|
|
3978
2228
|
end
|
|
3979
2229
|
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
2230
|
+
context "when timeout options are provided" do
|
|
2231
|
+
|
|
2232
|
+
let(:map_reduce) do
|
|
2233
|
+
Band.limit(2).no_timeout.map_reduce(map, reduce).out(replace: "test_bands")
|
|
2234
|
+
end
|
|
2235
|
+
|
|
2236
|
+
it "sets the timeout option on the query" do
|
|
2237
|
+
expect(map_reduce.send(:documents).operation.flags).to eq([ :no_cursor_timeout ])
|
|
2238
|
+
end
|
|
3985
2239
|
end
|
|
3986
2240
|
end
|
|
3987
2241
|
|
|
@@ -4008,7 +2262,7 @@ describe Mongoid::Criteria do
|
|
|
4008
2262
|
end
|
|
4009
2263
|
|
|
4010
2264
|
it "returns the max of the provided field" do
|
|
4011
|
-
max.
|
|
2265
|
+
expect(max).to eq(1000)
|
|
4012
2266
|
end
|
|
4013
2267
|
end
|
|
4014
2268
|
|
|
@@ -4021,7 +2275,7 @@ describe Mongoid::Criteria do
|
|
|
4021
2275
|
end
|
|
4022
2276
|
|
|
4023
2277
|
it "returns the document with the max value for the field" do
|
|
4024
|
-
max.
|
|
2278
|
+
expect(max).to eq(depeche)
|
|
4025
2279
|
end
|
|
4026
2280
|
end
|
|
4027
2281
|
end
|
|
@@ -4046,7 +2300,7 @@ describe Mongoid::Criteria do
|
|
|
4046
2300
|
end
|
|
4047
2301
|
|
|
4048
2302
|
it "returns the matching documents" do
|
|
4049
|
-
criteria.
|
|
2303
|
+
expect(criteria).to eq([ match ])
|
|
4050
2304
|
end
|
|
4051
2305
|
end
|
|
4052
2306
|
|
|
@@ -4077,27 +2331,27 @@ describe Mongoid::Criteria do
|
|
|
4077
2331
|
end
|
|
4078
2332
|
|
|
4079
2333
|
it "merges the selector" do
|
|
4080
|
-
merged.selector.
|
|
2334
|
+
expect(merged.selector).to eq({ "name" => "Depeche Mode" })
|
|
4081
2335
|
end
|
|
4082
2336
|
|
|
4083
2337
|
it "merges the options" do
|
|
4084
|
-
merged.options.
|
|
2338
|
+
expect(merged.options).to eq({ sort: { "name" => 1 }})
|
|
4085
2339
|
end
|
|
4086
2340
|
|
|
4087
2341
|
it "merges the documents" do
|
|
4088
|
-
merged.documents.
|
|
2342
|
+
expect(merged.documents).to eq([ band ])
|
|
4089
2343
|
end
|
|
4090
2344
|
|
|
4091
2345
|
it "merges the scoping options" do
|
|
4092
|
-
merged.scoping_options.
|
|
2346
|
+
expect(merged.scoping_options).to eq([ nil, nil ])
|
|
4093
2347
|
end
|
|
4094
2348
|
|
|
4095
2349
|
it "merges the inclusions" do
|
|
4096
|
-
merged.inclusions.
|
|
2350
|
+
expect(merged.inclusions).to eq([ metadata ])
|
|
4097
2351
|
end
|
|
4098
2352
|
|
|
4099
2353
|
it "returns a new criteria" do
|
|
4100
|
-
merged.
|
|
2354
|
+
expect(merged).to_not equal(criteria)
|
|
4101
2355
|
end
|
|
4102
2356
|
end
|
|
4103
2357
|
|
|
@@ -4116,23 +2370,23 @@ describe Mongoid::Criteria do
|
|
|
4116
2370
|
end
|
|
4117
2371
|
|
|
4118
2372
|
it "merges the selector" do
|
|
4119
|
-
merged.selector.
|
|
2373
|
+
expect(merged.selector).to eq({ "name" => "Depeche Mode" })
|
|
4120
2374
|
end
|
|
4121
2375
|
|
|
4122
2376
|
it "merges the options" do
|
|
4123
|
-
merged.options.
|
|
2377
|
+
expect(merged.options).to eq({ sort: { "name" => 1 }})
|
|
4124
2378
|
end
|
|
4125
2379
|
|
|
4126
2380
|
it "merges the scoping options" do
|
|
4127
|
-
merged.scoping_options.
|
|
2381
|
+
expect(merged.scoping_options).to eq([ nil, nil ])
|
|
4128
2382
|
end
|
|
4129
2383
|
|
|
4130
2384
|
it "merges the inclusions" do
|
|
4131
|
-
merged.inclusions.
|
|
2385
|
+
expect(merged.inclusions).to eq([ metadata ])
|
|
4132
2386
|
end
|
|
4133
2387
|
|
|
4134
2388
|
it "returns a new criteria" do
|
|
4135
|
-
merged.
|
|
2389
|
+
expect(merged).to_not equal(criteria)
|
|
4136
2390
|
end
|
|
4137
2391
|
end
|
|
4138
2392
|
end
|
|
@@ -4162,27 +2416,27 @@ describe Mongoid::Criteria do
|
|
|
4162
2416
|
end
|
|
4163
2417
|
|
|
4164
2418
|
it "merges the selector" do
|
|
4165
|
-
merged.selector.
|
|
2419
|
+
expect(merged.selector).to eq({ "name" => "Depeche Mode" })
|
|
4166
2420
|
end
|
|
4167
2421
|
|
|
4168
2422
|
it "merges the options" do
|
|
4169
|
-
merged.options.
|
|
2423
|
+
expect(merged.options).to eq({ sort: { "name" => 1 }})
|
|
4170
2424
|
end
|
|
4171
2425
|
|
|
4172
2426
|
it "merges the documents" do
|
|
4173
|
-
merged.documents.
|
|
2427
|
+
expect(merged.documents).to eq([ band ])
|
|
4174
2428
|
end
|
|
4175
2429
|
|
|
4176
2430
|
it "merges the scoping options" do
|
|
4177
|
-
merged.scoping_options.
|
|
2431
|
+
expect(merged.scoping_options).to eq([ nil, nil ])
|
|
4178
2432
|
end
|
|
4179
2433
|
|
|
4180
2434
|
it "merges the inclusions" do
|
|
4181
|
-
merged.inclusions.
|
|
2435
|
+
expect(merged.inclusions).to eq([ metadata ])
|
|
4182
2436
|
end
|
|
4183
2437
|
|
|
4184
2438
|
it "returns the same criteria" do
|
|
4185
|
-
merged.
|
|
2439
|
+
expect(merged).to equal(criteria)
|
|
4186
2440
|
end
|
|
4187
2441
|
end
|
|
4188
2442
|
|
|
@@ -4209,7 +2463,7 @@ describe Mongoid::Criteria do
|
|
|
4209
2463
|
end
|
|
4210
2464
|
|
|
4211
2465
|
it "returns the min of the provided field" do
|
|
4212
|
-
min.
|
|
2466
|
+
expect(min).to eq(500)
|
|
4213
2467
|
end
|
|
4214
2468
|
end
|
|
4215
2469
|
|
|
@@ -4222,7 +2476,7 @@ describe Mongoid::Criteria do
|
|
|
4222
2476
|
end
|
|
4223
2477
|
|
|
4224
2478
|
it "returns the document with the min value for the field" do
|
|
4225
|
-
min.
|
|
2479
|
+
expect(min).to eq(tool)
|
|
4226
2480
|
end
|
|
4227
2481
|
end
|
|
4228
2482
|
end
|
|
@@ -4243,7 +2497,7 @@ describe Mongoid::Criteria do
|
|
|
4243
2497
|
end
|
|
4244
2498
|
|
|
4245
2499
|
it "returns the matching documents" do
|
|
4246
|
-
criteria.
|
|
2500
|
+
expect(criteria).to eq([ match ])
|
|
4247
2501
|
end
|
|
4248
2502
|
end
|
|
4249
2503
|
|
|
@@ -4262,7 +2516,7 @@ describe Mongoid::Criteria do
|
|
|
4262
2516
|
end
|
|
4263
2517
|
|
|
4264
2518
|
it "returns the matching documents" do
|
|
4265
|
-
criteria.
|
|
2519
|
+
expect(criteria).to eq([ match ])
|
|
4266
2520
|
end
|
|
4267
2521
|
end
|
|
4268
2522
|
|
|
@@ -4281,7 +2535,7 @@ describe Mongoid::Criteria do
|
|
|
4281
2535
|
end
|
|
4282
2536
|
|
|
4283
2537
|
it "returns the matching documents" do
|
|
4284
|
-
criteria.
|
|
2538
|
+
expect(criteria).to eq([ match ])
|
|
4285
2539
|
end
|
|
4286
2540
|
end
|
|
4287
2541
|
|
|
@@ -4300,7 +2554,7 @@ describe Mongoid::Criteria do
|
|
|
4300
2554
|
end
|
|
4301
2555
|
|
|
4302
2556
|
it "returns the matching documents" do
|
|
4303
|
-
criteria.
|
|
2557
|
+
expect(criteria).to eq([ match ])
|
|
4304
2558
|
end
|
|
4305
2559
|
end
|
|
4306
2560
|
|
|
@@ -4319,7 +2573,7 @@ describe Mongoid::Criteria do
|
|
|
4319
2573
|
end
|
|
4320
2574
|
|
|
4321
2575
|
it "returns the matching documents" do
|
|
4322
|
-
criteria.
|
|
2576
|
+
expect(criteria).to eq([ match ])
|
|
4323
2577
|
end
|
|
4324
2578
|
end
|
|
4325
2579
|
|
|
@@ -4338,7 +2592,7 @@ describe Mongoid::Criteria do
|
|
|
4338
2592
|
end
|
|
4339
2593
|
|
|
4340
2594
|
it "returns the matching documents" do
|
|
4341
|
-
criteria.
|
|
2595
|
+
expect(criteria).to eq([ match ])
|
|
4342
2596
|
end
|
|
4343
2597
|
end
|
|
4344
2598
|
|
|
@@ -4357,11 +2611,13 @@ describe Mongoid::Criteria do
|
|
|
4357
2611
|
end
|
|
4358
2612
|
|
|
4359
2613
|
it "limits the returned fields" do
|
|
4360
|
-
|
|
2614
|
+
expect {
|
|
2615
|
+
criteria.first.name
|
|
2616
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
|
4361
2617
|
end
|
|
4362
2618
|
|
|
4363
2619
|
it "does not add _type to the fields" do
|
|
4364
|
-
criteria.options[:fields]["_type"].
|
|
2620
|
+
expect(criteria.options[:fields]["_type"]).to be_nil
|
|
4365
2621
|
end
|
|
4366
2622
|
end
|
|
4367
2623
|
|
|
@@ -4372,15 +2628,17 @@ describe Mongoid::Criteria do
|
|
|
4372
2628
|
end
|
|
4373
2629
|
|
|
4374
2630
|
it "includes the limited fields" do
|
|
4375
|
-
criteria.first.name.
|
|
2631
|
+
expect(criteria.first.name).to_not be_nil
|
|
4376
2632
|
end
|
|
4377
2633
|
|
|
4378
2634
|
it "excludes the non included fields" do
|
|
4379
|
-
|
|
2635
|
+
expect {
|
|
2636
|
+
criteria.first.active
|
|
2637
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
|
4380
2638
|
end
|
|
4381
2639
|
|
|
4382
2640
|
it "does not add _type to the fields" do
|
|
4383
|
-
criteria.options[:fields]["_type"].
|
|
2641
|
+
expect(criteria.options[:fields]["_type"]).to be_nil
|
|
4384
2642
|
end
|
|
4385
2643
|
end
|
|
4386
2644
|
|
|
@@ -4392,7 +2650,7 @@ describe Mongoid::Criteria do
|
|
|
4392
2650
|
|
|
4393
2651
|
it "only limits the fields on the correct model" do
|
|
4394
2652
|
criteria.each do |band|
|
|
4395
|
-
Person.new.age.
|
|
2653
|
+
expect(Person.new.age).to eq(100)
|
|
4396
2654
|
end
|
|
4397
2655
|
end
|
|
4398
2656
|
end
|
|
@@ -4405,7 +2663,7 @@ describe Mongoid::Criteria do
|
|
|
4405
2663
|
|
|
4406
2664
|
it "only limits the fields on the correct criteria" do
|
|
4407
2665
|
criteria.each do |band|
|
|
4408
|
-
Band.new.active.
|
|
2666
|
+
expect(Band.new.active).to be true
|
|
4409
2667
|
end
|
|
4410
2668
|
end
|
|
4411
2669
|
end
|
|
@@ -4419,7 +2677,7 @@ describe Mongoid::Criteria do
|
|
|
4419
2677
|
it "only limits the fields on the correct criteria" do
|
|
4420
2678
|
criteria.each do |band|
|
|
4421
2679
|
Band.all.each do |b|
|
|
4422
|
-
b.active.
|
|
2680
|
+
expect(b.active).to be true
|
|
4423
2681
|
end
|
|
4424
2682
|
end
|
|
4425
2683
|
end
|
|
@@ -4433,7 +2691,7 @@ describe Mongoid::Criteria do
|
|
|
4433
2691
|
end
|
|
4434
2692
|
|
|
4435
2693
|
it "adds _type to the fields" do
|
|
4436
|
-
criteria.options[:fields]["_type"].
|
|
2694
|
+
expect(criteria.options[:fields]["_type"]).to eq(1)
|
|
4437
2695
|
end
|
|
4438
2696
|
end
|
|
4439
2697
|
|
|
@@ -4446,7 +2704,7 @@ describe Mongoid::Criteria do
|
|
|
4446
2704
|
end
|
|
4447
2705
|
|
|
4448
2706
|
it "properly uses the database field name" do
|
|
4449
|
-
criteria.options.
|
|
2707
|
+
expect(criteria.options).to eq(fields: { "mobile_phones" => 1 })
|
|
4450
2708
|
end
|
|
4451
2709
|
end
|
|
4452
2710
|
end
|
|
@@ -4471,7 +2729,7 @@ describe Mongoid::Criteria do
|
|
|
4471
2729
|
end
|
|
4472
2730
|
|
|
4473
2731
|
it "returns the matching documents" do
|
|
4474
|
-
criteria.
|
|
2732
|
+
expect(criteria).to eq([ match ])
|
|
4475
2733
|
end
|
|
4476
2734
|
end
|
|
4477
2735
|
|
|
@@ -4482,7 +2740,7 @@ describe Mongoid::Criteria do
|
|
|
4482
2740
|
end
|
|
4483
2741
|
|
|
4484
2742
|
it "returns the matching documents" do
|
|
4485
|
-
criteria.
|
|
2743
|
+
expect(criteria).to eq([ match ])
|
|
4486
2744
|
end
|
|
4487
2745
|
end
|
|
4488
2746
|
end
|
|
@@ -4502,6 +2760,28 @@ describe Mongoid::Criteria do
|
|
|
4502
2760
|
Band.create(name: "Photek", likes: 1)
|
|
4503
2761
|
end
|
|
4504
2762
|
|
|
2763
|
+
context "when the field is aliased" do
|
|
2764
|
+
|
|
2765
|
+
let!(:expensive) do
|
|
2766
|
+
Product.create(price: 100000)
|
|
2767
|
+
end
|
|
2768
|
+
|
|
2769
|
+
let!(:cheap) do
|
|
2770
|
+
Product.create(price: 1)
|
|
2771
|
+
end
|
|
2772
|
+
|
|
2773
|
+
context "when using alias_attribute" do
|
|
2774
|
+
|
|
2775
|
+
let(:plucked) do
|
|
2776
|
+
Product.pluck(:price)
|
|
2777
|
+
end
|
|
2778
|
+
|
|
2779
|
+
it "uses the aliases" do
|
|
2780
|
+
expect(plucked).to eq([ 100000, 1 ])
|
|
2781
|
+
end
|
|
2782
|
+
end
|
|
2783
|
+
end
|
|
2784
|
+
|
|
4505
2785
|
context "when the criteria matches" do
|
|
4506
2786
|
|
|
4507
2787
|
context "when there are no duplicate values" do
|
|
@@ -4515,7 +2795,7 @@ describe Mongoid::Criteria do
|
|
|
4515
2795
|
end
|
|
4516
2796
|
|
|
4517
2797
|
it "returns the values" do
|
|
4518
|
-
plucked.
|
|
2798
|
+
expect(plucked).to eq([ "Depeche Mode", "Tool", "Photek" ])
|
|
4519
2799
|
end
|
|
4520
2800
|
|
|
4521
2801
|
context "when subsequently executing the criteria without a pluck" do
|
|
@@ -4526,6 +2806,17 @@ describe Mongoid::Criteria do
|
|
|
4526
2806
|
end
|
|
4527
2807
|
end
|
|
4528
2808
|
|
|
2809
|
+
context "when plucking mult-fields" do
|
|
2810
|
+
|
|
2811
|
+
let(:plucked) do
|
|
2812
|
+
Band.where(:name.exists => true).pluck(:name, :likes)
|
|
2813
|
+
end
|
|
2814
|
+
|
|
2815
|
+
it "returns the values" do
|
|
2816
|
+
expect(plucked).to eq([ ["Depeche Mode", 3], ["Tool", 3], ["Photek", 1] ])
|
|
2817
|
+
end
|
|
2818
|
+
end
|
|
2819
|
+
|
|
4529
2820
|
context "when there are duplicate values" do
|
|
4530
2821
|
|
|
4531
2822
|
let(:plucked) do
|
|
@@ -4533,7 +2824,7 @@ describe Mongoid::Criteria do
|
|
|
4533
2824
|
end
|
|
4534
2825
|
|
|
4535
2826
|
it "returns the duplicates" do
|
|
4536
|
-
plucked.
|
|
2827
|
+
expect(plucked).to eq([ 3, 3, 1 ])
|
|
4537
2828
|
end
|
|
4538
2829
|
end
|
|
4539
2830
|
end
|
|
@@ -4545,7 +2836,7 @@ describe Mongoid::Criteria do
|
|
|
4545
2836
|
end
|
|
4546
2837
|
|
|
4547
2838
|
it "returns an empty array" do
|
|
4548
|
-
plucked.
|
|
2839
|
+
expect(plucked).to be_empty
|
|
4549
2840
|
end
|
|
4550
2841
|
end
|
|
4551
2842
|
|
|
@@ -4556,7 +2847,32 @@ describe Mongoid::Criteria do
|
|
|
4556
2847
|
end
|
|
4557
2848
|
|
|
4558
2849
|
it "returns the field values" do
|
|
4559
|
-
plucked.
|
|
2850
|
+
expect(plucked).to eq([ depeche.id, tool.id, photek.id ])
|
|
2851
|
+
end
|
|
2852
|
+
end
|
|
2853
|
+
|
|
2854
|
+
context "when plucking a field that doesnt exist" do
|
|
2855
|
+
|
|
2856
|
+
context "when pluck one field" do
|
|
2857
|
+
|
|
2858
|
+
let(:plucked) do
|
|
2859
|
+
Band.all.pluck(:foo)
|
|
2860
|
+
end
|
|
2861
|
+
|
|
2862
|
+
it "returns a empty array" do
|
|
2863
|
+
expect(plucked).to eq([])
|
|
2864
|
+
end
|
|
2865
|
+
end
|
|
2866
|
+
|
|
2867
|
+
context "when pluck multiple fields" do
|
|
2868
|
+
|
|
2869
|
+
let(:plucked) do
|
|
2870
|
+
Band.all.pluck(:foo, :bar)
|
|
2871
|
+
end
|
|
2872
|
+
|
|
2873
|
+
it "returns a empty array" do
|
|
2874
|
+
expect(plucked).to eq([[], [], []])
|
|
2875
|
+
end
|
|
4560
2876
|
end
|
|
4561
2877
|
end
|
|
4562
2878
|
end
|
|
@@ -4576,7 +2892,7 @@ describe Mongoid::Criteria do
|
|
|
4576
2892
|
context "when asking about a model public class method" do
|
|
4577
2893
|
|
|
4578
2894
|
it "returns true" do
|
|
4579
|
-
criteria.
|
|
2895
|
+
expect(criteria).to respond_to(:ages)
|
|
4580
2896
|
end
|
|
4581
2897
|
end
|
|
4582
2898
|
|
|
@@ -4585,7 +2901,7 @@ describe Mongoid::Criteria do
|
|
|
4585
2901
|
context "when including private methods" do
|
|
4586
2902
|
|
|
4587
2903
|
it "returns true" do
|
|
4588
|
-
criteria.respond_to?(:for_ids, true).
|
|
2904
|
+
expect(criteria.respond_to?(:for_ids, true)).to be true
|
|
4589
2905
|
end
|
|
4590
2906
|
end
|
|
4591
2907
|
end
|
|
@@ -4593,7 +2909,7 @@ describe Mongoid::Criteria do
|
|
|
4593
2909
|
context "when asking about a model class public instance method" do
|
|
4594
2910
|
|
|
4595
2911
|
it "returns true" do
|
|
4596
|
-
criteria.respond_to?(:join).
|
|
2912
|
+
expect(criteria.respond_to?(:join)).to be true
|
|
4597
2913
|
end
|
|
4598
2914
|
end
|
|
4599
2915
|
|
|
@@ -4602,14 +2918,14 @@ describe Mongoid::Criteria do
|
|
|
4602
2918
|
context "when not including private methods" do
|
|
4603
2919
|
|
|
4604
2920
|
it "returns false" do
|
|
4605
|
-
criteria.
|
|
2921
|
+
expect(criteria).to_not respond_to(:fork)
|
|
4606
2922
|
end
|
|
4607
2923
|
end
|
|
4608
2924
|
|
|
4609
2925
|
context "when including private methods" do
|
|
4610
2926
|
|
|
4611
2927
|
it "returns true" do
|
|
4612
|
-
criteria.respond_to?(:fork, true).
|
|
2928
|
+
expect(criteria.respond_to?(:fork, true)).to be true
|
|
4613
2929
|
end
|
|
4614
2930
|
end
|
|
4615
2931
|
end
|
|
@@ -4617,7 +2933,7 @@ describe Mongoid::Criteria do
|
|
|
4617
2933
|
context "when asking about a criteria instance method" do
|
|
4618
2934
|
|
|
4619
2935
|
it "returns true" do
|
|
4620
|
-
criteria.
|
|
2936
|
+
expect(criteria).to respond_to(:context)
|
|
4621
2937
|
end
|
|
4622
2938
|
end
|
|
4623
2939
|
|
|
@@ -4626,14 +2942,14 @@ describe Mongoid::Criteria do
|
|
|
4626
2942
|
context "when not including private methods" do
|
|
4627
2943
|
|
|
4628
2944
|
it "returns false" do
|
|
4629
|
-
criteria.
|
|
2945
|
+
expect(criteria).to_not respond_to(:puts)
|
|
4630
2946
|
end
|
|
4631
2947
|
end
|
|
4632
2948
|
|
|
4633
2949
|
context "when including private methods" do
|
|
4634
2950
|
|
|
4635
2951
|
it "returns true" do
|
|
4636
|
-
criteria.respond_to?(:puts, true).
|
|
2952
|
+
expect(criteria.respond_to?(:puts, true)).to be true
|
|
4637
2953
|
end
|
|
4638
2954
|
end
|
|
4639
2955
|
end
|
|
@@ -4656,7 +2972,7 @@ describe Mongoid::Criteria do
|
|
|
4656
2972
|
end
|
|
4657
2973
|
|
|
4658
2974
|
it "sorts the results in memory" do
|
|
4659
|
-
sorted.
|
|
2975
|
+
expect(sorted).to eq([ tool, depeche ])
|
|
4660
2976
|
end
|
|
4661
2977
|
end
|
|
4662
2978
|
|
|
@@ -4683,7 +2999,7 @@ describe Mongoid::Criteria do
|
|
|
4683
2999
|
end
|
|
4684
3000
|
|
|
4685
3001
|
it "returns the sum of the provided field" do
|
|
4686
|
-
sum.
|
|
3002
|
+
expect(sum).to eq(1500)
|
|
4687
3003
|
end
|
|
4688
3004
|
end
|
|
4689
3005
|
|
|
@@ -4694,7 +3010,7 @@ describe Mongoid::Criteria do
|
|
|
4694
3010
|
end
|
|
4695
3011
|
|
|
4696
3012
|
it "returns the sum for the provided block" do
|
|
4697
|
-
sum.
|
|
3013
|
+
expect(sum).to eq(1500)
|
|
4698
3014
|
end
|
|
4699
3015
|
end
|
|
4700
3016
|
end
|
|
@@ -4711,7 +3027,7 @@ describe Mongoid::Criteria do
|
|
|
4711
3027
|
end
|
|
4712
3028
|
|
|
4713
3029
|
it "returns the executed criteria" do
|
|
4714
|
-
criteria.to_ary.
|
|
3030
|
+
expect(criteria.to_ary).to eq([ band ])
|
|
4715
3031
|
end
|
|
4716
3032
|
end
|
|
4717
3033
|
|
|
@@ -4726,7 +3042,7 @@ describe Mongoid::Criteria do
|
|
|
4726
3042
|
end
|
|
4727
3043
|
|
|
4728
3044
|
it "executes the criteria while properly giving the hint to Mongo" do
|
|
4729
|
-
expect { criteria.to_ary }.to raise_error(Moped::Errors::QueryFailure
|
|
3045
|
+
expect { criteria.to_ary }.to raise_error(Moped::Errors::QueryFailure)
|
|
4730
3046
|
end
|
|
4731
3047
|
end
|
|
4732
3048
|
|
|
@@ -4741,7 +3057,7 @@ describe Mongoid::Criteria do
|
|
|
4741
3057
|
end
|
|
4742
3058
|
|
|
4743
3059
|
it "executes the criteria while properly giving the hint to Mongo" do
|
|
4744
|
-
expect { criteria.to_ary }.to raise_error(Moped::Errors::QueryFailure
|
|
3060
|
+
expect { criteria.to_ary }.to raise_error(Moped::Errors::QueryFailure)
|
|
4745
3061
|
end
|
|
4746
3062
|
end
|
|
4747
3063
|
|
|
@@ -4759,7 +3075,32 @@ describe Mongoid::Criteria do
|
|
|
4759
3075
|
end
|
|
4760
3076
|
|
|
4761
3077
|
it "executes the criteria while properly giving the max scan to Mongo" do
|
|
4762
|
-
criteria.to_ary.
|
|
3078
|
+
expect(criteria.to_ary).to eq [band]
|
|
3079
|
+
end
|
|
3080
|
+
end
|
|
3081
|
+
|
|
3082
|
+
describe "#text_search" do
|
|
3083
|
+
|
|
3084
|
+
let(:criteria) do
|
|
3085
|
+
Word.all
|
|
3086
|
+
end
|
|
3087
|
+
|
|
3088
|
+
before do
|
|
3089
|
+
Word.with(database: "admin").mongo_session.command(setParameter: 1, textSearchEnabled: true)
|
|
3090
|
+
Word.create_indexes
|
|
3091
|
+
Word.create!(name: "phase", origin: "latin")
|
|
3092
|
+
end
|
|
3093
|
+
|
|
3094
|
+
after(:all) do
|
|
3095
|
+
Word.remove_indexes
|
|
3096
|
+
end
|
|
3097
|
+
|
|
3098
|
+
let(:search) do
|
|
3099
|
+
criteria.text_search("phase")
|
|
3100
|
+
end
|
|
3101
|
+
|
|
3102
|
+
it "returns all fields" do
|
|
3103
|
+
expect(search.first.origin).to eq("latin")
|
|
4763
3104
|
end
|
|
4764
3105
|
end
|
|
4765
3106
|
|
|
@@ -4770,7 +3111,7 @@ describe Mongoid::Criteria do
|
|
|
4770
3111
|
end
|
|
4771
3112
|
|
|
4772
3113
|
it "returns self" do
|
|
4773
|
-
criteria.to_criteria.
|
|
3114
|
+
expect(criteria.to_criteria).to eq(criteria)
|
|
4774
3115
|
end
|
|
4775
3116
|
end
|
|
4776
3117
|
|
|
@@ -4781,11 +3122,11 @@ describe Mongoid::Criteria do
|
|
|
4781
3122
|
end
|
|
4782
3123
|
|
|
4783
3124
|
it "returns a proc" do
|
|
4784
|
-
criteria.to_proc.
|
|
3125
|
+
expect(criteria.to_proc).to be_a(Proc)
|
|
4785
3126
|
end
|
|
4786
3127
|
|
|
4787
3128
|
it "wraps the criteria in the proc" do
|
|
4788
|
-
criteria.to_proc[].
|
|
3129
|
+
expect(criteria.to_proc[]).to eq(criteria)
|
|
4789
3130
|
end
|
|
4790
3131
|
end
|
|
4791
3132
|
|
|
@@ -4802,7 +3143,7 @@ describe Mongoid::Criteria do
|
|
|
4802
3143
|
end
|
|
4803
3144
|
|
|
4804
3145
|
it "returns documents with the provided type" do
|
|
4805
|
-
criteria.
|
|
3146
|
+
expect(criteria).to eq([ browser ])
|
|
4806
3147
|
end
|
|
4807
3148
|
end
|
|
4808
3149
|
|
|
@@ -4817,7 +3158,7 @@ describe Mongoid::Criteria do
|
|
|
4817
3158
|
end
|
|
4818
3159
|
|
|
4819
3160
|
it "returns documents with the provided types" do
|
|
4820
|
-
criteria.
|
|
3161
|
+
expect(criteria).to eq([ browser ])
|
|
4821
3162
|
end
|
|
4822
3163
|
end
|
|
4823
3164
|
end
|
|
@@ -4850,7 +3191,7 @@ describe Mongoid::Criteria do
|
|
|
4850
3191
|
end
|
|
4851
3192
|
|
|
4852
3193
|
it "returns the matching documents" do
|
|
4853
|
-
criteria.
|
|
3194
|
+
expect(criteria).to eq([ match ])
|
|
4854
3195
|
end
|
|
4855
3196
|
end
|
|
4856
3197
|
end
|
|
@@ -4864,18 +3205,18 @@ describe Mongoid::Criteria do
|
|
|
4864
3205
|
end
|
|
4865
3206
|
|
|
4866
3207
|
it "returns the matching documents" do
|
|
4867
|
-
criteria.
|
|
3208
|
+
expect(criteria).to eq([ match ])
|
|
4868
3209
|
end
|
|
4869
3210
|
end
|
|
4870
3211
|
|
|
4871
3212
|
context "when the criteria is an exact fk array match" do
|
|
4872
3213
|
|
|
4873
3214
|
let(:id_one) do
|
|
4874
|
-
|
|
3215
|
+
BSON::ObjectId.new
|
|
4875
3216
|
end
|
|
4876
3217
|
|
|
4877
3218
|
let(:id_two) do
|
|
4878
|
-
|
|
3219
|
+
BSON::ObjectId.new
|
|
4879
3220
|
end
|
|
4880
3221
|
|
|
4881
3222
|
let(:criteria) do
|
|
@@ -4883,7 +3224,7 @@ describe Mongoid::Criteria do
|
|
|
4883
3224
|
end
|
|
4884
3225
|
|
|
4885
3226
|
it "does not wrap the array in another array" do
|
|
4886
|
-
criteria.selector.
|
|
3227
|
+
expect(criteria.selector).to eq({ "agent_ids" => [ id_one, id_two ]})
|
|
4887
3228
|
end
|
|
4888
3229
|
end
|
|
4889
3230
|
end
|
|
@@ -4902,7 +3243,7 @@ describe Mongoid::Criteria do
|
|
|
4902
3243
|
end
|
|
4903
3244
|
|
|
4904
3245
|
it "returns the matching documents" do
|
|
4905
|
-
criteria.
|
|
3246
|
+
expect(criteria).to eq([ match ])
|
|
4906
3247
|
end
|
|
4907
3248
|
end
|
|
4908
3249
|
|
|
@@ -4913,7 +3254,7 @@ describe Mongoid::Criteria do
|
|
|
4913
3254
|
end
|
|
4914
3255
|
|
|
4915
3256
|
it "returns the matching documents" do
|
|
4916
|
-
criteria.
|
|
3257
|
+
expect(criteria).to eq([ match ])
|
|
4917
3258
|
end
|
|
4918
3259
|
end
|
|
4919
3260
|
end
|
|
@@ -4927,7 +3268,7 @@ describe Mongoid::Criteria do
|
|
|
4927
3268
|
context "when the method exists on the class" do
|
|
4928
3269
|
|
|
4929
3270
|
before do
|
|
4930
|
-
Person.
|
|
3271
|
+
expect(Person).to receive(:minor).and_call_original
|
|
4931
3272
|
end
|
|
4932
3273
|
|
|
4933
3274
|
it "calls the method on the class" do
|
|
@@ -4938,7 +3279,7 @@ describe Mongoid::Criteria do
|
|
|
4938
3279
|
context "when the method exists on the criteria" do
|
|
4939
3280
|
|
|
4940
3281
|
before do
|
|
4941
|
-
criteria.
|
|
3282
|
+
expect(criteria).to receive(:to_criteria).and_call_original
|
|
4942
3283
|
end
|
|
4943
3284
|
|
|
4944
3285
|
it "calls the method on the criteria" do
|
|
@@ -4949,7 +3290,7 @@ describe Mongoid::Criteria do
|
|
|
4949
3290
|
context "when the method exists on array" do
|
|
4950
3291
|
|
|
4951
3292
|
before do
|
|
4952
|
-
criteria.
|
|
3293
|
+
expect(criteria).to receive(:entries).and_call_original
|
|
4953
3294
|
end
|
|
4954
3295
|
|
|
4955
3296
|
it "calls the method on the criteria" do
|
|
@@ -4960,7 +3301,7 @@ describe Mongoid::Criteria do
|
|
|
4960
3301
|
context "when the method does not exist" do
|
|
4961
3302
|
|
|
4962
3303
|
before do
|
|
4963
|
-
criteria.
|
|
3304
|
+
expect(criteria).to receive(:entries).never
|
|
4964
3305
|
end
|
|
4965
3306
|
|
|
4966
3307
|
it "raises an error" do
|
|
@@ -4986,7 +3327,7 @@ describe Mongoid::Criteria do
|
|
|
4986
3327
|
end
|
|
4987
3328
|
|
|
4988
3329
|
it "passes the block through method_missing" do
|
|
4989
|
-
criteria.uniq(&:name).
|
|
3330
|
+
expect(criteria.uniq(&:name)).to eq([ band_one ])
|
|
4990
3331
|
end
|
|
4991
3332
|
end
|
|
4992
3333
|
|
|
@@ -4996,94 +3337,36 @@ describe Mongoid::Criteria do
|
|
|
4996
3337
|
Band.where(name: "Depeche Mode").with(collection: "artists")
|
|
4997
3338
|
end
|
|
4998
3339
|
|
|
4999
|
-
after do
|
|
5000
|
-
Band.persistence_options.clear
|
|
5001
|
-
end
|
|
5002
|
-
|
|
5003
3340
|
it "retains the criteria selection" do
|
|
5004
|
-
criteria.selector.
|
|
3341
|
+
expect(criteria.selector).to eq("name" => "Depeche Mode")
|
|
5005
3342
|
end
|
|
5006
3343
|
|
|
5007
3344
|
it "sets the persistence options" do
|
|
5008
|
-
|
|
3345
|
+
expect(criteria.persistence_options).to eq(collection: "artists")
|
|
5009
3346
|
end
|
|
5010
3347
|
end
|
|
5011
3348
|
|
|
5012
|
-
describe "#
|
|
3349
|
+
describe "#geo_spacial" do
|
|
5013
3350
|
|
|
5014
|
-
|
|
5015
|
-
Bar.create_indexes
|
|
5016
|
-
end
|
|
5017
|
-
|
|
5018
|
-
let!(:match) do
|
|
5019
|
-
Bar.create(location: [ 52.30, 13.25 ])
|
|
5020
|
-
end
|
|
5021
|
-
|
|
5022
|
-
let(:criteria) do
|
|
5023
|
-
Bar.within_box(location: [[ 50, 10 ], [ 60, 20 ]])
|
|
5024
|
-
end
|
|
5025
|
-
|
|
5026
|
-
it "returns the matching documents" do
|
|
5027
|
-
criteria.should eq([ match ])
|
|
5028
|
-
end
|
|
5029
|
-
end
|
|
5030
|
-
|
|
5031
|
-
describe "#within_circle" do
|
|
5032
|
-
|
|
5033
|
-
before do
|
|
5034
|
-
Bar.create_indexes
|
|
5035
|
-
end
|
|
5036
|
-
|
|
5037
|
-
let!(:match) do
|
|
5038
|
-
Bar.create(location: [ 52.30, 13.25 ])
|
|
5039
|
-
end
|
|
5040
|
-
|
|
5041
|
-
let(:criteria) do
|
|
5042
|
-
Bar.within_circle(location: [[ 52, 13 ], 0.5 ])
|
|
5043
|
-
end
|
|
5044
|
-
|
|
5045
|
-
it "returns the matching documents" do
|
|
5046
|
-
criteria.should eq([ match ])
|
|
5047
|
-
end
|
|
5048
|
-
end
|
|
5049
|
-
|
|
5050
|
-
describe "#within_polygon" do
|
|
5051
|
-
|
|
5052
|
-
before do
|
|
5053
|
-
Bar.create_indexes
|
|
5054
|
-
end
|
|
5055
|
-
|
|
5056
|
-
let!(:match) do
|
|
5057
|
-
Bar.create(location: [ 52.30, 13.25 ])
|
|
5058
|
-
end
|
|
5059
|
-
|
|
5060
|
-
let(:criteria) do
|
|
5061
|
-
Bar.within_polygon(
|
|
5062
|
-
location: [[ 50, 10 ], [ 50, 20 ], [ 60, 20 ], [ 60, 10 ]]
|
|
5063
|
-
)
|
|
5064
|
-
end
|
|
5065
|
-
|
|
5066
|
-
it "returns the matching documents" do
|
|
5067
|
-
criteria.should eq([ match ])
|
|
5068
|
-
end
|
|
5069
|
-
end
|
|
3351
|
+
context "when checking within a polygon" do
|
|
5070
3352
|
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
Bar.create_indexes
|
|
5075
|
-
end
|
|
3353
|
+
before do
|
|
3354
|
+
Bar.create_indexes
|
|
3355
|
+
end
|
|
5076
3356
|
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
3357
|
+
let!(:match) do
|
|
3358
|
+
Bar.create(location: [ 52.30, 13.25 ])
|
|
3359
|
+
end
|
|
5080
3360
|
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
3361
|
+
let(:criteria) do
|
|
3362
|
+
Bar.geo_spacial(
|
|
3363
|
+
:location.within_polygon => [[[ 50, 10 ], [ 50, 20 ], [ 60, 20 ], [ 60, 10 ], [ 50, 10 ]]]
|
|
3364
|
+
)
|
|
3365
|
+
end
|
|
5084
3366
|
|
|
5085
|
-
|
|
5086
|
-
|
|
3367
|
+
it "returns the matching documents" do
|
|
3368
|
+
expect(criteria).to eq([ match ])
|
|
3369
|
+
end
|
|
5087
3370
|
end
|
|
5088
3371
|
end
|
|
5089
3372
|
|
|
@@ -5102,7 +3385,7 @@ describe Mongoid::Criteria do
|
|
|
5102
3385
|
end
|
|
5103
3386
|
|
|
5104
3387
|
it "returns the matching documents" do
|
|
5105
|
-
criteria.
|
|
3388
|
+
expect(criteria).to eq([ match ])
|
|
5106
3389
|
end
|
|
5107
3390
|
end
|
|
5108
3391
|
|
|
@@ -5117,7 +3400,7 @@ describe Mongoid::Criteria do
|
|
|
5117
3400
|
end
|
|
5118
3401
|
|
|
5119
3402
|
it "returns the matching documents" do
|
|
5120
|
-
criteria.
|
|
3403
|
+
expect(criteria).to eq([ match ])
|
|
5121
3404
|
end
|
|
5122
3405
|
end
|
|
5123
3406
|
|
|
@@ -5132,7 +3415,7 @@ describe Mongoid::Criteria do
|
|
|
5132
3415
|
end
|
|
5133
3416
|
|
|
5134
3417
|
it "properly uses the database field name" do
|
|
5135
|
-
criteria.options.
|
|
3418
|
+
expect(criteria.options).to eq(fields: { "mobile_phones" => 0 })
|
|
5136
3419
|
end
|
|
5137
3420
|
end
|
|
5138
3421
|
end
|