mongoid 3.1.5 → 8.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +636 -33
- data/LICENSE +2 -1
- data/README.md +32 -24
- data/Rakefile +75 -5
- data/lib/config/locales/en.yml +301 -132
- data/lib/mongoid/association/accessors.rb +431 -0
- data/lib/mongoid/association/bindable.rb +227 -0
- data/lib/mongoid/association/builders.rb +86 -0
- data/lib/mongoid/association/constrainable.rb +42 -0
- data/lib/mongoid/association/depending.rb +128 -0
- data/lib/mongoid/association/eager_loadable.rb +57 -0
- data/lib/mongoid/association/embedded/batchable.rb +398 -0
- data/lib/mongoid/association/embedded/cyclic.rb +102 -0
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +74 -0
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +38 -0
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +111 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +135 -0
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +42 -0
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +45 -0
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +571 -0
- data/lib/mongoid/association/embedded/embeds_many.rb +183 -0
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +43 -0
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +53 -0
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +164 -0
- data/lib/mongoid/association/embedded/embeds_one.rb +150 -0
- data/lib/mongoid/association/embedded.rb +6 -0
- data/lib/mongoid/association/macros.rb +228 -0
- data/lib/mongoid/association/many.rb +202 -0
- data/lib/mongoid/association/marshalable.rb +31 -0
- data/lib/mongoid/association/nested/many.rb +192 -0
- data/lib/mongoid/association/nested/nested_buildable.rb +66 -0
- data/lib/mongoid/association/nested/one.rb +116 -0
- data/lib/mongoid/association/nested.rb +15 -0
- data/lib/mongoid/association/one.rb +53 -0
- data/lib/mongoid/association/options.rb +122 -0
- data/lib/mongoid/association/proxy.rb +200 -0
- data/lib/mongoid/association/referenced/auto_save.rb +74 -0
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +83 -0
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +48 -0
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +73 -0
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +124 -0
- data/lib/mongoid/association/referenced/belongs_to.rb +226 -0
- data/lib/mongoid/association/referenced/counter_cache.rb +152 -0
- data/lib/mongoid/association/referenced/eager.rb +163 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +72 -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 +53 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +345 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +273 -0
- data/lib/mongoid/association/referenced/has_many/binding.rb +36 -0
- data/lib/mongoid/association/referenced/has_many/buildable.rb +38 -0
- data/lib/mongoid/association/referenced/has_many/eager.rb +44 -0
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +494 -0
- data/lib/mongoid/association/referenced/has_many/proxy.rb +551 -0
- data/lib/mongoid/association/referenced/has_many.rb +251 -0
- data/lib/mongoid/association/referenced/has_one/binding.rb +42 -0
- data/lib/mongoid/association/referenced/has_one/buildable.rb +74 -0
- data/lib/mongoid/association/referenced/has_one/eager.rb +36 -0
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +113 -0
- data/lib/mongoid/association/referenced/has_one/proxy.rb +108 -0
- data/lib/mongoid/association/referenced/has_one.rb +184 -0
- data/lib/mongoid/association/referenced/syncable.rb +155 -0
- data/lib/mongoid/association/referenced.rb +9 -0
- data/lib/mongoid/association/reflections.rb +69 -0
- data/lib/mongoid/association/relatable.rb +489 -0
- data/lib/mongoid/association.rb +135 -0
- data/lib/mongoid/atomic/modifiers.rb +41 -61
- data/lib/mongoid/atomic/paths/embedded/many.rb +24 -8
- data/lib/mongoid/atomic/paths/embedded/one.rb +5 -8
- data/lib/mongoid/atomic/paths/embedded.rb +3 -34
- data/lib/mongoid/atomic/paths/root.rb +4 -20
- data/lib/mongoid/atomic/paths.rb +2 -1
- data/lib/mongoid/atomic.rb +52 -69
- data/lib/mongoid/attributes/dynamic.rb +141 -0
- data/lib/mongoid/attributes/nested.rb +93 -0
- data/lib/mongoid/attributes/processing.rb +35 -97
- data/lib/mongoid/attributes/projector.rb +119 -0
- data/lib/mongoid/attributes/readonly.rb +27 -10
- data/lib/mongoid/attributes.rb +159 -181
- data/lib/mongoid/cacheable.rb +33 -0
- data/lib/mongoid/changeable.rb +420 -0
- data/lib/mongoid/clients/factory.rb +105 -0
- data/lib/mongoid/clients/options.rb +111 -0
- data/lib/mongoid/clients/sessions.rb +113 -0
- data/lib/mongoid/clients/storage_options.rb +79 -0
- data/lib/mongoid/clients/validators/storage.rb +58 -0
- data/lib/mongoid/clients/validators.rb +3 -0
- data/lib/mongoid/clients.rb +79 -0
- data/lib/mongoid/composable.rb +128 -0
- data/lib/mongoid/config/environment.rb +51 -13
- data/lib/mongoid/config/options.rb +30 -18
- data/lib/mongoid/config/validators/client.rb +128 -0
- data/lib/mongoid/config/validators/option.rb +3 -4
- data/lib/mongoid/config/validators.rb +3 -2
- data/lib/mongoid/config.rb +170 -89
- data/lib/mongoid/contextual/aggregable/memory.rb +40 -27
- data/lib/mongoid/contextual/aggregable/mongo.rb +33 -36
- data/lib/mongoid/contextual/aggregable/none.rb +65 -0
- data/lib/mongoid/contextual/aggregable.rb +17 -0
- data/lib/mongoid/contextual/atomic.rb +80 -79
- data/lib/mongoid/contextual/command.rb +8 -11
- data/lib/mongoid/contextual/geo_near.rb +42 -44
- data/lib/mongoid/contextual/map_reduce.rb +33 -127
- data/lib/mongoid/contextual/memory.rb +226 -88
- data/lib/mongoid/contextual/mongo.rb +466 -293
- data/lib/mongoid/contextual/none.rb +193 -0
- data/lib/mongoid/contextual/queryable.rb +3 -4
- data/lib/mongoid/contextual.rb +11 -11
- data/lib/mongoid/copyable.rb +68 -20
- data/lib/mongoid/criteria/findable.rb +143 -0
- data/lib/mongoid/criteria/includable.rb +92 -0
- data/lib/mongoid/criteria/inspectable.rb +24 -0
- data/lib/mongoid/criteria/marshalable.rb +55 -0
- data/lib/mongoid/criteria/modifiable.rb +235 -0
- data/lib/mongoid/criteria/options.rb +24 -0
- data/lib/mongoid/criteria/permission.rb +71 -0
- data/lib/mongoid/criteria/queryable/aggregable.rb +109 -0
- data/lib/mongoid/criteria/queryable/expandable.rb +68 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +151 -0
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +57 -0
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +33 -0
- data/lib/mongoid/criteria/queryable/extensions/date.rb +63 -0
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +52 -0
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +163 -0
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +75 -0
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +81 -0
- data/lib/mongoid/criteria/queryable/extensions/object.rb +182 -0
- data/lib/mongoid/criteria/queryable/extensions/range.rb +102 -0
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +72 -0
- data/lib/mongoid/criteria/queryable/extensions/set.rb +33 -0
- data/lib/mongoid/criteria/queryable/extensions/string.rb +122 -0
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +74 -0
- data/lib/mongoid/criteria/queryable/extensions/time.rb +60 -0
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +66 -0
- data/lib/mongoid/criteria/queryable/extensions.rb +25 -0
- data/lib/mongoid/criteria/queryable/key.rb +177 -0
- data/lib/mongoid/criteria/queryable/macroable.rb +26 -0
- data/lib/mongoid/criteria/queryable/mergeable.rb +434 -0
- data/lib/mongoid/criteria/queryable/optional.rb +380 -0
- data/lib/mongoid/criteria/queryable/options.rb +136 -0
- data/lib/mongoid/criteria/queryable/pipeline.rb +106 -0
- data/lib/mongoid/criteria/queryable/selectable.rb +937 -0
- data/lib/mongoid/criteria/queryable/selector.rb +287 -0
- data/lib/mongoid/criteria/queryable/smash.rb +128 -0
- data/lib/mongoid/criteria/queryable/storable.rb +237 -0
- data/lib/mongoid/criteria/queryable.rb +90 -0
- data/lib/mongoid/criteria/scopable.rb +166 -0
- data/lib/mongoid/criteria.rb +177 -189
- data/lib/mongoid/deprecable.rb +36 -0
- data/lib/mongoid/deprecation.rb +25 -0
- data/lib/mongoid/document.rb +193 -139
- data/lib/mongoid/equality.rb +35 -18
- data/lib/mongoid/errors/ambiguous_relationship.rb +5 -6
- data/lib/mongoid/errors/callback.rb +2 -3
- data/lib/mongoid/errors/criteria_argument_required.rb +18 -0
- data/lib/mongoid/errors/delete_restriction.rb +10 -13
- data/lib/mongoid/errors/document_not_destroyed.rb +22 -0
- data/lib/mongoid/errors/document_not_found.rb +36 -21
- data/lib/mongoid/errors/empty_config_file.rb +25 -0
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +19 -0
- data/lib/mongoid/errors/invalid_collection.rb +2 -1
- data/lib/mongoid/errors/invalid_config_file.rb +25 -0
- data/lib/mongoid/errors/invalid_config_option.rb +3 -4
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +31 -0
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +24 -0
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +23 -0
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +32 -0
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +25 -0
- data/lib/mongoid/errors/invalid_expression_operator.rb +27 -0
- data/lib/mongoid/errors/invalid_field.rb +10 -9
- data/lib/mongoid/errors/invalid_field_operator.rb +32 -0
- data/lib/mongoid/errors/invalid_field_option.rb +2 -3
- data/lib/mongoid/errors/invalid_field_type.rb +26 -0
- data/lib/mongoid/errors/invalid_find.rb +2 -3
- data/lib/mongoid/errors/invalid_includes.rb +2 -3
- data/lib/mongoid/errors/invalid_index.rb +2 -3
- data/lib/mongoid/errors/invalid_options.rb +4 -5
- data/lib/mongoid/errors/invalid_path.rb +2 -3
- data/lib/mongoid/errors/invalid_persistence_option.rb +26 -0
- data/lib/mongoid/errors/invalid_query.rb +40 -0
- data/lib/mongoid/errors/invalid_relation.rb +61 -0
- data/lib/mongoid/errors/invalid_relation_option.rb +28 -0
- data/lib/mongoid/errors/invalid_scope.rb +2 -3
- data/lib/mongoid/errors/invalid_session_use.rb +21 -0
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +6 -5
- data/lib/mongoid/errors/invalid_storage_options.rb +4 -5
- data/lib/mongoid/errors/invalid_storage_parent.rb +25 -0
- data/lib/mongoid/errors/invalid_time.rb +2 -3
- data/lib/mongoid/errors/inverse_not_found.rb +4 -5
- data/lib/mongoid/errors/mixed_client_configuration.rb +27 -0
- data/lib/mongoid/errors/mixed_relations.rb +2 -3
- data/lib/mongoid/errors/mongoid_error.rb +22 -23
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +3 -4
- data/lib/mongoid/errors/no_client_config.rb +21 -0
- data/lib/mongoid/errors/no_client_database.rb +26 -0
- data/lib/mongoid/errors/no_client_hosts.rb +26 -0
- data/lib/mongoid/errors/no_clients_config.rb +19 -0
- data/lib/mongoid/errors/no_default_client.rb +22 -0
- data/lib/mongoid/errors/no_environment.rb +2 -3
- data/lib/mongoid/errors/no_map_reduce_output.rb +2 -3
- data/lib/mongoid/errors/no_metadata.rb +2 -3
- data/lib/mongoid/errors/no_parent.rb +2 -3
- data/lib/mongoid/errors/readonly_attribute.rb +3 -4
- data/lib/mongoid/errors/readonly_document.rb +21 -0
- data/lib/mongoid/errors/scope_overwrite.rb +2 -1
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +3 -1
- data/lib/mongoid/errors/unknown_attribute.rb +3 -4
- data/lib/mongoid/errors/unknown_model.rb +24 -0
- data/lib/mongoid/errors/unsaved_document.rb +3 -2
- data/lib/mongoid/errors/unsupported_javascript.rb +2 -3
- data/lib/mongoid/errors/validations.rb +2 -1
- data/lib/mongoid/errors.rb +30 -9
- data/lib/mongoid/evolvable.rb +4 -5
- data/lib/mongoid/extensions/array.rb +45 -52
- data/lib/mongoid/extensions/big_decimal.rb +41 -22
- data/lib/mongoid/extensions/binary.rb +42 -0
- data/lib/mongoid/extensions/boolean.rb +19 -17
- data/lib/mongoid/extensions/date.rb +33 -23
- data/lib/mongoid/extensions/date_time.rb +5 -13
- data/lib/mongoid/extensions/decimal128.rb +36 -0
- data/lib/mongoid/extensions/false_class.rb +5 -8
- data/lib/mongoid/extensions/float.rb +11 -16
- data/lib/mongoid/extensions/hash.rb +88 -49
- data/lib/mongoid/extensions/integer.rb +10 -18
- data/lib/mongoid/extensions/module.rb +3 -4
- data/lib/mongoid/extensions/nil_class.rb +2 -5
- data/lib/mongoid/extensions/object.rb +38 -62
- data/lib/mongoid/extensions/object_id.rb +7 -12
- data/lib/mongoid/extensions/range.rb +46 -17
- data/lib/mongoid/extensions/regexp.rb +15 -8
- data/lib/mongoid/extensions/set.rb +17 -15
- data/lib/mongoid/extensions/string.rb +40 -80
- data/lib/mongoid/extensions/symbol.rb +7 -23
- data/lib/mongoid/extensions/time.rb +42 -25
- data/lib/mongoid/extensions/time_with_zone.rb +27 -10
- data/lib/mongoid/extensions/true_class.rb +5 -8
- data/lib/mongoid/extensions.rb +31 -13
- data/lib/mongoid/factory.rb +99 -11
- data/lib/mongoid/fields/foreign_key.rb +26 -34
- data/lib/mongoid/fields/localized.rb +24 -13
- data/lib/mongoid/fields/standard.rb +19 -73
- data/lib/mongoid/fields/validators/macro.rb +56 -15
- data/lib/mongoid/fields/validators.rb +2 -1
- data/lib/mongoid/fields.rb +342 -87
- data/lib/mongoid/findable.rb +219 -0
- data/lib/mongoid/indexable/specification.rb +103 -0
- data/lib/mongoid/indexable/validators/options.rb +110 -0
- data/lib/mongoid/indexable.rb +148 -0
- data/lib/mongoid/inspectable.rb +52 -0
- data/lib/mongoid/interceptable.rb +312 -0
- data/lib/mongoid/loggable.rb +15 -18
- data/lib/mongoid/matchable.rb +23 -0
- data/lib/mongoid/matcher/all.rb +22 -0
- data/lib/mongoid/matcher/and.rb +21 -0
- data/lib/mongoid/matcher/bits.rb +41 -0
- data/lib/mongoid/matcher/bits_all_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_all_set.rb +20 -0
- data/lib/mongoid/matcher/bits_any_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_any_set.rb +20 -0
- data/lib/mongoid/matcher/elem_match.rb +36 -0
- data/lib/mongoid/matcher/elem_match_expression.rb +20 -0
- data/lib/mongoid/matcher/eq.rb +11 -0
- data/lib/mongoid/matcher/eq_impl.rb +67 -0
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +26 -0
- data/lib/mongoid/matcher/exists.rb +15 -0
- data/lib/mongoid/matcher/expression.rb +35 -0
- data/lib/mongoid/matcher/expression_operator.rb +19 -0
- data/lib/mongoid/matcher/field_expression.rb +62 -0
- data/lib/mongoid/matcher/field_operator.rb +54 -0
- data/lib/mongoid/matcher/gt.rb +17 -0
- data/lib/mongoid/matcher/gte.rb +17 -0
- data/lib/mongoid/matcher/in.rb +25 -0
- data/lib/mongoid/matcher/lt.rb +17 -0
- data/lib/mongoid/matcher/lte.rb +17 -0
- data/lib/mongoid/matcher/mod.rb +17 -0
- data/lib/mongoid/matcher/ne.rb +16 -0
- data/lib/mongoid/matcher/nin.rb +11 -0
- data/lib/mongoid/matcher/nor.rb +25 -0
- data/lib/mongoid/matcher/not.rb +29 -0
- data/lib/mongoid/matcher/or.rb +21 -0
- data/lib/mongoid/matcher/regex.rb +41 -0
- data/lib/mongoid/matcher/size.rb +26 -0
- data/lib/mongoid/matcher/type.rb +99 -0
- data/lib/mongoid/matcher.rb +115 -0
- data/lib/mongoid/persistable/creatable.rb +181 -0
- data/lib/mongoid/persistable/deletable.rb +132 -0
- data/lib/mongoid/persistable/destroyable.rb +57 -0
- data/lib/mongoid/persistable/incrementable.rb +35 -0
- data/lib/mongoid/persistable/logical.rb +36 -0
- data/lib/mongoid/persistable/poppable.rb +36 -0
- data/lib/mongoid/persistable/pullable.rb +50 -0
- data/lib/mongoid/persistable/pushable.rb +66 -0
- data/lib/mongoid/persistable/renamable.rb +37 -0
- data/lib/mongoid/persistable/savable.rb +47 -0
- data/lib/mongoid/persistable/settable.rb +93 -0
- data/lib/mongoid/persistable/unsettable.rb +36 -0
- data/lib/mongoid/persistable/updatable.rb +165 -0
- data/lib/mongoid/persistable/upsertable.rb +51 -0
- data/lib/mongoid/persistable.rb +305 -0
- data/lib/mongoid/persistence_context.rb +239 -0
- data/lib/mongoid/positional.rb +72 -0
- data/lib/mongoid/query_cache.rb +64 -0
- data/lib/mongoid/railtie.rb +35 -78
- data/lib/mongoid/railties/controller_runtime.rb +88 -0
- data/lib/mongoid/railties/database.rake +18 -25
- data/lib/mongoid/reloadable.rb +94 -0
- data/lib/mongoid/scopable.rb +324 -0
- data/lib/mongoid/selectable.rb +49 -0
- data/lib/mongoid/serializable.rb +170 -0
- data/lib/mongoid/shardable.rb +130 -0
- data/lib/mongoid/stateful.rb +134 -0
- data/lib/mongoid/stringified_symbol.rb +52 -0
- data/lib/mongoid/tasks/database.rake +38 -0
- data/lib/mongoid/tasks/database.rb +194 -0
- data/lib/mongoid/threaded/lifecycle.rb +28 -70
- data/lib/mongoid/threaded.rb +142 -219
- data/lib/mongoid/timestamps/created/short.rb +2 -1
- data/lib/mongoid/timestamps/created.rb +9 -5
- data/lib/mongoid/timestamps/short.rb +2 -1
- data/lib/mongoid/timestamps/timeless.rb +52 -16
- data/lib/mongoid/timestamps/updated/short.rb +4 -3
- data/lib/mongoid/timestamps/updated.rb +14 -9
- data/lib/mongoid/timestamps.rb +4 -3
- data/lib/mongoid/touchable.rb +131 -0
- data/lib/mongoid/traversable.rb +337 -0
- data/lib/mongoid/validatable/associated.rb +47 -0
- data/lib/mongoid/validatable/format.rb +21 -0
- data/lib/mongoid/validatable/length.rb +21 -0
- data/lib/mongoid/validatable/localizable.rb +29 -0
- data/lib/mongoid/validatable/macros.rb +89 -0
- data/lib/mongoid/validatable/presence.rb +81 -0
- data/lib/mongoid/validatable/queryable.rb +29 -0
- data/lib/mongoid/validatable/uniqueness.rb +304 -0
- data/lib/mongoid/validatable.rb +160 -0
- data/lib/mongoid/version.rb +3 -2
- data/lib/mongoid/warnings.rb +28 -0
- data/lib/mongoid.rb +68 -109
- data/lib/rails/generators/mongoid/config/config_generator.rb +10 -2
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +150 -45
- data/lib/rails/generators/mongoid/model/model_generator.rb +3 -3
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -4
- data/lib/rails/generators/mongoid_generator.rb +5 -41
- data/lib/rails/mongoid.rb +6 -129
- data/spec/README.md +33 -0
- data/spec/config/mongoid.yml +56 -25
- data/spec/config/mongoid_with_schema_map_uuid.yml +27 -0
- data/spec/integration/app_spec.rb +345 -0
- data/spec/integration/associations/belongs_to_spec.rb +33 -0
- data/spec/integration/associations/embedded_dirty_spec.rb +57 -0
- data/spec/integration/associations/embedded_spec.rb +283 -0
- data/spec/integration/associations/embeds_many_spec.rb +219 -0
- data/spec/integration/associations/embeds_one_spec.rb +41 -0
- data/spec/integration/associations/foreign_key_spec.rb +107 -0
- data/spec/integration/associations/foreign_key_spec_models.rb +64 -0
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +21 -0
- data/spec/integration/associations/has_many_spec.rb +128 -0
- data/spec/integration/associations/has_one_spec.rb +272 -0
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +115 -0
- data/spec/integration/associations/reverse_population_spec.rb +34 -0
- data/spec/integration/associations/reverse_population_spec_models.rb +36 -0
- data/spec/integration/associations/scope_option_spec.rb +101 -0
- data/spec/integration/atomic/modifiers_spec.rb +116 -0
- data/spec/integration/bson_regexp_raw_spec.rb +19 -0
- data/spec/integration/callbacks_models.rb +155 -0
- data/spec/integration/callbacks_spec.rb +450 -0
- data/spec/integration/contextual/empty_spec.rb +141 -0
- data/spec/integration/criteria/alias_query_spec.rb +161 -0
- data/spec/integration/criteria/date_field_spec.rb +40 -0
- data/spec/integration/criteria/default_scope_spec.rb +72 -0
- data/spec/integration/criteria/logical_spec.rb +124 -0
- data/spec/integration/criteria/range_spec.rb +359 -0
- data/spec/integration/criteria/time_with_zone_spec.rb +142 -0
- data/spec/integration/discriminator_key_spec.rb +392 -0
- data/spec/integration/discriminator_value_spec.rb +206 -0
- data/spec/integration/document_spec.rb +51 -0
- data/spec/integration/dots_and_dollars_spec.rb +277 -0
- data/spec/integration/i18n_fallbacks_spec.rb +89 -0
- data/spec/integration/matcher_examples_spec.rb +765 -0
- data/spec/integration/matcher_operator_data/all.yml +140 -0
- data/spec/integration/matcher_operator_data/and.yml +93 -0
- data/spec/integration/matcher_operator_data/bits_all_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_all_set.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_set.yml +159 -0
- data/spec/integration/matcher_operator_data/comment.yml +22 -0
- data/spec/integration/matcher_operator_data/elem_match.yml +409 -0
- data/spec/integration/matcher_operator_data/elem_match_expr.yml +213 -0
- data/spec/integration/matcher_operator_data/eq.yml +191 -0
- data/spec/integration/matcher_operator_data/exists.yml +213 -0
- data/spec/integration/matcher_operator_data/generic_op.yml +17 -0
- data/spec/integration/matcher_operator_data/gt.yml +132 -0
- data/spec/integration/matcher_operator_data/gt_types.yml +63 -0
- data/spec/integration/matcher_operator_data/gte.yml +132 -0
- data/spec/integration/matcher_operator_data/gte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/implicit.yml +331 -0
- data/spec/integration/matcher_operator_data/implicit_traversal.yml +112 -0
- data/spec/integration/matcher_operator_data/in.yml +210 -0
- data/spec/integration/matcher_operator_data/invalid_op.yml +59 -0
- data/spec/integration/matcher_operator_data/invalid_syntax.yml +39 -0
- data/spec/integration/matcher_operator_data/lt.yml +132 -0
- data/spec/integration/matcher_operator_data/lt_types.yml +15 -0
- data/spec/integration/matcher_operator_data/lte.yml +132 -0
- data/spec/integration/matcher_operator_data/lte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/mod.yml +55 -0
- data/spec/integration/matcher_operator_data/multiple.yml +29 -0
- data/spec/integration/matcher_operator_data/ne.yml +150 -0
- data/spec/integration/matcher_operator_data/ne_types.yml +15 -0
- data/spec/integration/matcher_operator_data/nin.yml +114 -0
- data/spec/integration/matcher_operator_data/nor.yml +126 -0
- data/spec/integration/matcher_operator_data/not.yml +196 -0
- data/spec/integration/matcher_operator_data/or.yml +137 -0
- data/spec/integration/matcher_operator_data/regex.yml +174 -0
- data/spec/integration/matcher_operator_data/regex_options.yml +72 -0
- data/spec/integration/matcher_operator_data/size.yml +174 -0
- data/spec/integration/matcher_operator_data/type.yml +70 -0
- data/spec/integration/matcher_operator_data/type_array.yml +16 -0
- data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
- data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
- data/spec/integration/matcher_operator_data/type_code.yml +26 -0
- data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
- data/spec/integration/matcher_operator_data/type_date.yml +39 -0
- data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
- data/spec/integration/matcher_operator_data/type_decimal.yml +41 -0
- data/spec/integration/matcher_operator_data/type_double.yml +15 -0
- data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
- data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
- data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_null.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
- data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
- data/spec/integration/matcher_operator_data/type_string.yml +15 -0
- data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
- data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
- data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
- data/spec/integration/matcher_operator_spec.rb +122 -0
- data/spec/integration/matcher_spec.rb +283 -0
- data/spec/integration/persistence/range_field_spec.rb +350 -0
- data/spec/integration/server_query_spec.rb +141 -0
- data/spec/integration/shardable_spec.rb +148 -0
- data/spec/integration/stringified_symbol_field_spec.rb +203 -0
- data/spec/lite_spec_helper.rb +83 -0
- data/spec/mongoid/association/accessors_spec.rb +1067 -0
- data/spec/mongoid/association/auto_save_spec.rb +403 -0
- data/spec/mongoid/association/builders_spec.rb +255 -0
- data/spec/mongoid/association/constrainable_spec.rb +117 -0
- data/spec/mongoid/association/counter_cache_spec.rb +452 -0
- data/spec/mongoid/association/depending_spec.rb +959 -0
- data/spec/mongoid/association/eager_spec.rb +282 -0
- data/spec/mongoid/association/embedded/cyclic_spec.rb +180 -0
- data/spec/mongoid/association/embedded/dirty_spec.rb +67 -0
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +174 -0
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +90 -0
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +619 -0
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +903 -0
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +56 -0
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +218 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +4863 -0
- data/spec/mongoid/association/embedded/embeds_many_models.rb +226 -0
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +63 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +932 -0
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +79 -0
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +106 -0
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +1025 -0
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +8 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +73 -0
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +28 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +984 -0
- data/spec/mongoid/association/macros_spec.rb +1116 -0
- data/spec/mongoid/association/nested/many_spec.rb +232 -0
- data/spec/mongoid/association/nested/one_spec.rb +253 -0
- data/spec/mongoid/association/options_spec.rb +1323 -0
- data/spec/mongoid/association/polymorphic_spec.rb +162 -0
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +244 -0
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +292 -0
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +412 -0
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +1388 -0
- data/spec/mongoid/association/referenced/belongs_to_models.rb +11 -0
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +57 -0
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2046 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +180 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +148 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +196 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +76 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +3836 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +92 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +39 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +1104 -0
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +155 -0
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +251 -0
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +290 -0
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +2232 -0
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +23 -0
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +4161 -0
- data/spec/mongoid/association/referenced/has_many_models.rb +97 -0
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_many_spec.rb +1273 -0
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +133 -0
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +159 -0
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +193 -0
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +1248 -0
- data/spec/mongoid/association/referenced/has_one_models.rb +113 -0
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +1383 -0
- data/spec/mongoid/association/reflections_spec.rb +92 -0
- data/spec/mongoid/association/syncable_spec.rb +513 -0
- data/spec/mongoid/association_spec.rb +191 -0
- data/spec/mongoid/atomic/modifiers_spec.rb +88 -39
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +10 -49
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +9 -49
- data/spec/mongoid/atomic/paths/root_spec.rb +5 -61
- data/spec/mongoid/atomic/paths_spec.rb +115 -35
- data/spec/mongoid/atomic_spec.rb +89 -42
- data/spec/mongoid/attributes/dynamic_spec.rb +152 -0
- data/spec/mongoid/attributes/nested_spec.rb +5000 -0
- data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
- data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
- data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
- data/spec/mongoid/attributes/projector_spec.rb +40 -0
- data/spec/mongoid/attributes/readonly_spec.rb +166 -64
- data/spec/mongoid/attributes_spec.rb +1418 -409
- data/spec/mongoid/cacheable_spec.rb +114 -0
- data/spec/mongoid/changeable_spec.rb +1914 -0
- data/spec/mongoid/clients/factory_spec.rb +426 -0
- data/spec/mongoid/clients/options_spec.rb +521 -0
- data/spec/mongoid/clients/sessions_spec.rb +297 -0
- data/spec/mongoid/clients/transactions_spec.rb +415 -0
- data/spec/mongoid/clients_spec.rb +1084 -0
- data/spec/mongoid/composable_spec.rb +33 -0
- data/spec/mongoid/config/environment_spec.rb +138 -17
- data/spec/mongoid/config/options_spec.rb +26 -7
- data/spec/mongoid/config_spec.rb +607 -93
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +433 -153
- data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +62 -0
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +221 -56
- data/spec/mongoid/contextual/aggregable/none_spec.rb +60 -0
- data/spec/mongoid/contextual/atomic_spec.rb +577 -162
- data/spec/mongoid/contextual/geo_near_spec.rb +104 -38
- data/spec/mongoid/contextual/map_reduce_spec.rb +137 -142
- data/spec/mongoid/contextual/memory_spec.rb +1880 -269
- data/spec/mongoid/contextual/mongo_spec.rb +2523 -601
- data/spec/mongoid/contextual/none_spec.rb +123 -0
- data/spec/mongoid/copyable_spec.rb +833 -76
- data/spec/mongoid/copyable_spec_models.rb +47 -0
- data/spec/mongoid/criteria/findable_spec.rb +1132 -0
- data/spec/mongoid/criteria/includable_spec.rb +1492 -0
- data/spec/mongoid/criteria/includable_spec_models.rb +54 -0
- data/spec/mongoid/criteria/inspectable_spec.rb +29 -0
- data/spec/mongoid/criteria/marshalable_spec.rb +47 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +1812 -0
- data/spec/mongoid/criteria/options_spec.rb +31 -0
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +372 -0
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +61 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +513 -0
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +169 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +60 -0
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +215 -0
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +343 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +434 -0
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +60 -0
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +67 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +314 -0
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +67 -0
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +79 -0
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +119 -0
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +110 -0
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +370 -0
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +91 -0
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +92 -0
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +41 -0
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +347 -0
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +169 -0
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +406 -0
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +387 -0
- data/spec/mongoid/criteria/queryable/key_spec.rb +96 -0
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +182 -0
- data/spec/mongoid/criteria/queryable/optional_spec.rb +1317 -0
- data/spec/mongoid/criteria/queryable/options_spec.rb +362 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +214 -0
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +139 -0
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +2119 -0
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +38 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +2462 -0
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +589 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +895 -0
- data/spec/mongoid/criteria/queryable/smash_spec.rb +32 -0
- data/spec/mongoid/criteria/queryable/storable_spec.rb +226 -0
- data/spec/mongoid/criteria/scopable_spec.rb +601 -0
- data/spec/mongoid/criteria_projection_spec.rb +410 -0
- data/spec/mongoid/criteria_spec.rb +1828 -3572
- data/spec/mongoid/document_fields_spec.rb +262 -0
- data/spec/mongoid/document_persistence_context_spec.rb +32 -0
- data/spec/mongoid/document_query_spec.rb +89 -0
- data/spec/mongoid/document_spec.rb +452 -221
- data/spec/mongoid/equality_spec.rb +155 -52
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +8 -6
- data/spec/mongoid/errors/callback_spec.rb +5 -3
- data/spec/mongoid/errors/delete_restriction_spec.rb +7 -5
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +35 -0
- data/spec/mongoid/errors/document_not_found_spec.rb +89 -11
- data/spec/mongoid/errors/invalid_collection_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_config_file_spec.rb +31 -0
- data/spec/mongoid/errors/invalid_config_option_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_field_option_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_field_spec.rb +6 -4
- data/spec/mongoid/errors/invalid_field_type_spec.rb +55 -0
- data/spec/mongoid/errors/invalid_find_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_includes_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_index_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_options_spec.rb +7 -5
- data/spec/mongoid/errors/invalid_path_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_relation_spec.rb +39 -0
- data/spec/mongoid/errors/invalid_scope_spec.rb +7 -5
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_time_spec.rb +5 -3
- data/spec/mongoid/errors/inverse_not_found_spec.rb +6 -4
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +31 -0
- data/spec/mongoid/errors/mixed_relations_spec.rb +5 -3
- data/spec/mongoid/errors/mongoid_error_spec.rb +45 -10
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +8 -6
- data/spec/mongoid/errors/no_client_config_spec.rb +31 -0
- data/spec/mongoid/errors/no_client_database_spec.rb +31 -0
- data/spec/mongoid/errors/no_client_hosts_spec.rb +31 -0
- data/spec/mongoid/errors/no_clients_config_spec.rb +31 -0
- data/spec/mongoid/errors/no_environment_spec.rb +8 -6
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +5 -3
- data/spec/mongoid/errors/no_metadata_spec.rb +5 -3
- data/spec/mongoid/errors/no_parent_spec.rb +6 -4
- data/spec/mongoid/errors/readonly_attribute_spec.rb +5 -3
- data/spec/mongoid/errors/readonly_document_spec.rb +31 -0
- data/spec/mongoid/errors/scope_overwrite_spec.rb +5 -3
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +6 -4
- data/spec/mongoid/errors/unknown_attribute_spec.rb +7 -5
- data/spec/mongoid/errors/unsaved_document_spec.rb +6 -4
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +5 -3
- data/spec/mongoid/errors/validations_spec.rb +9 -7
- data/spec/mongoid/extensions/array_spec.rb +108 -116
- data/spec/mongoid/extensions/big_decimal_spec.rb +838 -49
- data/spec/mongoid/extensions/binary_spec.rb +55 -18
- data/spec/mongoid/extensions/boolean_spec.rb +76 -74
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +339 -0
- data/spec/mongoid/extensions/date_spec.rb +59 -145
- data/spec/mongoid/extensions/date_time_spec.rb +35 -76
- data/spec/mongoid/extensions/decimal128_spec.rb +46 -0
- data/spec/mongoid/extensions/false_class_spec.rb +7 -5
- data/spec/mongoid/extensions/float_spec.rb +69 -62
- data/spec/mongoid/extensions/hash_spec.rb +197 -30
- data/spec/mongoid/extensions/integer_spec.rb +63 -65
- data/spec/mongoid/extensions/module_spec.rb +4 -2
- data/spec/mongoid/extensions/nil_class_spec.rb +3 -1
- data/spec/mongoid/extensions/object_id_spec.rb +136 -134
- data/spec/mongoid/extensions/object_spec.rb +53 -57
- data/spec/mongoid/extensions/range_spec.rb +287 -28
- data/spec/mongoid/extensions/regexp_spec.rb +71 -21
- data/spec/mongoid/extensions/set_spec.rb +112 -4
- data/spec/mongoid/extensions/string_spec.rb +188 -89
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +84 -0
- data/spec/mongoid/extensions/symbol_spec.rb +25 -30
- data/spec/mongoid/extensions/time_spec.rb +703 -110
- data/spec/mongoid/extensions/time_with_zone_spec.rb +82 -67
- data/spec/mongoid/extensions/true_class_spec.rb +7 -5
- data/spec/mongoid/extensions_spec.rb +43 -0
- data/spec/mongoid/factory_spec.rb +374 -25
- data/spec/mongoid/fields/foreign_key_spec.rb +116 -92
- data/spec/mongoid/fields/localized_spec.rb +177 -35
- data/spec/mongoid/fields/standard_spec.rb +15 -13
- data/spec/mongoid/fields_spec.rb +952 -238
- data/spec/mongoid/findable_spec.rb +632 -0
- data/spec/mongoid/indexable/specification_spec.rb +129 -0
- data/spec/mongoid/indexable_spec.rb +643 -0
- data/spec/mongoid/inspectable_spec.rb +86 -0
- data/spec/mongoid/interceptable_spec.rb +2373 -0
- data/spec/mongoid/interceptable_spec_models.rb +307 -0
- data/spec/mongoid/loggable_spec.rb +3 -1
- data/spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml +104 -0
- data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +239 -0
- data/spec/mongoid/matcher/extract_attribute_spec.rb +36 -0
- data/spec/mongoid/mongoizable_spec.rb +285 -0
- data/spec/mongoid/persistable/creatable_spec.rb +662 -0
- data/spec/mongoid/persistable/deletable_spec.rb +514 -0
- data/spec/mongoid/persistable/destroyable_spec.rb +455 -0
- data/spec/mongoid/persistable/incrementable_spec.rb +241 -0
- data/spec/mongoid/persistable/logical_spec.rb +159 -0
- data/spec/mongoid/persistable/poppable_spec.rb +131 -0
- data/spec/mongoid/persistable/pullable_spec.rb +258 -0
- data/spec/mongoid/persistable/pushable_spec.rb +353 -0
- data/spec/mongoid/persistable/renamable_spec.rb +151 -0
- data/spec/mongoid/persistable/savable_spec.rb +684 -0
- data/spec/mongoid/persistable/settable_spec.rb +544 -0
- data/spec/mongoid/persistable/unsettable_spec.rb +171 -0
- data/spec/mongoid/persistable/updatable_spec.rb +760 -0
- data/spec/mongoid/persistable/upsertable_spec.rb +122 -0
- data/spec/mongoid/persistable_spec.rb +321 -0
- data/spec/mongoid/persistence_context_spec.rb +745 -0
- data/spec/mongoid/positional_spec.rb +223 -0
- data/spec/mongoid/query_cache_middleware_spec.rb +50 -0
- data/spec/mongoid/query_cache_spec.rb +870 -0
- data/spec/mongoid/relations/proxy_spec.rb +125 -47
- data/spec/mongoid/reloadable_spec.rb +665 -0
- data/spec/mongoid/scopable_spec.rb +1234 -0
- data/spec/mongoid/selectable_spec.rb +136 -0
- data/spec/mongoid/serializable_spec.rb +963 -0
- data/spec/mongoid/shardable_models.rb +61 -0
- data/spec/mongoid/shardable_spec.rb +204 -0
- data/spec/mongoid/stateful_spec.rb +157 -0
- data/spec/mongoid/tasks/database_rake_spec.rb +287 -0
- data/spec/mongoid/tasks/database_spec.rb +181 -0
- data/spec/mongoid/threaded_spec.rb +88 -78
- data/spec/mongoid/timestamps/created/short_spec.rb +9 -7
- data/spec/mongoid/timestamps/created_spec.rb +8 -6
- data/spec/mongoid/timestamps/timeless_spec.rb +29 -10
- data/spec/mongoid/timestamps/updated/short_spec.rb +16 -14
- data/spec/mongoid/timestamps/updated_spec.rb +14 -16
- data/spec/mongoid/timestamps_spec.rb +406 -18
- data/spec/mongoid/timestamps_spec_models.rb +67 -0
- data/spec/mongoid/touchable_spec.rb +704 -0
- data/spec/mongoid/touchable_spec_models.rb +57 -0
- data/spec/mongoid/traversable_spec.rb +1410 -0
- data/spec/mongoid/validatable/associated_spec.rb +208 -0
- data/spec/mongoid/validatable/format_spec.rb +85 -0
- data/spec/mongoid/validatable/length_spec.rb +225 -0
- data/spec/mongoid/validatable/numericality_spec.rb +32 -0
- data/spec/mongoid/validatable/presence_spec.rb +592 -0
- data/spec/mongoid/validatable/uniqueness_spec.rb +2504 -0
- data/spec/mongoid/validatable_spec.rb +327 -0
- data/spec/mongoid/warnings_spec.rb +35 -0
- data/spec/mongoid_spec.rb +20 -20
- data/spec/rails/controller_extension/controller_runtime_spec.rb +112 -0
- data/spec/rails/mongoid_spec.rb +37 -354
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +231 -0
- data/spec/shared/lib/mrss/constraints.rb +378 -0
- data/spec/shared/lib/mrss/docker_runner.rb +291 -0
- data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +230 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +120 -0
- data/spec/shared/lib/mrss/session_registry.rb +69 -0
- data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
- data/spec/shared/lib/mrss/utils.rb +15 -0
- data/spec/shared/share/Dockerfile.erb +325 -0
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/config.sh +27 -0
- data/spec/shared/shlib/distro.sh +74 -0
- data/spec/shared/shlib/server.sh +392 -0
- data/spec/shared/shlib/set_env.sh +169 -0
- data/spec/spec_helper.rb +163 -42
- data/spec/support/authorization.rb +15 -0
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/constraints.rb +77 -0
- data/spec/support/expectations.rb +32 -0
- data/spec/support/helpers.rb +11 -0
- data/spec/support/macros.rb +81 -0
- data/spec/support/models/account.rb +38 -0
- data/spec/support/models/acolyte.rb +19 -0
- data/spec/support/models/actor.rb +20 -0
- data/spec/support/models/actress.rb +4 -0
- data/spec/support/models/address.rb +85 -0
- data/spec/support/models/address_component.rb +7 -0
- data/spec/support/models/address_number.rb +8 -0
- data/spec/support/models/agency.rb +7 -0
- data/spec/support/models/agent.rb +18 -0
- data/spec/support/models/album.rb +20 -0
- data/spec/support/models/alert.rb +9 -0
- data/spec/support/models/animal.rb +28 -0
- data/spec/support/models/answer.rb +8 -0
- data/spec/support/models/appointment.rb +9 -0
- data/spec/support/models/armrest.rb +9 -0
- data/spec/support/models/array_field.rb +7 -0
- data/spec/support/models/article.rb +14 -0
- data/spec/support/models/artist.rb +91 -0
- data/spec/support/models/artwork.rb +6 -0
- data/spec/support/models/audible_sound.rb +3 -0
- data/spec/support/models/audio.rb +7 -0
- data/spec/support/models/augmentation.rb +25 -0
- data/spec/support/models/author.rb +8 -0
- data/spec/support/models/baby.rb +6 -0
- data/spec/support/models/band.rb +40 -0
- data/spec/support/models/bar.rb +12 -0
- data/spec/support/models/basic.rb +8 -0
- data/spec/support/models/bed.rb +3 -0
- data/spec/support/models/big_palette.rb +4 -0
- data/spec/support/models/birthday.rb +15 -0
- data/spec/support/models/bolt.rb +7 -0
- data/spec/support/models/bomb.rb +6 -0
- data/spec/support/models/book.rb +18 -0
- data/spec/support/models/breed.rb +6 -0
- data/spec/support/models/browser.rb +8 -0
- data/spec/support/models/building.rb +8 -0
- data/spec/support/models/building_address.rb +9 -0
- data/spec/support/models/bus.rb +9 -0
- data/spec/support/models/business.rb +7 -0
- data/spec/support/models/callback_test.rb +11 -0
- data/spec/support/models/canvas.rb +27 -0
- data/spec/support/models/car.rb +3 -0
- data/spec/support/models/cat.rb +10 -0
- data/spec/support/models/catalog.rb +24 -0
- data/spec/support/models/category.rb +10 -0
- data/spec/support/models/child.rb +6 -0
- data/spec/support/models/child_doc.rb +24 -0
- data/spec/support/models/church.rb +8 -0
- data/spec/support/models/circle.rb +5 -0
- data/spec/support/models/circuit.rb +6 -0
- data/spec/support/models/circus.rb +12 -0
- data/spec/support/models/code.rb +15 -0
- data/spec/support/models/coding/pull_request.rb +11 -0
- data/spec/support/models/coding.rb +3 -0
- data/spec/support/models/comment.rb +18 -0
- data/spec/support/models/company.rb +7 -0
- data/spec/support/models/consumption_period.rb +9 -0
- data/spec/support/models/contextable_item.rb +7 -0
- data/spec/support/models/contractor.rb +7 -0
- data/spec/support/models/cookie.rb +8 -0
- data/spec/support/models/country_code.rb +12 -0
- data/spec/support/models/courier_job.rb +6 -0
- data/spec/support/models/crate.rb +12 -0
- data/spec/support/models/customer.rb +10 -0
- data/spec/support/models/customer_address.rb +11 -0
- data/spec/support/models/deed.rb +7 -0
- data/spec/support/models/definition.rb +11 -0
- data/spec/support/models/delegating_patient.rb +15 -0
- data/spec/support/models/description.rb +13 -0
- data/spec/support/models/dictionary.rb +18 -0
- data/spec/support/models/division.rb +12 -0
- data/spec/support/models/doctor.rb +14 -0
- data/spec/support/models/dog.rb +9 -0
- data/spec/support/models/dokument.rb +8 -0
- data/spec/support/models/draft.rb +11 -0
- data/spec/support/models/dragon.rb +6 -0
- data/spec/support/models/driver.rb +9 -0
- data/spec/support/models/drug.rb +8 -0
- data/spec/support/models/dungeon.rb +6 -0
- data/spec/support/models/edit.rb +7 -0
- data/spec/support/models/email.rb +8 -0
- data/spec/support/models/employer.rb +7 -0
- data/spec/support/models/entry.rb +8 -0
- data/spec/support/models/eraser.rb +3 -0
- data/spec/support/models/even.rb +9 -0
- data/spec/support/models/event.rb +24 -0
- data/spec/support/models/exhibition.rb +6 -0
- data/spec/support/models/exhibitor.rb +8 -0
- data/spec/support/models/explosion.rb +6 -0
- data/spec/support/models/eye.rb +11 -0
- data/spec/support/models/eye_bowl.rb +11 -0
- data/spec/support/models/face.rb +10 -0
- data/spec/support/models/fanatic.rb +8 -0
- data/spec/support/models/favorite.rb +8 -0
- data/spec/support/models/filesystem.rb +7 -0
- data/spec/support/models/fire_hydrant.rb +8 -0
- data/spec/support/models/firefox.rb +6 -0
- data/spec/support/models/fish.rb +9 -0
- data/spec/support/models/folder.rb +9 -0
- data/spec/support/models/folder_item.rb +11 -0
- data/spec/support/models/fruits.rb +36 -0
- data/spec/support/models/game.rb +21 -0
- data/spec/support/models/ghost.rb +9 -0
- data/spec/support/models/guitar.rb +4 -0
- data/spec/support/models/hole.rb +12 -0
- data/spec/support/models/home.rb +6 -0
- data/spec/support/models/house.rb +8 -0
- data/spec/support/models/html_writer.rb +5 -0
- data/spec/support/models/id_key.rb +8 -0
- data/spec/support/models/idnodef.rb +7 -0
- data/spec/support/models/image.rb +24 -0
- data/spec/support/models/implant.rb +27 -0
- data/spec/support/models/instrument.rb +8 -0
- data/spec/support/models/item.rb +10 -0
- data/spec/support/models/jar.rb +9 -0
- data/spec/support/models/kaleidoscope.rb +8 -0
- data/spec/support/models/kangaroo.rb +6 -0
- data/spec/support/models/label.rb +52 -0
- data/spec/support/models/language.rb +7 -0
- data/spec/support/models/lat_lng.rb +17 -0
- data/spec/support/models/league.rb +13 -0
- data/spec/support/models/learner.rb +4 -0
- data/spec/support/models/line_item.rb +8 -0
- data/spec/support/models/location.rb +10 -0
- data/spec/support/models/login.rb +10 -0
- data/spec/support/models/manufacturer.rb +9 -0
- data/spec/support/models/meat.rb +6 -0
- data/spec/support/models/membership.rb +7 -0
- data/spec/support/models/message.rb +13 -0
- data/spec/support/models/minim.rb +6 -0
- data/spec/support/models/mixed_drink.rb +6 -0
- data/spec/support/models/mop.rb +24 -0
- data/spec/support/models/movie.rb +15 -0
- data/spec/support/models/my_hash.rb +4 -0
- data/spec/support/models/name.rb +26 -0
- data/spec/support/models/name_only.rb +8 -0
- data/spec/support/models/node.rb +7 -0
- data/spec/support/models/note.rb +19 -0
- data/spec/support/models/nut.rb +7 -0
- data/spec/support/models/odd.rb +9 -0
- data/spec/support/models/order.rb +12 -0
- data/spec/support/models/ordered_post.rb +13 -0
- data/spec/support/models/ordered_preference.rb +8 -0
- data/spec/support/models/oscar.rb +16 -0
- data/spec/support/models/other_owner_object.rb +4 -0
- data/spec/support/models/override.rb +18 -0
- data/spec/support/models/ownable.rb +8 -0
- data/spec/support/models/owner.rb +10 -0
- data/spec/support/models/pack.rb +5 -0
- data/spec/support/models/page.rb +18 -0
- data/spec/support/models/page_question.rb +6 -0
- data/spec/support/models/palette.rb +9 -0
- data/spec/support/models/parent.rb +7 -0
- data/spec/support/models/parent_doc.rb +8 -0
- data/spec/support/models/passport.rb +22 -0
- data/spec/support/models/patient.rb +11 -0
- data/spec/support/models/pdf_writer.rb +5 -0
- data/spec/support/models/pencil.rb +3 -0
- data/spec/support/models/person.rb +231 -0
- data/spec/support/models/pet.rb +25 -0
- data/spec/support/models/pet_owner.rb +8 -0
- data/spec/support/models/phone.rb +13 -0
- data/spec/support/models/piano.rb +4 -0
- data/spec/support/models/pizza.rb +9 -0
- data/spec/support/models/player.rb +39 -0
- data/spec/support/models/post.rb +52 -0
- data/spec/support/models/post_genre.rb +8 -0
- data/spec/support/models/powerup.rb +25 -0
- data/spec/support/models/preference.rb +11 -0
- data/spec/support/models/princess.rb +12 -0
- data/spec/support/models/product.rb +19 -0
- data/spec/support/models/profile.rb +17 -0
- data/spec/support/models/pronunciation.rb +7 -0
- data/spec/support/models/pub.rb +8 -0
- data/spec/support/models/publication/encyclopedia.rb +11 -0
- data/spec/support/models/publication/review.rb +13 -0
- data/spec/support/models/publication.rb +4 -0
- data/spec/support/models/purchase.rb +6 -0
- data/spec/support/models/purchased_item.rb +10 -0
- data/spec/support/models/question.rb +10 -0
- data/spec/support/models/quiz.rb +9 -0
- data/spec/support/models/rating.rb +10 -0
- data/spec/support/models/record.rb +54 -0
- data/spec/support/models/registry.rb +7 -0
- data/spec/support/models/role.rb +9 -0
- data/spec/support/models/root_category.rb +6 -0
- data/spec/support/models/sandwich.rb +11 -0
- data/spec/support/models/scheduler.rb +9 -0
- data/spec/support/models/school.rb +14 -0
- data/spec/support/models/scribe.rb +7 -0
- data/spec/support/models/sealer.rb +7 -0
- data/spec/support/models/seat.rb +24 -0
- data/spec/support/models/seo.rb +9 -0
- data/spec/support/models/series.rb +7 -0
- data/spec/support/models/server.rb +15 -0
- data/spec/support/models/service.rb +24 -0
- data/spec/support/models/shape.rb +14 -0
- data/spec/support/models/shelf.rb +7 -0
- data/spec/support/models/shield.rb +18 -0
- data/spec/support/models/shipment_address.rb +5 -0
- data/spec/support/models/shipping_container.rb +7 -0
- data/spec/support/models/shipping_pack.rb +5 -0
- data/spec/support/models/shirt.rb +11 -0
- data/spec/support/models/shop.rb +8 -0
- data/spec/support/models/short_agent.rb +6 -0
- data/spec/support/models/short_quiz.rb +7 -0
- data/spec/support/models/simple.rb +7 -0
- data/spec/support/models/slave.rb +8 -0
- data/spec/support/models/song.rb +10 -0
- data/spec/support/models/sound.rb +7 -0
- data/spec/support/models/spacer.rb +7 -0
- data/spec/support/models/square.rb +6 -0
- data/spec/support/models/staff.rb +9 -0
- data/spec/support/models/store_as_dup_test1.rb +7 -0
- data/spec/support/models/store_as_dup_test2.rb +7 -0
- data/spec/support/models/store_as_dup_test3.rb +7 -0
- data/spec/support/models/store_as_dup_test4.rb +7 -0
- data/spec/support/models/strategy.rb +5 -0
- data/spec/support/models/student.rb +14 -0
- data/spec/support/models/sub_item.rb +5 -0
- data/spec/support/models/subscription.rb +7 -0
- data/spec/support/models/survey.rb +7 -0
- data/spec/support/models/symptom.rb +8 -0
- data/spec/support/models/system_role.rb +7 -0
- data/spec/support/models/tag.rb +10 -0
- data/spec/support/models/target.rb +7 -0
- data/spec/support/models/template.rb +7 -0
- data/spec/support/models/thing.rb +11 -0
- data/spec/support/models/threadlocker.rb +7 -0
- data/spec/support/models/title.rb +5 -0
- data/spec/support/models/tool.rb +10 -0
- data/spec/support/models/topping.rb +7 -0
- data/spec/support/models/toy.rb +9 -0
- data/spec/support/models/track.rb +40 -0
- data/spec/support/models/translation.rb +7 -0
- data/spec/support/models/tree.rb +11 -0
- data/spec/support/models/truck.rb +7 -0
- data/spec/support/models/updatable.rb +7 -0
- data/spec/support/models/user.rb +23 -0
- data/spec/support/models/user_account.rb +12 -0
- data/spec/support/models/validation_callback.rb +12 -0
- data/spec/support/models/vehicle.rb +18 -0
- data/spec/support/models/version.rb +7 -0
- data/spec/support/models/vertex.rb +8 -0
- data/spec/support/models/vet_visit.rb +7 -0
- data/spec/support/models/video.rb +15 -0
- data/spec/support/models/video_game.rb +3 -0
- data/spec/support/models/washer.rb +7 -0
- data/spec/support/models/weapon.rb +25 -0
- data/spec/support/models/wiki_page.rb +17 -0
- data/spec/support/models/word.rb +17 -0
- data/spec/support/models/word_origin.rb +13 -0
- data/spec/support/models/writer.rb +13 -0
- data/spec/support/schema_maps/schema_map_aws.json +17 -0
- data/spec/support/schema_maps/schema_map_aws_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_azure.json +17 -0
- data/spec/support/schema_maps/schema_map_azure_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_gcp.json +17 -0
- data/spec/support/schema_maps/schema_map_gcp_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_kmip.json +17 -0
- data/spec/support/schema_maps/schema_map_kmip_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_local.json +18 -0
- data/spec/support/schema_maps/schema_map_local_key_alt_names.json +12 -0
- data/spec/support/shared/time.rb +53 -0
- data/spec/support/spec_config.rb +64 -0
- data.tar.gz.sig +0 -0
- metadata +1582 -912
- metadata.gz.sig +0 -0
- data/lib/mongoid/atomic/positionable.rb +0 -73
- data/lib/mongoid/callbacks.rb +0 -314
- data/lib/mongoid/components.rb +0 -93
- data/lib/mongoid/config/inflections.rb +0 -6
- data/lib/mongoid/config/validators/session.rb +0 -140
- data/lib/mongoid/contextual/eager.rb +0 -158
- data/lib/mongoid/contextual/find_and_modify.rb +0 -69
- data/lib/mongoid/criterion/findable.rb +0 -179
- data/lib/mongoid/criterion/inspection.rb +0 -25
- data/lib/mongoid/criterion/marshalable.rb +0 -48
- data/lib/mongoid/criterion/modifiable.rb +0 -189
- data/lib/mongoid/criterion/scoping.rb +0 -158
- data/lib/mongoid/dirty.rb +0 -376
- data/lib/mongoid/errors/eager_load.rb +0 -22
- data/lib/mongoid/errors/mixed_session_configuration.rb +0 -28
- data/lib/mongoid/errors/no_default_session.rb +0 -23
- data/lib/mongoid/errors/no_session_config.rb +0 -22
- data/lib/mongoid/errors/no_session_database.rb +0 -27
- data/lib/mongoid/errors/no_session_hosts.rb +0 -27
- data/lib/mongoid/errors/no_sessions_config.rb +0 -20
- data/lib/mongoid/errors/versioning_not_on_root.rb +0 -23
- data/lib/mongoid/finders.rb +0 -130
- data/lib/mongoid/hierarchy.rb +0 -188
- data/lib/mongoid/identity_map.rb +0 -163
- data/lib/mongoid/indexes/validators/options.rb +0 -102
- data/lib/mongoid/indexes.rb +0 -154
- data/lib/mongoid/inspection.rb +0 -55
- data/lib/mongoid/json.rb +0 -16
- data/lib/mongoid/matchers/all.rb +0 -27
- data/lib/mongoid/matchers/and.rb +0 -30
- data/lib/mongoid/matchers/default.rb +0 -72
- data/lib/mongoid/matchers/exists.rb +0 -23
- data/lib/mongoid/matchers/gt.rb +0 -21
- data/lib/mongoid/matchers/gte.rb +0 -21
- data/lib/mongoid/matchers/in.rb +0 -24
- data/lib/mongoid/matchers/lt.rb +0 -21
- data/lib/mongoid/matchers/lte.rb +0 -21
- data/lib/mongoid/matchers/ne.rb +0 -21
- data/lib/mongoid/matchers/nin.rb +0 -21
- data/lib/mongoid/matchers/or.rb +0 -33
- data/lib/mongoid/matchers/size.rb +0 -21
- 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 -137
- 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 -32
- 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 -352
- data/lib/mongoid/railties/document.rb +0 -12
- data/lib/mongoid/relations/accessors.rb +0 -299
- data/lib/mongoid/relations/auto_save.rb +0 -107
- data/lib/mongoid/relations/binding.rb +0 -241
- data/lib/mongoid/relations/bindings/embedded/in.rb +0 -63
- data/lib/mongoid/relations/bindings/embedded/many.rb +0 -52
- data/lib/mongoid/relations/bindings/embedded/one.rb +0 -55
- data/lib/mongoid/relations/bindings/referenced/in.rb +0 -70
- data/lib/mongoid/relations/bindings/referenced/many.rb +0 -42
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +0 -67
- data/lib/mongoid/relations/bindings/referenced/one.rb +0 -44
- data/lib/mongoid/relations/bindings.rb +0 -9
- data/lib/mongoid/relations/builder.rb +0 -57
- data/lib/mongoid/relations/builders/embedded/in.rb +0 -29
- data/lib/mongoid/relations/builders/embedded/many.rb +0 -36
- data/lib/mongoid/relations/builders/embedded/one.rb +0 -30
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +0 -177
- data/lib/mongoid/relations/builders/nested_attributes/one.rb +0 -127
- data/lib/mongoid/relations/builders/referenced/in.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many.rb +0 -27
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +0 -40
- data/lib/mongoid/relations/builders/referenced/one.rb +0 -26
- data/lib/mongoid/relations/builders.rb +0 -104
- 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 -58
- data/lib/mongoid/relations/constraint.rb +0 -49
- data/lib/mongoid/relations/conversions.rb +0 -34
- data/lib/mongoid/relations/counter_cache.rb +0 -107
- data/lib/mongoid/relations/cyclic.rb +0 -107
- data/lib/mongoid/relations/embedded/batchable.rb +0 -356
- data/lib/mongoid/relations/embedded/in.rb +0 -231
- data/lib/mongoid/relations/embedded/many.rb +0 -659
- data/lib/mongoid/relations/embedded/one.rb +0 -223
- data/lib/mongoid/relations/macros.rb +0 -359
- data/lib/mongoid/relations/many.rb +0 -217
- data/lib/mongoid/relations/marshalable.rb +0 -32
- data/lib/mongoid/relations/metadata.rb +0 -1227
- data/lib/mongoid/relations/nested_builder.rb +0 -74
- data/lib/mongoid/relations/one.rb +0 -60
- data/lib/mongoid/relations/options.rb +0 -48
- data/lib/mongoid/relations/polymorphic.rb +0 -40
- data/lib/mongoid/relations/proxy.rb +0 -264
- data/lib/mongoid/relations/referenced/in.rb +0 -314
- data/lib/mongoid/relations/referenced/many.rb +0 -789
- data/lib/mongoid/relations/referenced/many_to_many.rb +0 -495
- data/lib/mongoid/relations/referenced/one.rb +0 -297
- data/lib/mongoid/relations/reflections.rb +0 -62
- data/lib/mongoid/relations/synchronization.rb +0 -169
- data/lib/mongoid/relations/targets/enumerable.rb +0 -473
- data/lib/mongoid/relations/targets.rb +0 -2
- data/lib/mongoid/relations/touchable.rb +0 -61
- data/lib/mongoid/relations.rb +0 -162
- data/lib/mongoid/reloading.rb +0 -92
- data/lib/mongoid/scoping.rb +0 -356
- data/lib/mongoid/serialization.rb +0 -161
- data/lib/mongoid/sessions/factory.rb +0 -129
- data/lib/mongoid/sessions/mongo_uri.rb +0 -93
- data/lib/mongoid/sessions/validators/storage.rb +0 -49
- data/lib/mongoid/sessions/validators.rb +0 -2
- data/lib/mongoid/sessions.rb +0 -433
- data/lib/mongoid/sharding.rb +0 -61
- data/lib/mongoid/state.rb +0 -97
- data/lib/mongoid/unit_of_work.rb +0 -61
- data/lib/mongoid/validations/associated.rb +0 -46
- data/lib/mongoid/validations/format.rb +0 -20
- data/lib/mongoid/validations/length.rb +0 -20
- data/lib/mongoid/validations/localizable.rb +0 -30
- data/lib/mongoid/validations/macros.rb +0 -93
- data/lib/mongoid/validations/presence.rb +0 -86
- data/lib/mongoid/validations/queryable.rb +0 -31
- data/lib/mongoid/validations/uniqueness.rb +0 -330
- data/lib/mongoid/validations.rb +0 -166
- 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/lib/support/ruby_version.rb +0 -26
- data/spec/app/models/account.rb +0 -32
- data/spec/app/models/acolyte.rb +0 -16
- data/spec/app/models/actor.rb +0 -19
- data/spec/app/models/actor_observer.rb +0 -15
- data/spec/app/models/actress.rb +0 -2
- data/spec/app/models/address.rb +0 -72
- data/spec/app/models/address_component.rb +0 -5
- data/spec/app/models/address_number.rb +0 -6
- data/spec/app/models/agency.rb +0 -5
- data/spec/app/models/agent.rb +0 -12
- data/spec/app/models/album.rb +0 -14
- data/spec/app/models/alert.rb +0 -5
- data/spec/app/models/animal.rb +0 -25
- data/spec/app/models/answer.rb +0 -4
- data/spec/app/models/appointment.rb +0 -7
- data/spec/app/models/article.rb +0 -13
- data/spec/app/models/artist.rb +0 -66
- data/spec/app/models/artwork.rb +0 -4
- data/spec/app/models/augmentation.rb +0 -11
- data/spec/app/models/author.rb +0 -6
- data/spec/app/models/band.rb +0 -25
- data/spec/app/models/bar.rb +0 -9
- data/spec/app/models/basic.rb +0 -6
- data/spec/app/models/bed.rb +0 -1
- data/spec/app/models/big_palette.rb +0 -2
- data/spec/app/models/birthday.rb +0 -13
- data/spec/app/models/book.rb +0 -12
- data/spec/app/models/breed.rb +0 -4
- data/spec/app/models/browser.rb +0 -6
- data/spec/app/models/building.rb +0 -7
- data/spec/app/models/building_address.rb +0 -7
- data/spec/app/models/bus.rb +0 -7
- data/spec/app/models/business.rb +0 -5
- data/spec/app/models/callback_recorder.rb +0 -25
- data/spec/app/models/callback_test.rb +0 -9
- data/spec/app/models/canvas.rb +0 -25
- data/spec/app/models/car.rb +0 -1
- data/spec/app/models/cat.rb +0 -8
- data/spec/app/models/category.rb +0 -8
- data/spec/app/models/child.rb +0 -4
- data/spec/app/models/child_doc.rb +0 -22
- data/spec/app/models/church.rb +0 -4
- data/spec/app/models/circle.rb +0 -3
- data/spec/app/models/circuit.rb +0 -4
- data/spec/app/models/circus.rb +0 -7
- data/spec/app/models/code.rb +0 -5
- data/spec/app/models/comment.rb +0 -16
- data/spec/app/models/contractor.rb +0 -7
- data/spec/app/models/cookie.rb +0 -6
- data/spec/app/models/country_code.rb +0 -8
- data/spec/app/models/definition.rb +0 -8
- data/spec/app/models/description.rb +0 -11
- data/spec/app/models/dictionary.rb +0 -10
- data/spec/app/models/division.rb +0 -10
- data/spec/app/models/doctor.rb +0 -12
- data/spec/app/models/dog.rb +0 -7
- data/spec/app/models/dokument.rb +0 -5
- data/spec/app/models/driver.rb +0 -7
- data/spec/app/models/drug.rb +0 -8
- data/spec/app/models/email.rb +0 -6
- data/spec/app/models/employer.rb +0 -5
- data/spec/app/models/entry.rb +0 -6
- data/spec/app/models/eraser.rb +0 -1
- data/spec/app/models/event.rb +0 -22
- data/spec/app/models/exhibition.rb +0 -4
- data/spec/app/models/exhibitor.rb +0 -5
- data/spec/app/models/eye.rb +0 -9
- data/spec/app/models/eye_bowl.rb +0 -9
- data/spec/app/models/face.rb +0 -8
- data/spec/app/models/favorite.rb +0 -6
- data/spec/app/models/filesystem.rb +0 -4
- data/spec/app/models/fire_hydrant.rb +0 -6
- data/spec/app/models/firefox.rb +0 -4
- data/spec/app/models/fish.rb +0 -8
- data/spec/app/models/folder.rb +0 -7
- data/spec/app/models/folder_item.rb +0 -9
- data/spec/app/models/fruits.rb +0 -28
- data/spec/app/models/game.rb +0 -21
- data/spec/app/models/ghost.rb +0 -7
- data/spec/app/models/home.rb +0 -4
- data/spec/app/models/house.rb +0 -8
- data/spec/app/models/html_writer.rb +0 -3
- data/spec/app/models/image.rb +0 -22
- data/spec/app/models/implant.rb +0 -16
- data/spec/app/models/item.rb +0 -12
- data/spec/app/models/jar.rb +0 -7
- data/spec/app/models/label.rb +0 -40
- data/spec/app/models/language.rb +0 -5
- data/spec/app/models/lat_lng.rb +0 -15
- data/spec/app/models/league.rb +0 -11
- data/spec/app/models/learner.rb +0 -2
- data/spec/app/models/line_item.rb +0 -6
- data/spec/app/models/location.rb +0 -8
- data/spec/app/models/login.rb +0 -8
- data/spec/app/models/manufacturer.rb +0 -7
- data/spec/app/models/meat.rb +0 -4
- data/spec/app/models/membership.rb +0 -4
- data/spec/app/models/mixed_drink.rb +0 -4
- data/spec/app/models/movie.rb +0 -12
- data/spec/app/models/my_hash.rb +0 -2
- data/spec/app/models/name.rb +0 -23
- data/spec/app/models/node.rb +0 -5
- data/spec/app/models/note.rb +0 -12
- data/spec/app/models/ordered_post.rb +0 -6
- data/spec/app/models/ordered_preference.rb +0 -6
- data/spec/app/models/oscar.rb +0 -15
- data/spec/app/models/override.rb +0 -16
- data/spec/app/models/ownable.rb +0 -6
- data/spec/app/models/owner.rb +0 -6
- data/spec/app/models/pack.rb +0 -3
- data/spec/app/models/page.rb +0 -5
- data/spec/app/models/page_question.rb +0 -4
- data/spec/app/models/palette.rb +0 -7
- data/spec/app/models/paranoid_phone.rb +0 -25
- data/spec/app/models/paranoid_post.rb +0 -36
- data/spec/app/models/parent.rb +0 -5
- data/spec/app/models/parent_doc.rb +0 -6
- data/spec/app/models/passport.rb +0 -5
- data/spec/app/models/patient.rb +0 -9
- data/spec/app/models/pdf_writer.rb +0 -3
- data/spec/app/models/pencil.rb +0 -1
- data/spec/app/models/person.rb +0 -201
- data/spec/app/models/pet.rb +0 -23
- data/spec/app/models/pet_owner.rb +0 -6
- data/spec/app/models/phone.rb +0 -11
- data/spec/app/models/phone_observer.rb +0 -6
- data/spec/app/models/pizza.rb +0 -7
- data/spec/app/models/player.rb +0 -35
- data/spec/app/models/post.rb +0 -43
- data/spec/app/models/powerup.rb +0 -11
- data/spec/app/models/preference.rb +0 -9
- data/spec/app/models/princess.rb +0 -8
- data/spec/app/models/product.rb +0 -17
- data/spec/app/models/profile.rb +0 -5
- data/spec/app/models/pronunciation.rb +0 -5
- data/spec/app/models/purchase.rb +0 -4
- data/spec/app/models/question.rb +0 -8
- data/spec/app/models/quiz.rb +0 -10
- data/spec/app/models/rating.rb +0 -8
- data/spec/app/models/record.rb +0 -46
- data/spec/app/models/registry.rb +0 -4
- data/spec/app/models/role.rb +0 -7
- data/spec/app/models/root_category.rb +0 -4
- data/spec/app/models/sandwich.rb +0 -4
- data/spec/app/models/scheduler.rb +0 -7
- data/spec/app/models/seo.rb +0 -7
- data/spec/app/models/series.rb +0 -4
- data/spec/app/models/server.rb +0 -13
- data/spec/app/models/service.rb +0 -22
- data/spec/app/models/shape.rb +0 -12
- data/spec/app/models/shelf.rb +0 -5
- data/spec/app/models/shipping_container.rb +0 -5
- data/spec/app/models/shipping_pack.rb +0 -3
- data/spec/app/models/shop.rb +0 -6
- data/spec/app/models/short_agent.rb +0 -4
- data/spec/app/models/short_quiz.rb +0 -5
- data/spec/app/models/slave.rb +0 -6
- data/spec/app/models/song.rb +0 -8
- data/spec/app/models/square.rb +0 -4
- data/spec/app/models/strategy.rb +0 -3
- data/spec/app/models/sub_item.rb +0 -3
- data/spec/app/models/subscription.rb +0 -4
- data/spec/app/models/survey.rb +0 -5
- data/spec/app/models/symptom.rb +0 -6
- data/spec/app/models/tag.rb +0 -8
- data/spec/app/models/target.rb +0 -5
- data/spec/app/models/template.rb +0 -5
- data/spec/app/models/thing.rb +0 -9
- data/spec/app/models/title.rb +0 -4
- data/spec/app/models/tool.rb +0 -8
- data/spec/app/models/topping.rb +0 -5
- data/spec/app/models/track.rb +0 -38
- data/spec/app/models/translation.rb +0 -5
- data/spec/app/models/tree.rb +0 -9
- data/spec/app/models/truck.rb +0 -3
- data/spec/app/models/user.rb +0 -21
- data/spec/app/models/user_account.rb +0 -10
- data/spec/app/models/validation_callback.rb +0 -10
- data/spec/app/models/vehicle.rb +0 -11
- data/spec/app/models/version.rb +0 -5
- data/spec/app/models/vet_visit.rb +0 -5
- data/spec/app/models/video.rb +0 -17
- data/spec/app/models/video_game.rb +0 -1
- data/spec/app/models/weapon.rb +0 -11
- data/spec/app/models/wiki_page.rb +0 -17
- data/spec/app/models/word.rb +0 -12
- data/spec/app/models/word_origin.rb +0 -11
- data/spec/app/models/writer.rb +0 -11
- data/spec/mongoid/atomic/positionable_spec.rb +0 -227
- data/spec/mongoid/attributes/processing_spec.rb +0 -149
- data/spec/mongoid/callbacks_spec.rb +0 -1564
- data/spec/mongoid/components_spec.rb +0 -24
- data/spec/mongoid/contextual/find_and_modify_spec.rb +0 -220
- data/spec/mongoid/criterion/destructive_spec.rb +0 -101
- data/spec/mongoid/criterion/inspection_spec.rb +0 -27
- data/spec/mongoid/criterion/marshalable_spec.rb +0 -28
- data/spec/mongoid/criterion/modifiable_spec.rb +0 -409
- data/spec/mongoid/criterion/modification_spec.rb +0 -402
- data/spec/mongoid/criterion/scoping_spec.rb +0 -391
- data/spec/mongoid/dirty_spec.rb +0 -1508
- data/spec/mongoid/errors/eager_load_spec.rb +0 -29
- data/spec/mongoid/errors/mixed_session_configuration_spec.rb +0 -29
- data/spec/mongoid/errors/no_session_config_spec.rb +0 -29
- data/spec/mongoid/errors/no_session_database_spec.rb +0 -29
- data/spec/mongoid/errors/no_session_hosts_spec.rb +0 -29
- data/spec/mongoid/errors/no_sessions_config_spec.rb +0 -29
- data/spec/mongoid/errors/versioning_not_on_root_spec.rb +0 -29
- 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/finders_spec.rb +0 -321
- data/spec/mongoid/hierarchy_spec.rb +0 -244
- data/spec/mongoid/identity_map_spec.rb +0 -564
- data/spec/mongoid/indexes_spec.rb +0 -404
- data/spec/mongoid/inspection_spec.rb +0 -57
- data/spec/mongoid/json_spec.rb +0 -33
- data/spec/mongoid/matchers/all_spec.rb +0 -31
- data/spec/mongoid/matchers/and_spec.rb +0 -162
- data/spec/mongoid/matchers/default_spec.rb +0 -130
- data/spec/mongoid/matchers/exists_spec.rb +0 -57
- data/spec/mongoid/matchers/gt_spec.rb +0 -74
- data/spec/mongoid/matchers/gte_spec.rb +0 -74
- data/spec/mongoid/matchers/in_spec.rb +0 -25
- data/spec/mongoid/matchers/lt_spec.rb +0 -74
- data/spec/mongoid/matchers/lte_spec.rb +0 -74
- data/spec/mongoid/matchers/ne_spec.rb +0 -25
- data/spec/mongoid/matchers/nin_spec.rb +0 -25
- data/spec/mongoid/matchers/or_spec.rb +0 -106
- data/spec/mongoid/matchers/size_spec.rb +0 -25
- data/spec/mongoid/matchers_spec.rb +0 -532
- data/spec/mongoid/multi_parameter_attributes_spec.rb +0 -128
- data/spec/mongoid/nested_attributes_spec.rb +0 -4945
- 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/railties/document_spec.rb +0 -24
- data/spec/mongoid/relations/accessors_spec.rb +0 -844
- data/spec/mongoid/relations/auto_save_spec.rb +0 -261
- data/spec/mongoid/relations/bindings/embedded/in_spec.rb +0 -171
- data/spec/mongoid/relations/bindings/embedded/many_spec.rb +0 -54
- data/spec/mongoid/relations/bindings/embedded/one_spec.rb +0 -77
- data/spec/mongoid/relations/bindings/referenced/in_spec.rb +0 -241
- data/spec/mongoid/relations/bindings/referenced/many_spec.rb +0 -153
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +0 -178
- data/spec/mongoid/relations/bindings/referenced/one_spec.rb +0 -131
- data/spec/mongoid/relations/builders/embedded/in_spec.rb +0 -34
- data/spec/mongoid/relations/builders/embedded/many_spec.rb +0 -132
- data/spec/mongoid/relations/builders/embedded/one_spec.rb +0 -99
- data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +0 -234
- data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +0 -250
- data/spec/mongoid/relations/builders/referenced/in_spec.rb +0 -241
- 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 -124
- data/spec/mongoid/relations/builders_spec.rb +0 -226
- 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 -74
- data/spec/mongoid/relations/conversions_spec.rb +0 -126
- data/spec/mongoid/relations/counter_cache_spec.rb +0 -205
- data/spec/mongoid/relations/cyclic_spec.rb +0 -156
- data/spec/mongoid/relations/embedded/dirty_spec.rb +0 -65
- data/spec/mongoid/relations/embedded/in_spec.rb +0 -580
- data/spec/mongoid/relations/embedded/many_spec.rb +0 -3841
- data/spec/mongoid/relations/embedded/one_spec.rb +0 -1055
- data/spec/mongoid/relations/macros_spec.rb +0 -625
- data/spec/mongoid/relations/metadata_spec.rb +0 -2030
- data/spec/mongoid/relations/options_spec.rb +0 -35
- data/spec/mongoid/relations/polymorphic_spec.rb +0 -132
- data/spec/mongoid/relations/referenced/in_spec.rb +0 -1501
- data/spec/mongoid/relations/referenced/many_spec.rb +0 -3632
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +0 -3561
- data/spec/mongoid/relations/referenced/one_spec.rb +0 -1331
- data/spec/mongoid/relations/reflections_spec.rb +0 -101
- data/spec/mongoid/relations/synchronization_spec.rb +0 -453
- data/spec/mongoid/relations/targets/enumerable_spec.rb +0 -1710
- data/spec/mongoid/relations_spec.rb +0 -188
- data/spec/mongoid/reloading_spec.rb +0 -305
- data/spec/mongoid/scoping_spec.rb +0 -978
- data/spec/mongoid/serialization_spec.rb +0 -833
- data/spec/mongoid/sessions/factory_spec.rb +0 -312
- data/spec/mongoid/sessions/mongo_uri_spec.rb +0 -103
- data/spec/mongoid/sessions_spec.rb +0 -1111
- data/spec/mongoid/sharding_spec.rb +0 -61
- data/spec/mongoid/state_spec.rb +0 -102
- data/spec/mongoid/unit_of_work_spec.rb +0 -196
- data/spec/mongoid/validations/associated_spec.rb +0 -183
- data/spec/mongoid/validations/format_spec.rb +0 -83
- data/spec/mongoid/validations/length_spec.rb +0 -223
- data/spec/mongoid/validations/numericality_spec.rb +0 -30
- data/spec/mongoid/validations/presence_spec.rb +0 -592
- data/spec/mongoid/validations/uniqueness_spec.rb +0 -2399
- data/spec/mongoid/validations_spec.rb +0 -309
- data/spec/mongoid/versioning_spec.rb +0 -540
- data/spec/rack/mongoid/middleware/identity_map_spec.rb +0 -72
@@ -1,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
4
|
+
require_relative './attributes/nested_spec_models'
|
2
5
|
|
3
6
|
describe Mongoid::Attributes do
|
4
7
|
|
@@ -11,13 +14,199 @@ describe Mongoid::Attributes do
|
|
11
14
|
end
|
12
15
|
|
13
16
|
it "does not cause an infinite loop" do
|
14
|
-
account.overridden.
|
17
|
+
expect(account.overridden).to eq("not recommended")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when the attribute was excluded in a criteria" do
|
22
|
+
|
23
|
+
let!(:person) do
|
24
|
+
Person.create!(title: "sir")
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when the attribute is localized" do
|
28
|
+
|
29
|
+
before do
|
30
|
+
person.update_attribute(:desc, "test")
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when the context includes" do
|
34
|
+
|
35
|
+
context "when the attribute exists" do
|
36
|
+
|
37
|
+
let(:from_db) do
|
38
|
+
Person.only(:desc).first
|
39
|
+
end
|
40
|
+
|
41
|
+
it "does not raise an error" do
|
42
|
+
expect(from_db.desc).to eq("test")
|
43
|
+
end
|
44
|
+
|
45
|
+
context "accessing via []" do
|
46
|
+
|
47
|
+
it "does not raise an error" do
|
48
|
+
expect(from_db["desc"]).to eq("test")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when calling only on a sub-document" do
|
53
|
+
|
54
|
+
let(:title) {"Executive"}
|
55
|
+
let(:city) {"NYC"}
|
56
|
+
let!(:agent) do
|
57
|
+
agent = Agent.new(:title => title)
|
58
|
+
agent.build_address(:city => city)
|
59
|
+
agent.save!()
|
60
|
+
agent
|
61
|
+
end
|
62
|
+
let(:from_db) do
|
63
|
+
Agent.only(:title, "address.city").first
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when the field is in the only" do
|
67
|
+
|
68
|
+
it "does not raise an error" do
|
69
|
+
expect(from_db.address.city).to eq(city)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "accessing via []" do
|
74
|
+
|
75
|
+
it "does not raise an error" do
|
76
|
+
expect(from_db["address.city"]).to eq(city)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when the attribute is a hash field' do
|
83
|
+
|
84
|
+
before do
|
85
|
+
person.update_attribute(:map, map)
|
86
|
+
end
|
87
|
+
|
88
|
+
let(:map) do
|
89
|
+
{ 'dates' => { 'y' => { '2016' => 'Berlin' } } }
|
90
|
+
end
|
91
|
+
|
92
|
+
let(:from_db) do
|
93
|
+
Person.only('map.dates.y.2016').first
|
94
|
+
end
|
95
|
+
|
96
|
+
it "does not raise an error" do
|
97
|
+
expect(from_db.map).to eq(map)
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when only one of the hash fields is projected' do
|
101
|
+
|
102
|
+
let(:map) do
|
103
|
+
{ 'dates' => { 'y' => { '2016' => 'Berlin', '2017' => 'Munich' } } }
|
104
|
+
end
|
105
|
+
|
106
|
+
let(:expected) do
|
107
|
+
{ 'dates' => { 'y' => {
|
108
|
+
'2016' => 'Berlin',
|
109
|
+
} } }
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'retrieves only the projected fields' do
|
113
|
+
expect(from_db.map).to eq(expected)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'when several of the hash fields is projected' do
|
118
|
+
|
119
|
+
let(:map) do
|
120
|
+
{ 'dates' => { 'y' => {
|
121
|
+
'2016' => 'Berlin',
|
122
|
+
'2017' => 'Munich',
|
123
|
+
'2018' => 'Krakow',
|
124
|
+
} } }
|
125
|
+
end
|
126
|
+
|
127
|
+
let(:expected) do
|
128
|
+
{ 'dates' => { 'y' => {
|
129
|
+
'2016' => 'Berlin',
|
130
|
+
'2018' => 'Krakow',
|
131
|
+
} } }
|
132
|
+
end
|
133
|
+
|
134
|
+
let(:from_db) do
|
135
|
+
Person.only('map.dates.y.2016', 'map.dates.y.2018').first
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'retrieves only the projected fields' do
|
139
|
+
expect(from_db.map).to eq(expected)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "when the context excludes" do
|
146
|
+
|
147
|
+
context "when the attribute exists" do
|
148
|
+
|
149
|
+
let(:from_db) do
|
150
|
+
Person.without(:pets).first
|
151
|
+
end
|
152
|
+
|
153
|
+
it "does not raise an error" do
|
154
|
+
expect(from_db.desc).to eq("test")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context "when excluding with only" do
|
161
|
+
|
162
|
+
let(:from_db) do
|
163
|
+
Person.only(:_id).first
|
164
|
+
end
|
165
|
+
|
166
|
+
it "raises an error" do
|
167
|
+
expect {
|
168
|
+
from_db.title
|
169
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
170
|
+
end
|
171
|
+
|
172
|
+
context "accessing via []" do
|
173
|
+
|
174
|
+
it "raises an error" do
|
175
|
+
expect {
|
176
|
+
from_db["title"]
|
177
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "when excluding with without" do
|
183
|
+
|
184
|
+
let(:from_db) do
|
185
|
+
Person.without(:title).first
|
186
|
+
end
|
187
|
+
|
188
|
+
it "raises an error" do
|
189
|
+
expect {
|
190
|
+
from_db.title
|
191
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
192
|
+
end
|
15
193
|
end
|
16
194
|
end
|
17
195
|
end
|
18
196
|
|
19
197
|
describe "#[]" do
|
20
198
|
|
199
|
+
context 'when the document has a custom attribute type' do
|
200
|
+
|
201
|
+
let(:bar) do
|
202
|
+
Bar.create!(lat_lng: LatLng.new(52.30, 13.25))
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'returns the demongoized version of the attribute' do
|
206
|
+
expect(bar.reload[:lat_lng]).to be_a(LatLng)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
21
210
|
context "when the document is a new record" do
|
22
211
|
|
23
212
|
let(:person) do
|
@@ -33,14 +222,14 @@ describe Mongoid::Attributes do
|
|
33
222
|
context "when passing just the name" do
|
34
223
|
|
35
224
|
it "returns the full value" do
|
36
|
-
person[:desc].
|
225
|
+
expect(person[:desc]).to eq("testing")
|
37
226
|
end
|
38
227
|
end
|
39
228
|
|
40
229
|
context "when passing the name with locale" do
|
41
230
|
|
42
231
|
it "returns the value for the locale" do
|
43
|
-
person["desc.en"].
|
232
|
+
expect(person["desc.en"]).to eq("testing")
|
44
233
|
end
|
45
234
|
end
|
46
235
|
end
|
@@ -48,7 +237,7 @@ describe Mongoid::Attributes do
|
|
48
237
|
context "when attribute does not exist" do
|
49
238
|
|
50
239
|
it "returns the default value" do
|
51
|
-
person[:age].
|
240
|
+
expect(person[:age]).to eq(100)
|
52
241
|
end
|
53
242
|
end
|
54
243
|
|
@@ -59,7 +248,7 @@ describe Mongoid::Attributes do
|
|
59
248
|
end
|
60
249
|
|
61
250
|
it "returns the value" do
|
62
|
-
person[:owner_id].
|
251
|
+
expect(person[:owner_id]).to eq(5)
|
63
252
|
end
|
64
253
|
end
|
65
254
|
end
|
@@ -67,315 +256,265 @@ describe Mongoid::Attributes do
|
|
67
256
|
context "when the document is an existing record" do
|
68
257
|
|
69
258
|
let!(:person) do
|
70
|
-
Person.create(title: "sir")
|
259
|
+
Person.create!(title: "sir")
|
71
260
|
end
|
72
261
|
|
73
|
-
context "when the attribute
|
74
|
-
|
75
|
-
before do
|
76
|
-
person.collection
|
77
|
-
.find({ _id: person.id })
|
78
|
-
.update({ "$unset" => { age: 1 }})
|
79
|
-
end
|
262
|
+
context "when the attribute was excluded in a criteria" do
|
80
263
|
|
81
|
-
context "when
|
264
|
+
context "when excluding with only" do
|
82
265
|
|
83
|
-
let(:
|
84
|
-
Person.
|
266
|
+
let(:from_db) do
|
267
|
+
Person.only(:_id).first
|
85
268
|
end
|
86
269
|
|
87
|
-
it "
|
88
|
-
|
270
|
+
it "raises an error" do
|
271
|
+
expect {
|
272
|
+
from_db[:title]
|
273
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
89
274
|
end
|
90
275
|
end
|
91
276
|
|
92
|
-
context "when
|
277
|
+
context "when excluding with without" do
|
93
278
|
|
94
|
-
|
95
|
-
|
96
|
-
person.reload
|
97
|
-
Mongoid.raise_not_found_error = true
|
279
|
+
let(:from_db) do
|
280
|
+
Person.without(:title).first
|
98
281
|
end
|
99
282
|
|
100
|
-
it "
|
101
|
-
|
283
|
+
it "raises an error" do
|
284
|
+
expect {
|
285
|
+
from_db[:title]
|
286
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
102
287
|
end
|
103
288
|
end
|
104
289
|
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "#[]=" do
|
109
|
-
|
110
|
-
let(:person) do
|
111
|
-
Person.new
|
112
|
-
end
|
113
|
-
|
114
|
-
context "when setting the attribute to nil" do
|
115
|
-
|
116
|
-
before do
|
117
|
-
person[:age] = nil
|
118
|
-
end
|
119
|
-
|
120
|
-
it "does not use the default value" do
|
121
|
-
person.age.should be_nil
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "when field has a default value" do
|
126
|
-
|
127
|
-
before do
|
128
|
-
person[:terms] = true
|
129
|
-
end
|
130
|
-
|
131
|
-
it "allows overwriting of the default value" do
|
132
|
-
person.terms.should be_true
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
290
|
|
137
|
-
|
291
|
+
context "when the field was not explicitly defined" do
|
138
292
|
|
139
|
-
|
293
|
+
context "when excluding with only and the field was not excluded" do
|
140
294
|
|
141
|
-
|
142
|
-
|
143
|
-
|
295
|
+
let(:from_db) do
|
296
|
+
Person.only(:_id).first
|
297
|
+
end
|
144
298
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
299
|
+
it "raises an error" do
|
300
|
+
expect {
|
301
|
+
from_db[:undefined_field]
|
302
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
303
|
+
end
|
304
|
+
end
|
149
305
|
|
150
|
-
|
306
|
+
context "when excluding with without and the field was excluded" do
|
151
307
|
|
152
|
-
|
153
|
-
|
154
|
-
|
308
|
+
let(:from_db) do
|
309
|
+
Person.without(:title).first
|
310
|
+
end
|
155
311
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
312
|
+
it "raises an error" do
|
313
|
+
expect {
|
314
|
+
from_db[:title]
|
315
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
316
|
+
end
|
317
|
+
end
|
160
318
|
|
161
|
-
|
319
|
+
context "when excluding with without and the field was not excluded" do
|
162
320
|
|
163
|
-
|
164
|
-
|
165
|
-
|
321
|
+
let(:from_db) do
|
322
|
+
Person.without(:title).first
|
323
|
+
end
|
166
324
|
|
167
|
-
|
168
|
-
|
325
|
+
it "returns nil" do
|
326
|
+
from_db[:undefined_field].should be nil
|
327
|
+
end
|
328
|
+
end
|
169
329
|
end
|
170
|
-
end
|
171
330
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
end
|
331
|
+
context 'when projecting with #only' do
|
332
|
+
let!(:person) do
|
333
|
+
Person.create!(title: 'sir', name: { first_name: 'Jose', language: { name: 'es' } })
|
334
|
+
end
|
177
335
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
end
|
336
|
+
context 'when projecting an embedded association' do
|
337
|
+
let(:from_db) do
|
338
|
+
Person.only(:name).first
|
339
|
+
end
|
183
340
|
|
184
|
-
|
341
|
+
context 'when retrieving a field of the association using the dot notation' do
|
185
342
|
|
186
|
-
|
343
|
+
it 'retrieves the field' do
|
344
|
+
expect(from_db['name.first_name']).to eq 'Jose'
|
345
|
+
end
|
346
|
+
end
|
187
347
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
)
|
348
|
+
context 'when retrieving a field of a nested association using the dot notation' do
|
349
|
+
it 'retrieves the field' do
|
350
|
+
expect(from_db['name.language.name']).to eq 'es'
|
351
|
+
end
|
352
|
+
end
|
194
353
|
end
|
195
354
|
|
196
|
-
|
197
|
-
|
198
|
-
|
355
|
+
context 'when projecting a sub-association of an embedded association' do
|
356
|
+
let(:from_db) do
|
357
|
+
Person.only('name.language').first
|
358
|
+
end
|
199
359
|
|
200
|
-
|
201
|
-
|
202
|
-
|
360
|
+
context 'when retrieving a field under the projected sub-association' do
|
361
|
+
it 'retrieves the field' do
|
362
|
+
expect(from_db['name.language.name']).to eq 'es'
|
363
|
+
end
|
364
|
+
end
|
203
365
|
|
204
|
-
|
205
|
-
|
366
|
+
context 'when retrieving a non-projected field' do
|
367
|
+
it 'raises MissingAttributeError' do
|
368
|
+
expect do
|
369
|
+
from_db['name.first_name']
|
370
|
+
end.to raise_error(ActiveModel::MissingAttributeError)
|
371
|
+
end
|
372
|
+
end
|
206
373
|
end
|
207
374
|
end
|
208
375
|
|
209
|
-
context "when
|
210
|
-
|
211
|
-
let(:article) do
|
212
|
-
Article.new({
|
213
|
-
title: "Some Title",
|
214
|
-
is_rss: true,
|
215
|
-
user_login: "SomeLogin"
|
216
|
-
}, as: :parser
|
217
|
-
)
|
218
|
-
end
|
219
|
-
|
220
|
-
it "sets the title field" do
|
221
|
-
article.title.should eq("Some Title")
|
222
|
-
end
|
376
|
+
context "when the attribute does not exist" do
|
223
377
|
|
224
|
-
|
225
|
-
|
378
|
+
before do
|
379
|
+
person.collection
|
380
|
+
.find({ _id: person.id })
|
381
|
+
.update_one({ "$unset" => { age: 1 }})
|
226
382
|
end
|
227
383
|
|
228
|
-
|
229
|
-
article.user_login.should be_nil
|
230
|
-
end
|
231
|
-
end
|
384
|
+
context "when found" do
|
232
385
|
|
233
|
-
|
386
|
+
let(:found) do
|
387
|
+
Person.find(person.id)
|
388
|
+
end
|
234
389
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
is_rss: true,
|
239
|
-
user_login: "SomeLogin"
|
240
|
-
}, without_protection: true
|
241
|
-
)
|
390
|
+
it "returns the default value" do
|
391
|
+
expect(found[:age]).to eq(100)
|
392
|
+
end
|
242
393
|
end
|
243
394
|
|
244
|
-
|
245
|
-
article.title.should eq("Some Title")
|
246
|
-
end
|
395
|
+
context "when reloaded" do
|
247
396
|
|
248
|
-
|
249
|
-
|
250
|
-
|
397
|
+
before do
|
398
|
+
Mongoid.raise_not_found_error = false
|
399
|
+
person.reload
|
400
|
+
Mongoid.raise_not_found_error = true
|
401
|
+
end
|
251
402
|
|
252
|
-
|
253
|
-
|
403
|
+
it "returns the default value" do
|
404
|
+
expect(person[:age]).to eq(100)
|
405
|
+
end
|
254
406
|
end
|
255
407
|
end
|
256
408
|
end
|
257
409
|
end
|
258
410
|
|
259
|
-
describe "
|
411
|
+
describe "#[]=" do
|
260
412
|
|
261
|
-
context
|
413
|
+
context 'when the document has a custom attribute type' do
|
262
414
|
|
263
|
-
let(:
|
264
|
-
|
415
|
+
let(:bar) do
|
416
|
+
Bar.new.tap do |b|
|
417
|
+
b[:lat_lng] = LatLng.new(52.30, 13.25)
|
418
|
+
b.save!
|
419
|
+
end
|
265
420
|
end
|
266
421
|
|
267
|
-
it
|
268
|
-
|
422
|
+
it 'sets the demongoized version of the attribute' do
|
423
|
+
expect(bar.reload.lat_lng).to be_a(LatLng)
|
269
424
|
end
|
270
425
|
end
|
271
426
|
|
272
|
-
|
427
|
+
let(:person) do
|
428
|
+
Person.new
|
429
|
+
end
|
273
430
|
|
274
|
-
|
275
|
-
Game.new(_id: "ABBA")
|
276
|
-
end
|
431
|
+
context "when setting the attribute to nil" do
|
277
432
|
|
278
|
-
|
279
|
-
|
433
|
+
let!(:age) do
|
434
|
+
person[:age] = nil
|
280
435
|
end
|
281
|
-
end
|
282
436
|
|
283
|
-
|
284
|
-
|
285
|
-
let(:person) do
|
286
|
-
Person.instantiate("_id" => "1", "security_code" => "ABBA")
|
437
|
+
it "does not use the default value" do
|
438
|
+
expect(person.age).to be_nil
|
287
439
|
end
|
288
440
|
|
289
|
-
it "
|
290
|
-
|
441
|
+
it "returns the set value" do
|
442
|
+
expect(age).to be_nil
|
291
443
|
end
|
292
444
|
end
|
293
445
|
|
294
|
-
context "when
|
446
|
+
context "when field has a default value" do
|
295
447
|
|
296
|
-
let(:
|
297
|
-
|
448
|
+
let!(:terms) do
|
449
|
+
person[:terms] = true
|
298
450
|
end
|
299
451
|
|
300
|
-
it "
|
301
|
-
person.
|
302
|
-
person.security_code.should eq("ABBA")
|
452
|
+
it "allows overwriting of the default value" do
|
453
|
+
expect(person.terms).to be true
|
303
454
|
end
|
304
|
-
end
|
305
|
-
|
306
|
-
context "when mass assignment role is indicated" do
|
307
455
|
|
308
|
-
|
309
|
-
|
456
|
+
it "returns the set value" do
|
457
|
+
expect(terms).to eq(true)
|
310
458
|
end
|
459
|
+
end
|
311
460
|
|
312
|
-
|
313
|
-
|
314
|
-
before do
|
315
|
-
item.assign_attributes(
|
316
|
-
title: "Some Title",
|
317
|
-
is_rss: true,
|
318
|
-
user_login: "SomeLogin"
|
319
|
-
)
|
320
|
-
end
|
461
|
+
context 'when the field is not explicitly defined' do
|
462
|
+
let(:bar) { Bar.new }
|
321
463
|
|
322
|
-
|
323
|
-
|
324
|
-
|
464
|
+
before do
|
465
|
+
bar['missing_field'] = 42
|
466
|
+
end
|
325
467
|
|
326
|
-
|
327
|
-
|
328
|
-
|
468
|
+
it 'writes the value into attributes' do
|
469
|
+
bar.attributes.should == {'_id' => bar.id, 'missing_field' => 42}
|
470
|
+
end
|
329
471
|
|
330
|
-
|
331
|
-
|
332
|
-
end
|
472
|
+
it 'makes the attribute accessible via []' do
|
473
|
+
bar['missing_field'].should == 42
|
333
474
|
end
|
334
475
|
|
335
|
-
context
|
476
|
+
context 'when writing fields on a document with projection' do
|
336
477
|
|
337
|
-
|
338
|
-
|
339
|
-
{ title: "Some Title",
|
340
|
-
is_rss: true,
|
341
|
-
user_login: "SomeLogin" }, as: :parser
|
342
|
-
)
|
478
|
+
let!(:person) do
|
479
|
+
Person.create!(title: "sir")
|
343
480
|
end
|
344
481
|
|
345
|
-
|
346
|
-
item.user_login.should eq("SomeLogin")
|
347
|
-
end
|
482
|
+
context "when excluding with only and the field was not excluded" do
|
348
483
|
|
349
|
-
|
350
|
-
|
351
|
-
|
484
|
+
let(:from_db) do
|
485
|
+
Person.only(:_id).first
|
486
|
+
end
|
352
487
|
|
353
|
-
|
354
|
-
|
488
|
+
it "raises an error" do
|
489
|
+
expect {
|
490
|
+
from_db[:undefined_field] = 'x'
|
491
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
492
|
+
end
|
355
493
|
end
|
356
|
-
end
|
357
494
|
|
358
|
-
|
495
|
+
context "when excluding with without and the field was excluded" do
|
359
496
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
is_rss: true,
|
364
|
-
user_login: "SomeLogin"
|
365
|
-
}, without_protection: true
|
366
|
-
)
|
367
|
-
end
|
497
|
+
let(:from_db) do
|
498
|
+
Person.without(:title).first
|
499
|
+
end
|
368
500
|
|
369
|
-
|
370
|
-
|
501
|
+
it "raises an error" do
|
502
|
+
expect {
|
503
|
+
from_db[:title] = 'x'
|
504
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
505
|
+
end
|
371
506
|
end
|
372
507
|
|
373
|
-
|
374
|
-
item.user_login.should eq("SomeLogin")
|
375
|
-
end
|
508
|
+
context "when excluding with without and the field was not excluded" do
|
376
509
|
|
377
|
-
|
378
|
-
|
510
|
+
let(:from_db) do
|
511
|
+
Person.without(:title).first
|
512
|
+
end
|
513
|
+
|
514
|
+
it "writes the value" do
|
515
|
+
from_db[:undefined_field] = 'x'
|
516
|
+
from_db[:undefined_field].should == 'x'
|
517
|
+
end
|
379
518
|
end
|
380
519
|
end
|
381
520
|
end
|
@@ -388,7 +527,18 @@ describe Mongoid::Attributes do
|
|
388
527
|
end
|
389
528
|
|
390
529
|
it "delegates to #id" do
|
391
|
-
person._id.
|
530
|
+
expect(person._id).to eq(person.id)
|
531
|
+
end
|
532
|
+
|
533
|
+
context "when #id alias is overridden" do
|
534
|
+
|
535
|
+
let(:object) do
|
536
|
+
IdKey.new(key: 'foo')
|
537
|
+
end
|
538
|
+
|
539
|
+
it "delegates to another method" do
|
540
|
+
expect(object.id).to eq(object.key)
|
541
|
+
end
|
392
542
|
end
|
393
543
|
end
|
394
544
|
|
@@ -397,9 +547,10 @@ describe Mongoid::Attributes do
|
|
397
547
|
after(:all) do
|
398
548
|
Person.field(
|
399
549
|
:_id,
|
400
|
-
type:
|
550
|
+
type: BSON::ObjectId,
|
401
551
|
pre_processed: true,
|
402
|
-
default: ->{
|
552
|
+
default: ->{ BSON::ObjectId.new },
|
553
|
+
overwrite: true
|
403
554
|
)
|
404
555
|
end
|
405
556
|
|
@@ -408,9 +559,10 @@ describe Mongoid::Attributes do
|
|
408
559
|
before(:all) do
|
409
560
|
Person.field(
|
410
561
|
:_id,
|
411
|
-
type:
|
562
|
+
type: BSON::ObjectId,
|
412
563
|
pre_processed: true,
|
413
|
-
default: ->{
|
564
|
+
default: ->{ BSON::ObjectId.new },
|
565
|
+
overwrite: true
|
414
566
|
)
|
415
567
|
end
|
416
568
|
|
@@ -419,7 +571,7 @@ describe Mongoid::Attributes do
|
|
419
571
|
end
|
420
572
|
|
421
573
|
let(:bson_id) do
|
422
|
-
|
574
|
+
BSON::ObjectId.new
|
423
575
|
end
|
424
576
|
|
425
577
|
context "when providing an object id" do
|
@@ -429,7 +581,7 @@ describe Mongoid::Attributes do
|
|
429
581
|
end
|
430
582
|
|
431
583
|
it "sets the id as the object id" do
|
432
|
-
person.id.
|
584
|
+
expect(person.id).to eq(bson_id)
|
433
585
|
end
|
434
586
|
end
|
435
587
|
|
@@ -440,7 +592,7 @@ describe Mongoid::Attributes do
|
|
440
592
|
end
|
441
593
|
|
442
594
|
it "sets the id as the object id" do
|
443
|
-
person.id.
|
595
|
+
expect(person.id).to eq(bson_id)
|
444
596
|
end
|
445
597
|
end
|
446
598
|
|
@@ -451,9 +603,22 @@ describe Mongoid::Attributes do
|
|
451
603
|
end
|
452
604
|
|
453
605
|
it "sets the id as the supplied value to_s" do
|
454
|
-
person.id.
|
606
|
+
expect(person.id).to eq(2)
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
context "when #id= alias is overridden" do
|
611
|
+
|
612
|
+
let(:object) do
|
613
|
+
IdKey.new(key: 'foo')
|
614
|
+
end
|
615
|
+
|
616
|
+
it "delegates to another method" do
|
617
|
+
object.id = 'bar'
|
618
|
+
expect(object.id).to eq('bar')
|
455
619
|
end
|
456
620
|
end
|
621
|
+
|
457
622
|
end
|
458
623
|
|
459
624
|
context "when using string ids" do
|
@@ -463,7 +628,8 @@ describe Mongoid::Attributes do
|
|
463
628
|
:_id,
|
464
629
|
type: String,
|
465
630
|
pre_processed: true,
|
466
|
-
default: ->{
|
631
|
+
default: ->{ BSON::ObjectId.new.to_s },
|
632
|
+
overwrite: true
|
467
633
|
)
|
468
634
|
end
|
469
635
|
|
@@ -472,7 +638,7 @@ describe Mongoid::Attributes do
|
|
472
638
|
end
|
473
639
|
|
474
640
|
let(:bson_id) do
|
475
|
-
|
641
|
+
BSON::ObjectId.new
|
476
642
|
end
|
477
643
|
|
478
644
|
context "when providing an object id" do
|
@@ -482,7 +648,7 @@ describe Mongoid::Attributes do
|
|
482
648
|
end
|
483
649
|
|
484
650
|
it "sets the id as the string of the object id" do
|
485
|
-
person.id.
|
651
|
+
expect(person.id).to eq(bson_id.to_s)
|
486
652
|
end
|
487
653
|
end
|
488
654
|
|
@@ -493,7 +659,7 @@ describe Mongoid::Attributes do
|
|
493
659
|
end
|
494
660
|
|
495
661
|
it "sets the id as the string" do
|
496
|
-
person.id.
|
662
|
+
expect(person.id).to eq(bson_id.to_s)
|
497
663
|
end
|
498
664
|
end
|
499
665
|
|
@@ -504,7 +670,7 @@ describe Mongoid::Attributes do
|
|
504
670
|
end
|
505
671
|
|
506
672
|
it "sets the id as the supplied value to_s" do
|
507
|
-
person.id.
|
673
|
+
expect(person.id).to eq("2")
|
508
674
|
end
|
509
675
|
end
|
510
676
|
end
|
@@ -512,7 +678,7 @@ describe Mongoid::Attributes do
|
|
512
678
|
context "when using integer ids" do
|
513
679
|
|
514
680
|
before(:all) do
|
515
|
-
Person.field(:_id, type: Integer)
|
681
|
+
Person.field(:_id, type: Integer, overwrite: true)
|
516
682
|
end
|
517
683
|
|
518
684
|
let(:person) do
|
@@ -526,7 +692,7 @@ describe Mongoid::Attributes do
|
|
526
692
|
end
|
527
693
|
|
528
694
|
it "sets the id as the integer" do
|
529
|
-
person.id.
|
695
|
+
expect(person.id).to eq(1)
|
530
696
|
end
|
531
697
|
end
|
532
698
|
|
@@ -537,7 +703,7 @@ describe Mongoid::Attributes do
|
|
537
703
|
end
|
538
704
|
|
539
705
|
it "sets the id as the supplied value" do
|
540
|
-
person.id.
|
706
|
+
expect(person.id).to eq(2)
|
541
707
|
end
|
542
708
|
end
|
543
709
|
end
|
@@ -553,27 +719,23 @@ describe Mongoid::Attributes do
|
|
553
719
|
Person.new(attributes)
|
554
720
|
end
|
555
721
|
|
556
|
-
before do
|
557
|
-
Mongoid.configure.allow_dynamic_fields = true
|
558
|
-
end
|
559
|
-
|
560
722
|
context "when an attribute exists" do
|
561
723
|
|
562
724
|
it "allows the getter" do
|
563
|
-
person.testing.
|
725
|
+
expect(person.testing).to eq("Testing")
|
564
726
|
end
|
565
727
|
|
566
728
|
it "allows the setter" do
|
567
729
|
person.testing = "Test"
|
568
|
-
person.testing.
|
730
|
+
expect(person.testing).to eq("Test")
|
569
731
|
end
|
570
732
|
|
571
733
|
it "allows the getter before_type_cast" do
|
572
|
-
person.testing_before_type_cast.
|
734
|
+
expect(person.testing_before_type_cast).to eq("Testing")
|
573
735
|
end
|
574
736
|
|
575
737
|
it "returns true for respond_to?" do
|
576
|
-
person.respond_to?(:testing).
|
738
|
+
expect(person.respond_to?(:testing)).to be true
|
577
739
|
end
|
578
740
|
end
|
579
741
|
|
@@ -588,28 +750,17 @@ describe Mongoid::Attributes do
|
|
588
750
|
end
|
589
751
|
|
590
752
|
it "mongoizes the dynamic field" do
|
591
|
-
person.new_years.
|
753
|
+
expect(person.new_years).to be_a(Time)
|
592
754
|
end
|
593
755
|
|
594
756
|
it "keeps the same value" do
|
595
|
-
person.new_years.
|
757
|
+
expect(person.new_years).to eq(new_years)
|
596
758
|
end
|
597
759
|
end
|
598
760
|
end
|
599
761
|
|
600
762
|
describe "#process" do
|
601
763
|
|
602
|
-
context "when passing non accessible fields" do
|
603
|
-
|
604
|
-
let(:person) do
|
605
|
-
Person.new(owner_id: 6)
|
606
|
-
end
|
607
|
-
|
608
|
-
it "does not set the value" do
|
609
|
-
person.owner_id.should be_nil
|
610
|
-
end
|
611
|
-
end
|
612
|
-
|
613
764
|
context "when attributes dont have fields defined" do
|
614
765
|
|
615
766
|
let(:attributes) do
|
@@ -626,43 +777,26 @@ describe Mongoid::Attributes do
|
|
626
777
|
Person.new(attributes)
|
627
778
|
end
|
628
779
|
|
629
|
-
before do
|
630
|
-
Mongoid.configure.allow_dynamic_fields = true
|
631
|
-
end
|
632
|
-
|
633
780
|
context "when attribute is a string" do
|
634
781
|
|
635
782
|
it "adds the string to the attributes" do
|
636
|
-
person.attributes["nofieldstring"].
|
783
|
+
expect(person.attributes["nofieldstring"]).to eq("Testing")
|
637
784
|
end
|
638
785
|
end
|
639
786
|
|
640
787
|
context "when attribute is not a string" do
|
641
788
|
|
642
789
|
it "adds a cast value to the attributes" do
|
643
|
-
person.attributes["nofieldint"].
|
790
|
+
expect(person.attributes["nofieldint"]).to eq(5)
|
644
791
|
end
|
645
792
|
end
|
646
793
|
end
|
647
794
|
|
648
795
|
context "when not allowing dynamic fields" do
|
649
796
|
|
650
|
-
|
651
|
-
{ nofieldstring: "Testing" }
|
652
|
-
end
|
653
|
-
|
654
|
-
before do
|
655
|
-
Mongoid.configure.allow_dynamic_fields = false
|
656
|
-
Person.fields.delete(:nofieldstring)
|
657
|
-
end
|
658
|
-
|
659
|
-
after do
|
660
|
-
Mongoid.configure.allow_dynamic_fields = true
|
661
|
-
end
|
662
|
-
|
663
|
-
it "raises an unknown attribute error" do
|
797
|
+
it "raises an unknown attribute error on instantiation" do
|
664
798
|
expect {
|
665
|
-
|
799
|
+
Account.new({ anothernew: "Test" })
|
666
800
|
}.to raise_error(Mongoid::Errors::UnknownAttribute)
|
667
801
|
end
|
668
802
|
end
|
@@ -671,7 +805,7 @@ describe Mongoid::Attributes do
|
|
671
805
|
context "when supplied hash has string values" do
|
672
806
|
|
673
807
|
let(:bson_id) do
|
674
|
-
|
808
|
+
BSON::ObjectId.new
|
675
809
|
end
|
676
810
|
|
677
811
|
let!(:attributes) do
|
@@ -695,15 +829,15 @@ describe Mongoid::Attributes do
|
|
695
829
|
end
|
696
830
|
|
697
831
|
it "casts integers" do
|
698
|
-
person[:age].
|
832
|
+
expect(person[:age]).to eq(30)
|
699
833
|
end
|
700
834
|
|
701
835
|
it "casts booleans" do
|
702
|
-
person[:terms].
|
836
|
+
expect(person[:terms]).to be true
|
703
837
|
end
|
704
838
|
|
705
839
|
it "sets empty strings to nil" do
|
706
|
-
person[:score].
|
840
|
+
expect(person[:score]).to be_nil
|
707
841
|
end
|
708
842
|
end
|
709
843
|
|
@@ -724,7 +858,7 @@ describe Mongoid::Attributes do
|
|
724
858
|
end
|
725
859
|
|
726
860
|
it "sets the associations" do
|
727
|
-
person.name.
|
861
|
+
expect(person.name).to eq(name)
|
728
862
|
end
|
729
863
|
end
|
730
864
|
|
@@ -743,11 +877,11 @@ describe Mongoid::Attributes do
|
|
743
877
|
end
|
744
878
|
|
745
879
|
it "sets the parent association" do
|
746
|
-
person.game.
|
880
|
+
expect(person.game).to eq(game)
|
747
881
|
end
|
748
882
|
|
749
883
|
it "sets the inverse association" do
|
750
|
-
game.person.
|
884
|
+
expect(game.person).to eq(person)
|
751
885
|
end
|
752
886
|
end
|
753
887
|
|
@@ -762,7 +896,7 @@ describe Mongoid::Attributes do
|
|
762
896
|
end
|
763
897
|
|
764
898
|
it "sets the association" do
|
765
|
-
name.person.
|
899
|
+
expect(name.person).to eq(person)
|
766
900
|
end
|
767
901
|
end
|
768
902
|
end
|
@@ -782,7 +916,7 @@ describe Mongoid::Attributes do
|
|
782
916
|
end
|
783
917
|
|
784
918
|
it "calls the setter for the association" do
|
785
|
-
person.employer_id.
|
919
|
+
expect(person.employer_id).to eq("1")
|
786
920
|
end
|
787
921
|
end
|
788
922
|
|
@@ -797,7 +931,7 @@ describe Mongoid::Attributes do
|
|
797
931
|
end
|
798
932
|
|
799
933
|
it "sets the empty array" do
|
800
|
-
person.aliases.
|
934
|
+
expect(person.aliases).to be_empty
|
801
935
|
end
|
802
936
|
end
|
803
937
|
|
@@ -812,7 +946,20 @@ describe Mongoid::Attributes do
|
|
812
946
|
end
|
813
947
|
|
814
948
|
it "sets the empty hash" do
|
815
|
-
person.map.
|
949
|
+
expect(person.map).to eq({})
|
950
|
+
end
|
951
|
+
end
|
952
|
+
|
953
|
+
context "when providing tainted parameters" do
|
954
|
+
|
955
|
+
let(:params) do
|
956
|
+
ActionController::Parameters.new(title: "sir")
|
957
|
+
end
|
958
|
+
|
959
|
+
it "raises an error" do
|
960
|
+
expect {
|
961
|
+
Person.new(params)
|
962
|
+
}.to raise_error(ActiveModel::ForbiddenAttributesError)
|
816
963
|
end
|
817
964
|
end
|
818
965
|
end
|
@@ -832,12 +979,23 @@ describe Mongoid::Attributes do
|
|
832
979
|
end
|
833
980
|
|
834
981
|
it "only overwrites supplied attributes" do
|
835
|
-
person.title.
|
982
|
+
expect(person.title).to eq("Sir")
|
836
983
|
end
|
837
984
|
end
|
838
985
|
|
839
986
|
describe "#read_attribute" do
|
840
987
|
|
988
|
+
context 'when the document has a custom attribute type' do
|
989
|
+
|
990
|
+
let(:bar) do
|
991
|
+
Bar.create!(lat_lng: LatLng.new(52.30, 13.25))
|
992
|
+
end
|
993
|
+
|
994
|
+
it 'returns the demongoized version of the attribute' do
|
995
|
+
expect(bar.reload.read_attribute(:lat_lng)).to be_a(LatLng)
|
996
|
+
end
|
997
|
+
end
|
998
|
+
|
841
999
|
context "when the document is a new record" do
|
842
1000
|
|
843
1001
|
let(:person) do
|
@@ -847,8 +1005,8 @@ describe Mongoid::Attributes do
|
|
847
1005
|
context "when attribute does not exist" do
|
848
1006
|
|
849
1007
|
it "returns the default value" do
|
850
|
-
person.age.
|
851
|
-
person.pets.
|
1008
|
+
expect(person.age).to eq(100)
|
1009
|
+
expect(person.pets).to be false
|
852
1010
|
end
|
853
1011
|
|
854
1012
|
end
|
@@ -860,7 +1018,7 @@ describe Mongoid::Attributes do
|
|
860
1018
|
end
|
861
1019
|
|
862
1020
|
it "returns the value" do
|
863
|
-
person.read_attribute(:owner_id).
|
1021
|
+
expect(person.read_attribute(:owner_id)).to eq(5)
|
864
1022
|
end
|
865
1023
|
end
|
866
1024
|
end
|
@@ -868,7 +1026,7 @@ describe Mongoid::Attributes do
|
|
868
1026
|
context "when the document is an existing record" do
|
869
1027
|
|
870
1028
|
let(:person) do
|
871
|
-
Person.create
|
1029
|
+
Person.create!
|
872
1030
|
end
|
873
1031
|
|
874
1032
|
context "when the attribute does not exist" do
|
@@ -876,40 +1034,99 @@ describe Mongoid::Attributes do
|
|
876
1034
|
before do
|
877
1035
|
person.collection
|
878
1036
|
.find({ _id: person.id })
|
879
|
-
.
|
1037
|
+
.update_one({ "$unset" => { age: 1 }})
|
880
1038
|
Mongoid.raise_not_found_error = false
|
881
1039
|
person.reload
|
882
1040
|
Mongoid.raise_not_found_error = true
|
883
1041
|
end
|
884
1042
|
|
885
1043
|
it "returns the default value" do
|
886
|
-
person.age.
|
1044
|
+
expect(person.age).to eq(100)
|
887
1045
|
end
|
888
1046
|
end
|
889
1047
|
end
|
1048
|
+
|
1049
|
+
context "when attribute has an aliased name" do
|
1050
|
+
|
1051
|
+
let(:person) do
|
1052
|
+
Person.new
|
1053
|
+
end
|
1054
|
+
|
1055
|
+
before(:each) do
|
1056
|
+
person.write_attribute(:t, "aliased field to test")
|
1057
|
+
end
|
1058
|
+
|
1059
|
+
it "returns the value of the aliased field" do
|
1060
|
+
expect(person.read_attribute(:test)).to eq("aliased field to test")
|
1061
|
+
end
|
1062
|
+
end
|
890
1063
|
end
|
891
1064
|
|
892
1065
|
describe "#read_attribute_before_type_cast" do
|
1066
|
+
|
893
1067
|
let(:person) do
|
894
|
-
Person.create
|
1068
|
+
Person.create!
|
895
1069
|
end
|
896
1070
|
|
897
1071
|
context "when the attribute has not yet been assigned" do
|
898
1072
|
|
899
1073
|
it "returns the default value" do
|
900
|
-
person.age_before_type_cast.
|
1074
|
+
expect(person.age_before_type_cast).to eq(100)
|
901
1075
|
end
|
902
1076
|
end
|
903
1077
|
|
904
1078
|
context "after the attribute has been assigned" do
|
905
1079
|
|
906
1080
|
it "returns the default value" do
|
907
|
-
person.age = "
|
908
|
-
person.age_before_type_cast.
|
1081
|
+
person.age = "42"
|
1082
|
+
expect(person.age_before_type_cast).to eq("42")
|
909
1083
|
end
|
910
1084
|
end
|
911
|
-
end
|
912
1085
|
|
1086
|
+
context 'when reading fields on a document with projection' do
|
1087
|
+
|
1088
|
+
let!(:person) do
|
1089
|
+
Person.create!(title: "sir")
|
1090
|
+
end
|
1091
|
+
|
1092
|
+
context "when excluding with only and the field was not excluded" do
|
1093
|
+
|
1094
|
+
let(:from_db) do
|
1095
|
+
Person.only(:_id).first
|
1096
|
+
end
|
1097
|
+
|
1098
|
+
it "raises an error" do
|
1099
|
+
expect {
|
1100
|
+
from_db.read_attribute(:undefined_field)
|
1101
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
1102
|
+
end
|
1103
|
+
end
|
1104
|
+
|
1105
|
+
context "when excluding with without and the field was excluded" do
|
1106
|
+
|
1107
|
+
let(:from_db) do
|
1108
|
+
Person.without(:title).first
|
1109
|
+
end
|
1110
|
+
|
1111
|
+
it "raises an error" do
|
1112
|
+
expect {
|
1113
|
+
from_db.read_attribute(:title)
|
1114
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
1115
|
+
end
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
context "when excluding with without and the field was not excluded" do
|
1119
|
+
|
1120
|
+
let(:from_db) do
|
1121
|
+
Person.without(:title).first
|
1122
|
+
end
|
1123
|
+
|
1124
|
+
it "returns nil" do
|
1125
|
+
from_db.read_attribute(:undefined_field).should be nil
|
1126
|
+
end
|
1127
|
+
end
|
1128
|
+
end
|
1129
|
+
end
|
913
1130
|
|
914
1131
|
describe "#attribute_present?" do
|
915
1132
|
|
@@ -922,7 +1139,7 @@ describe Mongoid::Attributes do
|
|
922
1139
|
context "when attribute does not exist" do
|
923
1140
|
|
924
1141
|
it "returns false" do
|
925
|
-
person.attribute_present?(:owner_id).
|
1142
|
+
expect(person.attribute_present?(:owner_id)).to be false
|
926
1143
|
end
|
927
1144
|
end
|
928
1145
|
|
@@ -932,7 +1149,7 @@ describe Mongoid::Attributes do
|
|
932
1149
|
end
|
933
1150
|
|
934
1151
|
it "returns true" do
|
935
|
-
person.attribute_present?(:owner_id).
|
1152
|
+
expect(person.attribute_present?(:owner_id)).to be true
|
936
1153
|
end
|
937
1154
|
end
|
938
1155
|
end
|
@@ -940,7 +1157,7 @@ describe Mongoid::Attributes do
|
|
940
1157
|
context "when the document is an existing record" do
|
941
1158
|
|
942
1159
|
let(:person) do
|
943
|
-
Person.create
|
1160
|
+
Person.create!
|
944
1161
|
end
|
945
1162
|
|
946
1163
|
context "when the attribute does not exist" do
|
@@ -948,14 +1165,14 @@ describe Mongoid::Attributes do
|
|
948
1165
|
before do
|
949
1166
|
person.collection
|
950
1167
|
.find({ _id: person.id })
|
951
|
-
.
|
1168
|
+
.update_one({ "$unset" => { age: 1 }})
|
952
1169
|
Mongoid.raise_not_found_error = false
|
953
1170
|
person.reload
|
954
1171
|
Mongoid.raise_not_found_error = true
|
955
1172
|
end
|
956
1173
|
|
957
1174
|
it "returns true" do
|
958
|
-
person.attribute_present?(:age).
|
1175
|
+
expect(person.attribute_present?(:age)).to be true
|
959
1176
|
end
|
960
1177
|
end
|
961
1178
|
end
|
@@ -972,7 +1189,7 @@ describe Mongoid::Attributes do
|
|
972
1189
|
|
973
1190
|
it "return true" do
|
974
1191
|
person.terms = false
|
975
|
-
person.attribute_present?(:terms).
|
1192
|
+
expect(person.attribute_present?(:terms)).to be true
|
976
1193
|
end
|
977
1194
|
end
|
978
1195
|
|
@@ -980,7 +1197,7 @@ describe Mongoid::Attributes do
|
|
980
1197
|
|
981
1198
|
it "return true" do
|
982
1199
|
person.terms = false
|
983
|
-
person.attribute_present?(:terms).
|
1200
|
+
expect(person.attribute_present?(:terms)).to be true
|
984
1201
|
end
|
985
1202
|
end
|
986
1203
|
end
|
@@ -993,7 +1210,19 @@ describe Mongoid::Attributes do
|
|
993
1210
|
end
|
994
1211
|
|
995
1212
|
it "return false" do
|
996
|
-
person.attribute_present?(:title).
|
1213
|
+
expect(person.attribute_present?(:title)).to be false
|
1214
|
+
end
|
1215
|
+
end
|
1216
|
+
|
1217
|
+
context "when the attribute is not on only list" do
|
1218
|
+
|
1219
|
+
before { Person.create! }
|
1220
|
+
let(:person) do
|
1221
|
+
Person.only(:id).first
|
1222
|
+
end
|
1223
|
+
|
1224
|
+
it "return false" do
|
1225
|
+
expect(person.attribute_present?(:foobar)).to be false
|
997
1226
|
end
|
998
1227
|
end
|
999
1228
|
end
|
@@ -1009,14 +1238,14 @@ describe Mongoid::Attributes do
|
|
1009
1238
|
context "when provided a symbol" do
|
1010
1239
|
|
1011
1240
|
it "returns true" do
|
1012
|
-
person.has_attribute?(:title).
|
1241
|
+
expect(person.has_attribute?(:title)).to be true
|
1013
1242
|
end
|
1014
1243
|
end
|
1015
1244
|
|
1016
1245
|
context "when provided a string" do
|
1017
1246
|
|
1018
1247
|
it "returns true" do
|
1019
|
-
person.has_attribute?("title").
|
1248
|
+
expect(person.has_attribute?("title")).to be true
|
1020
1249
|
end
|
1021
1250
|
end
|
1022
1251
|
end
|
@@ -1024,7 +1253,7 @@ describe Mongoid::Attributes do
|
|
1024
1253
|
context "when the key is not in the attributes" do
|
1025
1254
|
|
1026
1255
|
it "returns false" do
|
1027
|
-
person.has_attribute?(:employer_id).
|
1256
|
+
expect(person.has_attribute?(:employer_id)).to be false
|
1028
1257
|
end
|
1029
1258
|
end
|
1030
1259
|
end
|
@@ -1037,16 +1266,16 @@ describe Mongoid::Attributes do
|
|
1037
1266
|
|
1038
1267
|
context "before the attribute has been assigned" do
|
1039
1268
|
|
1040
|
-
it "returns
|
1041
|
-
person.has_attribute_before_type_cast?(:age).
|
1269
|
+
it "returns true" do
|
1270
|
+
expect(person.has_attribute_before_type_cast?(:age)).to be true
|
1042
1271
|
end
|
1043
1272
|
end
|
1044
1273
|
|
1045
1274
|
context "after the attribute has been assigned" do
|
1046
1275
|
|
1047
1276
|
it "returns true" do
|
1048
|
-
person.age = '
|
1049
|
-
person.has_attribute_before_type_cast?(:age).
|
1277
|
+
person.age = '42'
|
1278
|
+
expect(person.has_attribute_before_type_cast?(:age)).to be true
|
1050
1279
|
end
|
1051
1280
|
end
|
1052
1281
|
end
|
@@ -1056,7 +1285,7 @@ describe Mongoid::Attributes do
|
|
1056
1285
|
context "when the attribute exists" do
|
1057
1286
|
|
1058
1287
|
let(:person) do
|
1059
|
-
Person.create(title: "Sir")
|
1288
|
+
Person.create!(title: "Sir")
|
1060
1289
|
end
|
1061
1290
|
|
1062
1291
|
before do
|
@@ -1064,21 +1293,21 @@ describe Mongoid::Attributes do
|
|
1064
1293
|
end
|
1065
1294
|
|
1066
1295
|
it "removes the attribute" do
|
1067
|
-
person.title.
|
1296
|
+
expect(person.title).to be_nil
|
1068
1297
|
end
|
1069
1298
|
|
1070
1299
|
it "removes the key from the attributes hash" do
|
1071
|
-
person.has_attribute?(:title).
|
1300
|
+
expect(person.has_attribute?(:title)).to be false
|
1072
1301
|
end
|
1073
1302
|
|
1074
1303
|
context "when saving after the removal" do
|
1075
1304
|
|
1076
1305
|
before do
|
1077
|
-
person.save
|
1306
|
+
person.save!
|
1078
1307
|
end
|
1079
1308
|
|
1080
1309
|
it "persists the removal" do
|
1081
|
-
person.reload.has_attribute?(:title).
|
1310
|
+
expect(person.reload.has_attribute?(:title)).to be false
|
1082
1311
|
end
|
1083
1312
|
end
|
1084
1313
|
end
|
@@ -1094,26 +1323,26 @@ describe Mongoid::Attributes do
|
|
1094
1323
|
end
|
1095
1324
|
|
1096
1325
|
before do
|
1097
|
-
person.save
|
1326
|
+
person.save!
|
1098
1327
|
person.pet.remove_attribute(:name)
|
1099
1328
|
end
|
1100
1329
|
|
1101
1330
|
it "removes the attribute" do
|
1102
|
-
person.pet.name.
|
1331
|
+
expect(person.pet.name).to be_nil
|
1103
1332
|
end
|
1104
1333
|
|
1105
1334
|
it "removes the key from the attributes hash" do
|
1106
|
-
person.pet.has_attribute?(:name).
|
1335
|
+
expect(person.pet.has_attribute?(:name)).to be false
|
1107
1336
|
end
|
1108
1337
|
|
1109
1338
|
context "when saving after the removal" do
|
1110
1339
|
|
1111
1340
|
before do
|
1112
|
-
person.save
|
1341
|
+
person.save!
|
1113
1342
|
end
|
1114
1343
|
|
1115
1344
|
it "persists the removal" do
|
1116
|
-
person.reload.pet.has_attribute?(:name).
|
1345
|
+
expect(person.reload.pet.has_attribute?(:name)).to be false
|
1117
1346
|
end
|
1118
1347
|
end
|
1119
1348
|
|
@@ -1130,7 +1359,7 @@ describe Mongoid::Attributes do
|
|
1130
1359
|
end
|
1131
1360
|
|
1132
1361
|
it "does not fail" do
|
1133
|
-
person.title.
|
1362
|
+
expect(person.title).to be_nil
|
1134
1363
|
end
|
1135
1364
|
end
|
1136
1365
|
|
@@ -1145,7 +1374,70 @@ describe Mongoid::Attributes do
|
|
1145
1374
|
end
|
1146
1375
|
|
1147
1376
|
it "does not add a delayed unset operation" do
|
1148
|
-
person.delayed_atomic_unsets.
|
1377
|
+
expect(person.delayed_atomic_unsets).to be_empty
|
1378
|
+
end
|
1379
|
+
end
|
1380
|
+
|
1381
|
+
context "when the attribute is aliased" do
|
1382
|
+
|
1383
|
+
context 'when the database name is used' do
|
1384
|
+
|
1385
|
+
let(:person) do
|
1386
|
+
Person.create!(at: Time.now)
|
1387
|
+
end
|
1388
|
+
|
1389
|
+
before do
|
1390
|
+
person.remove_attribute(:at)
|
1391
|
+
end
|
1392
|
+
|
1393
|
+
it "removes the attribute" do
|
1394
|
+
expect(person.at).to be_nil
|
1395
|
+
end
|
1396
|
+
|
1397
|
+
it "removes the key from the attributes hash" do
|
1398
|
+
expect(person.has_attribute?(:at)).to be false
|
1399
|
+
end
|
1400
|
+
|
1401
|
+
context "when saving after the removal" do
|
1402
|
+
|
1403
|
+
before do
|
1404
|
+
person.save!
|
1405
|
+
end
|
1406
|
+
|
1407
|
+
it "persists the removal" do
|
1408
|
+
expect(person.reload.has_attribute?(:at)).to be false
|
1409
|
+
end
|
1410
|
+
end
|
1411
|
+
end
|
1412
|
+
|
1413
|
+
context 'when the alias is used' do
|
1414
|
+
|
1415
|
+
let(:person) do
|
1416
|
+
Person.create!(aliased_timestamp: Time.now)
|
1417
|
+
end
|
1418
|
+
|
1419
|
+
before do
|
1420
|
+
person.remove_attribute(:aliased_timestamp)
|
1421
|
+
end
|
1422
|
+
|
1423
|
+
it "removes the attribute" do
|
1424
|
+
expect(person.aliased_timestamp).to be_nil
|
1425
|
+
end
|
1426
|
+
|
1427
|
+
it "removes the key from the attributes hash" do
|
1428
|
+
expect(person.has_attribute?(:aliased_timestamp)).to be false
|
1429
|
+
end
|
1430
|
+
|
1431
|
+
context "when saving after the removal" do
|
1432
|
+
|
1433
|
+
before do
|
1434
|
+
person.save!
|
1435
|
+
end
|
1436
|
+
|
1437
|
+
it "persists the removal" do
|
1438
|
+
expect(person.reload.has_attribute?(:aliased_timestamp)).to be false
|
1439
|
+
end
|
1440
|
+
end
|
1149
1441
|
end
|
1150
1442
|
end
|
1151
1443
|
end
|
@@ -1158,10 +1450,6 @@ describe Mongoid::Attributes do
|
|
1158
1450
|
Person.new
|
1159
1451
|
end
|
1160
1452
|
|
1161
|
-
before(:all) do
|
1162
|
-
Mongoid.allow_dynamic_fields = true
|
1163
|
-
end
|
1164
|
-
|
1165
1453
|
context "when asking for the getter" do
|
1166
1454
|
|
1167
1455
|
context "when the attribute exists" do
|
@@ -1171,14 +1459,14 @@ describe Mongoid::Attributes do
|
|
1171
1459
|
end
|
1172
1460
|
|
1173
1461
|
it "returns true" do
|
1174
|
-
person.
|
1462
|
+
expect(person).to respond_to(:attr)
|
1175
1463
|
end
|
1176
1464
|
end
|
1177
1465
|
|
1178
1466
|
context "when the attribute does not exist" do
|
1179
1467
|
|
1180
1468
|
it "returns false" do
|
1181
|
-
person.
|
1469
|
+
expect(person).to_not respond_to(:attr)
|
1182
1470
|
end
|
1183
1471
|
end
|
1184
1472
|
end
|
@@ -1192,14 +1480,14 @@ describe Mongoid::Attributes do
|
|
1192
1480
|
end
|
1193
1481
|
|
1194
1482
|
it "returns true" do
|
1195
|
-
person.
|
1483
|
+
expect(person).to respond_to(:attr=)
|
1196
1484
|
end
|
1197
1485
|
end
|
1198
1486
|
|
1199
1487
|
context "when the attribute does not exist" do
|
1200
1488
|
|
1201
1489
|
it "returns false" do
|
1202
|
-
person.
|
1490
|
+
expect(person).to_not respond_to(:attr=)
|
1203
1491
|
end
|
1204
1492
|
end
|
1205
1493
|
end
|
@@ -1207,29 +1495,21 @@ describe Mongoid::Attributes do
|
|
1207
1495
|
|
1208
1496
|
context "when not allowing dynamic fields" do
|
1209
1497
|
|
1210
|
-
let(:
|
1211
|
-
|
1212
|
-
end
|
1213
|
-
|
1214
|
-
before(:all) do
|
1215
|
-
Mongoid.allow_dynamic_fields = false
|
1216
|
-
end
|
1217
|
-
|
1218
|
-
after(:all) do
|
1219
|
-
Mongoid.allow_dynamic_fields = true
|
1498
|
+
let(:bar) do
|
1499
|
+
Bar.new
|
1220
1500
|
end
|
1221
1501
|
|
1222
1502
|
context "when asking for the getter" do
|
1223
1503
|
|
1224
1504
|
it "returns false" do
|
1225
|
-
|
1505
|
+
expect(bar).to_not respond_to(:attr)
|
1226
1506
|
end
|
1227
1507
|
end
|
1228
1508
|
|
1229
1509
|
context "when asking for the setter" do
|
1230
1510
|
|
1231
1511
|
it "returns false" do
|
1232
|
-
|
1512
|
+
expect(bar).to_not respond_to(:attr=)
|
1233
1513
|
end
|
1234
1514
|
end
|
1235
1515
|
end
|
@@ -1244,17 +1524,18 @@ describe Mongoid::Attributes do
|
|
1244
1524
|
end
|
1245
1525
|
|
1246
1526
|
it "returns the default value" do
|
1247
|
-
person.age.
|
1527
|
+
expect(person.age).to eq(100)
|
1248
1528
|
end
|
1249
1529
|
end
|
1250
1530
|
|
1251
1531
|
context "when setting an attribute that needs type casting" do
|
1532
|
+
|
1252
1533
|
let(:person) do
|
1253
|
-
Person.new(age: "
|
1534
|
+
Person.new(age: "42")
|
1254
1535
|
end
|
1255
1536
|
|
1256
1537
|
it "should store the attribute before type cast" do
|
1257
|
-
person.age_before_type_cast.
|
1538
|
+
expect(person.age_before_type_cast).to eq("42")
|
1258
1539
|
end
|
1259
1540
|
end
|
1260
1541
|
|
@@ -1265,7 +1546,7 @@ describe Mongoid::Attributes do
|
|
1265
1546
|
end
|
1266
1547
|
|
1267
1548
|
it "does not use the default value" do
|
1268
|
-
person.age.
|
1549
|
+
expect(person.age).to be_nil
|
1269
1550
|
end
|
1270
1551
|
end
|
1271
1552
|
|
@@ -1280,7 +1561,7 @@ describe Mongoid::Attributes do
|
|
1280
1561
|
end
|
1281
1562
|
|
1282
1563
|
it "allows overwriting of the default value" do
|
1283
|
-
person.terms.
|
1564
|
+
expect(person.terms).to be true
|
1284
1565
|
end
|
1285
1566
|
end
|
1286
1567
|
|
@@ -1294,8 +1575,146 @@ describe Mongoid::Attributes do
|
|
1294
1575
|
person.write_attribute(:test, "aliased field to test")
|
1295
1576
|
end
|
1296
1577
|
|
1297
|
-
it "allows the field name to be
|
1298
|
-
person.t.
|
1578
|
+
it "allows the field name to be updated" do
|
1579
|
+
expect(person.t).to eq("aliased field to test")
|
1580
|
+
end
|
1581
|
+
end
|
1582
|
+
|
1583
|
+
context "when attribute is a Hash" do
|
1584
|
+
let(:person) { Person.new map: { somekey: "somevalue" } }
|
1585
|
+
|
1586
|
+
it "writes nil when trying to set a value of invalid type - array" do
|
1587
|
+
person.map = []
|
1588
|
+
expect(person.map).to be_nil
|
1589
|
+
end
|
1590
|
+
|
1591
|
+
it "writes nil when trying to set a value of invalid type - boolean" do
|
1592
|
+
person.map = false
|
1593
|
+
expect(person.map).to be_nil
|
1594
|
+
end
|
1595
|
+
|
1596
|
+
it "can set a Hash value" do
|
1597
|
+
expect(person.map).to eq( { somekey: "somevalue" } )
|
1598
|
+
end
|
1599
|
+
end
|
1600
|
+
|
1601
|
+
context "when attribute is an Array" do
|
1602
|
+
let(:person) { Person.new aliases: [ :alias_1 ] }
|
1603
|
+
|
1604
|
+
it "can set an Array Value" do
|
1605
|
+
expect(person.aliases).to eq([ :alias_1 ])
|
1606
|
+
end
|
1607
|
+
|
1608
|
+
it "writes nil when trying to set a value of invalid type - hash" do
|
1609
|
+
person.aliases = {}
|
1610
|
+
expect(person.aliases).to be_nil
|
1611
|
+
end
|
1612
|
+
|
1613
|
+
it "writes nil when trying to set a value of invalid type - boolean" do
|
1614
|
+
person.aliases = false
|
1615
|
+
expect(person.aliases).to be_nil
|
1616
|
+
end
|
1617
|
+
end
|
1618
|
+
|
1619
|
+
context "when attribute is localized and #attributes is a BSON::Document" do
|
1620
|
+
let(:dictionary) { Dictionary.new }
|
1621
|
+
|
1622
|
+
before do
|
1623
|
+
allow(dictionary).to receive(:attributes).and_return(BSON::Document.new)
|
1624
|
+
end
|
1625
|
+
|
1626
|
+
it "sets the value for the current locale" do
|
1627
|
+
dictionary.write_attribute(:description, 'foo')
|
1628
|
+
expect(dictionary.description).to eq('foo')
|
1629
|
+
end
|
1630
|
+
end
|
1631
|
+
|
1632
|
+
context 'when writing fields on a document with projection' do
|
1633
|
+
|
1634
|
+
let!(:person) do
|
1635
|
+
Person.create!(title: "sir")
|
1636
|
+
end
|
1637
|
+
|
1638
|
+
context "when excluding with only and the field was not excluded" do
|
1639
|
+
|
1640
|
+
let(:from_db) do
|
1641
|
+
Person.only(:_id).first
|
1642
|
+
end
|
1643
|
+
|
1644
|
+
it "raises an error" do
|
1645
|
+
expect {
|
1646
|
+
from_db.write_attribute(:undefined_field, 'x')
|
1647
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
1648
|
+
end
|
1649
|
+
end
|
1650
|
+
|
1651
|
+
context "when excluding with without and the field was excluded" do
|
1652
|
+
|
1653
|
+
let(:from_db) do
|
1654
|
+
Person.without(:title).first
|
1655
|
+
end
|
1656
|
+
|
1657
|
+
it "raises an error" do
|
1658
|
+
expect {
|
1659
|
+
from_db.write_attribute(:title, 'x')
|
1660
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
1661
|
+
end
|
1662
|
+
end
|
1663
|
+
|
1664
|
+
context "when excluding with without and the field was not excluded" do
|
1665
|
+
|
1666
|
+
let(:from_db) do
|
1667
|
+
Person.without(:title).first
|
1668
|
+
end
|
1669
|
+
|
1670
|
+
it "writes the value" do
|
1671
|
+
from_db.write_attribute(:undefined_field, 'x')
|
1672
|
+
from_db.read_attribute(:undefined_field).should == 'x'
|
1673
|
+
end
|
1674
|
+
end
|
1675
|
+
end
|
1676
|
+
|
1677
|
+
context "when comparing the object_ids of the written value" do
|
1678
|
+
config_override :legacy_attributes, false
|
1679
|
+
|
1680
|
+
before do
|
1681
|
+
Person.create!
|
1682
|
+
end
|
1683
|
+
|
1684
|
+
let(:person) do
|
1685
|
+
Person.first
|
1686
|
+
end
|
1687
|
+
|
1688
|
+
context "when the field is not resizable" do
|
1689
|
+
let(:test) do
|
1690
|
+
person.write_attribute(:test, "aliased field to test")
|
1691
|
+
end
|
1692
|
+
|
1693
|
+
it "has the same object_id as the attributes hash value" do
|
1694
|
+
expect(test.object_id).to eq(person.test.object_id)
|
1695
|
+
end
|
1696
|
+
end
|
1697
|
+
|
1698
|
+
context "when the field is resizable" do
|
1699
|
+
|
1700
|
+
let(:arrays) do
|
1701
|
+
person.write_attribute(:arrays, [])
|
1702
|
+
end
|
1703
|
+
|
1704
|
+
it "has the same object_id as the attributes hash value" do
|
1705
|
+
expect(arrays.object_id).to eq(person.arrays.object_id)
|
1706
|
+
end
|
1707
|
+
end
|
1708
|
+
|
1709
|
+
context "when the field is a HABTM foreign key array" do
|
1710
|
+
|
1711
|
+
let(:preference_ids) do
|
1712
|
+
person.write_attribute(:preference_ids, [])
|
1713
|
+
end
|
1714
|
+
|
1715
|
+
it "has the same object_id as the attributes hash value" do
|
1716
|
+
expect(preference_ids.object_id).to eq(person.preference_ids.object_id)
|
1717
|
+
end
|
1299
1718
|
end
|
1300
1719
|
end
|
1301
1720
|
end
|
@@ -1316,11 +1735,11 @@ describe Mongoid::Attributes do
|
|
1316
1735
|
context "when the key has not been specified as a field" do
|
1317
1736
|
|
1318
1737
|
before do
|
1319
|
-
person.
|
1738
|
+
allow(person).to receive(:fields).and_return({})
|
1320
1739
|
end
|
1321
1740
|
|
1322
1741
|
it "returns the value" do
|
1323
|
-
person.send(:typed_value_for, "age", "51").
|
1742
|
+
person.send(:typed_value_for, "age", expect("51")).to eq("51")
|
1324
1743
|
end
|
1325
1744
|
end
|
1326
1745
|
end
|
@@ -1332,7 +1751,22 @@ describe Mongoid::Attributes do
|
|
1332
1751
|
end
|
1333
1752
|
|
1334
1753
|
it "typecasts proc values" do
|
1335
|
-
person.age.
|
1754
|
+
expect(person.age).to eq(100)
|
1755
|
+
end
|
1756
|
+
end
|
1757
|
+
|
1758
|
+
describe "#typed_attributes" do
|
1759
|
+
|
1760
|
+
let(:date_time) do
|
1761
|
+
DateTime.current
|
1762
|
+
end
|
1763
|
+
|
1764
|
+
let(:user) do
|
1765
|
+
User.new(last_login: date_time)
|
1766
|
+
end
|
1767
|
+
|
1768
|
+
it 'returns typecasted attributes' do
|
1769
|
+
expect(user.typed_attributes).to include("last_login" => date_time)
|
1336
1770
|
end
|
1337
1771
|
end
|
1338
1772
|
|
@@ -1351,7 +1785,7 @@ describe Mongoid::Attributes do
|
|
1351
1785
|
end
|
1352
1786
|
|
1353
1787
|
it "sets nested documents" do
|
1354
|
-
person.videos.first.title.
|
1788
|
+
expect(person.videos.first.title).to eq("Fight Club")
|
1355
1789
|
end
|
1356
1790
|
end
|
1357
1791
|
|
@@ -1372,7 +1806,7 @@ describe Mongoid::Attributes do
|
|
1372
1806
|
end
|
1373
1807
|
|
1374
1808
|
it "properly casts values" do
|
1375
|
-
person.age.
|
1809
|
+
expect(person.age).to eq(50)
|
1376
1810
|
end
|
1377
1811
|
end
|
1378
1812
|
|
@@ -1383,11 +1817,38 @@ describe Mongoid::Attributes do
|
|
1383
1817
|
end
|
1384
1818
|
|
1385
1819
|
it "does not set anything" do
|
1386
|
-
person.age.
|
1820
|
+
expect(person.age).to eq(100)
|
1387
1821
|
end
|
1388
1822
|
end
|
1389
1823
|
end
|
1390
1824
|
|
1825
|
+
context "copying from instance" do
|
1826
|
+
|
1827
|
+
let(:person) do
|
1828
|
+
Person.new
|
1829
|
+
end
|
1830
|
+
|
1831
|
+
let(:instance) do
|
1832
|
+
Person.new(attributes)
|
1833
|
+
end
|
1834
|
+
|
1835
|
+
let(:attributes) do
|
1836
|
+
{ age: 50, range: 1..100 }
|
1837
|
+
end
|
1838
|
+
|
1839
|
+
before do
|
1840
|
+
person.send(method, instance.attributes)
|
1841
|
+
end
|
1842
|
+
|
1843
|
+
it "properly copies values" do
|
1844
|
+
expect(person.age).to eq(50)
|
1845
|
+
end
|
1846
|
+
|
1847
|
+
it "properly copies ranges" do
|
1848
|
+
expect(person.range).to eq(1..100)
|
1849
|
+
end
|
1850
|
+
end
|
1851
|
+
|
1391
1852
|
context "on a parent document" do
|
1392
1853
|
|
1393
1854
|
context "when the parent has a has many through a has one" do
|
@@ -1411,8 +1872,8 @@ describe Mongoid::Attributes do
|
|
1411
1872
|
end
|
1412
1873
|
|
1413
1874
|
it "does not overwrite child attributes if not in the hash" do
|
1414
|
-
owner.pet.name.
|
1415
|
-
owner.pet.vet_visits.size.
|
1875
|
+
expect(owner.pet.name).to eq("Bingo")
|
1876
|
+
expect(owner.pet.vet_visits.size).to eq(1)
|
1416
1877
|
end
|
1417
1878
|
end
|
1418
1879
|
|
@@ -1436,11 +1897,11 @@ describe Mongoid::Attributes do
|
|
1436
1897
|
end
|
1437
1898
|
|
1438
1899
|
it "has 3 new entries" do
|
1439
|
-
pet.vet_visits.count.
|
1900
|
+
expect(pet.vet_visits.count).to eq 3
|
1440
1901
|
end
|
1441
1902
|
|
1442
1903
|
it "persists the changes" do
|
1443
|
-
pet.reload.vet_visits.count.
|
1904
|
+
expect(pet.reload.vet_visits.count).to eq 3
|
1444
1905
|
end
|
1445
1906
|
end
|
1446
1907
|
|
@@ -1478,7 +1939,7 @@ describe Mongoid::Attributes do
|
|
1478
1939
|
end
|
1479
1940
|
|
1480
1941
|
it "sets the child attributes on the parent" do
|
1481
|
-
name.attributes.
|
1942
|
+
expect(name.attributes).to eq(
|
1482
1943
|
{ "_id" => "Test-User", "first_name" => "Test2", "last_name" => "User2" }
|
1483
1944
|
)
|
1484
1945
|
end
|
@@ -1500,7 +1961,7 @@ describe Mongoid::Attributes do
|
|
1500
1961
|
end
|
1501
1962
|
|
1502
1963
|
it "updates the child attributes on the parent" do
|
1503
|
-
address.attributes.
|
1964
|
+
expect(address.attributes).to eq(
|
1504
1965
|
{ "_id" => "test", "street" => "Test2" }
|
1505
1966
|
)
|
1506
1967
|
end
|
@@ -1509,6 +1970,61 @@ describe Mongoid::Attributes do
|
|
1509
1970
|
end
|
1510
1971
|
end
|
1511
1972
|
|
1973
|
+
describe '#unalias_attribute' do
|
1974
|
+
let(:shirt) { Shirt.new }
|
1975
|
+
let(:id) { '1234' }
|
1976
|
+
|
1977
|
+
context 'when creating object' do
|
1978
|
+
let(:shirt) { Shirt.new(id: id) }
|
1979
|
+
|
1980
|
+
it 'id and _id are not the same' do
|
1981
|
+
expect(shirt.id).to eq(id)
|
1982
|
+
expect(shirt._id).not_to eq(id)
|
1983
|
+
end
|
1984
|
+
end
|
1985
|
+
|
1986
|
+
context 'update' do
|
1987
|
+
before do
|
1988
|
+
shirt.update(id: id)
|
1989
|
+
end
|
1990
|
+
|
1991
|
+
it 'updates id but not_id' do
|
1992
|
+
expect(shirt.id).to eq(id)
|
1993
|
+
expect(shirt._id).not_to eq(id)
|
1994
|
+
end
|
1995
|
+
end
|
1996
|
+
|
1997
|
+
context 'id=' do
|
1998
|
+
before do
|
1999
|
+
shirt.id = id
|
2000
|
+
end
|
2001
|
+
|
2002
|
+
it 'sets id and not _id' do
|
2003
|
+
expect(shirt.id).to eq(id)
|
2004
|
+
expect(shirt._id).not_to eq(id)
|
2005
|
+
end
|
2006
|
+
end
|
2007
|
+
|
2008
|
+
context 'id?' do
|
2009
|
+
context 'with null id' do
|
2010
|
+
it 'returns false' do
|
2011
|
+
expect(shirt.id?).to be false
|
2012
|
+
expect(shirt._id?).to be true
|
2013
|
+
end
|
2014
|
+
end
|
2015
|
+
|
2016
|
+
context 'with id' do
|
2017
|
+
before do
|
2018
|
+
shirt.id = id
|
2019
|
+
end
|
2020
|
+
|
2021
|
+
it 'returns true' do
|
2022
|
+
expect(shirt.id?).to be true
|
2023
|
+
end
|
2024
|
+
end
|
2025
|
+
end
|
2026
|
+
end
|
2027
|
+
|
1512
2028
|
describe "#alias_attribute" do
|
1513
2029
|
|
1514
2030
|
let(:product) do
|
@@ -1521,38 +2037,42 @@ describe Mongoid::Attributes do
|
|
1521
2037
|
product.cost = 500
|
1522
2038
|
end
|
1523
2039
|
|
2040
|
+
it "adds the alias for criteria" do
|
2041
|
+
expect(Product.where(cost: 500).selector).to eq("price" => 500)
|
2042
|
+
end
|
2043
|
+
|
1524
2044
|
it "aliases the getter" do
|
1525
|
-
product.cost.
|
2045
|
+
expect(product.cost).to eq(500)
|
1526
2046
|
end
|
1527
2047
|
|
1528
|
-
it "aliases the
|
1529
|
-
product.cost
|
2048
|
+
it "aliases the existence check" do
|
2049
|
+
expect(product.cost?).to be true
|
1530
2050
|
end
|
1531
2051
|
|
1532
2052
|
it "aliases *_changed?" do
|
1533
|
-
product.cost_changed
|
2053
|
+
expect(product.cost_changed?).to be true
|
1534
2054
|
end
|
1535
2055
|
|
1536
2056
|
it "aliases *_change" do
|
1537
|
-
product.cost_change.
|
2057
|
+
expect(product.cost_change).to eq([ nil, 500 ])
|
1538
2058
|
end
|
1539
2059
|
|
1540
2060
|
it "aliases *_will_change!" do
|
1541
|
-
product.
|
2061
|
+
expect(product).to respond_to(:cost_will_change!)
|
1542
2062
|
end
|
1543
2063
|
|
1544
2064
|
it "aliases *_was" do
|
1545
|
-
product.cost_was.
|
2065
|
+
expect(product.cost_was).to be_nil
|
1546
2066
|
end
|
1547
2067
|
|
1548
2068
|
it "aliases reset_*!" do
|
1549
2069
|
product.reset_cost!
|
1550
|
-
product.cost.
|
2070
|
+
expect(product.cost).to be_nil
|
1551
2071
|
end
|
1552
2072
|
|
1553
2073
|
it "aliases *_before_type_cast" do
|
1554
|
-
product.cost = "
|
1555
|
-
product.cost_before_type_cast.
|
2074
|
+
product.cost = "42"
|
2075
|
+
expect(product.cost_before_type_cast).to eq("42")
|
1556
2076
|
end
|
1557
2077
|
end
|
1558
2078
|
|
@@ -1563,32 +2083,32 @@ describe Mongoid::Attributes do
|
|
1563
2083
|
end
|
1564
2084
|
|
1565
2085
|
it "aliases the getter" do
|
1566
|
-
product.price.
|
2086
|
+
expect(product.price).to eq(500)
|
1567
2087
|
end
|
1568
2088
|
|
1569
|
-
it "aliases the
|
1570
|
-
product.price
|
2089
|
+
it "aliases the existence check" do
|
2090
|
+
expect(product.price?).to be true
|
1571
2091
|
end
|
1572
2092
|
|
1573
2093
|
it "aliases *_changed?" do
|
1574
|
-
product.price_changed
|
2094
|
+
expect(product.price_changed?).to be true
|
1575
2095
|
end
|
1576
2096
|
|
1577
2097
|
it "aliases *_change" do
|
1578
|
-
product.price_change.
|
2098
|
+
expect(product.price_change).to eq([ nil, 500 ])
|
1579
2099
|
end
|
1580
2100
|
|
1581
2101
|
it "aliases *_will_change!" do
|
1582
|
-
product.
|
2102
|
+
expect(product).to respond_to(:price_will_change!)
|
1583
2103
|
end
|
1584
2104
|
|
1585
2105
|
it "aliases *_was" do
|
1586
|
-
product.price_was.
|
2106
|
+
expect(product.price_was).to be_nil
|
1587
2107
|
end
|
1588
2108
|
|
1589
2109
|
it "aliases reset_*!" do
|
1590
2110
|
product.reset_price!
|
1591
|
-
product.price.
|
2111
|
+
expect(product.price).to be_nil
|
1592
2112
|
end
|
1593
2113
|
end
|
1594
2114
|
end
|
@@ -1596,11 +2116,11 @@ describe Mongoid::Attributes do
|
|
1596
2116
|
context "when persisting nil attributes" do
|
1597
2117
|
|
1598
2118
|
let!(:person) do
|
1599
|
-
Person.create(score: nil)
|
2119
|
+
Person.create!(score: nil)
|
1600
2120
|
end
|
1601
2121
|
|
1602
2122
|
it "has an entry in the attributes" do
|
1603
|
-
person.reload.attributes.
|
2123
|
+
expect(person.reload.attributes).to have_key("score")
|
1604
2124
|
end
|
1605
2125
|
end
|
1606
2126
|
|
@@ -1611,8 +2131,8 @@ describe Mongoid::Attributes do
|
|
1611
2131
|
end
|
1612
2132
|
|
1613
2133
|
it "saves the default" do
|
1614
|
-
expect { person.save }.to_not raise_error
|
1615
|
-
person.last_drink_taken_at.
|
2134
|
+
expect { person.save! }.to_not raise_error
|
2135
|
+
expect(person.last_drink_taken_at).to eq(1.day.ago.in_time_zone("Alaska").to_date)
|
1616
2136
|
end
|
1617
2137
|
end
|
1618
2138
|
|
@@ -1621,11 +2141,11 @@ describe Mongoid::Attributes do
|
|
1621
2141
|
context "when no value exists in the database" do
|
1622
2142
|
|
1623
2143
|
let(:person) do
|
1624
|
-
Person.create
|
2144
|
+
Person.create!
|
1625
2145
|
end
|
1626
2146
|
|
1627
2147
|
it "applies the default value" do
|
1628
|
-
person.last_drink_taken_at.
|
2148
|
+
expect(person.last_drink_taken_at).to eq(1.day.ago.in_time_zone("Alaska").to_date)
|
1629
2149
|
end
|
1630
2150
|
end
|
1631
2151
|
|
@@ -1634,7 +2154,7 @@ describe Mongoid::Attributes do
|
|
1634
2154
|
context "when the value is not nil" do
|
1635
2155
|
|
1636
2156
|
let!(:person) do
|
1637
|
-
Person.create(age: 50)
|
2157
|
+
Person.create!(age: 50)
|
1638
2158
|
end
|
1639
2159
|
|
1640
2160
|
let(:from_db) do
|
@@ -1642,14 +2162,14 @@ describe Mongoid::Attributes do
|
|
1642
2162
|
end
|
1643
2163
|
|
1644
2164
|
it "does not set the default" do
|
1645
|
-
from_db.age.
|
2165
|
+
expect(from_db.age).to eq(50)
|
1646
2166
|
end
|
1647
2167
|
end
|
1648
2168
|
|
1649
2169
|
context "when the value is explicitly nil" do
|
1650
2170
|
|
1651
2171
|
let!(:person) do
|
1652
|
-
Person.create(age: nil)
|
2172
|
+
Person.create!(age: nil)
|
1653
2173
|
end
|
1654
2174
|
|
1655
2175
|
let(:from_db) do
|
@@ -1657,14 +2177,14 @@ describe Mongoid::Attributes do
|
|
1657
2177
|
end
|
1658
2178
|
|
1659
2179
|
it "does not set the default" do
|
1660
|
-
from_db.age.
|
2180
|
+
expect(from_db.age).to be_nil
|
1661
2181
|
end
|
1662
2182
|
end
|
1663
2183
|
|
1664
2184
|
context "when the default is a proc" do
|
1665
2185
|
|
1666
2186
|
let!(:account) do
|
1667
|
-
Account.create(name: "savings", balance:
|
2187
|
+
Account.create!(name: "savings", balance: 100)
|
1668
2188
|
end
|
1669
2189
|
|
1670
2190
|
let(:from_db) do
|
@@ -1672,34 +2192,523 @@ describe Mongoid::Attributes do
|
|
1672
2192
|
end
|
1673
2193
|
|
1674
2194
|
it "applies the defaults after all attributes are set" do
|
1675
|
-
from_db.
|
2195
|
+
expect(from_db).to be_balanced
|
2196
|
+
end
|
2197
|
+
end
|
2198
|
+
end
|
2199
|
+
end
|
2200
|
+
|
2201
|
+
context 'when calling the attribute check method' do
|
2202
|
+
|
2203
|
+
context 'when the attribute is blank' do
|
2204
|
+
let(:person) do
|
2205
|
+
Person.create!(title: '')
|
2206
|
+
end
|
2207
|
+
|
2208
|
+
it 'returns false' do
|
2209
|
+
expect(person.title?).to be(false)
|
2210
|
+
end
|
2211
|
+
end
|
2212
|
+
|
2213
|
+
context 'when the attribute is localized' do
|
2214
|
+
let(:person) do
|
2215
|
+
Person.create!
|
2216
|
+
end
|
2217
|
+
|
2218
|
+
context 'after initialization when the field is nil' do
|
2219
|
+
|
2220
|
+
it 'returns false' do
|
2221
|
+
expect(person.desc?).to be(false)
|
2222
|
+
end
|
2223
|
+
end
|
2224
|
+
|
2225
|
+
context 'when setting the field to nil' do
|
2226
|
+
|
2227
|
+
it 'applies the localization when checking the attribute' do
|
2228
|
+
person.desc = nil
|
2229
|
+
expect(person.desc?).to be(false)
|
2230
|
+
end
|
2231
|
+
end
|
2232
|
+
|
2233
|
+
context 'when the field is a boolean' do
|
2234
|
+
|
2235
|
+
before do
|
2236
|
+
person.desc = false
|
2237
|
+
end
|
2238
|
+
|
2239
|
+
it 'applies the localization when checking the attribute' do
|
2240
|
+
expect(person.desc?).to be(false)
|
1676
2241
|
end
|
1677
2242
|
end
|
1678
2243
|
end
|
2244
|
+
|
2245
|
+
context 'when the attribute is not localized' do
|
2246
|
+
let(:person) do
|
2247
|
+
Person.create!(username: 'localized')
|
2248
|
+
end
|
2249
|
+
|
2250
|
+
before do
|
2251
|
+
person.username = nil
|
2252
|
+
end
|
2253
|
+
|
2254
|
+
it 'does not apply localization when checking the attribute' do
|
2255
|
+
expect(person.username?).to be(false)
|
2256
|
+
end
|
2257
|
+
end
|
1679
2258
|
end
|
1680
2259
|
|
1681
|
-
context "when
|
2260
|
+
context "when an attribute is removed then set" do
|
2261
|
+
let(:cat) { Cat.create!(name: "Neil") }
|
1682
2262
|
|
1683
2263
|
before do
|
1684
|
-
|
2264
|
+
cat.remove_attribute("name")
|
2265
|
+
cat.name = "Nissim"
|
2266
|
+
cat.save!
|
2267
|
+
cat.reload
|
1685
2268
|
end
|
1686
2269
|
|
1687
|
-
|
1688
|
-
|
2270
|
+
it "correctly sets the attribute" do
|
2271
|
+
expect(cat.name).to eq("Nissim")
|
2272
|
+
end
|
2273
|
+
end
|
2274
|
+
|
2275
|
+
describe "attributes after setting an association without reloading" do
|
2276
|
+
|
2277
|
+
context "on embeds_many" do
|
2278
|
+
|
2279
|
+
context "when not setting anything" do
|
2280
|
+
let(:doc) { NestedBook.create! }
|
2281
|
+
|
2282
|
+
it "doesn't add attributes" do
|
2283
|
+
expect(doc.attributes).to_not have_key("pages")
|
2284
|
+
end
|
2285
|
+
|
2286
|
+
it "has the same attributes after reloading" do
|
2287
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2288
|
+
end
|
2289
|
+
end
|
2290
|
+
|
2291
|
+
context "when using nested attributes" do
|
2292
|
+
let(:doc) { NestedBook.create! }
|
2293
|
+
|
2294
|
+
before do
|
2295
|
+
doc.update_attributes({ pages_attributes: [ {} ] })
|
2296
|
+
end
|
2297
|
+
|
2298
|
+
it "updates the attributes" do
|
2299
|
+
expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
|
2300
|
+
end
|
2301
|
+
|
2302
|
+
it "has the same attributes after reloading" do
|
2303
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2304
|
+
end
|
2305
|
+
end
|
2306
|
+
|
2307
|
+
context "when doing assignments" do
|
2308
|
+
let(:doc) { NestedBook.create! }
|
2309
|
+
before do
|
2310
|
+
doc.pages = [NestedPage.new]
|
2311
|
+
end
|
2312
|
+
|
2313
|
+
it "updates the attributes" do
|
2314
|
+
expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
|
2315
|
+
end
|
2316
|
+
|
2317
|
+
it "has the same attributes after reloading" do
|
2318
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2319
|
+
end
|
2320
|
+
end
|
2321
|
+
|
2322
|
+
context "when replacing assignments" do
|
2323
|
+
let(:doc) { NestedBook.create! }
|
2324
|
+
before do
|
2325
|
+
doc.pages = [NestedPage.new(number: 1)]
|
2326
|
+
doc.pages = [NestedPage.new(number: 2)]
|
2327
|
+
end
|
2328
|
+
|
2329
|
+
it "updates the attributes" do
|
2330
|
+
expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id, "number" => 2 }])
|
2331
|
+
end
|
2332
|
+
|
2333
|
+
it "has the same attributes after reloading" do
|
2334
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2335
|
+
end
|
2336
|
+
end
|
2337
|
+
|
2338
|
+
context "when setting to nil" do
|
2339
|
+
let(:doc) { NestedBook.create! }
|
2340
|
+
before do
|
2341
|
+
doc.pages = [NestedPage.new(number: 1)]
|
2342
|
+
doc.pages = nil
|
2343
|
+
end
|
2344
|
+
|
2345
|
+
it "updates the attributes" do
|
2346
|
+
expect(doc.attributes).to_not have_key("pages")
|
2347
|
+
end
|
2348
|
+
|
2349
|
+
it "has the same attributes after reloading" do
|
2350
|
+
expect({ "pages" => [] }.merge(doc.attributes)).to eq(doc.reload.attributes)
|
2351
|
+
end
|
2352
|
+
end
|
2353
|
+
|
2354
|
+
context "when setting to nil and back" do
|
2355
|
+
let(:doc) { NestedBook.create! }
|
2356
|
+
let(:page) { NestedPage.new }
|
2357
|
+
before do
|
2358
|
+
doc.pages = [page]
|
2359
|
+
doc.pages = nil
|
2360
|
+
doc.pages = [page]
|
2361
|
+
end
|
2362
|
+
|
2363
|
+
it "updates the attributes" do
|
2364
|
+
expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
|
2365
|
+
end
|
2366
|
+
|
2367
|
+
it "has the same attributes after reloading" do
|
2368
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2369
|
+
end
|
2370
|
+
end
|
2371
|
+
|
2372
|
+
context "when pushing" do
|
2373
|
+
let(:doc) { NestedBook.create! }
|
2374
|
+
before do
|
2375
|
+
doc.pages << NestedPage.new
|
2376
|
+
end
|
2377
|
+
|
2378
|
+
it "updates the attributes" do
|
2379
|
+
expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
|
2380
|
+
end
|
2381
|
+
|
2382
|
+
it "has the same attributes after reloading" do
|
2383
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2384
|
+
end
|
2385
|
+
end
|
2386
|
+
|
2387
|
+
[:shift, :pop].each do |meth|
|
2388
|
+
context "when performing #{meth}" do
|
2389
|
+
let(:doc) { NestedBook.create! }
|
2390
|
+
before do
|
2391
|
+
doc.pages << NestedPage.new
|
2392
|
+
doc.pages << NestedPage.new
|
2393
|
+
doc.pages << NestedPage.new
|
2394
|
+
|
2395
|
+
doc.pages.send(meth, 2)
|
2396
|
+
end
|
2397
|
+
|
2398
|
+
it "updates the attributes" do
|
2399
|
+
expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
|
2400
|
+
end
|
2401
|
+
|
2402
|
+
it "has the same attributes after reloading" do
|
2403
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2404
|
+
end
|
2405
|
+
end
|
2406
|
+
end
|
2407
|
+
|
2408
|
+
context "when concatting" do
|
2409
|
+
let(:doc) { NestedBook.create! }
|
2410
|
+
before do
|
2411
|
+
doc.pages << NestedPage.new
|
2412
|
+
doc.pages.concat([NestedPage.new, NestedPage.new])
|
2413
|
+
end
|
2414
|
+
|
2415
|
+
it "updates the attributes" do
|
2416
|
+
expect(doc.attributes["pages"].count).to eq 3
|
2417
|
+
end
|
2418
|
+
|
2419
|
+
it "has the same attributes after reloading" do
|
2420
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2421
|
+
end
|
2422
|
+
end
|
2423
|
+
|
2424
|
+
[:build, :create].each do |meth|
|
2425
|
+
context "when preforming #{meth}" do
|
2426
|
+
let(:doc) { NestedBook.create! }
|
2427
|
+
before do
|
2428
|
+
doc.pages.send(meth)
|
2429
|
+
end
|
2430
|
+
|
2431
|
+
it "updates the attributes" do
|
2432
|
+
expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
|
2433
|
+
end
|
2434
|
+
|
2435
|
+
it "has the same attributes after reloading" do
|
2436
|
+
doc.pages.first.save
|
2437
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2438
|
+
end
|
2439
|
+
end
|
2440
|
+
end
|
2441
|
+
|
2442
|
+
context "when clearing" do
|
2443
|
+
let(:doc) { NestedBook.create! }
|
2444
|
+
before do
|
2445
|
+
doc.pages << NestedPage.new
|
2446
|
+
doc.pages << NestedPage.new
|
2447
|
+
doc.pages << NestedPage.new
|
2448
|
+
|
2449
|
+
doc.pages.clear
|
2450
|
+
end
|
2451
|
+
|
2452
|
+
it "updates the attributes" do
|
2453
|
+
expect(doc.attributes).to_not have_key("pages")
|
2454
|
+
end
|
2455
|
+
|
2456
|
+
it "has the same attributes after reloading" do
|
2457
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2458
|
+
end
|
2459
|
+
end
|
2460
|
+
|
2461
|
+
[:delete_all, :destroy_all, :remove_all].each do |meth|
|
2462
|
+
context "when performing: #{meth}" do
|
2463
|
+
let(:doc) { NestedBook.create! }
|
2464
|
+
before do
|
2465
|
+
doc.pages << NestedPage.new
|
2466
|
+
doc.pages << NestedPage.new
|
2467
|
+
doc.pages << NestedPage.new
|
2468
|
+
|
2469
|
+
doc.pages.send(meth)
|
2470
|
+
end
|
2471
|
+
|
2472
|
+
it "updates the attributes" do
|
2473
|
+
expect(doc.attributes).to_not have_key("pages")
|
2474
|
+
end
|
2475
|
+
|
2476
|
+
it "has the same attributes after reloading" do
|
2477
|
+
expect({ "pages" => [] }.merge(doc.attributes)).to eq(doc.reload.attributes)
|
2478
|
+
end
|
2479
|
+
end
|
2480
|
+
end
|
2481
|
+
|
2482
|
+
context "when deleting" do
|
2483
|
+
let(:doc) { NestedBook.create! }
|
2484
|
+
let(:page) { NestedPage.new }
|
2485
|
+
before do
|
2486
|
+
doc.pages << page
|
2487
|
+
doc.pages << NestedPage.new
|
2488
|
+
doc.pages << NestedPage.new
|
2489
|
+
|
2490
|
+
doc.pages.delete(page)
|
2491
|
+
end
|
2492
|
+
|
2493
|
+
it "updates the attributes" do
|
2494
|
+
expect(doc.attributes["pages"].count).to eq 2
|
2495
|
+
end
|
2496
|
+
|
2497
|
+
it "has the same attributes after reloading" do
|
2498
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2499
|
+
end
|
2500
|
+
end
|
2501
|
+
|
2502
|
+
context "when doing delete_one" do
|
2503
|
+
let(:doc) { NestedBook.create! }
|
2504
|
+
let(:page) { NestedPage.new }
|
2505
|
+
before do
|
2506
|
+
doc.pages << page
|
2507
|
+
doc.pages << NestedPage.new
|
2508
|
+
doc.pages << NestedPage.new
|
2509
|
+
|
2510
|
+
doc.pages.send(:delete_one, page)
|
2511
|
+
end
|
2512
|
+
|
2513
|
+
it "updates the attributes" do
|
2514
|
+
expect(doc.attributes["pages"].count).to eq 2
|
2515
|
+
end
|
2516
|
+
end
|
2517
|
+
|
2518
|
+
context "when assigning an array of hashes" do
|
2519
|
+
let(:doc) { NestedBook.create! }
|
2520
|
+
before do
|
2521
|
+
doc.pages = [{}]
|
2522
|
+
end
|
2523
|
+
|
2524
|
+
it "updates the attributes" do
|
2525
|
+
expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
|
2526
|
+
end
|
2527
|
+
|
2528
|
+
it "has the same attributes after reloading" do
|
2529
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2530
|
+
end
|
2531
|
+
end
|
2532
|
+
|
2533
|
+
context "when assigning twice" do
|
2534
|
+
let(:doc) { NestedBook.create! }
|
2535
|
+
before do
|
2536
|
+
doc.pages = [{ number: 1 }]
|
2537
|
+
doc.pages = [{}]
|
2538
|
+
end
|
2539
|
+
|
2540
|
+
it "updates the attributes" do
|
2541
|
+
expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
|
2542
|
+
end
|
2543
|
+
|
2544
|
+
it "has the same attributes after reloading" do
|
2545
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2546
|
+
end
|
2547
|
+
end
|
1689
2548
|
end
|
1690
2549
|
|
1691
|
-
context "
|
2550
|
+
context "on embeds_one" do
|
1692
2551
|
|
1693
|
-
|
2552
|
+
let(:attrs) { { "title" => "Title" } }
|
2553
|
+
|
2554
|
+
context "when using nested attributes" do
|
2555
|
+
let(:doc) { NestedBook.create! }
|
1694
2556
|
|
1695
2557
|
before do
|
1696
|
-
|
2558
|
+
doc.update_attributes({ cover_attributes: attrs })
|
2559
|
+
end
|
2560
|
+
|
2561
|
+
it "updates the attributes" do
|
2562
|
+
expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
|
1697
2563
|
end
|
1698
2564
|
|
1699
|
-
it "
|
1700
|
-
|
2565
|
+
it "has the same attributes after reloading" do
|
2566
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
1701
2567
|
end
|
1702
2568
|
end
|
2569
|
+
|
2570
|
+
context "when doing assignments" do
|
2571
|
+
let(:doc) { NestedBook.create! }
|
2572
|
+
before do
|
2573
|
+
doc.cover = NestedCover.new(attrs)
|
2574
|
+
end
|
2575
|
+
|
2576
|
+
it "updates the attributes" do
|
2577
|
+
expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
|
2578
|
+
end
|
2579
|
+
|
2580
|
+
it "has the same attributes after reloading" do
|
2581
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2582
|
+
end
|
2583
|
+
end
|
2584
|
+
|
2585
|
+
context "when replacing assignments" do
|
2586
|
+
let(:doc) { NestedBook.create! }
|
2587
|
+
before do
|
2588
|
+
doc.cover = NestedCover.new("title" => "Title1")
|
2589
|
+
doc.cover = NestedCover.new(attrs)
|
2590
|
+
end
|
2591
|
+
|
2592
|
+
it "updates the attributes" do
|
2593
|
+
expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
|
2594
|
+
end
|
2595
|
+
|
2596
|
+
it "has the same attributes after reloading" do
|
2597
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2598
|
+
end
|
2599
|
+
end
|
2600
|
+
|
2601
|
+
context "when setting to nil" do
|
2602
|
+
let(:doc) { NestedBook.create! }
|
2603
|
+
before do
|
2604
|
+
doc.cover = NestedCover.new(attrs)
|
2605
|
+
doc.cover = nil
|
2606
|
+
end
|
2607
|
+
|
2608
|
+
it "updates the attributes" do
|
2609
|
+
expect(doc.attributes.key?("cover")).to be false
|
2610
|
+
end
|
2611
|
+
|
2612
|
+
it "has the same attributes after reloading" do
|
2613
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2614
|
+
end
|
2615
|
+
end
|
2616
|
+
|
2617
|
+
context "when setting to nil and back" do
|
2618
|
+
let(:doc) { NestedBook.create! }
|
2619
|
+
before do
|
2620
|
+
doc.cover = NestedCover.new(attrs)
|
2621
|
+
doc.cover = nil
|
2622
|
+
doc.cover = NestedCover.new(attrs)
|
2623
|
+
end
|
2624
|
+
|
2625
|
+
it "updates the attributes" do
|
2626
|
+
expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
|
2627
|
+
end
|
2628
|
+
|
2629
|
+
|
2630
|
+
it "has the same attributes after reloading" do
|
2631
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2632
|
+
end
|
2633
|
+
end
|
2634
|
+
|
2635
|
+
[:build, :create].each do |meth|
|
2636
|
+
context "when preforming #{meth}" do
|
2637
|
+
let(:doc) { NestedBook.create! }
|
2638
|
+
before do
|
2639
|
+
doc.send("#{meth}_cover", attrs)
|
2640
|
+
end
|
2641
|
+
|
2642
|
+
it "updates the attributes" do
|
2643
|
+
expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
|
2644
|
+
end
|
2645
|
+
|
2646
|
+
it "has the same attributes after reloading" do
|
2647
|
+
doc.cover.save
|
2648
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2649
|
+
end
|
2650
|
+
end
|
2651
|
+
end
|
2652
|
+
|
2653
|
+
context "when assigning a hash" do
|
2654
|
+
let(:doc) { NestedBook.create! }
|
2655
|
+
before do
|
2656
|
+
doc.cover = attrs
|
2657
|
+
end
|
2658
|
+
|
2659
|
+
it "updates the attributes" do
|
2660
|
+
expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
|
2661
|
+
end
|
2662
|
+
|
2663
|
+
it "has the same attributes after reloading" do
|
2664
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2665
|
+
end
|
2666
|
+
end
|
2667
|
+
|
2668
|
+
context "when assigning twice" do
|
2669
|
+
let(:doc) { NestedBook.create! }
|
2670
|
+
before do
|
2671
|
+
doc.cover = { "title" => "1984" }
|
2672
|
+
doc.cover = attrs
|
2673
|
+
end
|
2674
|
+
|
2675
|
+
it "updates the attributes" do
|
2676
|
+
expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
|
2677
|
+
end
|
2678
|
+
|
2679
|
+
it "has the same attributes after reloading" do
|
2680
|
+
expect(doc.attributes).to eq(doc.reload.attributes)
|
2681
|
+
end
|
2682
|
+
end
|
2683
|
+
end
|
2684
|
+
end
|
2685
|
+
|
2686
|
+
context "when modifiying a hash referenced with the [] notation" do
|
2687
|
+
let(:church) { Church.create!(location: { x: 1 }) }
|
2688
|
+
|
2689
|
+
before do
|
2690
|
+
church[:location].merge!(y: 2)
|
2691
|
+
church.save!
|
2692
|
+
church.reload
|
2693
|
+
end
|
2694
|
+
|
2695
|
+
it "persists the updated hash" do
|
2696
|
+
church.location.should == { "x" => 1, "y" => 2 }
|
2697
|
+
end
|
2698
|
+
end
|
2699
|
+
|
2700
|
+
context "when modifiying a set referenced with the [] notation" do
|
2701
|
+
let(:catalog) { Catalog.create!(set_field: [ 1 ].to_set) }
|
2702
|
+
|
2703
|
+
before do
|
2704
|
+
catalog[:set_field] << 2
|
2705
|
+
catalog.save!
|
2706
|
+
catalog.reload
|
2707
|
+
end
|
2708
|
+
|
2709
|
+
it "persists the updated hash" do
|
2710
|
+
pending "MONGOID-2951"
|
2711
|
+
catalog.set_field.should == Set.new([ 1, 2 ])
|
1703
2712
|
end
|
1704
2713
|
end
|
1705
2714
|
end
|