mongoid 6.4.8 → 7.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/LICENSE +1 -0
- data/README.md +4 -3
- data/Rakefile +33 -7
- data/lib/config/locales/en.yml +17 -0
- data/lib/mongoid/association/accessors.rb +339 -0
- data/lib/mongoid/{relations/binding.rb → association/bindable.rb} +32 -52
- data/lib/mongoid/association/builders.rb +92 -0
- data/lib/mongoid/{relations/constraint.rb → association/constrainable.rb} +11 -22
- data/lib/mongoid/association/depending.rb +137 -0
- data/lib/mongoid/{relations/eager.rb → association/eager_loadable.rb} +11 -11
- data/lib/mongoid/{relations → association}/embedded/batchable.rb +19 -19
- data/lib/mongoid/association/embedded/cyclic.rb +109 -0
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +56 -0
- data/lib/mongoid/{relations/builders/embedded/in.rb → association/embedded/embedded_in/buildable.rb} +12 -6
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +121 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +154 -0
- data/lib/mongoid/{relations/bindings/embedded/many.rb → association/embedded/embeds_many/binding.rb} +11 -9
- data/lib/mongoid/{relations/builders/embedded/many.rb → association/embedded/embeds_many/buildable.rb} +13 -7
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +552 -0
- data/lib/mongoid/association/embedded/embeds_many.rb +211 -0
- data/lib/mongoid/{relations/bindings/embedded/one.rb → association/embedded/embeds_one/binding.rb} +12 -10
- data/lib/mongoid/{relations/builders/embedded/one.rb → association/embedded/embeds_one/buildable.rb} +13 -7
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +130 -0
- data/lib/mongoid/association/embedded/embeds_one.rb +174 -0
- data/lib/mongoid/association/embedded.rb +4 -0
- data/lib/mongoid/association/macros.rb +204 -0
- data/lib/mongoid/{relations → association}/many.rb +19 -49
- data/lib/mongoid/{relations → association}/marshalable.rb +6 -4
- data/lib/mongoid/association/nested/many.rb +200 -0
- data/lib/mongoid/association/nested/nested_buildable.rb +72 -0
- data/lib/mongoid/association/nested/one.rb +127 -0
- data/lib/mongoid/association/nested.rb +15 -0
- data/lib/mongoid/{relations → association}/one.rb +6 -6
- data/lib/mongoid/association/options.rb +152 -0
- data/lib/mongoid/{relations → association}/proxy.rb +45 -59
- data/lib/mongoid/association/referenced/auto_save.rb +79 -0
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +87 -0
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +46 -0
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +36 -0
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +136 -0
- data/lib/mongoid/association/referenced/belongs_to.rb +248 -0
- data/lib/mongoid/association/referenced/counter_cache.rb +163 -0
- data/lib/mongoid/association/referenced/eager.rb +162 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +71 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +40 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +52 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +312 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +290 -0
- data/lib/mongoid/{relations/bindings/referenced/many.rb → association/referenced/has_many/binding.rb} +6 -5
- data/lib/mongoid/association/referenced/has_many/buildable.rb +38 -0
- data/lib/mongoid/association/referenced/has_many/eager.rb +43 -0
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +510 -0
- data/lib/mongoid/association/referenced/has_many/proxy.rb +578 -0
- data/lib/mongoid/association/referenced/has_many.rb +275 -0
- data/lib/mongoid/{relations/bindings/referenced/one.rb → association/referenced/has_one/binding.rb} +11 -8
- data/lib/mongoid/association/referenced/has_one/buildable.rb +60 -0
- data/lib/mongoid/association/referenced/has_one/eager.rb +35 -0
- data/lib/mongoid/{relations/builders/nested_attributes/one.rb → association/referenced/has_one/nested_builder.rb} +9 -9
- data/lib/mongoid/association/referenced/has_one/proxy.rb +113 -0
- data/lib/mongoid/association/referenced/has_one.rb +204 -0
- data/lib/mongoid/association/referenced/syncable.rb +170 -0
- data/lib/mongoid/association/referenced.rb +7 -0
- data/lib/mongoid/{relations → association}/reflections.rb +21 -17
- data/lib/mongoid/association/relatable.rb +511 -0
- data/lib/mongoid/{relations.rb → association.rb} +57 -56
- 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 +1 -1
- data/lib/mongoid/atomic.rb +14 -4
- data/lib/mongoid/attributes/dynamic.rb +16 -15
- data/lib/mongoid/attributes/nested.rb +22 -11
- data/lib/mongoid/attributes/processing.rb +2 -2
- data/lib/mongoid/attributes/readonly.rb +2 -4
- data/lib/mongoid/attributes.rb +55 -31
- data/lib/mongoid/changeable.rb +1 -1
- data/lib/mongoid/clients/options.rb +7 -5
- data/lib/mongoid/clients/sessions.rb +20 -4
- data/lib/mongoid/composable.rb +4 -4
- data/lib/mongoid/config/environment.rb +21 -8
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/geo_near.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +21 -3
- data/lib/mongoid/contextual/mongo.rb +10 -8
- data/lib/mongoid/copyable.rb +11 -6
- data/lib/mongoid/criteria/includable.rb +14 -14
- data/lib/mongoid/criteria/modifiable.rb +8 -3
- data/lib/mongoid/criteria/options.rb +2 -2
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +3 -3
- data/lib/mongoid/criteria/queryable/extensions/string.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/time.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +12 -0
- data/lib/mongoid/criteria/queryable/key.rb +67 -8
- data/lib/mongoid/criteria/queryable/mergeable.rb +5 -4
- data/lib/mongoid/criteria/queryable/pipeline.rb +10 -5
- data/lib/mongoid/criteria/queryable/selectable.rb +5 -3
- data/lib/mongoid/criteria/queryable/selector.rb +9 -31
- data/lib/mongoid/criteria.rb +9 -3
- data/lib/mongoid/document.rb +14 -4
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +32 -0
- data/lib/mongoid/errors/invalid_relation_option.rb +29 -0
- data/lib/mongoid/errors/unknown_model.rb +25 -0
- data/lib/mongoid/errors.rb +3 -0
- data/lib/mongoid/extensions/array.rb +5 -5
- data/lib/mongoid/extensions/hash.rb +9 -4
- data/lib/mongoid/extensions/object.rb +4 -4
- data/lib/mongoid/extensions/range.rb +1 -0
- data/lib/mongoid/extensions/regexp.rb +1 -1
- data/lib/mongoid/extensions/string.rb +2 -2
- data/lib/mongoid/extensions.rb +0 -4
- data/lib/mongoid/factory.rb +13 -3
- data/lib/mongoid/fields/foreign_key.rb +5 -5
- data/lib/mongoid/fields/standard.rb +2 -14
- data/lib/mongoid/fields/validators/macro.rb +1 -1
- data/lib/mongoid/fields.rb +5 -4
- data/lib/mongoid/indexable.rb +4 -1
- data/lib/mongoid/interceptable.rb +8 -6
- data/lib/mongoid/matchable/all.rb +4 -3
- data/lib/mongoid/matchable/and.rb +1 -1
- data/lib/mongoid/matchable/default.rb +71 -24
- data/lib/mongoid/matchable/elem_match.rb +9 -3
- data/lib/mongoid/matchable/eq.rb +22 -0
- data/lib/mongoid/matchable/ne.rb +1 -1
- data/lib/mongoid/matchable/regexp.rb +2 -2
- data/lib/mongoid/matchable.rb +17 -16
- data/lib/mongoid/persistable/deletable.rb +7 -6
- data/lib/mongoid/persistable/incrementable.rb +1 -1
- data/lib/mongoid/persistable/logical.rb +1 -1
- data/lib/mongoid/persistable/pushable.rb +11 -2
- data/lib/mongoid/persistable/settable.rb +57 -12
- data/lib/mongoid/persistable.rb +4 -5
- data/lib/mongoid/persistence_context.rb +26 -11
- data/lib/mongoid/positional.rb +1 -1
- data/lib/mongoid/query_cache.rb +4 -2
- data/lib/mongoid/serializable.rb +4 -4
- data/lib/mongoid/shardable.rb +1 -1
- data/lib/mongoid/touchable.rb +102 -0
- data/lib/mongoid/traversable.rb +3 -3
- data/lib/mongoid/validatable/macros.rb +1 -1
- data/lib/mongoid/validatable/presence.rb +2 -2
- data/lib/mongoid/validatable/uniqueness.rb +5 -5
- data/lib/mongoid/validatable.rb +8 -8
- data/lib/mongoid/version.rb +2 -1
- data/lib/mongoid.rb +1 -0
- data/lib/rails/generators/mongoid/config/config_generator.rb +8 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +3 -0
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
- data/spec/README.md +18 -0
- data/spec/app/models/animal.rb +2 -1
- data/spec/app/models/bomb.rb +1 -1
- data/spec/app/models/customer.rb +11 -0
- data/spec/app/models/customer_address.rb +12 -0
- data/spec/app/models/message.rb +1 -1
- data/spec/app/models/minim.rb +7 -0
- data/spec/app/models/other_owner_object.rb +2 -0
- data/spec/app/models/person.rb +5 -2
- data/spec/app/models/shipment_address.rb +1 -0
- data/spec/app/models/store_as_dup_test3.rb +7 -0
- data/spec/app/models/store_as_dup_test4.rb +7 -0
- data/spec/app/models/updatable.rb +7 -0
- data/spec/app/models/vertex.rb +6 -0
- data/spec/app/models/wiki_page.rb +1 -1
- data/spec/config/mongoid.yml +13 -3
- data/spec/integration/app_spec.rb +341 -0
- data/spec/integration/associations/belongs_to_spec.rb +13 -0
- data/spec/integration/associations/embedded_spec.rb +176 -0
- data/spec/integration/callbacks_models.rb +49 -0
- data/spec/integration/callbacks_spec.rb +216 -0
- data/spec/integration/criteria/date_field_spec.rb +41 -0
- data/spec/integration/criteria/time_with_zone_spec.rb +32 -0
- data/spec/integration/matchable_spec.rb +680 -0
- data/spec/lite_spec_helper.rb +71 -0
- data/spec/mongoid/{relations → association}/accessors_spec.rb +40 -1
- data/spec/mongoid/{relations → association}/auto_save_spec.rb +60 -12
- data/spec/mongoid/{relations → association}/builders_spec.rb +1 -1
- data/spec/mongoid/association/constrainable_spec.rb +115 -0
- data/spec/mongoid/{relations → association}/counter_cache_spec.rb +1 -1
- data/spec/mongoid/association/depending_spec.rb +866 -0
- data/spec/mongoid/{relations → association}/eager_spec.rb +12 -12
- data/spec/mongoid/{relations → association/embedded}/cyclic_spec.rb +1 -1
- data/spec/mongoid/{relations → association}/embedded/dirty_spec.rb +0 -0
- data/spec/mongoid/{relations/bindings/embedded/in_spec.rb → association/embedded/embedded_in/binding_spec.rb} +13 -13
- data/spec/mongoid/{relations/builders/embedded/in_spec.rb → association/embedded/embedded_in/buildable_spec.rb} +9 -9
- data/spec/mongoid/{relations/embedded/in_spec.rb → association/embedded/embedded_in/proxy_spec.rb} +55 -77
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +901 -0
- data/spec/mongoid/{relations/bindings/embedded/many_spec.rb → association/embedded/embeds_many/binding_spec.rb} +3 -3
- data/spec/mongoid/{relations/builders/embedded/many_spec.rb → association/embedded/embeds_many/buildable_spec.rb} +17 -45
- data/spec/mongoid/{relations/embedded/many_spec.rb → association/embedded/embeds_many/proxy_spec.rb} +124 -182
- data/spec/mongoid/association/embedded/embeds_many_models.rb +53 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +862 -0
- data/spec/mongoid/{relations/bindings/embedded/one_spec.rb → association/embedded/embeds_one/binding_spec.rb} +4 -4
- data/spec/mongoid/{relations/builders/embedded/one_spec.rb → association/embedded/embeds_one/buildable_spec.rb} +14 -34
- data/spec/mongoid/{relations/embedded/one_spec.rb → association/embedded/embeds_one/proxy_spec.rb} +39 -84
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +6 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +51 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +954 -0
- data/spec/mongoid/{relations → association}/macros_spec.rb +148 -73
- data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/many_spec.rb +16 -19
- data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/one_spec.rb +17 -20
- data/spec/mongoid/association/options_spec.rb +1321 -0
- data/spec/mongoid/{relations → association}/polymorphic_spec.rb +66 -34
- data/spec/mongoid/{relations/bindings/referenced/in_spec.rb → association/referenced/belongs_to/binding_spec.rb} +7 -7
- data/spec/mongoid/{relations/builders/referenced/in_spec.rb → association/referenced/belongs_to/buildable_spec.rb} +46 -79
- data/spec/mongoid/{relations/eager/belongs_to_spec.rb → association/referenced/belongs_to/eager_spec.rb} +33 -14
- data/spec/mongoid/{relations/referenced/in_spec.rb → association/referenced/belongs_to/proxy_spec.rb} +57 -91
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2023 -0
- data/spec/mongoid/{relations/bindings/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +121 -0
- data/spec/mongoid/{relations/eager/has_and_belongs_to_many_spec.rb → association/referenced/has_and_belongs_to_many/eager_spec.rb} +26 -7
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +56 -0
- data/spec/mongoid/{relations/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/proxy_spec.rb} +247 -99
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +26 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +1027 -0
- data/spec/mongoid/{relations/bindings/referenced/many_spec.rb → association/referenced/has_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +119 -0
- data/spec/mongoid/{relations/eager/has_many_spec.rb → association/referenced/has_many/eager_spec.rb} +26 -11
- data/spec/mongoid/{relations/targets → association/referenced/has_many}/enumerable_spec.rb +227 -1
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +23 -0
- data/spec/mongoid/{relations/referenced/many_spec.rb → association/referenced/has_many/proxy_spec.rb} +30 -94
- data/spec/mongoid/association/referenced/has_many_models.rb +37 -0
- data/spec/mongoid/association/referenced/has_many_spec.rb +1225 -0
- data/spec/mongoid/{relations/bindings/referenced/one_spec.rb → association/referenced/has_one/binding_spec.rb} +4 -4
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +113 -0
- data/spec/mongoid/{relations/eager/has_one_spec.rb → association/referenced/has_one/eager_spec.rb} +10 -10
- data/spec/mongoid/{relations/referenced/one_spec.rb → association/referenced/has_one/proxy_spec.rb} +9 -109
- data/spec/mongoid/association/referenced/has_one_models.rb +48 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +1360 -0
- data/spec/mongoid/{relations → association}/reflections_spec.rb +1 -12
- data/spec/mongoid/{relations/synchronization_spec.rb → association/syncable_spec.rb} +4 -2
- data/spec/mongoid/{relations_spec.rb → association_spec.rb} +1 -1
- data/spec/mongoid/atomic/modifiers_spec.rb +2 -2
- data/spec/mongoid/atomic/paths_spec.rb +41 -0
- data/spec/mongoid/atomic_spec.rb +4 -4
- data/spec/mongoid/attributes/dynamic_spec.rb +153 -0
- data/spec/mongoid/attributes/nested_spec.rb +29 -11
- data/spec/mongoid/attributes/readonly_spec.rb +80 -125
- data/spec/mongoid/attributes_spec.rb +298 -9
- data/spec/mongoid/clients/factory_spec.rb +20 -38
- data/spec/mongoid/clients/options_spec.rb +64 -50
- data/spec/mongoid/clients/sessions_spec.rb +9 -5
- data/spec/mongoid/clients/transactions_spec.rb +390 -0
- data/spec/mongoid/clients_spec.rb +70 -10
- data/spec/mongoid/config_spec.rb +27 -1
- data/spec/mongoid/contextual/atomic_spec.rb +37 -14
- data/spec/mongoid/contextual/geo_near_spec.rb +11 -2
- data/spec/mongoid/contextual/map_reduce_spec.rb +20 -5
- data/spec/mongoid/contextual/memory_spec.rb +19 -0
- data/spec/mongoid/contextual/mongo_spec.rb +107 -56
- data/spec/mongoid/copyable_spec.rb +90 -6
- data/spec/mongoid/copyable_spec_models.rb +17 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +173 -1
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +54 -0
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -7
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +44 -1
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +19 -7
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +28 -1
- data/spec/mongoid/criteria/queryable/key_spec.rb +48 -6
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +12 -0
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +762 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +5 -224
- data/spec/mongoid/criteria/queryable/selector_spec.rb +37 -0
- data/spec/mongoid/criteria_spec.rb +36 -19
- data/spec/mongoid/document_fields_spec.rb +88 -0
- data/spec/mongoid/document_persistence_context_spec.rb +33 -0
- data/spec/mongoid/document_spec.rb +29 -4
- data/spec/mongoid/extensions/array_spec.rb +11 -15
- data/spec/mongoid/extensions/hash_spec.rb +18 -1
- data/spec/mongoid/extensions/object_spec.rb +7 -11
- data/spec/mongoid/extensions/range_spec.rb +7 -0
- data/spec/mongoid/factory_spec.rb +21 -3
- data/spec/mongoid/fields/foreign_key_spec.rb +24 -32
- data/spec/mongoid/fields_spec.rb +1 -1
- data/spec/mongoid/indexable_spec.rb +24 -12
- data/spec/mongoid/interceptable_spec.rb +22 -1
- data/spec/mongoid/matchable/default_spec.rb +10 -3
- data/spec/mongoid/matchable/elem_match_spec.rb +20 -0
- data/spec/mongoid/matchable/eq_spec.rb +48 -0
- data/spec/mongoid/matchable/regexp_spec.rb +2 -2
- data/spec/mongoid/matchable_spec.rb +2 -2
- data/spec/mongoid/persistable/pushable_spec.rb +55 -1
- data/spec/mongoid/persistable/savable_spec.rb +5 -5
- data/spec/mongoid/persistable/settable_spec.rb +125 -10
- data/spec/mongoid/persistable_spec.rb +21 -6
- data/spec/mongoid/persistence_context_spec.rb +1 -1
- data/spec/mongoid/query_cache_spec.rb +65 -27
- data/spec/mongoid/relations/proxy_spec.rb +124 -124
- data/spec/mongoid/scopable_spec.rb +2 -1
- data/spec/mongoid/shardable_spec.rb +32 -12
- data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
- data/spec/mongoid/tasks/database_spec.rb +1 -1
- data/spec/mongoid/{relations/touchable_spec.rb → touchable_spec.rb} +40 -1
- data/spec/mongoid/validatable/associated_spec.rb +1 -1
- data/spec/mongoid/validatable/presence_spec.rb +7 -6
- data/spec/mongoid/validatable/uniqueness_spec.rb +33 -6
- data/spec/mongoid/validatable_spec.rb +1 -1
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +221 -0
- data/spec/shared/lib/mrss/constraints.rb +354 -0
- data/spec/shared/lib/mrss/docker_runner.rb +265 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +191 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +115 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +162 -0
- data/spec/shared/lib/mrss/utils.rb +15 -0
- data/spec/shared/share/Dockerfile.erb +231 -0
- data/spec/shared/shlib/distro.sh +73 -0
- data/spec/shared/shlib/server.sh +290 -0
- data/spec/shared/shlib/set_env.sh +128 -0
- data/spec/spec_helper.rb +34 -49
- data/spec/support/cluster_config.rb +3 -3
- data/spec/support/constraints.rb +21 -76
- data/spec/support/expectations.rb +17 -3
- data/spec/support/spec_config.rb +20 -7
- data.tar.gz.sig +0 -0
- metadata +646 -541
- metadata.gz.sig +1 -5
- data/lib/mongoid/relations/accessors.rb +0 -267
- data/lib/mongoid/relations/auto_save.rb +0 -94
- data/lib/mongoid/relations/bindings/embedded/in.rb +0 -59
- data/lib/mongoid/relations/bindings/referenced/in.rb +0 -65
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +0 -70
- data/lib/mongoid/relations/bindings.rb +0 -9
- data/lib/mongoid/relations/builder.rb +0 -57
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +0 -199
- data/lib/mongoid/relations/builders/referenced/in.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +0 -39
- data/lib/mongoid/relations/builders/referenced/one.rb +0 -26
- data/lib/mongoid/relations/builders.rb +0 -106
- data/lib/mongoid/relations/cascading/delete.rb +0 -44
- data/lib/mongoid/relations/cascading/destroy.rb +0 -43
- data/lib/mongoid/relations/cascading/nullify.rb +0 -35
- data/lib/mongoid/relations/cascading/restrict.rb +0 -39
- data/lib/mongoid/relations/cascading.rb +0 -56
- data/lib/mongoid/relations/conversions.rb +0 -34
- data/lib/mongoid/relations/counter_cache.rb +0 -160
- data/lib/mongoid/relations/cyclic.rb +0 -107
- data/lib/mongoid/relations/eager/base.rb +0 -153
- data/lib/mongoid/relations/eager/belongs_to.rb +0 -31
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +0 -47
- data/lib/mongoid/relations/eager/has_many.rb +0 -38
- data/lib/mongoid/relations/eager/has_one.rb +0 -30
- data/lib/mongoid/relations/embedded/in.rb +0 -241
- data/lib/mongoid/relations/embedded/many.rb +0 -683
- data/lib/mongoid/relations/embedded/one.rb +0 -235
- data/lib/mongoid/relations/macros.rb +0 -367
- data/lib/mongoid/relations/metadata.rb +0 -1179
- data/lib/mongoid/relations/nested_builder.rb +0 -74
- data/lib/mongoid/relations/options.rb +0 -49
- data/lib/mongoid/relations/polymorphic.rb +0 -39
- data/lib/mongoid/relations/referenced/in.rb +0 -304
- data/lib/mongoid/relations/referenced/many.rb +0 -812
- data/lib/mongoid/relations/referenced/many_to_many.rb +0 -479
- data/lib/mongoid/relations/referenced/one.rb +0 -290
- data/lib/mongoid/relations/synchronization.rb +0 -169
- data/lib/mongoid/relations/targets/enumerable.rb +0 -493
- data/lib/mongoid/relations/targets.rb +0 -2
- data/lib/mongoid/relations/touchable.rb +0 -97
- data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +0 -184
- data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +0 -201
- data/spec/mongoid/relations/builders/referenced/many_spec.rb +0 -137
- data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +0 -178
- data/spec/mongoid/relations/builders/referenced/one_spec.rb +0 -111
- data/spec/mongoid/relations/cascading/delete_spec.rb +0 -101
- data/spec/mongoid/relations/cascading/destroy_spec.rb +0 -47
- data/spec/mongoid/relations/cascading/nullify_spec.rb +0 -32
- data/spec/mongoid/relations/cascading/restrict_spec.rb +0 -68
- data/spec/mongoid/relations/cascading_spec.rb +0 -355
- data/spec/mongoid/relations/constraint_spec.rb +0 -75
- data/spec/mongoid/relations/conversions_spec.rb +0 -128
- data/spec/mongoid/relations/metadata_spec.rb +0 -1985
- data/spec/mongoid/relations/options_spec.rb +0 -35
@@ -0,0 +1,176 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
require_relative '../../mongoid/association/embedded/embeds_many_models'
|
6
|
+
require_relative '../../mongoid/association/embedded/embeds_one_models'
|
7
|
+
|
8
|
+
describe 'embedded associations' do
|
9
|
+
|
10
|
+
describe 'parent association' do
|
11
|
+
let(:parent) do
|
12
|
+
parent_cls.new
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'embeds_one' do
|
16
|
+
|
17
|
+
shared_examples 'is set' do
|
18
|
+
it 'is set' do
|
19
|
+
parent.child = child_cls.new
|
20
|
+
parent.child.parent.should == parent
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'class_name set without leading ::' do
|
25
|
+
let(:parent_cls) { EomParent }
|
26
|
+
let(:child_cls) { EomChild }
|
27
|
+
|
28
|
+
it_behaves_like 'is set'
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'class_name set with leading ::' do
|
32
|
+
let(:parent_cls) { EomCcParent }
|
33
|
+
let(:child_cls) { EomCcChild }
|
34
|
+
|
35
|
+
it_behaves_like 'is set'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'embeds_many' do
|
40
|
+
|
41
|
+
let(:child) { parent.legislators.new }
|
42
|
+
|
43
|
+
shared_examples 'is set' do
|
44
|
+
it 'is set' do
|
45
|
+
child.congress.should == parent
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'class_name set without leading ::' do
|
50
|
+
let(:parent_cls) { EmmCongress }
|
51
|
+
|
52
|
+
it_behaves_like 'is set'
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'class_name set with leading ::' do
|
56
|
+
let(:parent_cls) { EmmCcCongress }
|
57
|
+
|
58
|
+
it_behaves_like 'is set'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'without default order' do
|
64
|
+
let(:congress) do
|
65
|
+
EmmCongress.create!
|
66
|
+
end
|
67
|
+
|
68
|
+
let(:legislator) do
|
69
|
+
EmmLegislator.create!(congress: congress, a: 1)
|
70
|
+
end
|
71
|
+
|
72
|
+
shared_examples_for 'an embedded association' do
|
73
|
+
it 'adds child documents to parent association object' do
|
74
|
+
legislator
|
75
|
+
congress.legislators._target.should == [legislator]
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'adds child documents to parent association object criteria' do
|
79
|
+
legislator
|
80
|
+
congress.legislators.criteria.documents.should == [legislator]
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'populates documents on parent association object' do
|
84
|
+
congress.legislators.documents.should == [legislator]
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns created child when referencing embedded association' do
|
88
|
+
congress.legislators.should == [legislator]
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'returns created child when referencing Criteria created from embedded association' do
|
92
|
+
congress.legislators.all.should be_a(Mongoid::Criteria)
|
93
|
+
congress.legislators.all.to_a.should == [legislator]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when association was not previously referenced' do
|
98
|
+
before do
|
99
|
+
legislator
|
100
|
+
end
|
101
|
+
|
102
|
+
it_behaves_like 'an embedded association'
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'when association was previously referenced' do
|
106
|
+
before do
|
107
|
+
# This query must be before the product is created
|
108
|
+
congress.legislators.where(a: 1).first
|
109
|
+
|
110
|
+
legislator
|
111
|
+
end
|
112
|
+
|
113
|
+
it_behaves_like 'an embedded association'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'with default order' do
|
118
|
+
let(:manufactory) do
|
119
|
+
EmmManufactory.create!
|
120
|
+
end
|
121
|
+
|
122
|
+
let(:product) do
|
123
|
+
EmmProduct.create!(manufactory: manufactory, name: 'Car')
|
124
|
+
end
|
125
|
+
|
126
|
+
shared_examples_for 'adds child documents to parent association' do
|
127
|
+
it 'adds child documents to parent association' do
|
128
|
+
manufactory.products._target.should == [product]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
shared_examples_for 'an embedded association' do
|
133
|
+
it 'adds child documents to parent association object' do
|
134
|
+
product
|
135
|
+
manufactory.products._target.should == [product]
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'adds child documents to parent association object criteria' do
|
139
|
+
product
|
140
|
+
manufactory.products.criteria.documents.should == [product]
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'populates documents on parent association object' do
|
144
|
+
manufactory.products.documents.should == [product]
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'returns created child when referencing embedded association' do
|
148
|
+
manufactory.products.should == [product]
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'returns created child when referencing Criteria created from embedded association' do
|
152
|
+
manufactory.products.all.should be_a(Mongoid::Criteria)
|
153
|
+
manufactory.products.all.to_a.should == [product]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'when association is not loaded' do
|
158
|
+
before do
|
159
|
+
product
|
160
|
+
end
|
161
|
+
|
162
|
+
it_behaves_like 'an embedded association'
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when association is loaded' do
|
166
|
+
before do
|
167
|
+
# This query must be before the product is created
|
168
|
+
manufactory.products.where(name: "Car").first
|
169
|
+
|
170
|
+
product
|
171
|
+
end
|
172
|
+
|
173
|
+
it_behaves_like 'an embedded association'
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class Galaxy
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
field :age, type: Integer
|
5
|
+
|
6
|
+
before_validation :set_age
|
7
|
+
|
8
|
+
embeds_many :stars
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def set_age
|
13
|
+
self.age ||= 100_000
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Star
|
18
|
+
include Mongoid::Document
|
19
|
+
|
20
|
+
embedded_in :galaxy
|
21
|
+
|
22
|
+
field :age, type: Integer
|
23
|
+
|
24
|
+
before_validation :set_age
|
25
|
+
|
26
|
+
embeds_many :planets
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def set_age
|
31
|
+
self.age ||= 42_000
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Planet
|
36
|
+
include Mongoid::Document
|
37
|
+
|
38
|
+
embedded_in :star
|
39
|
+
|
40
|
+
field :age, type: Integer
|
41
|
+
|
42
|
+
before_validation :set_age
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def set_age
|
47
|
+
self.age ||= 2_000
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,216 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
require_relative './callbacks_models'
|
6
|
+
|
7
|
+
describe 'callbacks integration tests' do
|
8
|
+
context 'when modifying attributes in a callback' do
|
9
|
+
|
10
|
+
context 'when creating top-level document' do
|
11
|
+
context 'top level document' do
|
12
|
+
let(:instance) do
|
13
|
+
Galaxy.create!
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'writes the attribute value into the model' do
|
17
|
+
instance.age.should == 100_000
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'persists the attribute value' do
|
21
|
+
Galaxy.find(instance.id).age.should == 100_000
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'embedded document' do
|
26
|
+
shared_examples 'persists the attribute value' do
|
27
|
+
it 'writes the attribute value into the model' do
|
28
|
+
instance.stars.first.age.should == 42_000
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'persists the attribute value' do
|
32
|
+
Galaxy.find(instance.id).stars.first.age.should == 42_000
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'set as a document instance' do
|
37
|
+
let(:instance) do
|
38
|
+
Galaxy.create!(stars: [Star.new])
|
39
|
+
end
|
40
|
+
|
41
|
+
include_examples 'persists the attribute value'
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'set as attributes on parent' do
|
45
|
+
let(:instance) do
|
46
|
+
Galaxy.create!(stars: [{}])
|
47
|
+
end
|
48
|
+
|
49
|
+
include_examples 'persists the attribute value'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'nested embedded document' do
|
54
|
+
shared_examples 'persists the attribute value' do
|
55
|
+
it 'writes the attribute value into the model' do
|
56
|
+
instance.stars.first.planets.first.age.should == 2_000
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'persists the attribute value' do
|
60
|
+
Galaxy.find(instance.id).stars.first.planets.first.age.should == 2_000
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'set as a document instance' do
|
65
|
+
let(:instance) do
|
66
|
+
Galaxy.create!(stars: [Star.new(
|
67
|
+
planets: [Planet.new],
|
68
|
+
)])
|
69
|
+
end
|
70
|
+
|
71
|
+
include_examples 'persists the attribute value'
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'set as attributes on parent' do
|
75
|
+
let(:instance) do
|
76
|
+
Galaxy.create!(stars: [
|
77
|
+
planets: [{}],
|
78
|
+
])
|
79
|
+
end
|
80
|
+
|
81
|
+
include_examples 'persists the attribute value'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when updating top-level document via #save' do
|
87
|
+
let!(:instance) do
|
88
|
+
Galaxy.create!
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'embedded document' do
|
92
|
+
shared_examples 'persists the attribute value' do
|
93
|
+
it 'writes the attribute value into the model' do
|
94
|
+
instance.stars.first.age.should == 42_000
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'persists the attribute value' do
|
98
|
+
Galaxy.find(instance.id).stars.first.age.should == 42_000
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'set as a document instance' do
|
103
|
+
before do
|
104
|
+
instance.stars = [Star.new]
|
105
|
+
instance.save!
|
106
|
+
end
|
107
|
+
|
108
|
+
include_examples 'persists the attribute value'
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'set as attributes on parent' do
|
112
|
+
before do
|
113
|
+
instance.stars = [{}]
|
114
|
+
instance.save!
|
115
|
+
end
|
116
|
+
|
117
|
+
include_examples 'persists the attribute value'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'nested embedded document' do
|
122
|
+
shared_examples 'persists the attribute value' do
|
123
|
+
it 'writes the attribute value into the model' do
|
124
|
+
instance.stars.first.planets.first.age.should == 2_000
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'persists the attribute value' do
|
128
|
+
Galaxy.find(instance.id).stars.first.planets.first.age.should == 2_000
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'set as a document instance' do
|
133
|
+
before do
|
134
|
+
instance.stars = [Star.new(planets: [Planet.new])]
|
135
|
+
instance.save!
|
136
|
+
end
|
137
|
+
|
138
|
+
include_examples 'persists the attribute value'
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'set as attributes on parent' do
|
142
|
+
before do
|
143
|
+
instance.stars = [planets: [{}]]
|
144
|
+
instance.save!
|
145
|
+
end
|
146
|
+
|
147
|
+
include_examples 'persists the attribute value'
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'when updating top-level document via #update_attributes' do
|
153
|
+
let!(:instance) do
|
154
|
+
Galaxy.create!
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'embedded document' do
|
158
|
+
shared_examples 'persists the attribute value' do
|
159
|
+
it 'writes the attribute value into the model' do
|
160
|
+
instance.stars.first.age.should == 42_000
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'persists the attribute value' do
|
164
|
+
Galaxy.find(instance.id).stars.first.age.should == 42_000
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'set as a document instance' do
|
169
|
+
before do
|
170
|
+
instance.update_attributes(stars: [Star.new])
|
171
|
+
end
|
172
|
+
|
173
|
+
include_examples 'persists the attribute value'
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'set as attributes on parent' do
|
177
|
+
before do
|
178
|
+
instance.update_attributes(stars: [{}])
|
179
|
+
end
|
180
|
+
|
181
|
+
include_examples 'persists the attribute value'
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'nested embedded document' do
|
186
|
+
shared_examples 'persists the attribute value' do
|
187
|
+
it 'writes the attribute value into the model' do
|
188
|
+
instance.stars.first.planets.first.age.should == 2_000
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'persists the attribute value' do
|
192
|
+
pending 'MONGOID-4476'
|
193
|
+
|
194
|
+
Galaxy.find(instance.id).stars.first.planets.first.age.should == 2_000
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'set as a document instance' do
|
199
|
+
before do
|
200
|
+
instance.update_attributes(stars: [Star.new(planets: [Planet.new])])
|
201
|
+
end
|
202
|
+
|
203
|
+
include_examples 'persists the attribute value'
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'set as attributes on parent' do
|
207
|
+
before do
|
208
|
+
instance.update_attributes(stars: [planets: [{}]])
|
209
|
+
end
|
210
|
+
|
211
|
+
include_examples 'persists the attribute value'
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe 'Queries on Date fields' do
|
7
|
+
let(:query) do
|
8
|
+
Band.where(founded: arg)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:selector) { query.selector }
|
12
|
+
|
13
|
+
shared_examples 'converts to beginning of day in UTC' do
|
14
|
+
it 'converts to beginning of day in UTC' do
|
15
|
+
selector['founded'].should == arg.dup.beginning_of_day.utc.beginning_of_day
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'using Time' do
|
20
|
+
let(:arg) do
|
21
|
+
Time.now.freeze
|
22
|
+
end
|
23
|
+
|
24
|
+
it_behaves_like 'converts to beginning of day in UTC'
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'using TimeWithZone' do
|
28
|
+
let(:time_zone_name) { 'Pacific Time (US & Canada)' }
|
29
|
+
let(:arg) { Time.now.in_time_zone(time_zone_name).freeze }
|
30
|
+
|
31
|
+
it_behaves_like 'converts to beginning of day in UTC'
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'using DateTime' do
|
35
|
+
let(:arg) do
|
36
|
+
DateTime.now.freeze
|
37
|
+
end
|
38
|
+
|
39
|
+
it_behaves_like 'converts to beginning of day in UTC'
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe 'TimeWithZone in queries' do
|
7
|
+
context 'in a non-UTC time zone' do
|
8
|
+
let(:time_zone_name) { 'Pacific Time (US & Canada)' }
|
9
|
+
|
10
|
+
before do
|
11
|
+
time = Time.now
|
12
|
+
expect(time.utc_offset).not_to eq(time.in_time_zone(time_zone_name).utc_offset)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:time_in_zone) { Time.now.in_time_zone(time_zone_name) }
|
16
|
+
|
17
|
+
let(:view_lt) do
|
18
|
+
Agency.collection.find(updated_at: {'$lt' => time_in_zone + 10.minutes})
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:view_gt) do
|
22
|
+
Agency.collection.find(updated_at: {'$gt' => time_in_zone - 10.minutes})
|
23
|
+
end
|
24
|
+
|
25
|
+
let!(:agency) { Agency.create!.reload }
|
26
|
+
|
27
|
+
it 'finds the document' do
|
28
|
+
view_lt.to_a.should == [agency.attributes]
|
29
|
+
view_gt.to_a.should == [agency.attributes]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|