mongoid 3.1.5 → 8.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/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
data/spec/mongoid/fields_spec.rb
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "spec_helper"
|
|
2
4
|
|
|
3
5
|
describe Mongoid::Fields do
|
|
4
|
-
|
|
5
|
-
before(:all) do
|
|
6
|
-
Mongoid.use_activesupport_time_zone = false
|
|
7
|
-
end
|
|
6
|
+
config_override :use_activesupport_time_zone, false
|
|
8
7
|
|
|
9
8
|
describe "#\{field}_translations" do
|
|
10
9
|
|
|
@@ -18,6 +17,7 @@ describe Mongoid::Fields do
|
|
|
18
17
|
|
|
19
18
|
before do
|
|
20
19
|
product.description = "test"
|
|
20
|
+
I18n.enforce_available_locales = false
|
|
21
21
|
::I18n.locale = :de
|
|
22
22
|
product.description = "The best"
|
|
23
23
|
end
|
|
@@ -31,10 +31,14 @@ describe Mongoid::Fields do
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
it "returns all the translations" do
|
|
34
|
-
translations.
|
|
34
|
+
expect(translations).to eq(
|
|
35
35
|
{ "en" => "test", "de" => "The best" }
|
|
36
36
|
)
|
|
37
37
|
end
|
|
38
|
+
|
|
39
|
+
it "returns translations as a HashWithIndifferentAccess" do
|
|
40
|
+
expect(translations[:en]).to eq("test")
|
|
41
|
+
end
|
|
38
42
|
end
|
|
39
43
|
|
|
40
44
|
context "when translations do not exist" do
|
|
@@ -42,25 +46,33 @@ describe Mongoid::Fields do
|
|
|
42
46
|
context "when no default is provided" do
|
|
43
47
|
|
|
44
48
|
it "returns an empty hash" do
|
|
45
|
-
product.description_translations.
|
|
49
|
+
expect(product.description_translations).to be_empty
|
|
46
50
|
end
|
|
47
51
|
end
|
|
48
52
|
|
|
49
53
|
context "when a default is provided" do
|
|
50
54
|
|
|
51
55
|
it "returns the translations with the default" do
|
|
52
|
-
product.name_translations.
|
|
56
|
+
expect(product.name_translations).to eq(
|
|
53
57
|
{ "en" => "no translation" }
|
|
54
58
|
)
|
|
55
59
|
end
|
|
56
60
|
end
|
|
57
61
|
end
|
|
62
|
+
|
|
63
|
+
it "should have alias method #\{field}_t" do
|
|
64
|
+
expect(product.method(:name_t)).to eq product.method(:name_translations)
|
|
65
|
+
end
|
|
58
66
|
end
|
|
59
67
|
|
|
60
68
|
context "when the field is not localized" do
|
|
61
69
|
|
|
62
70
|
it "does not respond to the method" do
|
|
63
|
-
product.
|
|
71
|
+
expect(product).to_not respond_to(:price_translations)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "does not respond to the alias method" do
|
|
75
|
+
expect(product).to_not respond_to(:price_t)
|
|
64
76
|
end
|
|
65
77
|
end
|
|
66
78
|
end
|
|
@@ -88,28 +100,28 @@ describe Mongoid::Fields do
|
|
|
88
100
|
end
|
|
89
101
|
|
|
90
102
|
it "sets the raw values of the translations" do
|
|
91
|
-
product.description_translations.
|
|
103
|
+
expect(product.description_translations).to eq(translations)
|
|
92
104
|
end
|
|
93
105
|
|
|
94
106
|
context "when saving the new translations" do
|
|
95
107
|
|
|
96
108
|
before do
|
|
97
|
-
product.save
|
|
109
|
+
product.save!
|
|
98
110
|
end
|
|
99
111
|
|
|
100
112
|
it "persists the changes" do
|
|
101
|
-
product.reload.description_translations.
|
|
113
|
+
expect(product.reload.description_translations).to eq(translations)
|
|
102
114
|
end
|
|
103
115
|
|
|
104
116
|
context "when updating the translations" do
|
|
105
117
|
|
|
106
118
|
before do
|
|
107
119
|
product.description_translations = { "en" => "overwritten" }
|
|
108
|
-
product.save
|
|
120
|
+
product.save!
|
|
109
121
|
end
|
|
110
122
|
|
|
111
123
|
it "persists the changes" do
|
|
112
|
-
product.reload.description_translations.
|
|
124
|
+
expect(product.reload.description_translations).to eq(
|
|
113
125
|
{ "en" => "overwritten" }
|
|
114
126
|
)
|
|
115
127
|
end
|
|
@@ -128,7 +140,7 @@ describe Mongoid::Fields do
|
|
|
128
140
|
end
|
|
129
141
|
|
|
130
142
|
it "sets the mongoized values of the translations" do
|
|
131
|
-
dictionary.description_translations.
|
|
143
|
+
expect(dictionary.description_translations).to eq(
|
|
132
144
|
{ "en" => "1", "de" => "2" }
|
|
133
145
|
)
|
|
134
146
|
end
|
|
@@ -136,11 +148,11 @@ describe Mongoid::Fields do
|
|
|
136
148
|
context "when saving the new translations" do
|
|
137
149
|
|
|
138
150
|
before do
|
|
139
|
-
dictionary.save
|
|
151
|
+
dictionary.save!
|
|
140
152
|
end
|
|
141
153
|
|
|
142
154
|
it "persists the changes" do
|
|
143
|
-
dictionary.reload.description_translations.
|
|
155
|
+
expect(dictionary.reload.description_translations).to eq(
|
|
144
156
|
{ "en" => "1", "de" => "2" }
|
|
145
157
|
)
|
|
146
158
|
end
|
|
@@ -149,23 +161,31 @@ describe Mongoid::Fields do
|
|
|
149
161
|
|
|
150
162
|
before do
|
|
151
163
|
dictionary.description_translations = { "en" => "overwritten" }
|
|
152
|
-
dictionary.save
|
|
164
|
+
dictionary.save!
|
|
153
165
|
end
|
|
154
166
|
|
|
155
167
|
it "persists the changes" do
|
|
156
|
-
dictionary.reload.description_translations.
|
|
168
|
+
expect(dictionary.reload.description_translations).to eq(
|
|
157
169
|
{ "en" => "overwritten" }
|
|
158
170
|
)
|
|
159
171
|
end
|
|
160
172
|
end
|
|
161
173
|
end
|
|
162
174
|
end
|
|
175
|
+
|
|
176
|
+
it "should have alias method #\{field}_t=" do
|
|
177
|
+
expect(product.method(:name_t=)).to eq product.method(:name_translations=)
|
|
178
|
+
end
|
|
163
179
|
end
|
|
164
180
|
|
|
165
181
|
context "when the field is not localized" do
|
|
166
182
|
|
|
167
183
|
it "does not respond to the method" do
|
|
168
|
-
product.
|
|
184
|
+
expect(product).to_not respond_to(:price_translations=)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
it "does not respond to the alias method" do
|
|
188
|
+
expect(product).to_not respond_to(:price_t=)
|
|
169
189
|
end
|
|
170
190
|
end
|
|
171
191
|
end
|
|
@@ -179,7 +199,7 @@ describe Mongoid::Fields do
|
|
|
179
199
|
context "when the document is subclassed" do
|
|
180
200
|
|
|
181
201
|
it "does not include the child aliases" do
|
|
182
|
-
person.aliased_fields.keys.
|
|
202
|
+
expect(person.aliased_fields.keys).to_not include("spec")
|
|
183
203
|
end
|
|
184
204
|
end
|
|
185
205
|
end
|
|
@@ -193,19 +213,19 @@ describe Mongoid::Fields do
|
|
|
193
213
|
end
|
|
194
214
|
|
|
195
215
|
it "includes the _id field" do
|
|
196
|
-
shape.attribute_names.
|
|
216
|
+
expect(shape.attribute_names).to include("_id")
|
|
197
217
|
end
|
|
198
218
|
|
|
199
219
|
it "includes the _type field" do
|
|
200
|
-
shape.attribute_names.
|
|
220
|
+
expect(shape.attribute_names).to include("_type")
|
|
201
221
|
end
|
|
202
222
|
|
|
203
223
|
it "includes its own fields" do
|
|
204
|
-
shape.attribute_names.
|
|
224
|
+
expect(shape.attribute_names).to include("x")
|
|
205
225
|
end
|
|
206
226
|
|
|
207
227
|
it "does not return subclass fields" do
|
|
208
|
-
shape.attribute_names.
|
|
228
|
+
expect(shape.attribute_names).to_not include("radius")
|
|
209
229
|
end
|
|
210
230
|
end
|
|
211
231
|
|
|
@@ -216,23 +236,23 @@ describe Mongoid::Fields do
|
|
|
216
236
|
end
|
|
217
237
|
|
|
218
238
|
it "includes the _id field" do
|
|
219
|
-
circle.attribute_names.
|
|
239
|
+
expect(circle.attribute_names).to include("_id")
|
|
220
240
|
end
|
|
221
241
|
|
|
222
242
|
it "includes the _type field" do
|
|
223
|
-
circle.attribute_names.
|
|
243
|
+
expect(circle.attribute_names).to include("_type")
|
|
224
244
|
end
|
|
225
245
|
|
|
226
246
|
it "includes the first parent field" do
|
|
227
|
-
circle.attribute_names.
|
|
247
|
+
expect(circle.attribute_names).to include("x")
|
|
228
248
|
end
|
|
229
249
|
|
|
230
250
|
it "includes the second parent field" do
|
|
231
|
-
circle.attribute_names.
|
|
251
|
+
expect(circle.attribute_names).to include("y")
|
|
232
252
|
end
|
|
233
253
|
|
|
234
254
|
it "includes the child fields" do
|
|
235
|
-
circle.attribute_names.
|
|
255
|
+
expect(circle.attribute_names).to include("radius")
|
|
236
256
|
end
|
|
237
257
|
end
|
|
238
258
|
end
|
|
@@ -242,42 +262,42 @@ describe Mongoid::Fields do
|
|
|
242
262
|
context "when the class is a parent" do
|
|
243
263
|
|
|
244
264
|
it "includes the _id field" do
|
|
245
|
-
Shape.attribute_names.
|
|
265
|
+
expect(Shape.attribute_names).to include("_id")
|
|
246
266
|
end
|
|
247
267
|
|
|
248
268
|
it "includes the _type field" do
|
|
249
|
-
Shape.attribute_names.
|
|
269
|
+
expect(Shape.attribute_names).to include("_type")
|
|
250
270
|
end
|
|
251
271
|
|
|
252
272
|
it "includes its own fields" do
|
|
253
|
-
Shape.attribute_names.
|
|
273
|
+
expect(Shape.attribute_names).to include("x")
|
|
254
274
|
end
|
|
255
275
|
|
|
256
276
|
it "does not return subclass fields" do
|
|
257
|
-
Shape.attribute_names.
|
|
277
|
+
expect(Shape.attribute_names).to_not include("radius")
|
|
258
278
|
end
|
|
259
279
|
end
|
|
260
280
|
|
|
261
281
|
context "when the class is a subclass" do
|
|
262
282
|
|
|
263
283
|
it "includes the _id field" do
|
|
264
|
-
Circle.attribute_names.
|
|
284
|
+
expect(Circle.attribute_names).to include("_id")
|
|
265
285
|
end
|
|
266
286
|
|
|
267
287
|
it "includes the _type field" do
|
|
268
|
-
Circle.attribute_names.
|
|
288
|
+
expect(Circle.attribute_names).to include("_type")
|
|
269
289
|
end
|
|
270
290
|
|
|
271
291
|
it "includes the first parent field" do
|
|
272
|
-
Circle.attribute_names.
|
|
292
|
+
expect(Circle.attribute_names).to include("x")
|
|
273
293
|
end
|
|
274
294
|
|
|
275
295
|
it "includes the second parent field" do
|
|
276
|
-
Circle.attribute_names.
|
|
296
|
+
expect(Circle.attribute_names).to include("y")
|
|
277
297
|
end
|
|
278
298
|
|
|
279
299
|
it "includes the child fields" do
|
|
280
|
-
Circle.attribute_names.
|
|
300
|
+
expect(Circle.attribute_names).to include("radius")
|
|
281
301
|
end
|
|
282
302
|
end
|
|
283
303
|
end
|
|
@@ -289,12 +309,114 @@ describe Mongoid::Fields do
|
|
|
289
309
|
end
|
|
290
310
|
end
|
|
291
311
|
|
|
312
|
+
context "when providing a root Boolean type" do
|
|
313
|
+
|
|
314
|
+
let(:klass) do
|
|
315
|
+
Class.new do
|
|
316
|
+
include Mongoid::Document
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
it "converts to Mongoid::Boolean" do
|
|
321
|
+
expect(klass.field(:test, type: Mongoid::Boolean).type).to be(Mongoid::Boolean)
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
context "when using symbol types" do
|
|
326
|
+
|
|
327
|
+
let(:klass) do
|
|
328
|
+
Class.new do
|
|
329
|
+
include Mongoid::Document
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
it "converts :array to Array" do
|
|
334
|
+
expect(klass.field(:test, type: :array).type).to be(Array)
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
it "converts :big_decimal to BigDecimal" do
|
|
338
|
+
expect(klass.field(:test, type: :big_decimal).type).to be(BigDecimal)
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
it "converts :binary to BSON::Binary" do
|
|
342
|
+
expect(klass.field(:test, type: :binary).type).to be(BSON::Binary)
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
it "converts :boolean to Mongoid::Boolean" do
|
|
346
|
+
expect(klass.field(:test, type: :boolean).type).to be(Mongoid::Boolean)
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
it "converts :date to Date" do
|
|
350
|
+
expect(klass.field(:test, type: :date).type).to be(Date)
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
it "converts :date_time to DateTime" do
|
|
354
|
+
expect(klass.field(:test, type: :date_time).type).to be(DateTime)
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
it "converts :float to Float" do
|
|
358
|
+
expect(klass.field(:test, type: :float).type).to be(Float)
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
it "converts :hash to Hash" do
|
|
362
|
+
expect(klass.field(:test, type: :hash).type).to be(Hash)
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
it "converts :integer to Integer" do
|
|
366
|
+
expect(klass.field(:test, type: :integer).type).to be(Integer)
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
it "converts :object_id to BSON::ObjectId" do
|
|
370
|
+
expect(klass.field(:test, type: :object_id).type).to be(BSON::ObjectId)
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
it "converts :range to Range" do
|
|
374
|
+
expect(klass.field(:test, type: :range).type).to be(Range)
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
it "converts :regexp to Rexegp" do
|
|
378
|
+
expect(klass.field(:test, type: :regexp).type).to be(Regexp)
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
it "converts :set to Set" do
|
|
382
|
+
expect(klass.field(:test, type: :set).type).to be(Set)
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
it "converts :string to String" do
|
|
386
|
+
expect(klass.field(:test, type: :string).type).to be(String)
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
it "converts :symbol to Symbol" do
|
|
390
|
+
expect(klass.field(:test, type: :symbol).type).to be(Symbol)
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
it "converts :time to Time" do
|
|
394
|
+
expect(klass.field(:test, type: :time).type).to be(Time)
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
context 'when using an unknown symbol' do
|
|
398
|
+
it 'raises InvalidFieldType' do
|
|
399
|
+
lambda do
|
|
400
|
+
klass.field(:test, type: :bogus)
|
|
401
|
+
end.should raise_error(Mongoid::Errors::InvalidFieldType, /defines a field 'test' with an unknown type value :bogus/)
|
|
402
|
+
end
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
context 'when using an unknown string' do
|
|
406
|
+
it 'raises InvalidFieldType' do
|
|
407
|
+
lambda do
|
|
408
|
+
klass.field(:test, type: 'bogus')
|
|
409
|
+
end.should raise_error(Mongoid::Errors::InvalidFieldType, /defines a field 'test' with an unknown type value "bogus"/)
|
|
410
|
+
end
|
|
411
|
+
end
|
|
412
|
+
end
|
|
413
|
+
|
|
292
414
|
context "when the options are valid" do
|
|
293
415
|
|
|
294
416
|
context "when the options are all standard" do
|
|
295
417
|
|
|
296
418
|
before do
|
|
297
|
-
Band.field :acceptable, type: Boolean
|
|
419
|
+
Band.field :acceptable, type: Mongoid::Boolean
|
|
298
420
|
end
|
|
299
421
|
|
|
300
422
|
after do
|
|
@@ -302,18 +424,56 @@ describe Mongoid::Fields do
|
|
|
302
424
|
end
|
|
303
425
|
|
|
304
426
|
it "adds the field to the model" do
|
|
305
|
-
Band.fields["acceptable"].
|
|
427
|
+
expect(Band.fields["acceptable"]).to_not be_nil
|
|
306
428
|
end
|
|
307
429
|
end
|
|
308
430
|
|
|
309
431
|
context "when a custom option is provided" do
|
|
310
432
|
|
|
311
433
|
before do
|
|
312
|
-
Band.field :acceptable, type: Boolean, custom: true
|
|
434
|
+
Band.field :acceptable, type: Mongoid::Boolean, custom: true
|
|
313
435
|
end
|
|
314
436
|
|
|
315
437
|
it "adds the field to the model" do
|
|
316
|
-
Band.fields["acceptable"].
|
|
438
|
+
expect(Band.fields["acceptable"]).to_not be_nil
|
|
439
|
+
end
|
|
440
|
+
end
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
context "when the Symbol type is used" do
|
|
444
|
+
|
|
445
|
+
before do
|
|
446
|
+
Mongoid::Warnings.class_eval do
|
|
447
|
+
@symbol_type_deprecated = false
|
|
448
|
+
end
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
after do
|
|
452
|
+
Label.fields.delete("should_warn")
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
it "warns that the BSON symbol type is deprecated" do
|
|
456
|
+
expect(Mongoid.logger).to receive(:warn)
|
|
457
|
+
|
|
458
|
+
Label.field :should_warn, type: Symbol
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
it "warns on first use of Symbol type only" do
|
|
462
|
+
expect(Mongoid.logger).to receive(:warn).once
|
|
463
|
+
|
|
464
|
+
Label.field :should_warn, type: Symbol
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
context 'when using Symbol field type in multiple classes' do
|
|
468
|
+
after do
|
|
469
|
+
Truck.fields.delete("should_warn")
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
it "warns on first use of Symbol type only" do
|
|
473
|
+
expect(Mongoid.logger).to receive(:warn).once
|
|
474
|
+
|
|
475
|
+
Label.field :should_warn, type: Symbol
|
|
476
|
+
Truck.field :should_warn, type: Symbol
|
|
317
477
|
end
|
|
318
478
|
end
|
|
319
479
|
end
|
|
@@ -322,7 +482,7 @@ describe Mongoid::Fields do
|
|
|
322
482
|
|
|
323
483
|
it "raises an error" do
|
|
324
484
|
expect {
|
|
325
|
-
|
|
485
|
+
Label.field :unacceptable, bad: true
|
|
326
486
|
}.to raise_error(Mongoid::Errors::InvalidFieldOption)
|
|
327
487
|
end
|
|
328
488
|
end
|
|
@@ -333,7 +493,7 @@ describe Mongoid::Fields do
|
|
|
333
493
|
context "when the field is binary" do
|
|
334
494
|
|
|
335
495
|
let(:binary) do
|
|
336
|
-
|
|
496
|
+
BSON::Binary.new("testing", :md5)
|
|
337
497
|
end
|
|
338
498
|
|
|
339
499
|
let(:registry) do
|
|
@@ -341,7 +501,7 @@ describe Mongoid::Fields do
|
|
|
341
501
|
end
|
|
342
502
|
|
|
343
503
|
it "returns the binary data intact" do
|
|
344
|
-
registry.data.
|
|
504
|
+
expect(registry.data).to eq(binary)
|
|
345
505
|
end
|
|
346
506
|
end
|
|
347
507
|
|
|
@@ -362,7 +522,7 @@ describe Mongoid::Fields do
|
|
|
362
522
|
end
|
|
363
523
|
|
|
364
524
|
it "returns the default locale value" do
|
|
365
|
-
description.
|
|
525
|
+
expect(description).to eq("The best")
|
|
366
526
|
end
|
|
367
527
|
end
|
|
368
528
|
|
|
@@ -382,7 +542,7 @@ describe Mongoid::Fields do
|
|
|
382
542
|
end
|
|
383
543
|
|
|
384
544
|
it "returns the set locale value" do
|
|
385
|
-
description.
|
|
545
|
+
expect(description).to eq("The best")
|
|
386
546
|
end
|
|
387
547
|
end
|
|
388
548
|
|
|
@@ -403,7 +563,7 @@ describe Mongoid::Fields do
|
|
|
403
563
|
end
|
|
404
564
|
|
|
405
565
|
it "returns the current locale value" do
|
|
406
|
-
description.
|
|
566
|
+
expect(description).to eq("Cheaper drinks")
|
|
407
567
|
end
|
|
408
568
|
end
|
|
409
569
|
end
|
|
@@ -417,15 +577,151 @@ describe Mongoid::Fields do
|
|
|
417
577
|
context "when the attribute has not been assigned" do
|
|
418
578
|
|
|
419
579
|
it "delgates to the getter" do
|
|
420
|
-
person.age_before_type_cast.
|
|
580
|
+
expect(person.age_before_type_cast).to eq(person.age)
|
|
421
581
|
end
|
|
422
582
|
end
|
|
423
583
|
|
|
424
584
|
context "when the attribute has been assigned" do
|
|
425
585
|
|
|
426
586
|
it "returns the attribute before type cast" do
|
|
427
|
-
person.age = "
|
|
428
|
-
person.age_before_type_cast.
|
|
587
|
+
person.age = "42"
|
|
588
|
+
expect(person.age_before_type_cast).to eq("42")
|
|
589
|
+
end
|
|
590
|
+
end
|
|
591
|
+
|
|
592
|
+
context "when reloading" do
|
|
593
|
+
|
|
594
|
+
let(:product) do
|
|
595
|
+
Product.create!(price: '1')
|
|
596
|
+
end
|
|
597
|
+
|
|
598
|
+
before do
|
|
599
|
+
product.reload
|
|
600
|
+
end
|
|
601
|
+
|
|
602
|
+
it "resets the attributes_before_type_cast to the attributes hash" do
|
|
603
|
+
expect(product.attributes_before_type_cast).to eq(product.attributes)
|
|
604
|
+
end
|
|
605
|
+
|
|
606
|
+
it "the *_before_type_cast method returns the demongoized value" do
|
|
607
|
+
expect(product.price_before_type_cast).to eq(1)
|
|
608
|
+
end
|
|
609
|
+
end
|
|
610
|
+
|
|
611
|
+
context "when reloading and writing a demongoizable value" do
|
|
612
|
+
|
|
613
|
+
let(:product) do
|
|
614
|
+
Product.create!.tap do |product|
|
|
615
|
+
Product.collection.update_one({ _id: product.id }, { :$set => { price: '1' }})
|
|
616
|
+
end
|
|
617
|
+
end
|
|
618
|
+
|
|
619
|
+
before do
|
|
620
|
+
product.reload
|
|
621
|
+
end
|
|
622
|
+
|
|
623
|
+
it "resets the attributes_before_type_cast to the attributes hash" do
|
|
624
|
+
expect(product.attributes_before_type_cast).to eq(product.attributes)
|
|
625
|
+
end
|
|
626
|
+
|
|
627
|
+
it "the *_before_type_cast method returns the mongoized value" do
|
|
628
|
+
expect(product.price_before_type_cast).to eq('1')
|
|
629
|
+
end
|
|
630
|
+
end
|
|
631
|
+
|
|
632
|
+
context "when reading from the db" do
|
|
633
|
+
|
|
634
|
+
let(:product) do
|
|
635
|
+
Product.create!(price: '1')
|
|
636
|
+
end
|
|
637
|
+
|
|
638
|
+
let(:from_db) do
|
|
639
|
+
Product.find(product.id)
|
|
640
|
+
end
|
|
641
|
+
|
|
642
|
+
it "resets the attributes_before_type_cast to the attributes hash" do
|
|
643
|
+
expect(from_db.attributes_before_type_cast).to eq(from_db.attributes)
|
|
644
|
+
end
|
|
645
|
+
|
|
646
|
+
it "the *_before_type_cast method returns the demongoized value" do
|
|
647
|
+
expect(from_db.price_before_type_cast).to eq(1)
|
|
648
|
+
end
|
|
649
|
+
end
|
|
650
|
+
|
|
651
|
+
context "when reading from the db after writing a demongoizable value" do
|
|
652
|
+
|
|
653
|
+
let(:product) do
|
|
654
|
+
Product.create!.tap do |product|
|
|
655
|
+
Product.collection.update_one({ _id: product.id }, { :$set => { price: '1' }})
|
|
656
|
+
end
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
let(:from_db) do
|
|
660
|
+
Product.find(product.id)
|
|
661
|
+
end
|
|
662
|
+
|
|
663
|
+
it "resets the attributes_before_type_cast to the attributes hash" do
|
|
664
|
+
expect(from_db.attributes_before_type_cast).to eq(from_db.attributes)
|
|
665
|
+
end
|
|
666
|
+
|
|
667
|
+
it "the *_before_type_cast method returns the mongoized value" do
|
|
668
|
+
expect(from_db.price_before_type_cast).to eq('1')
|
|
669
|
+
end
|
|
670
|
+
end
|
|
671
|
+
|
|
672
|
+
context "when making a new model" do
|
|
673
|
+
|
|
674
|
+
context "when using new with no options" do
|
|
675
|
+
let(:product) { Product.new }
|
|
676
|
+
|
|
677
|
+
it "sets the attributes_before_type_cast to the attributes hash" do
|
|
678
|
+
expect(product.attributes_before_type_cast).to eq(product.attributes)
|
|
679
|
+
end
|
|
680
|
+
end
|
|
681
|
+
|
|
682
|
+
context "when using new with options" do
|
|
683
|
+
let(:product) { Product.new(price: '1') }
|
|
684
|
+
|
|
685
|
+
let(:abtc) do
|
|
686
|
+
product.attributes.merge('price' => '1')
|
|
687
|
+
end
|
|
688
|
+
|
|
689
|
+
it "has the attributes before type cast" do
|
|
690
|
+
expect(product.attributes_before_type_cast).to eq(abtc)
|
|
691
|
+
end
|
|
692
|
+
end
|
|
693
|
+
|
|
694
|
+
context "when persisting the model" do
|
|
695
|
+
let(:product) { Product.new(price: '1') }
|
|
696
|
+
|
|
697
|
+
let(:abtc) do
|
|
698
|
+
product.attributes.merge('price' => '1')
|
|
699
|
+
end
|
|
700
|
+
|
|
701
|
+
before do
|
|
702
|
+
expect(product.attributes_before_type_cast).to eq(abtc)
|
|
703
|
+
product.save!
|
|
704
|
+
end
|
|
705
|
+
|
|
706
|
+
it "resets the attributes_before_type_cast to the attributes" do
|
|
707
|
+
expect(product.attributes_before_type_cast).to eq(product.attributes)
|
|
708
|
+
end
|
|
709
|
+
end
|
|
710
|
+
|
|
711
|
+
context "when using create! without options" do
|
|
712
|
+
let(:product) { Product.create! }
|
|
713
|
+
|
|
714
|
+
it "resets the attributes_before_type_cast to the attributes" do
|
|
715
|
+
expect(product.attributes_before_type_cast).to eq(product.attributes)
|
|
716
|
+
end
|
|
717
|
+
end
|
|
718
|
+
|
|
719
|
+
context "when using create! with options" do
|
|
720
|
+
let(:product) { Product.create!(price: '1') }
|
|
721
|
+
|
|
722
|
+
it "resets the attributes_before_type_cast to the attributes" do
|
|
723
|
+
expect(product.attributes_before_type_cast).to eq(product.attributes)
|
|
724
|
+
end
|
|
429
725
|
end
|
|
430
726
|
end
|
|
431
727
|
end
|
|
@@ -436,10 +732,24 @@ describe Mongoid::Fields do
|
|
|
436
732
|
Product.new
|
|
437
733
|
end
|
|
438
734
|
|
|
735
|
+
context "when setting via the setter" do
|
|
736
|
+
|
|
737
|
+
it "returns the set value" do
|
|
738
|
+
expect(product.price = 10).to eq(10)
|
|
739
|
+
end
|
|
740
|
+
end
|
|
741
|
+
|
|
742
|
+
context "when setting via send" do
|
|
743
|
+
|
|
744
|
+
it "returns the set value" do
|
|
745
|
+
expect(product.send(:price=, 10)).to eq(10)
|
|
746
|
+
end
|
|
747
|
+
end
|
|
748
|
+
|
|
439
749
|
context "when the field is binary" do
|
|
440
750
|
|
|
441
751
|
let(:binary) do
|
|
442
|
-
|
|
752
|
+
BSON::Binary.new("testing", :md5)
|
|
443
753
|
end
|
|
444
754
|
|
|
445
755
|
let(:registry) do
|
|
@@ -451,7 +761,7 @@ describe Mongoid::Fields do
|
|
|
451
761
|
end
|
|
452
762
|
|
|
453
763
|
it "returns the binary data intact" do
|
|
454
|
-
registry.data.
|
|
764
|
+
expect(registry.data).to eq(binary)
|
|
455
765
|
end
|
|
456
766
|
end
|
|
457
767
|
|
|
@@ -459,18 +769,18 @@ describe Mongoid::Fields do
|
|
|
459
769
|
|
|
460
770
|
before do
|
|
461
771
|
product.stores = [ "kadewe", "karstadt" ]
|
|
462
|
-
product.save
|
|
772
|
+
product.save!
|
|
463
773
|
end
|
|
464
774
|
|
|
465
775
|
context "when setting the value to nil" do
|
|
466
776
|
|
|
467
777
|
before do
|
|
468
778
|
product.stores = nil
|
|
469
|
-
product.save
|
|
779
|
+
product.save!
|
|
470
780
|
end
|
|
471
781
|
|
|
472
782
|
it "allows the set" do
|
|
473
|
-
product.stores.
|
|
783
|
+
expect(product.stores).to be_nil
|
|
474
784
|
end
|
|
475
785
|
end
|
|
476
786
|
|
|
@@ -478,15 +788,15 @@ describe Mongoid::Fields do
|
|
|
478
788
|
|
|
479
789
|
before do
|
|
480
790
|
product.stores = [ "kadewe", nil ]
|
|
481
|
-
product.save
|
|
791
|
+
product.save!
|
|
482
792
|
end
|
|
483
793
|
|
|
484
794
|
it "allows the set of nil values" do
|
|
485
|
-
product.stores.
|
|
795
|
+
expect(product.stores).to eq([ "kadewe", nil ])
|
|
486
796
|
end
|
|
487
797
|
|
|
488
798
|
it "persists the nil values" do
|
|
489
|
-
product.reload.stores.
|
|
799
|
+
expect(product.reload.stores).to eq([ "kadewe", nil ])
|
|
490
800
|
end
|
|
491
801
|
end
|
|
492
802
|
|
|
@@ -494,15 +804,15 @@ describe Mongoid::Fields do
|
|
|
494
804
|
|
|
495
805
|
before do
|
|
496
806
|
product.stores = [ "karstadt", "kadewe" ]
|
|
497
|
-
product.save
|
|
807
|
+
product.save!
|
|
498
808
|
end
|
|
499
809
|
|
|
500
810
|
it "reverses the values" do
|
|
501
|
-
product.stores.
|
|
811
|
+
expect(product.stores).to eq([ "karstadt", "kadewe" ])
|
|
502
812
|
end
|
|
503
813
|
|
|
504
814
|
it "persists the changes" do
|
|
505
|
-
product.reload.stores.
|
|
815
|
+
expect(product.reload.stores).to eq([ "karstadt", "kadewe" ])
|
|
506
816
|
end
|
|
507
817
|
end
|
|
508
818
|
end
|
|
@@ -520,7 +830,7 @@ describe Mongoid::Fields do
|
|
|
520
830
|
end
|
|
521
831
|
|
|
522
832
|
it "sets the value in the default locale" do
|
|
523
|
-
description.
|
|
833
|
+
expect(description).to eq({ "en" => "Cheap drinks" })
|
|
524
834
|
end
|
|
525
835
|
end
|
|
526
836
|
|
|
@@ -540,7 +850,7 @@ describe Mongoid::Fields do
|
|
|
540
850
|
end
|
|
541
851
|
|
|
542
852
|
it "sets the value in the default locale" do
|
|
543
|
-
description.
|
|
853
|
+
expect(description).to eq({ "de" => "Cheaper drinks" })
|
|
544
854
|
end
|
|
545
855
|
end
|
|
546
856
|
|
|
@@ -561,12 +871,28 @@ describe Mongoid::Fields do
|
|
|
561
871
|
end
|
|
562
872
|
|
|
563
873
|
it "sets the value in both locales" do
|
|
564
|
-
description.
|
|
874
|
+
expect(description).to eq(
|
|
565
875
|
{ "de" => "Cheaper drinks", "en" => "Cheap drinks" }
|
|
566
876
|
)
|
|
567
877
|
end
|
|
568
878
|
end
|
|
569
879
|
end
|
|
880
|
+
|
|
881
|
+
context "when the field needs to be mongoized" do
|
|
882
|
+
|
|
883
|
+
before do
|
|
884
|
+
product.price = "1"
|
|
885
|
+
product.save!
|
|
886
|
+
end
|
|
887
|
+
|
|
888
|
+
it "mongoizes the value" do
|
|
889
|
+
expect(product.price).to eq(1)
|
|
890
|
+
end
|
|
891
|
+
|
|
892
|
+
it "stores the value in the mongoized form" do
|
|
893
|
+
expect(product.attributes_before_type_cast["price"]).to eq(1)
|
|
894
|
+
end
|
|
895
|
+
end
|
|
570
896
|
end
|
|
571
897
|
|
|
572
898
|
describe "#defaults" do
|
|
@@ -584,7 +910,7 @@ describe Mongoid::Fields do
|
|
|
584
910
|
context "when provided a default array" do
|
|
585
911
|
|
|
586
912
|
before do
|
|
587
|
-
Person.field(:array_testing, type: Array, default: [])
|
|
913
|
+
Person.field(:array_testing, type: Array, default: [], overwrite: true)
|
|
588
914
|
end
|
|
589
915
|
|
|
590
916
|
after do
|
|
@@ -593,7 +919,7 @@ describe Mongoid::Fields do
|
|
|
593
919
|
end
|
|
594
920
|
|
|
595
921
|
it "returns an equal object of a different instance" do
|
|
596
|
-
person_one.array_testing.object_id.
|
|
922
|
+
expect(person_one.array_testing.object_id).to_not eq(
|
|
597
923
|
person_two.array_testing.object_id
|
|
598
924
|
)
|
|
599
925
|
end
|
|
@@ -602,7 +928,7 @@ describe Mongoid::Fields do
|
|
|
602
928
|
context "when provided a default hash" do
|
|
603
929
|
|
|
604
930
|
before do
|
|
605
|
-
Person.field(:hash_testing, type: Hash, default: {})
|
|
931
|
+
Person.field(:hash_testing, type: Hash, default: {}, overwrite: true)
|
|
606
932
|
end
|
|
607
933
|
|
|
608
934
|
after do
|
|
@@ -610,7 +936,7 @@ describe Mongoid::Fields do
|
|
|
610
936
|
end
|
|
611
937
|
|
|
612
938
|
it "returns an equal object of a different instance" do
|
|
613
|
-
person_one.hash_testing.object_id.
|
|
939
|
+
expect(person_one.hash_testing.object_id).to_not eq(
|
|
614
940
|
person_two.hash_testing.object_id
|
|
615
941
|
)
|
|
616
942
|
end
|
|
@@ -624,7 +950,8 @@ describe Mongoid::Fields do
|
|
|
624
950
|
Person.field(
|
|
625
951
|
:generated_testing,
|
|
626
952
|
type: Float,
|
|
627
|
-
default: ->{ Time.now.to_f }
|
|
953
|
+
default: ->{ Time.now.to_f },
|
|
954
|
+
overwrite: true
|
|
628
955
|
)
|
|
629
956
|
end
|
|
630
957
|
|
|
@@ -634,7 +961,7 @@ describe Mongoid::Fields do
|
|
|
634
961
|
end
|
|
635
962
|
|
|
636
963
|
it "returns an equal object of a different instance" do
|
|
637
|
-
person_one.generated_testing.object_id.
|
|
964
|
+
expect(person_one.generated_testing.object_id).to_not eq(
|
|
638
965
|
person_two.generated_testing.object_id
|
|
639
966
|
)
|
|
640
967
|
end
|
|
@@ -646,7 +973,8 @@ describe Mongoid::Fields do
|
|
|
646
973
|
Person.field(
|
|
647
974
|
:rank,
|
|
648
975
|
type: Integer,
|
|
649
|
-
default: ->{ title? ? 1 : 2 }
|
|
976
|
+
default: ->{ title? ? 1 : 2 },
|
|
977
|
+
overwrite: true
|
|
650
978
|
)
|
|
651
979
|
end
|
|
652
980
|
|
|
@@ -656,7 +984,7 @@ describe Mongoid::Fields do
|
|
|
656
984
|
end
|
|
657
985
|
|
|
658
986
|
it "yields the document to the proc" do
|
|
659
|
-
Person.new.rank.
|
|
987
|
+
expect(Person.new.rank).to eq(2)
|
|
660
988
|
end
|
|
661
989
|
end
|
|
662
990
|
end
|
|
@@ -669,7 +997,8 @@ describe Mongoid::Fields do
|
|
|
669
997
|
end
|
|
670
998
|
|
|
671
999
|
it "does not return subclass defaults" do
|
|
672
|
-
shape.pre_processed_defaults.
|
|
1000
|
+
expect(shape.pre_processed_defaults).to eq([ "_id", "x", "y" ])
|
|
1001
|
+
expect(shape.post_processed_defaults).to eq([ "_type" ])
|
|
673
1002
|
end
|
|
674
1003
|
end
|
|
675
1004
|
|
|
@@ -680,7 +1009,8 @@ describe Mongoid::Fields do
|
|
|
680
1009
|
end
|
|
681
1010
|
|
|
682
1011
|
it "has the parent and child defaults" do
|
|
683
|
-
circle.pre_processed_defaults.
|
|
1012
|
+
expect(circle.pre_processed_defaults).to eq([ "_id", "x", "y", "radius" ])
|
|
1013
|
+
expect(circle.post_processed_defaults).to eq([ "_type" ])
|
|
684
1014
|
end
|
|
685
1015
|
end
|
|
686
1016
|
end
|
|
@@ -688,19 +1018,42 @@ describe Mongoid::Fields do
|
|
|
688
1018
|
describe ".field" do
|
|
689
1019
|
|
|
690
1020
|
it "returns the generated field" do
|
|
691
|
-
Person.field(:testing).
|
|
1021
|
+
expect(Person.field(:testing)).to eq(Person.fields["testing"])
|
|
692
1022
|
end
|
|
693
1023
|
|
|
694
1024
|
context "when the field name conflicts with mongoid's internals" do
|
|
695
1025
|
|
|
696
|
-
|
|
1026
|
+
[:_association, :invalid].each do |meth|
|
|
1027
|
+
context "when the field is named #{meth}" do
|
|
1028
|
+
|
|
1029
|
+
it "raises an error" do
|
|
1030
|
+
expect {
|
|
1031
|
+
Person.field(meth)
|
|
1032
|
+
}.to raise_error(Mongoid::Errors::InvalidField, /Defining a field named '#{meth}' is not allowed/)
|
|
1033
|
+
end
|
|
1034
|
+
end
|
|
1035
|
+
end
|
|
1036
|
+
end
|
|
1037
|
+
|
|
1038
|
+
context "when field already exist and validate_duplicate is enable" do
|
|
1039
|
+
context 'when exception is enabled' do
|
|
1040
|
+
config_override :duplicate_fields_exception, true
|
|
697
1041
|
|
|
698
1042
|
it "raises an error" do
|
|
699
1043
|
expect {
|
|
700
|
-
Person.field(:
|
|
1044
|
+
Person.field(:title)
|
|
701
1045
|
}.to raise_error(Mongoid::Errors::InvalidField)
|
|
702
1046
|
end
|
|
703
1047
|
end
|
|
1048
|
+
|
|
1049
|
+
context 'when exception is disabled' do
|
|
1050
|
+
config_override :duplicate_fields_exception, false
|
|
1051
|
+
it "doesn't raise an error" do
|
|
1052
|
+
expect {
|
|
1053
|
+
Class.new(Person)
|
|
1054
|
+
}.to_not raise_error
|
|
1055
|
+
end
|
|
1056
|
+
end
|
|
704
1057
|
end
|
|
705
1058
|
|
|
706
1059
|
context "when the field is a time" do
|
|
@@ -724,7 +1077,7 @@ describe Mongoid::Fields do
|
|
|
724
1077
|
end
|
|
725
1078
|
|
|
726
1079
|
it "performs the necessary time conversions" do
|
|
727
|
-
person.lunch_time.to_s.
|
|
1080
|
+
expect(person.lunch_time.to_s).to eq(time.getlocal.to_s)
|
|
728
1081
|
end
|
|
729
1082
|
end
|
|
730
1083
|
end
|
|
@@ -732,7 +1085,7 @@ describe Mongoid::Fields do
|
|
|
732
1085
|
context "when providing no options" do
|
|
733
1086
|
|
|
734
1087
|
before do
|
|
735
|
-
Person.field(:testing)
|
|
1088
|
+
Person.field(:testing, overwrite: true)
|
|
736
1089
|
end
|
|
737
1090
|
|
|
738
1091
|
let(:person) do
|
|
@@ -740,15 +1093,15 @@ describe Mongoid::Fields do
|
|
|
740
1093
|
end
|
|
741
1094
|
|
|
742
1095
|
it "adds a reader for the fields defined" do
|
|
743
|
-
person.testing.
|
|
1096
|
+
expect(person.testing).to eq("Test")
|
|
744
1097
|
end
|
|
745
1098
|
|
|
746
1099
|
it "adds a writer for the fields defined" do
|
|
747
|
-
(person.testing = "Testy").
|
|
1100
|
+
(person.testing = expect("Testy")).to eq("Testy")
|
|
748
1101
|
end
|
|
749
1102
|
|
|
750
|
-
it "adds an
|
|
751
|
-
Person.new.testing
|
|
1103
|
+
it "adds an existence method" do
|
|
1104
|
+
expect(Person.new.testing?).to be false
|
|
752
1105
|
end
|
|
753
1106
|
|
|
754
1107
|
context "when overwriting an existing field" do
|
|
@@ -765,7 +1118,7 @@ describe Mongoid::Fields do
|
|
|
765
1118
|
end
|
|
766
1119
|
|
|
767
1120
|
it "properly overwrites the method" do
|
|
768
|
-
person.testing_override_called.
|
|
1121
|
+
expect(person.testing_override_called).to be true
|
|
769
1122
|
end
|
|
770
1123
|
end
|
|
771
1124
|
end
|
|
@@ -777,7 +1130,7 @@ describe Mongoid::Fields do
|
|
|
777
1130
|
end
|
|
778
1131
|
|
|
779
1132
|
it "returns the given value" do
|
|
780
|
-
bob.reading.
|
|
1133
|
+
expect(bob.reading).to eq(10.023)
|
|
781
1134
|
end
|
|
782
1135
|
end
|
|
783
1136
|
|
|
@@ -788,7 +1141,7 @@ describe Mongoid::Fields do
|
|
|
788
1141
|
end
|
|
789
1142
|
|
|
790
1143
|
it "adds an accessor method with a question mark" do
|
|
791
|
-
person.terms
|
|
1144
|
+
expect(person.terms?).to be true
|
|
792
1145
|
end
|
|
793
1146
|
end
|
|
794
1147
|
|
|
@@ -799,39 +1152,39 @@ describe Mongoid::Fields do
|
|
|
799
1152
|
end
|
|
800
1153
|
|
|
801
1154
|
before do
|
|
802
|
-
Person.field :aliased, as: :alias, type: Boolean
|
|
1155
|
+
Person.field :aliased, as: :alias, type: Mongoid::Boolean, overwrite: true
|
|
803
1156
|
end
|
|
804
1157
|
|
|
805
1158
|
it "uses the alias to write the attribute" do
|
|
806
|
-
(person.alias = true).
|
|
1159
|
+
expect(person.alias = true).to be true
|
|
807
1160
|
end
|
|
808
1161
|
|
|
809
1162
|
it "uses the alias to read the attribute" do
|
|
810
|
-
person.alias.
|
|
1163
|
+
expect(person.alias).to be true
|
|
811
1164
|
end
|
|
812
1165
|
|
|
813
1166
|
it "uses the alias for the query method" do
|
|
814
|
-
person.
|
|
1167
|
+
expect(person).to be_alias
|
|
815
1168
|
end
|
|
816
1169
|
|
|
817
1170
|
it "uses the name to write the attribute" do
|
|
818
|
-
(person.aliased = true).
|
|
1171
|
+
expect(person.aliased = true).to be true
|
|
819
1172
|
end
|
|
820
1173
|
|
|
821
1174
|
it "uses the name to read the attribute" do
|
|
822
|
-
person.aliased.
|
|
1175
|
+
expect(person.aliased).to be true
|
|
823
1176
|
end
|
|
824
1177
|
|
|
825
1178
|
it "uses the name for the query method" do
|
|
826
|
-
person.
|
|
1179
|
+
expect(person).to be_aliased
|
|
827
1180
|
end
|
|
828
1181
|
|
|
829
1182
|
it "creates dirty methods for the name" do
|
|
830
|
-
person.
|
|
1183
|
+
expect(person).to respond_to(:aliased_changed?)
|
|
831
1184
|
end
|
|
832
1185
|
|
|
833
1186
|
it "creates dirty methods for the alias" do
|
|
834
|
-
person.
|
|
1187
|
+
expect(person).to respond_to(:alias_changed?)
|
|
835
1188
|
end
|
|
836
1189
|
|
|
837
1190
|
context "when changing the name" do
|
|
@@ -841,11 +1194,11 @@ describe Mongoid::Fields do
|
|
|
841
1194
|
end
|
|
842
1195
|
|
|
843
1196
|
it "sets name_changed?" do
|
|
844
|
-
person.aliased_changed
|
|
1197
|
+
expect(person.aliased_changed?).to be true
|
|
845
1198
|
end
|
|
846
1199
|
|
|
847
1200
|
it "sets alias_changed?" do
|
|
848
|
-
person.alias_changed
|
|
1201
|
+
expect(person.alias_changed?).to be true
|
|
849
1202
|
end
|
|
850
1203
|
end
|
|
851
1204
|
|
|
@@ -856,11 +1209,11 @@ describe Mongoid::Fields do
|
|
|
856
1209
|
end
|
|
857
1210
|
|
|
858
1211
|
it "sets name_changed?" do
|
|
859
|
-
person.aliased_changed
|
|
1212
|
+
expect(person.aliased_changed?).to be true
|
|
860
1213
|
end
|
|
861
1214
|
|
|
862
1215
|
it "sets alias_changed?" do
|
|
863
|
-
person.alias_changed
|
|
1216
|
+
expect(person.alias_changed?).to be true
|
|
864
1217
|
end
|
|
865
1218
|
end
|
|
866
1219
|
|
|
@@ -871,7 +1224,7 @@ describe Mongoid::Fields do
|
|
|
871
1224
|
end
|
|
872
1225
|
|
|
873
1226
|
it "properly serializes the aliased field" do
|
|
874
|
-
criteria.selector.
|
|
1227
|
+
expect(criteria.selector).to eq({ "aliased" => true })
|
|
875
1228
|
end
|
|
876
1229
|
end
|
|
877
1230
|
end
|
|
@@ -889,44 +1242,24 @@ describe Mongoid::Fields do
|
|
|
889
1242
|
context "when option is provided" do
|
|
890
1243
|
|
|
891
1244
|
it "calls the handler with the model" do
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
end
|
|
895
|
-
|
|
896
|
-
User.field :custom, option: true
|
|
897
|
-
end
|
|
898
|
-
|
|
899
|
-
it "calls the handler with the field" do
|
|
900
|
-
handler.should_receive(:call).with do |_,field,_|
|
|
901
|
-
field.should eql User.fields["custom"]
|
|
902
|
-
end
|
|
903
|
-
|
|
904
|
-
User.field :custom, option: true
|
|
905
|
-
end
|
|
906
|
-
|
|
907
|
-
it "calls the handler with the option value" do
|
|
908
|
-
handler.should_receive(:call).with do |_,_,value|
|
|
909
|
-
value.should eql true
|
|
910
|
-
end
|
|
911
|
-
|
|
912
|
-
User.field :custom, option: true
|
|
1245
|
+
User.field :custom, option: true, overwrite: true
|
|
1246
|
+
expect(User.fields["custom"].options[:option]).to be_truthy
|
|
913
1247
|
end
|
|
914
1248
|
end
|
|
915
1249
|
|
|
916
1250
|
context "when option is nil" do
|
|
917
1251
|
|
|
918
1252
|
it "calls the handler" do
|
|
919
|
-
handler.
|
|
920
|
-
User.field :custom, option: nil
|
|
1253
|
+
expect(handler).to receive(:call)
|
|
1254
|
+
User.field :custom, option: nil, overwrite: true
|
|
921
1255
|
end
|
|
922
1256
|
end
|
|
923
1257
|
|
|
924
1258
|
context "when option is not provided" do
|
|
925
1259
|
|
|
926
1260
|
it "does not call the handler" do
|
|
927
|
-
handler.
|
|
928
|
-
|
|
929
|
-
User.field :custom
|
|
1261
|
+
expect(handler).to receive(:call).never
|
|
1262
|
+
User.field :custom, overwrite: true
|
|
930
1263
|
end
|
|
931
1264
|
end
|
|
932
1265
|
end
|
|
@@ -941,11 +1274,15 @@ describe Mongoid::Fields do
|
|
|
941
1274
|
end
|
|
942
1275
|
|
|
943
1276
|
it "includes its own fields" do
|
|
944
|
-
shape.fields.keys.
|
|
1277
|
+
expect(shape.fields.keys).to include("x")
|
|
945
1278
|
end
|
|
946
1279
|
|
|
947
1280
|
it "does not return subclass fields" do
|
|
948
|
-
shape.fields.keys.
|
|
1281
|
+
expect(shape.fields.keys).to_not include("radius")
|
|
1282
|
+
end
|
|
1283
|
+
|
|
1284
|
+
it 'includes _type field' do
|
|
1285
|
+
expect(shape.fields.keys).to include("_type")
|
|
949
1286
|
end
|
|
950
1287
|
end
|
|
951
1288
|
|
|
@@ -956,15 +1293,37 @@ describe Mongoid::Fields do
|
|
|
956
1293
|
end
|
|
957
1294
|
|
|
958
1295
|
it "includes the first parent field" do
|
|
959
|
-
circle.fields.keys.
|
|
1296
|
+
expect(circle.fields.keys).to include("x")
|
|
960
1297
|
end
|
|
961
1298
|
|
|
962
1299
|
it "includes the second parent field" do
|
|
963
|
-
circle.fields.keys.
|
|
1300
|
+
expect(circle.fields.keys).to include("y")
|
|
964
1301
|
end
|
|
965
1302
|
|
|
966
1303
|
it "includes the child fields" do
|
|
967
|
-
circle.fields.keys.
|
|
1304
|
+
expect(circle.fields.keys).to include("radius")
|
|
1305
|
+
end
|
|
1306
|
+
|
|
1307
|
+
it 'includes _type field' do
|
|
1308
|
+
expect(circle.fields.keys).to include("_type")
|
|
1309
|
+
end
|
|
1310
|
+
end
|
|
1311
|
+
|
|
1312
|
+
context "on new subclasses" do
|
|
1313
|
+
it "all subclasses get the discriminator key" do
|
|
1314
|
+
class DiscriminatorParent
|
|
1315
|
+
include Mongoid::Document
|
|
1316
|
+
end
|
|
1317
|
+
|
|
1318
|
+
class DiscriminatorChild1 < DiscriminatorParent
|
|
1319
|
+
end
|
|
1320
|
+
|
|
1321
|
+
class DiscriminatorChild2 < DiscriminatorParent
|
|
1322
|
+
end
|
|
1323
|
+
|
|
1324
|
+
expect(DiscriminatorParent.fields.keys).to include("_type")
|
|
1325
|
+
expect(DiscriminatorChild1.fields.keys).to include("_type")
|
|
1326
|
+
expect(DiscriminatorChild2.fields.keys).to include("_type")
|
|
968
1327
|
end
|
|
969
1328
|
end
|
|
970
1329
|
end
|
|
@@ -972,7 +1331,7 @@ describe Mongoid::Fields do
|
|
|
972
1331
|
describe ".replace_field" do
|
|
973
1332
|
|
|
974
1333
|
let!(:original) do
|
|
975
|
-
Person.field(:id_test, type:
|
|
1334
|
+
Person.field(:id_test, type: BSON::ObjectId, label: "id")
|
|
976
1335
|
end
|
|
977
1336
|
|
|
978
1337
|
let!(:altered) do
|
|
@@ -988,11 +1347,11 @@ describe Mongoid::Fields do
|
|
|
988
1347
|
end
|
|
989
1348
|
|
|
990
1349
|
it "sets the new type on the field" do
|
|
991
|
-
new_field.type.
|
|
1350
|
+
expect(new_field.type).to eq(String)
|
|
992
1351
|
end
|
|
993
1352
|
|
|
994
1353
|
it "keeps the options from the old field" do
|
|
995
|
-
new_field.options[:label].
|
|
1354
|
+
expect(new_field.options[:label]).to eq("id")
|
|
996
1355
|
end
|
|
997
1356
|
end
|
|
998
1357
|
|
|
@@ -1009,7 +1368,7 @@ describe Mongoid::Fields do
|
|
|
1009
1368
|
end
|
|
1010
1369
|
|
|
1011
1370
|
it "resets the fields" do
|
|
1012
|
-
fields.keys.
|
|
1371
|
+
expect(fields.keys).to include("user_id")
|
|
1013
1372
|
end
|
|
1014
1373
|
end
|
|
1015
1374
|
|
|
@@ -1020,7 +1379,7 @@ describe Mongoid::Fields do
|
|
|
1020
1379
|
end
|
|
1021
1380
|
|
|
1022
1381
|
it "resets the fields" do
|
|
1023
|
-
fields.keys.
|
|
1382
|
+
expect(fields.keys).to include("user_id")
|
|
1024
1383
|
end
|
|
1025
1384
|
end
|
|
1026
1385
|
end
|
|
@@ -1032,158 +1391,153 @@ describe Mongoid::Fields do
|
|
|
1032
1391
|
end
|
|
1033
1392
|
|
|
1034
1393
|
it "sets the default value pre process" do
|
|
1035
|
-
person.map_with_default.
|
|
1394
|
+
expect(person.map_with_default).to eq({ "key" => "testing" })
|
|
1036
1395
|
end
|
|
1037
1396
|
end
|
|
1038
1397
|
|
|
1039
|
-
context "when
|
|
1398
|
+
context "when a field is defined as a big decimal" do
|
|
1040
1399
|
|
|
1041
|
-
context
|
|
1400
|
+
context 'when Mongoid.map_big_decimal_to_decimal128 is false' do
|
|
1401
|
+
config_override :map_big_decimal_to_decimal128, false
|
|
1042
1402
|
|
|
1043
|
-
|
|
1403
|
+
let(:band) do
|
|
1404
|
+
Band.new(name: "Tool")
|
|
1405
|
+
end
|
|
1044
1406
|
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1407
|
+
let(:decimal) do
|
|
1408
|
+
BigDecimal("1000000.00")
|
|
1409
|
+
end
|
|
1048
1410
|
|
|
1049
|
-
|
|
1050
|
-
Person.attr_protected :id, :_id, :_type
|
|
1051
|
-
end
|
|
1411
|
+
context "when setting to a big decimal" do
|
|
1052
1412
|
|
|
1053
|
-
|
|
1054
|
-
|
|
1413
|
+
before do
|
|
1414
|
+
band.sales = decimal
|
|
1055
1415
|
end
|
|
1056
1416
|
|
|
1057
|
-
it "
|
|
1058
|
-
|
|
1417
|
+
it "properly persists as a string" do
|
|
1418
|
+
expect(band.attributes["sales"]).to eq(decimal.to_s)
|
|
1059
1419
|
end
|
|
1060
1420
|
|
|
1061
|
-
it "
|
|
1062
|
-
|
|
1421
|
+
it "returns the proper big decimal" do
|
|
1422
|
+
expect(band.sales).to eq(decimal)
|
|
1063
1423
|
end
|
|
1064
1424
|
end
|
|
1065
1425
|
|
|
1066
|
-
context "when
|
|
1426
|
+
context "when setting to a string" do
|
|
1067
1427
|
|
|
1068
1428
|
before do
|
|
1069
|
-
|
|
1070
|
-
end
|
|
1071
|
-
|
|
1072
|
-
let(:bson_id) do
|
|
1073
|
-
Moped::BSON::ObjectId.new
|
|
1429
|
+
band.sales = decimal.to_s
|
|
1074
1430
|
end
|
|
1075
1431
|
|
|
1076
|
-
it "
|
|
1077
|
-
|
|
1432
|
+
it "properly persists as a string" do
|
|
1433
|
+
expect(band.attributes["sales"]).to eq(decimal.to_s)
|
|
1078
1434
|
end
|
|
1079
1435
|
|
|
1080
|
-
it "
|
|
1081
|
-
|
|
1436
|
+
it "returns the proper big decimal" do
|
|
1437
|
+
expect(band.sales).to eq(decimal)
|
|
1082
1438
|
end
|
|
1083
1439
|
end
|
|
1084
|
-
end
|
|
1085
1440
|
|
|
1086
|
-
|
|
1441
|
+
context "when setting to an integer" do
|
|
1087
1442
|
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1443
|
+
before do
|
|
1444
|
+
band.sales = decimal.to_i
|
|
1445
|
+
end
|
|
1091
1446
|
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1447
|
+
it "properly persists as a string" do
|
|
1448
|
+
expect(band.attributes["sales"]).to eq("1000000")
|
|
1449
|
+
end
|
|
1095
1450
|
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
include Mongoid::Document
|
|
1451
|
+
it "returns the proper big decimal" do
|
|
1452
|
+
expect(band.sales).to eq(decimal)
|
|
1099
1453
|
end
|
|
1100
1454
|
end
|
|
1101
1455
|
|
|
1102
|
-
|
|
1103
|
-
Moped::BSON::ObjectId.new
|
|
1104
|
-
end
|
|
1456
|
+
context "when setting to a float" do
|
|
1105
1457
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1458
|
+
before do
|
|
1459
|
+
band.sales = decimal.to_f
|
|
1460
|
+
end
|
|
1109
1461
|
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1462
|
+
it "properly persists as a string" do
|
|
1463
|
+
expect(band.attributes["sales"]).to eq(decimal.to_s)
|
|
1464
|
+
end
|
|
1113
1465
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1466
|
+
it "returns the proper big decimal" do
|
|
1467
|
+
expect(band.sales).to eq(decimal)
|
|
1468
|
+
end
|
|
1116
1469
|
end
|
|
1117
1470
|
end
|
|
1118
|
-
end
|
|
1119
1471
|
|
|
1120
|
-
|
|
1472
|
+
context 'when Mongoid.map_big_decimal_to_decimal128 is true' do
|
|
1473
|
+
config_override :map_big_decimal_to_decimal128, true
|
|
1121
1474
|
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1475
|
+
let(:band) do
|
|
1476
|
+
Band.new(name: "Tool")
|
|
1477
|
+
end
|
|
1125
1478
|
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1479
|
+
let(:decimal) do
|
|
1480
|
+
BigDecimal("1000000.00")
|
|
1481
|
+
end
|
|
1129
1482
|
|
|
1130
|
-
|
|
1483
|
+
context "when setting to a big decimal" do
|
|
1131
1484
|
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1485
|
+
before do
|
|
1486
|
+
band.sales = decimal
|
|
1487
|
+
end
|
|
1135
1488
|
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1489
|
+
it "properly persists as a BSON::Decimal128" do
|
|
1490
|
+
expect(band.attributes["sales"]).to eq(BSON::Decimal128.new(decimal))
|
|
1491
|
+
end
|
|
1139
1492
|
|
|
1140
|
-
|
|
1141
|
-
|
|
1493
|
+
it "returns the proper big decimal" do
|
|
1494
|
+
expect(band.sales).to eq(decimal)
|
|
1495
|
+
end
|
|
1142
1496
|
end
|
|
1143
|
-
end
|
|
1144
1497
|
|
|
1145
|
-
|
|
1498
|
+
context "when setting to a string" do
|
|
1146
1499
|
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1500
|
+
before do
|
|
1501
|
+
band.sales = decimal.to_s
|
|
1502
|
+
end
|
|
1150
1503
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1504
|
+
it "persists as a BSON::Decimal128" do
|
|
1505
|
+
expect(band.attributes["sales"]).to eq(BSON::Decimal128.new(decimal.to_s))
|
|
1506
|
+
end
|
|
1154
1507
|
|
|
1155
|
-
|
|
1156
|
-
|
|
1508
|
+
it "returns the proper big decimal" do
|
|
1509
|
+
expect(band.sales).to eq(decimal)
|
|
1510
|
+
end
|
|
1157
1511
|
end
|
|
1158
|
-
end
|
|
1159
1512
|
|
|
1160
|
-
|
|
1513
|
+
context "when setting to an integer" do
|
|
1161
1514
|
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1515
|
+
before do
|
|
1516
|
+
band.sales = decimal.to_i
|
|
1517
|
+
end
|
|
1165
1518
|
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1519
|
+
it "persists as a BSON::Decimal128" do
|
|
1520
|
+
expect(band.attributes["sales"]).to eq(BSON::Decimal128.new(decimal.to_i.to_s))
|
|
1521
|
+
end
|
|
1169
1522
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1523
|
+
it "returns the proper big decimal" do
|
|
1524
|
+
expect(band.sales).to eq(decimal)
|
|
1525
|
+
end
|
|
1172
1526
|
end
|
|
1173
|
-
end
|
|
1174
1527
|
|
|
1175
|
-
|
|
1528
|
+
context "when setting to a float" do
|
|
1176
1529
|
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1530
|
+
before do
|
|
1531
|
+
band.sales = decimal.to_f
|
|
1532
|
+
end
|
|
1180
1533
|
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1534
|
+
it "properly persists as a BSON::Decimal128" do
|
|
1535
|
+
expect(band.attributes["sales"]).to eq(BSON::Decimal128.new(decimal.to_f.to_s))
|
|
1536
|
+
end
|
|
1184
1537
|
|
|
1185
|
-
|
|
1186
|
-
|
|
1538
|
+
it "returns the proper big decimal" do
|
|
1539
|
+
expect(band.sales).to eq(decimal)
|
|
1540
|
+
end
|
|
1187
1541
|
end
|
|
1188
1542
|
end
|
|
1189
1543
|
end
|
|
@@ -1191,7 +1545,7 @@ describe Mongoid::Fields do
|
|
|
1191
1545
|
context "when the field is a hash of arrays" do
|
|
1192
1546
|
|
|
1193
1547
|
let(:person) do
|
|
1194
|
-
Person.create
|
|
1548
|
+
Person.create!
|
|
1195
1549
|
end
|
|
1196
1550
|
|
|
1197
1551
|
let(:map) do
|
|
@@ -1205,11 +1559,11 @@ describe Mongoid::Fields do
|
|
|
1205
1559
|
before do
|
|
1206
1560
|
person.map = map
|
|
1207
1561
|
person.map["stack1"].reverse!
|
|
1208
|
-
person.save
|
|
1562
|
+
person.save!
|
|
1209
1563
|
end
|
|
1210
1564
|
|
|
1211
1565
|
it "properly updates the hash" do
|
|
1212
|
-
person.map.
|
|
1566
|
+
expect(person.map).to eq(
|
|
1213
1567
|
{
|
|
1214
1568
|
"stack1" => [ 4, 3, 2, 1 ],
|
|
1215
1569
|
"stack2" => [ 1, 2, 3, 4 ],
|
|
@@ -1219,7 +1573,7 @@ describe Mongoid::Fields do
|
|
|
1219
1573
|
end
|
|
1220
1574
|
|
|
1221
1575
|
it "persists the changes" do
|
|
1222
|
-
person.reload.map.
|
|
1576
|
+
expect(person.reload.map).to eq(
|
|
1223
1577
|
{
|
|
1224
1578
|
"stack1" => [ 4, 3, 2, 1 ],
|
|
1225
1579
|
"stack2" => [ 1, 2, 3, 4 ],
|
|
@@ -1242,11 +1596,371 @@ describe Mongoid::Fields do
|
|
|
1242
1596
|
end
|
|
1243
1597
|
|
|
1244
1598
|
it "does not override the parent" do
|
|
1245
|
-
canvas.foo.
|
|
1599
|
+
expect(canvas.foo).to eq("original")
|
|
1246
1600
|
end
|
|
1247
1601
|
|
|
1248
1602
|
it "overrides the default" do
|
|
1249
|
-
test.foo.
|
|
1603
|
+
expect(test.foo).to eq("overridden")
|
|
1604
|
+
end
|
|
1605
|
+
end
|
|
1606
|
+
end
|
|
1607
|
+
|
|
1608
|
+
context "when a localized field is a boolean" do
|
|
1609
|
+
|
|
1610
|
+
context "when the default is true" do
|
|
1611
|
+
|
|
1612
|
+
let(:definition) do
|
|
1613
|
+
Definition.new
|
|
1614
|
+
end
|
|
1615
|
+
|
|
1616
|
+
it "returns the proper predicate result" do
|
|
1617
|
+
expect(definition).to be_active
|
|
1618
|
+
end
|
|
1619
|
+
end
|
|
1620
|
+
end
|
|
1621
|
+
|
|
1622
|
+
describe '_type field' do
|
|
1623
|
+
context 'on parent class' do
|
|
1624
|
+
let(:shape) { Shape.new }
|
|
1625
|
+
|
|
1626
|
+
it 'is correctly set' do
|
|
1627
|
+
shape.attributes['_type'].should == 'Shape'
|
|
1628
|
+
end
|
|
1629
|
+
end
|
|
1630
|
+
|
|
1631
|
+
context 'on child class' do
|
|
1632
|
+
let(:circle) { Circle.new }
|
|
1633
|
+
|
|
1634
|
+
it 'is correctly set' do
|
|
1635
|
+
circle.attributes['_type'].should == 'Circle'
|
|
1636
|
+
end
|
|
1637
|
+
end
|
|
1638
|
+
end
|
|
1639
|
+
|
|
1640
|
+
describe '.database_field_name' do
|
|
1641
|
+
|
|
1642
|
+
shared_examples_for 'database_field_name' do
|
|
1643
|
+
subject { Person.database_field_name(key) }
|
|
1644
|
+
|
|
1645
|
+
context 'non-aliased field name' do
|
|
1646
|
+
let(:key) { 't' }
|
|
1647
|
+
it { is_expected.to eq 't' }
|
|
1648
|
+
end
|
|
1649
|
+
|
|
1650
|
+
context 'aliased field name' do
|
|
1651
|
+
let(:key) { 'test' }
|
|
1652
|
+
it { is_expected.to eq 't' }
|
|
1653
|
+
end
|
|
1654
|
+
|
|
1655
|
+
context 'non-aliased embeds one relation' do
|
|
1656
|
+
let(:key) { 'pass' }
|
|
1657
|
+
it { is_expected.to eq 'pass' }
|
|
1658
|
+
end
|
|
1659
|
+
|
|
1660
|
+
context 'aliased embeds one relation' do
|
|
1661
|
+
let(:key) { 'passport' }
|
|
1662
|
+
it { is_expected.to eq 'pass' }
|
|
1663
|
+
end
|
|
1664
|
+
|
|
1665
|
+
context 'non-aliased embeds many relation' do
|
|
1666
|
+
let(:key) { 'mobile_phones' }
|
|
1667
|
+
it { is_expected.to eq 'mobile_phones' }
|
|
1668
|
+
end
|
|
1669
|
+
|
|
1670
|
+
context 'aliased embeds many relation' do
|
|
1671
|
+
let(:key) { 'phones' }
|
|
1672
|
+
it { is_expected.to eq 'mobile_phones' }
|
|
1673
|
+
end
|
|
1674
|
+
|
|
1675
|
+
context 'non-aliased embeds one field' do
|
|
1676
|
+
let(:key) { 'pass.exp' }
|
|
1677
|
+
it { is_expected.to eq 'pass.exp' }
|
|
1678
|
+
end
|
|
1679
|
+
|
|
1680
|
+
context 'aliased embeds one field' do
|
|
1681
|
+
let(:key) { 'passport.expiration_date' }
|
|
1682
|
+
it { is_expected.to eq 'pass.exp' }
|
|
1683
|
+
end
|
|
1684
|
+
|
|
1685
|
+
context 'non-aliased embeds many field' do
|
|
1686
|
+
let(:key) { 'mobile_phones.landline' }
|
|
1687
|
+
it { is_expected.to eq 'mobile_phones.landline' }
|
|
1688
|
+
end
|
|
1689
|
+
|
|
1690
|
+
context 'aliased embeds many field' do
|
|
1691
|
+
let(:key) { 'phones.extension' }
|
|
1692
|
+
it { is_expected.to eq 'mobile_phones.ext' }
|
|
1693
|
+
end
|
|
1694
|
+
|
|
1695
|
+
context 'aliased multi-level embedded document' do
|
|
1696
|
+
let(:key) { 'phones.extension' }
|
|
1697
|
+
it { is_expected.to eq 'mobile_phones.ext' }
|
|
1698
|
+
end
|
|
1699
|
+
|
|
1700
|
+
context 'non-aliased multi-level embedded document' do
|
|
1701
|
+
let(:key) { 'phones.extension' }
|
|
1702
|
+
it { is_expected.to eq 'mobile_phones.ext' }
|
|
1703
|
+
end
|
|
1704
|
+
|
|
1705
|
+
context 'aliased multi-level embedded document field' do
|
|
1706
|
+
let(:key) { 'mobile_phones.country_code.code' }
|
|
1707
|
+
it { is_expected.to eq 'mobile_phones.country_code.code' }
|
|
1708
|
+
end
|
|
1709
|
+
|
|
1710
|
+
context 'non-aliased multi-level embedded document field' do
|
|
1711
|
+
let(:key) { 'phones.country_code.iso_alpha2_code' }
|
|
1712
|
+
it { is_expected.to eq 'mobile_phones.country_code.iso' }
|
|
1713
|
+
end
|
|
1714
|
+
|
|
1715
|
+
context 'when field is unknown' do
|
|
1716
|
+
let(:key) { 'shenanigans' }
|
|
1717
|
+
it { is_expected.to eq 'shenanigans' }
|
|
1718
|
+
end
|
|
1719
|
+
|
|
1720
|
+
context 'when embedded field is unknown' do
|
|
1721
|
+
let(:key) { 'phones.bamboozle' }
|
|
1722
|
+
it { is_expected.to eq 'mobile_phones.bamboozle' }
|
|
1723
|
+
end
|
|
1724
|
+
|
|
1725
|
+
context 'when multi-level embedded field is unknown' do
|
|
1726
|
+
let(:key) { 'phones.bamboozle.brouhaha' }
|
|
1727
|
+
it { is_expected.to eq 'mobile_phones.bamboozle.brouhaha' }
|
|
1728
|
+
end
|
|
1729
|
+
end
|
|
1730
|
+
|
|
1731
|
+
shared_examples_for 'pre-fix database_field_name' do
|
|
1732
|
+
subject { Person.database_field_name(key) }
|
|
1733
|
+
|
|
1734
|
+
context 'non-aliased field name' do
|
|
1735
|
+
let(:key) { 't' }
|
|
1736
|
+
it { is_expected.to eq 't' }
|
|
1737
|
+
end
|
|
1738
|
+
|
|
1739
|
+
context 'aliased field name' do
|
|
1740
|
+
let(:key) { 'test' }
|
|
1741
|
+
it { is_expected.to eq 't' }
|
|
1742
|
+
end
|
|
1743
|
+
|
|
1744
|
+
context 'non-aliased embeds one relation' do
|
|
1745
|
+
let(:key) { 'pass' }
|
|
1746
|
+
it { is_expected.to eq 'pass' }
|
|
1747
|
+
end
|
|
1748
|
+
|
|
1749
|
+
context 'aliased embeds one relation' do
|
|
1750
|
+
let(:key) { 'passport' }
|
|
1751
|
+
it { is_expected.to eq 'pass' }
|
|
1752
|
+
end
|
|
1753
|
+
|
|
1754
|
+
context 'non-aliased embeds many relation' do
|
|
1755
|
+
let(:key) { 'mobile_phones' }
|
|
1756
|
+
it { is_expected.to eq 'mobile_phones' }
|
|
1757
|
+
end
|
|
1758
|
+
|
|
1759
|
+
context 'aliased embeds many relation' do
|
|
1760
|
+
let(:key) { 'phones' }
|
|
1761
|
+
it { is_expected.to eq 'mobile_phones' }
|
|
1762
|
+
end
|
|
1763
|
+
|
|
1764
|
+
context 'non-aliased embeds one field' do
|
|
1765
|
+
let(:key) { 'pass.exp' }
|
|
1766
|
+
it { is_expected.to eq 'pass.exp' }
|
|
1767
|
+
end
|
|
1768
|
+
|
|
1769
|
+
context 'aliased embeds one field' do
|
|
1770
|
+
let(:key) { 'passport.expiration_date' }
|
|
1771
|
+
it { is_expected.to eq 'passport.expiration_date' }
|
|
1772
|
+
end
|
|
1773
|
+
|
|
1774
|
+
context 'non-aliased embeds many field' do
|
|
1775
|
+
let(:key) { 'mobile_phones.landline' }
|
|
1776
|
+
it { is_expected.to eq 'mobile_phones.landline' }
|
|
1777
|
+
end
|
|
1778
|
+
|
|
1779
|
+
context 'aliased embeds many field' do
|
|
1780
|
+
let(:key) { 'phones.extension' }
|
|
1781
|
+
it { is_expected.to eq 'phones.extension' }
|
|
1782
|
+
end
|
|
1783
|
+
|
|
1784
|
+
context 'aliased multi-level embedded document' do
|
|
1785
|
+
let(:key) { 'phones.extension' }
|
|
1786
|
+
it { is_expected.to eq 'phones.extension' }
|
|
1787
|
+
end
|
|
1788
|
+
|
|
1789
|
+
context 'non-aliased multi-level embedded document' do
|
|
1790
|
+
let(:key) { 'phones.extension' }
|
|
1791
|
+
it { is_expected.to eq 'phones.extension' }
|
|
1792
|
+
end
|
|
1793
|
+
|
|
1794
|
+
context 'aliased multi-level embedded document field' do
|
|
1795
|
+
let(:key) { 'mobile_phones.country_code.code' }
|
|
1796
|
+
it { is_expected.to eq 'mobile_phones.country_code.code' }
|
|
1797
|
+
end
|
|
1798
|
+
|
|
1799
|
+
context 'non-aliased multi-level embedded document field' do
|
|
1800
|
+
let(:key) { 'phones.country_code.iso_alpha2_code' }
|
|
1801
|
+
it { is_expected.to eq 'phones.country_code.iso_alpha2_code' }
|
|
1802
|
+
end
|
|
1803
|
+
|
|
1804
|
+
context 'when field is unknown' do
|
|
1805
|
+
let(:key) { 'shenanigans' }
|
|
1806
|
+
it { is_expected.to eq 'shenanigans' }
|
|
1807
|
+
end
|
|
1808
|
+
|
|
1809
|
+
context 'when embedded field is unknown' do
|
|
1810
|
+
let(:key) { 'phones.bamboozle' }
|
|
1811
|
+
it { is_expected.to eq 'phones.bamboozle' }
|
|
1812
|
+
end
|
|
1813
|
+
|
|
1814
|
+
context 'when multi-level embedded field is unknown' do
|
|
1815
|
+
let(:key) { 'phones.bamboozle.brouhaha' }
|
|
1816
|
+
it { is_expected.to eq 'phones.bamboozle.brouhaha' }
|
|
1817
|
+
end
|
|
1818
|
+
end
|
|
1819
|
+
|
|
1820
|
+
context "when the broken_alias_handling is not set" do
|
|
1821
|
+
config_override :broken_alias_handling, false
|
|
1822
|
+
|
|
1823
|
+
context 'given nil' do
|
|
1824
|
+
subject { Person.database_field_name(nil) }
|
|
1825
|
+
it { is_expected.to eq nil }
|
|
1826
|
+
end
|
|
1827
|
+
|
|
1828
|
+
context 'given an empty String' do
|
|
1829
|
+
subject { Person.database_field_name('') }
|
|
1830
|
+
it { is_expected.to eq nil }
|
|
1831
|
+
end
|
|
1832
|
+
|
|
1833
|
+
context 'given a String' do
|
|
1834
|
+
subject { Person.database_field_name(key.to_s) }
|
|
1835
|
+
it_behaves_like 'database_field_name'
|
|
1836
|
+
end
|
|
1837
|
+
|
|
1838
|
+
context 'given a Symbol' do
|
|
1839
|
+
subject { Person.database_field_name(key.to_sym) }
|
|
1840
|
+
it_behaves_like 'database_field_name'
|
|
1841
|
+
end
|
|
1842
|
+
end
|
|
1843
|
+
|
|
1844
|
+
context "when the broken_alias_handling is set" do
|
|
1845
|
+
config_override :broken_alias_handling, true
|
|
1846
|
+
|
|
1847
|
+
context 'given nil' do
|
|
1848
|
+
subject { Person.database_field_name(nil) }
|
|
1849
|
+
it { is_expected.to eq nil }
|
|
1850
|
+
end
|
|
1851
|
+
|
|
1852
|
+
context 'given an empty String' do
|
|
1853
|
+
subject { Person.database_field_name('') }
|
|
1854
|
+
it { is_expected.to eq "" }
|
|
1855
|
+
end
|
|
1856
|
+
|
|
1857
|
+
context 'given a String' do
|
|
1858
|
+
subject { Person.database_field_name(key.to_s) }
|
|
1859
|
+
it_behaves_like 'pre-fix database_field_name'
|
|
1860
|
+
end
|
|
1861
|
+
|
|
1862
|
+
context 'given a Symbol' do
|
|
1863
|
+
subject { Person.database_field_name(key.to_sym) }
|
|
1864
|
+
it_behaves_like 'pre-fix database_field_name'
|
|
1865
|
+
end
|
|
1866
|
+
end
|
|
1867
|
+
|
|
1868
|
+
context 'when getting the database field name of a belongs_to associations' do
|
|
1869
|
+
# These tests only apply when the flag is not set
|
|
1870
|
+
config_override :broken_alias_handling, false
|
|
1871
|
+
|
|
1872
|
+
context "when the broken_alias_handling is not set" do
|
|
1873
|
+
context "when the association is the last item" do
|
|
1874
|
+
let(:name) do
|
|
1875
|
+
Game.database_field_name("person")
|
|
1876
|
+
end
|
|
1877
|
+
|
|
1878
|
+
it "gets the alias" do
|
|
1879
|
+
expect(name).to eq("person_id")
|
|
1880
|
+
end
|
|
1881
|
+
end
|
|
1882
|
+
|
|
1883
|
+
context "when the association is not the last item" do
|
|
1884
|
+
let(:name) do
|
|
1885
|
+
Game.database_field_name("person.name")
|
|
1886
|
+
end
|
|
1887
|
+
|
|
1888
|
+
it "gets the alias" do
|
|
1889
|
+
expect(name).to eq("person.name")
|
|
1890
|
+
end
|
|
1891
|
+
end
|
|
1892
|
+
end
|
|
1893
|
+
end
|
|
1894
|
+
end
|
|
1895
|
+
|
|
1896
|
+
describe "#get_field" do
|
|
1897
|
+
|
|
1898
|
+
let(:klass) { Person }
|
|
1899
|
+
let(:field) { klass.cleanse_localized_field_names(field_name) }
|
|
1900
|
+
|
|
1901
|
+
context "when cleansing a field" do
|
|
1902
|
+
let(:field_name) { "employer_id" }
|
|
1903
|
+
it "returns the correct field name" do
|
|
1904
|
+
expect(field).to eq(field_name)
|
|
1905
|
+
end
|
|
1906
|
+
end
|
|
1907
|
+
|
|
1908
|
+
context "when cleansing a localized field" do
|
|
1909
|
+
let(:field_name) { "desc" }
|
|
1910
|
+
it "returns the correct field name" do
|
|
1911
|
+
expect(field).to eq(field_name)
|
|
1912
|
+
end
|
|
1913
|
+
end
|
|
1914
|
+
|
|
1915
|
+
context "when cleansing a translation field" do
|
|
1916
|
+
let(:field_name) { "desc_translations" }
|
|
1917
|
+
it "returns the correct field name" do
|
|
1918
|
+
expect(field).to eq("desc")
|
|
1919
|
+
end
|
|
1920
|
+
end
|
|
1921
|
+
|
|
1922
|
+
context "when cleansing an existing translation field" do
|
|
1923
|
+
let(:field_name) { "localized_translations" }
|
|
1924
|
+
it "returns the correct field name" do
|
|
1925
|
+
expect(field).to eq(field_name)
|
|
1926
|
+
end
|
|
1927
|
+
end
|
|
1928
|
+
|
|
1929
|
+
context "when cleansing an existing translation field with a _translations" do
|
|
1930
|
+
let(:field_name) { "localized_translations_translations" }
|
|
1931
|
+
it "returns the correct field name" do
|
|
1932
|
+
expect(field).to eq("localized_translations")
|
|
1933
|
+
end
|
|
1934
|
+
end
|
|
1935
|
+
|
|
1936
|
+
context "when cleansing dotted translation field" do
|
|
1937
|
+
config_override :broken_alias_handling, false
|
|
1938
|
+
let(:field_name) { "passport.name_translations.asd" }
|
|
1939
|
+
it "returns the correct field name" do
|
|
1940
|
+
expect(field).to eq("pass.name.asd")
|
|
1941
|
+
end
|
|
1942
|
+
end
|
|
1943
|
+
|
|
1944
|
+
context "when cleansing dotted translation field as a symbol" do
|
|
1945
|
+
config_override :broken_alias_handling, false
|
|
1946
|
+
let(:field_name) { "passport.name_translations.asd".to_sym }
|
|
1947
|
+
it "returns the correct field name" do
|
|
1948
|
+
expect(field).to eq("pass.name.asd")
|
|
1949
|
+
end
|
|
1950
|
+
end
|
|
1951
|
+
|
|
1952
|
+
context "when cleansing dotted existing translation field" do
|
|
1953
|
+
config_override :broken_alias_handling, false
|
|
1954
|
+
let(:field_name) { "passport.localized_translations.asd" }
|
|
1955
|
+
it "returns the correct field name" do
|
|
1956
|
+
expect(field).to eq("pass.localized_translations.asd")
|
|
1957
|
+
end
|
|
1958
|
+
end
|
|
1959
|
+
|
|
1960
|
+
context "when cleansing aliased dotted translation field" do
|
|
1961
|
+
let(:field_name) { "pass.name_translations.asd" }
|
|
1962
|
+
it "returns the correct field name" do
|
|
1963
|
+
expect(field).to eq("pass.name.asd")
|
|
1250
1964
|
end
|
|
1251
1965
|
end
|
|
1252
1966
|
end
|