mongoid 6.4.8 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Rakefile +0 -26
- data/lib/config/locales/en.yml +17 -0
- data/lib/mongoid/association/accessors.rb +339 -0
- data/lib/mongoid/{relations/binding.rb → association/bindable.rb} +32 -52
- data/lib/mongoid/association/builders.rb +92 -0
- data/lib/mongoid/{relations/constraint.rb → association/constrainable.rb} +11 -22
- data/lib/mongoid/association/depending.rb +116 -0
- data/lib/mongoid/{relations/eager.rb → association/eager_loadable.rb} +11 -11
- data/lib/mongoid/{relations → association}/embedded/batchable.rb +21 -21
- data/lib/mongoid/association/embedded/cyclic.rb +109 -0
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +56 -0
- data/lib/mongoid/{relations/builders/embedded/in.rb → association/embedded/embedded_in/buildable.rb} +12 -6
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +121 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +154 -0
- data/lib/mongoid/{relations/bindings/embedded/many.rb → association/embedded/embeds_many/binding.rb} +11 -9
- data/lib/mongoid/{relations/builders/embedded/many.rb → association/embedded/embeds_many/buildable.rb} +13 -7
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +529 -0
- data/lib/mongoid/association/embedded/embeds_many.rb +210 -0
- data/lib/mongoid/{relations/bindings/embedded/one.rb → association/embedded/embeds_one/binding.rb} +12 -10
- data/lib/mongoid/{relations/builders/embedded/one.rb → association/embedded/embeds_one/buildable.rb} +13 -7
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +130 -0
- data/lib/mongoid/association/embedded/embeds_one.rb +173 -0
- data/lib/mongoid/association/embedded.rb +4 -0
- data/lib/mongoid/association/macros.rb +204 -0
- data/lib/mongoid/{relations → association}/many.rb +20 -50
- data/lib/mongoid/{relations → association}/marshalable.rb +6 -4
- data/lib/mongoid/association/nested/many.rb +200 -0
- data/lib/mongoid/association/nested/nested_buildable.rb +72 -0
- data/lib/mongoid/association/nested/one.rb +127 -0
- data/lib/mongoid/association/nested.rb +15 -0
- data/lib/mongoid/{relations → association}/one.rb +6 -6
- data/lib/mongoid/association/options.rb +152 -0
- data/lib/mongoid/{relations → association}/proxy.rb +31 -58
- data/lib/mongoid/association/referenced/auto_save.rb +79 -0
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +87 -0
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +46 -0
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +36 -0
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +136 -0
- data/lib/mongoid/association/referenced/belongs_to.rb +248 -0
- data/lib/mongoid/association/referenced/counter_cache.rb +163 -0
- data/lib/mongoid/association/referenced/eager.rb +159 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +71 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +40 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +52 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +310 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +290 -0
- data/lib/mongoid/{relations/bindings/referenced/many.rb → association/referenced/has_many/binding.rb} +6 -5
- data/lib/mongoid/association/referenced/has_many/buildable.rb +38 -0
- data/lib/mongoid/association/referenced/has_many/eager.rb +43 -0
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +510 -0
- data/lib/mongoid/association/referenced/has_many/proxy.rb +578 -0
- data/lib/mongoid/association/referenced/has_many.rb +275 -0
- data/lib/mongoid/{relations/bindings/referenced/one.rb → association/referenced/has_one/binding.rb} +11 -8
- data/lib/mongoid/association/referenced/has_one/buildable.rb +60 -0
- data/lib/mongoid/association/referenced/has_one/eager.rb +35 -0
- data/lib/mongoid/{relations/builders/nested_attributes/one.rb → association/referenced/has_one/nested_builder.rb} +9 -9
- data/lib/mongoid/association/referenced/has_one/proxy.rb +113 -0
- data/lib/mongoid/association/referenced/has_one.rb +204 -0
- data/lib/mongoid/association/referenced/syncable.rb +170 -0
- data/lib/mongoid/association/referenced.rb +7 -0
- data/lib/mongoid/{relations → association}/reflections.rb +21 -17
- data/lib/mongoid/association/relatable.rb +415 -0
- data/lib/mongoid/association/touchable.rb +97 -0
- data/lib/mongoid/association.rb +150 -0
- data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
- data/lib/mongoid/atomic.rb +4 -4
- data/lib/mongoid/attributes/dynamic.rb +2 -2
- data/lib/mongoid/attributes/nested.rb +10 -10
- data/lib/mongoid/attributes/processing.rb +2 -2
- data/lib/mongoid/attributes/readonly.rb +2 -4
- data/lib/mongoid/attributes.rb +22 -13
- data/lib/mongoid/changeable.rb +1 -1
- data/lib/mongoid/clients/options.rb +1 -1
- data/lib/mongoid/clients/sessions.rb +2 -2
- data/lib/mongoid/composable.rb +4 -4
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/geo_near.rb +1 -1
- data/lib/mongoid/contextual/map_reduce.rb +4 -4
- data/lib/mongoid/contextual/memory.rb +25 -7
- data/lib/mongoid/contextual/mongo.rb +13 -11
- data/lib/mongoid/copyable.rb +6 -6
- data/lib/mongoid/criteria/includable.rb +14 -14
- data/lib/mongoid/criteria/modifiable.rb +8 -14
- data/lib/mongoid/criteria/queryable/extensions/string.rb +1 -1
- data/lib/mongoid/criteria/queryable/pipeline.rb +10 -5
- data/lib/mongoid/criteria/queryable/selectable.rb +10 -34
- data/lib/mongoid/criteria.rb +2 -2
- data/lib/mongoid/document.rb +6 -6
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +32 -0
- data/lib/mongoid/errors/invalid_relation_option.rb +29 -0
- data/lib/mongoid/errors/unknown_model.rb +25 -0
- data/lib/mongoid/errors.rb +3 -0
- data/lib/mongoid/extensions/array.rb +5 -5
- data/lib/mongoid/extensions/big_decimal.rb +1 -1
- data/lib/mongoid/extensions/hash.rb +5 -2
- data/lib/mongoid/extensions/object.rb +4 -4
- data/lib/mongoid/extensions/range.rb +1 -0
- data/lib/mongoid/extensions/regexp.rb +0 -1
- data/lib/mongoid/extensions/string.rb +1 -3
- data/lib/mongoid/extensions.rb +0 -4
- data/lib/mongoid/factory.rb +13 -3
- data/lib/mongoid/fields/foreign_key.rb +5 -5
- data/lib/mongoid/fields/standard.rb +2 -14
- data/lib/mongoid/fields/validators/macro.rb +1 -1
- data/lib/mongoid/fields.rb +3 -3
- data/lib/mongoid/indexable.rb +8 -5
- data/lib/mongoid/interceptable.rb +5 -5
- data/lib/mongoid/matchable/and.rb +1 -1
- data/lib/mongoid/matchable/elem_match.rb +9 -3
- data/lib/mongoid/matchable.rb +0 -3
- data/lib/mongoid/persistable/creatable.rb +2 -2
- data/lib/mongoid/persistable/deletable.rb +9 -8
- data/lib/mongoid/persistable/incrementable.rb +1 -1
- data/lib/mongoid/persistable/logical.rb +1 -1
- data/lib/mongoid/persistable/settable.rb +5 -5
- data/lib/mongoid/persistable/updatable.rb +2 -2
- data/lib/mongoid/persistable/upsertable.rb +1 -1
- data/lib/mongoid/persistable.rb +5 -6
- data/lib/mongoid/persistence_context.rb +1 -5
- data/lib/mongoid/query_cache.rb +19 -64
- data/lib/mongoid/railtie.rb +0 -17
- data/lib/mongoid/reloadable.rb +1 -1
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +4 -4
- data/lib/mongoid/shardable.rb +1 -1
- data/lib/mongoid/tasks/database.rb +2 -2
- data/lib/mongoid/threaded.rb +0 -36
- data/lib/mongoid/traversable.rb +3 -3
- data/lib/mongoid/validatable/presence.rb +2 -2
- data/lib/mongoid/validatable/uniqueness.rb +4 -4
- data/lib/mongoid/validatable.rb +8 -8
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +3 -0
- data/spec/app/models/animal.rb +2 -1
- data/spec/app/models/bomb.rb +1 -1
- data/spec/app/models/message.rb +1 -1
- data/spec/app/models/person.rb +5 -2
- data/spec/app/models/shipment_address.rb +1 -0
- data/spec/app/models/vertex.rb +6 -0
- data/spec/app/models/wiki_page.rb +1 -1
- data/spec/config/mongoid.yml +1 -0
- data/spec/mongoid/{relations → association}/accessors_spec.rb +1 -1
- data/spec/mongoid/{relations → association}/auto_save_spec.rb +60 -12
- data/spec/mongoid/{relations → association}/builders_spec.rb +1 -1
- data/spec/mongoid/association/constrainable_spec.rb +115 -0
- data/spec/mongoid/{relations → association}/counter_cache_spec.rb +1 -1
- data/spec/mongoid/association/depending_spec.rb +613 -0
- data/spec/mongoid/{relations → association}/eager_spec.rb +12 -12
- data/spec/mongoid/{relations → association/embedded}/cyclic_spec.rb +1 -1
- data/spec/mongoid/{relations/bindings/embedded/in_spec.rb → association/embedded/embedded_in/binding_spec.rb} +13 -13
- data/spec/mongoid/{relations/builders/embedded/in_spec.rb → association/embedded/embedded_in/buildable_spec.rb} +9 -9
- data/spec/mongoid/{relations/embedded/in_spec.rb → association/embedded/embedded_in/proxy_spec.rb} +5 -77
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +843 -0
- data/spec/mongoid/{relations/bindings/embedded/many_spec.rb → association/embedded/embeds_many/binding_spec.rb} +3 -3
- data/spec/mongoid/{relations/builders/embedded/many_spec.rb → association/embedded/embeds_many/buildable_spec.rb} +17 -45
- data/spec/mongoid/{relations/embedded/many_spec.rb → association/embedded/embeds_many/proxy_spec.rb} +140 -428
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +852 -0
- data/spec/mongoid/{relations/bindings/embedded/one_spec.rb → association/embedded/embeds_one/binding_spec.rb} +4 -4
- data/spec/mongoid/{relations/builders/embedded/one_spec.rb → association/embedded/embeds_one/buildable_spec.rb} +14 -34
- data/spec/mongoid/{relations/embedded/one_spec.rb → association/embedded/embeds_one/proxy_spec.rb} +39 -84
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +908 -0
- data/spec/mongoid/{relations → association}/macros_spec.rb +148 -73
- data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/many_spec.rb +16 -19
- data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/one_spec.rb +17 -20
- data/spec/mongoid/association/options_spec.rb +1321 -0
- data/spec/mongoid/{relations → association}/polymorphic_spec.rb +7 -34
- data/spec/mongoid/{relations/bindings/referenced/in_spec.rb → association/referenced/belongs_to/binding_spec.rb} +7 -7
- data/spec/mongoid/{relations/builders/referenced/in_spec.rb → association/referenced/belongs_to/buildable_spec.rb} +46 -79
- data/spec/mongoid/{relations/eager/belongs_to_spec.rb → association/referenced/belongs_to/eager_spec.rb} +9 -9
- data/spec/mongoid/{relations/referenced/in_spec.rb → association/referenced/belongs_to/proxy_spec.rb} +57 -91
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +1963 -0
- data/spec/mongoid/{relations/bindings/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +121 -0
- data/spec/mongoid/{relations/eager/has_and_belongs_to_many_spec.rb → association/referenced/has_and_belongs_to_many/eager_spec.rb} +5 -5
- data/spec/mongoid/{relations/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/proxy_spec.rb} +107 -98
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +1027 -0
- data/spec/mongoid/{relations/bindings/referenced/many_spec.rb → association/referenced/has_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +119 -0
- data/spec/mongoid/{relations/eager/has_many_spec.rb → association/referenced/has_many/eager_spec.rb} +26 -11
- data/spec/mongoid/{relations/targets → association/referenced/has_many}/enumerable_spec.rb +122 -1
- data/spec/mongoid/{relations/referenced/many_spec.rb → association/referenced/has_many/proxy_spec.rb} +28 -93
- data/spec/mongoid/association/referenced/has_many_spec.rb +1225 -0
- data/spec/mongoid/{relations/bindings/referenced/one_spec.rb → association/referenced/has_one/binding_spec.rb} +4 -4
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +113 -0
- data/spec/mongoid/{relations/eager/has_one_spec.rb → association/referenced/has_one/eager_spec.rb} +10 -10
- data/spec/mongoid/{relations/referenced/one_spec.rb → association/referenced/has_one/proxy_spec.rb} +9 -109
- data/spec/mongoid/association/referenced/has_one_spec.rb +1244 -0
- data/spec/mongoid/{relations → association}/reflections_spec.rb +1 -12
- data/spec/mongoid/{relations/synchronization_spec.rb → association/syncable_spec.rb} +4 -2
- data/spec/mongoid/{relations → association}/touchable_spec.rb +19 -1
- data/spec/mongoid/{relations_spec.rb → association_spec.rb} +1 -1
- data/spec/mongoid/atomic/modifiers_spec.rb +2 -2
- data/spec/mongoid/atomic_spec.rb +4 -4
- data/spec/mongoid/attributes/nested_spec.rb +14 -12
- data/spec/mongoid/attributes/readonly_spec.rb +80 -125
- data/spec/mongoid/attributes_spec.rb +38 -2
- data/spec/mongoid/clients/factory_spec.rb +28 -52
- data/spec/mongoid/clients/options_spec.rb +65 -69
- data/spec/mongoid/clients/sessions_spec.rb +4 -13
- data/spec/mongoid/config_spec.rb +24 -0
- data/spec/mongoid/contextual/geo_near_spec.rb +0 -1
- data/spec/mongoid/contextual/memory_spec.rb +19 -0
- data/spec/mongoid/contextual/mongo_spec.rb +30 -5
- data/spec/mongoid/copyable_spec.rb +34 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +183 -60
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +3 -3
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +43 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +12 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +3 -42
- data/spec/mongoid/criteria/queryable/selector_spec.rb +2 -2
- data/spec/mongoid/criteria/scopable_spec.rb +0 -81
- data/spec/mongoid/criteria_spec.rb +16 -19
- data/spec/mongoid/document_spec.rb +2 -56
- data/spec/mongoid/extensions/array_spec.rb +11 -15
- data/spec/mongoid/extensions/big_decimal_spec.rb +9 -9
- data/spec/mongoid/extensions/hash_spec.rb +18 -1
- data/spec/mongoid/extensions/object_spec.rb +7 -11
- data/spec/mongoid/extensions/range_spec.rb +7 -0
- data/spec/mongoid/extensions/regexp_spec.rb +0 -23
- data/spec/mongoid/extensions/string_spec.rb +7 -35
- data/spec/mongoid/factory_spec.rb +19 -1
- data/spec/mongoid/fields/foreign_key_spec.rb +24 -32
- data/spec/mongoid/fields_spec.rb +2 -2
- data/spec/mongoid/findable_spec.rb +1 -1
- data/spec/mongoid/indexable_spec.rb +18 -8
- data/spec/mongoid/interceptable_spec.rb +22 -1
- data/spec/mongoid/matchable/elem_match_spec.rb +20 -0
- data/spec/mongoid/matchable_spec.rb +1 -26
- data/spec/mongoid/persistable/incrementable_spec.rb +6 -6
- data/spec/mongoid/persistable/savable_spec.rb +2 -2
- data/spec/mongoid/persistable/settable_spec.rb +1 -35
- data/spec/mongoid/persistable_spec.rb +21 -6
- data/spec/mongoid/query_cache_spec.rb +16 -99
- data/spec/mongoid/relations/proxy_spec.rb +124 -124
- data/spec/mongoid/scopable_spec.rb +0 -13
- data/spec/mongoid/shardable_spec.rb +32 -12
- data/spec/mongoid/threaded_spec.rb +0 -68
- data/spec/mongoid/validatable/associated_spec.rb +1 -1
- data/spec/mongoid/validatable/presence_spec.rb +7 -6
- data/spec/mongoid/validatable_spec.rb +1 -1
- data/spec/spec_helper.rb +12 -14
- data.tar.gz.sig +1 -1
- metadata +192 -207
- metadata.gz.sig +0 -0
- data/lib/mongoid/matchable/nor.rb +0 -37
- data/lib/mongoid/railties/controller_runtime.rb +0 -86
- data/lib/mongoid/relations/accessors.rb +0 -267
- data/lib/mongoid/relations/auto_save.rb +0 -94
- data/lib/mongoid/relations/bindings/embedded/in.rb +0 -59
- data/lib/mongoid/relations/bindings/referenced/in.rb +0 -65
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +0 -70
- data/lib/mongoid/relations/bindings.rb +0 -9
- data/lib/mongoid/relations/builder.rb +0 -57
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +0 -199
- data/lib/mongoid/relations/builders/referenced/in.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +0 -39
- data/lib/mongoid/relations/builders/referenced/one.rb +0 -26
- data/lib/mongoid/relations/builders.rb +0 -106
- data/lib/mongoid/relations/cascading/delete.rb +0 -44
- data/lib/mongoid/relations/cascading/destroy.rb +0 -43
- data/lib/mongoid/relations/cascading/nullify.rb +0 -35
- data/lib/mongoid/relations/cascading/restrict.rb +0 -39
- data/lib/mongoid/relations/cascading.rb +0 -56
- data/lib/mongoid/relations/conversions.rb +0 -34
- data/lib/mongoid/relations/counter_cache.rb +0 -160
- data/lib/mongoid/relations/cyclic.rb +0 -107
- data/lib/mongoid/relations/eager/base.rb +0 -153
- data/lib/mongoid/relations/eager/belongs_to.rb +0 -31
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +0 -47
- data/lib/mongoid/relations/eager/has_many.rb +0 -38
- data/lib/mongoid/relations/eager/has_one.rb +0 -30
- data/lib/mongoid/relations/embedded/in.rb +0 -241
- data/lib/mongoid/relations/embedded/many.rb +0 -683
- data/lib/mongoid/relations/embedded/one.rb +0 -235
- data/lib/mongoid/relations/macros.rb +0 -367
- data/lib/mongoid/relations/metadata.rb +0 -1179
- data/lib/mongoid/relations/nested_builder.rb +0 -74
- data/lib/mongoid/relations/options.rb +0 -49
- data/lib/mongoid/relations/polymorphic.rb +0 -39
- data/lib/mongoid/relations/referenced/in.rb +0 -304
- data/lib/mongoid/relations/referenced/many.rb +0 -812
- data/lib/mongoid/relations/referenced/many_to_many.rb +0 -479
- data/lib/mongoid/relations/referenced/one.rb +0 -290
- data/lib/mongoid/relations/synchronization.rb +0 -169
- data/lib/mongoid/relations/targets/enumerable.rb +0 -493
- data/lib/mongoid/relations/targets.rb +0 -2
- data/lib/mongoid/relations/touchable.rb +0 -97
- data/lib/mongoid/relations.rb +0 -148
- data/spec/app/models/array_field.rb +0 -7
- data/spec/app/models/delegating_patient.rb +0 -16
- data/spec/integration/document_spec.rb +0 -22
- 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/matchable/nor_spec.rb +0 -209
- data/spec/mongoid/relations/builders/referenced/many_spec.rb +0 -137
- data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +0 -178
- data/spec/mongoid/relations/builders/referenced/one_spec.rb +0 -111
- data/spec/mongoid/relations/cascading/delete_spec.rb +0 -101
- data/spec/mongoid/relations/cascading/destroy_spec.rb +0 -47
- data/spec/mongoid/relations/cascading/nullify_spec.rb +0 -32
- data/spec/mongoid/relations/cascading/restrict_spec.rb +0 -68
- data/spec/mongoid/relations/cascading_spec.rb +0 -355
- data/spec/mongoid/relations/constraint_spec.rb +0 -75
- data/spec/mongoid/relations/conversions_spec.rb +0 -128
- data/spec/mongoid/relations/metadata_spec.rb +0 -1985
- data/spec/mongoid/relations/options_spec.rb +0 -35
- data/spec/rails/controller_extension/controller_runtime_spec.rb +0 -110
- data/spec/support/cluster_config.rb +0 -158
- data/spec/support/constraints.rb +0 -101
- data/spec/support/macros.rb +0 -20
- data/spec/support/session_registry.rb +0 -50
- data/spec/support/spec_config.rb +0 -42
- /data/spec/mongoid/{relations → association}/embedded/dirty_spec.rb +0 -0
|
@@ -388,85 +388,4 @@ describe Mongoid::Criteria::Scopable do
|
|
|
388
388
|
end
|
|
389
389
|
end
|
|
390
390
|
end
|
|
391
|
-
|
|
392
|
-
describe 'scope and where' do
|
|
393
|
-
class ScopeWhereModel
|
|
394
|
-
include Mongoid::Document
|
|
395
|
-
|
|
396
|
-
scope :foo, -> { where(foo: true) }
|
|
397
|
-
end
|
|
398
|
-
|
|
399
|
-
shared_examples_for 'restricts to both' do
|
|
400
|
-
it 'restricts to both' do
|
|
401
|
-
expect(result.selector['foo']).to eq(true)
|
|
402
|
-
expect(result.selector['hello']).to eq('world')
|
|
403
|
-
end
|
|
404
|
-
end
|
|
405
|
-
|
|
406
|
-
context 'scope is given first' do
|
|
407
|
-
let(:result) { ScopeWhereModel.foo.where(hello: 'world') }
|
|
408
|
-
|
|
409
|
-
it_behaves_like 'restricts to both'
|
|
410
|
-
end
|
|
411
|
-
|
|
412
|
-
context 'where is given first' do
|
|
413
|
-
let(:result) { ScopeWhereModel.where(hello: 'world').foo }
|
|
414
|
-
|
|
415
|
-
it_behaves_like 'restricts to both'
|
|
416
|
-
end
|
|
417
|
-
end
|
|
418
|
-
|
|
419
|
-
describe 'scope with argument and where' do
|
|
420
|
-
class ArgumentScopeWhereModel
|
|
421
|
-
include Mongoid::Document
|
|
422
|
-
|
|
423
|
-
scope :my_text_search, ->(search) { where('$text' => {'$search' => search}) }
|
|
424
|
-
end
|
|
425
|
-
|
|
426
|
-
shared_examples_for 'restricts to both' do
|
|
427
|
-
it 'restricts to both' do
|
|
428
|
-
expect(result.selector['$text']).to eq({'$search' => 'bar'})
|
|
429
|
-
expect(result.selector['hello']).to eq('world')
|
|
430
|
-
end
|
|
431
|
-
end
|
|
432
|
-
|
|
433
|
-
context 'scope is given first' do
|
|
434
|
-
let(:result) { ArgumentScopeWhereModel.my_text_search('bar').where(hello: 'world') }
|
|
435
|
-
|
|
436
|
-
it_behaves_like 'restricts to both'
|
|
437
|
-
end
|
|
438
|
-
|
|
439
|
-
context 'where is given first' do
|
|
440
|
-
let(:result) { ArgumentScopeWhereModel.where(hello: 'world').my_text_search('bar') }
|
|
441
|
-
|
|
442
|
-
it_behaves_like 'restricts to both'
|
|
443
|
-
end
|
|
444
|
-
end
|
|
445
|
-
|
|
446
|
-
describe 'built in text search scope and where' do
|
|
447
|
-
class TextSearchScopeWhereModel
|
|
448
|
-
include Mongoid::Document
|
|
449
|
-
|
|
450
|
-
# using the default text_search scope
|
|
451
|
-
end
|
|
452
|
-
|
|
453
|
-
shared_examples_for 'restricts to both' do
|
|
454
|
-
it 'restricts to both' do
|
|
455
|
-
expect(result.selector['$text']).to eq({'$search' => 'bar'})
|
|
456
|
-
expect(result.selector['hello']).to eq('world')
|
|
457
|
-
end
|
|
458
|
-
end
|
|
459
|
-
|
|
460
|
-
context 'scope is given first' do
|
|
461
|
-
let(:result) { TextSearchScopeWhereModel.text_search('bar').where(hello: 'world') }
|
|
462
|
-
|
|
463
|
-
it_behaves_like 'restricts to both'
|
|
464
|
-
end
|
|
465
|
-
|
|
466
|
-
context 'where is given first' do
|
|
467
|
-
let(:result) { TextSearchScopeWhereModel.where(hello: 'world').text_search('bar') }
|
|
468
|
-
|
|
469
|
-
it_behaves_like 'restricts to both'
|
|
470
|
-
end
|
|
471
|
-
end
|
|
472
391
|
end
|
|
@@ -975,7 +975,6 @@ describe Mongoid::Criteria do
|
|
|
975
975
|
end
|
|
976
976
|
|
|
977
977
|
describe "#geo_near" do
|
|
978
|
-
max_server_version '4.0'
|
|
979
978
|
|
|
980
979
|
before do
|
|
981
980
|
Bar.create_indexes
|
|
@@ -1445,18 +1444,18 @@ describe Mongoid::Criteria do
|
|
|
1445
1444
|
end
|
|
1446
1445
|
end
|
|
1447
1446
|
|
|
1448
|
-
context "when including the same
|
|
1447
|
+
context "when including the same association multiple times" do
|
|
1449
1448
|
|
|
1450
1449
|
let(:criteria) do
|
|
1451
1450
|
Person.all.includes(:posts, :posts).includes(:posts)
|
|
1452
1451
|
end
|
|
1453
1452
|
|
|
1454
|
-
let(:
|
|
1453
|
+
let(:association) do
|
|
1455
1454
|
Person.reflect_on_association(:posts)
|
|
1456
1455
|
end
|
|
1457
1456
|
|
|
1458
|
-
it "does not duplicate the
|
|
1459
|
-
expect(criteria.inclusions).to eq([
|
|
1457
|
+
it "does not duplicate the association in the inclusions" do
|
|
1458
|
+
expect(criteria.inclusions).to eq([ association ])
|
|
1460
1459
|
end
|
|
1461
1460
|
end
|
|
1462
1461
|
|
|
@@ -2218,12 +2217,12 @@ describe Mongoid::Criteria do
|
|
|
2218
2217
|
Band.includes(:records)
|
|
2219
2218
|
end
|
|
2220
2219
|
|
|
2221
|
-
let(:
|
|
2220
|
+
let(:association) do
|
|
2222
2221
|
Band.relations["records"]
|
|
2223
2222
|
end
|
|
2224
2223
|
|
|
2225
2224
|
it "returns the inclusions" do
|
|
2226
|
-
expect(criteria.inclusions).to eq([
|
|
2225
|
+
expect(criteria.inclusions).to eq([ association ])
|
|
2227
2226
|
end
|
|
2228
2227
|
end
|
|
2229
2228
|
|
|
@@ -2233,16 +2232,16 @@ describe Mongoid::Criteria do
|
|
|
2233
2232
|
Band.all
|
|
2234
2233
|
end
|
|
2235
2234
|
|
|
2236
|
-
let(:
|
|
2235
|
+
let(:association) do
|
|
2237
2236
|
Band.relations["records"]
|
|
2238
2237
|
end
|
|
2239
2238
|
|
|
2240
2239
|
before do
|
|
2241
|
-
criteria.inclusions = [
|
|
2240
|
+
criteria.inclusions = [ association ]
|
|
2242
2241
|
end
|
|
2243
2242
|
|
|
2244
2243
|
it "sets the inclusions" do
|
|
2245
|
-
expect(criteria.inclusions).to eq([
|
|
2244
|
+
expect(criteria.inclusions).to eq([ association ])
|
|
2246
2245
|
end
|
|
2247
2246
|
end
|
|
2248
2247
|
|
|
@@ -2410,7 +2409,7 @@ describe Mongoid::Criteria do
|
|
|
2410
2409
|
end
|
|
2411
2410
|
end
|
|
2412
2411
|
|
|
2413
|
-
let(:
|
|
2412
|
+
let(:association) do
|
|
2414
2413
|
Band.relations["records"]
|
|
2415
2414
|
end
|
|
2416
2415
|
|
|
@@ -2435,7 +2434,7 @@ describe Mongoid::Criteria do
|
|
|
2435
2434
|
end
|
|
2436
2435
|
|
|
2437
2436
|
it "merges the inclusions" do
|
|
2438
|
-
expect(merged.inclusions).to eq([
|
|
2437
|
+
expect(merged.inclusions).to eq([ association ])
|
|
2439
2438
|
end
|
|
2440
2439
|
|
|
2441
2440
|
it "returns a new criteria" do
|
|
@@ -2449,7 +2448,7 @@ describe Mongoid::Criteria do
|
|
|
2449
2448
|
{ klass: Band, includes: [ :records ] }
|
|
2450
2449
|
end
|
|
2451
2450
|
|
|
2452
|
-
let(:
|
|
2451
|
+
let(:association) do
|
|
2453
2452
|
Band.relations["records"]
|
|
2454
2453
|
end
|
|
2455
2454
|
|
|
@@ -2470,7 +2469,7 @@ describe Mongoid::Criteria do
|
|
|
2470
2469
|
end
|
|
2471
2470
|
|
|
2472
2471
|
it "merges the inclusions" do
|
|
2473
|
-
expect(merged.inclusions).to eq([
|
|
2472
|
+
expect(merged.inclusions).to eq([ association ])
|
|
2474
2473
|
end
|
|
2475
2474
|
|
|
2476
2475
|
it "returns a new criteria" do
|
|
@@ -2495,7 +2494,7 @@ describe Mongoid::Criteria do
|
|
|
2495
2494
|
end
|
|
2496
2495
|
end
|
|
2497
2496
|
|
|
2498
|
-
let(:
|
|
2497
|
+
let(:association) do
|
|
2499
2498
|
Band.relations["records"]
|
|
2500
2499
|
end
|
|
2501
2500
|
|
|
@@ -2520,7 +2519,7 @@ describe Mongoid::Criteria do
|
|
|
2520
2519
|
end
|
|
2521
2520
|
|
|
2522
2521
|
it "merges the inclusions" do
|
|
2523
|
-
expect(merged.inclusions).to eq([
|
|
2522
|
+
expect(merged.inclusions).to eq([ association ])
|
|
2524
2523
|
end
|
|
2525
2524
|
|
|
2526
2525
|
it "returns the same criteria" do
|
|
@@ -3322,8 +3321,6 @@ describe Mongoid::Criteria do
|
|
|
3322
3321
|
end
|
|
3323
3322
|
|
|
3324
3323
|
describe "#max_scan" do
|
|
3325
|
-
max_server_version '4.0'
|
|
3326
|
-
|
|
3327
3324
|
let!(:band) do
|
|
3328
3325
|
Band.create(name: "Depeche Mode")
|
|
3329
3326
|
end
|
|
@@ -3468,7 +3465,7 @@ describe Mongoid::Criteria do
|
|
|
3468
3465
|
context "when querying on a big decimal" do
|
|
3469
3466
|
|
|
3470
3467
|
let(:sales) do
|
|
3471
|
-
BigDecimal('0.1')
|
|
3468
|
+
BigDecimal.new('0.1')
|
|
3472
3469
|
end
|
|
3473
3470
|
|
|
3474
3471
|
let!(:band) do
|
|
@@ -94,11 +94,11 @@ describe Mongoid::Document do
|
|
|
94
94
|
context "when the document is not subclassed" do
|
|
95
95
|
|
|
96
96
|
let(:types) do
|
|
97
|
-
|
|
97
|
+
Kangaroo._types
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
it "returns the document" do
|
|
101
|
-
expect(types).to eq([ "
|
|
101
|
+
expect(types).to eq([ "Kangaroo" ])
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
104
|
|
|
@@ -433,60 +433,6 @@ describe Mongoid::Document do
|
|
|
433
433
|
end
|
|
434
434
|
end
|
|
435
435
|
end
|
|
436
|
-
|
|
437
|
-
context ':compact option' do
|
|
438
|
-
|
|
439
|
-
before do
|
|
440
|
-
# These tests require a specific set of defined attributes
|
|
441
|
-
# on the model
|
|
442
|
-
expect(church.as_json.keys.sort).to eq(%w(_id location name))
|
|
443
|
-
end
|
|
444
|
-
|
|
445
|
-
context 'there is a nil valued attribute' do
|
|
446
|
-
let(:church) do
|
|
447
|
-
Church.create!(name: 'St. Basil')
|
|
448
|
-
end
|
|
449
|
-
|
|
450
|
-
it 'returns non-nil fields and _id only' do
|
|
451
|
-
actual = church.as_json(compact: true)
|
|
452
|
-
expect(actual).to eq('_id' => church.id, 'name' => 'St. Basil')
|
|
453
|
-
end
|
|
454
|
-
end
|
|
455
|
-
|
|
456
|
-
context 'all attrbutes are nil valued' do
|
|
457
|
-
let(:church) do
|
|
458
|
-
Church.create!
|
|
459
|
-
end
|
|
460
|
-
|
|
461
|
-
it 'returns a hash with _id only' do
|
|
462
|
-
actual = church.as_json(compact: true)
|
|
463
|
-
expect(actual).to eq('_id' => church.id)
|
|
464
|
-
end
|
|
465
|
-
end
|
|
466
|
-
|
|
467
|
-
context 'there are no nil valued attributes' do
|
|
468
|
-
let(:church) do
|
|
469
|
-
Church.create!(name: 'St. Basil', location: {})
|
|
470
|
-
end
|
|
471
|
-
|
|
472
|
-
it 'returns all fields and _id' do
|
|
473
|
-
actual = church.as_json(compact: true)
|
|
474
|
-
expect(actual).to eq('_id' => church.id, 'name' => 'St. Basil',
|
|
475
|
-
'location' => {})
|
|
476
|
-
end
|
|
477
|
-
end
|
|
478
|
-
|
|
479
|
-
context 'when option is specified as a truthy value' do
|
|
480
|
-
let(:church) do
|
|
481
|
-
Church.create!(name: 'St. Basil')
|
|
482
|
-
end
|
|
483
|
-
|
|
484
|
-
it 'returns non-nil fields and _id only' do
|
|
485
|
-
actual = church.as_json(compact: 1)
|
|
486
|
-
expect(actual).to eq('_id' => church.id, 'name' => 'St. Basil')
|
|
487
|
-
end
|
|
488
|
-
end
|
|
489
|
-
end
|
|
490
436
|
end
|
|
491
437
|
|
|
492
438
|
describe "#as_document" do
|
|
@@ -204,14 +204,10 @@ describe Mongoid::Extensions::Array do
|
|
|
204
204
|
|
|
205
205
|
context "when the related model uses object ids" do
|
|
206
206
|
|
|
207
|
-
let(:
|
|
207
|
+
let(:association) do
|
|
208
208
|
Person.relations["preferences"]
|
|
209
209
|
end
|
|
210
210
|
|
|
211
|
-
let(:constraint) do
|
|
212
|
-
metadata.constraint
|
|
213
|
-
end
|
|
214
|
-
|
|
215
211
|
context "when provided an object id" do
|
|
216
212
|
|
|
217
213
|
let(:object_id) do
|
|
@@ -219,7 +215,7 @@ describe Mongoid::Extensions::Array do
|
|
|
219
215
|
end
|
|
220
216
|
|
|
221
217
|
let(:fk) do
|
|
222
|
-
Array.__mongoize_fk__(
|
|
218
|
+
Array.__mongoize_fk__(association, object_id)
|
|
223
219
|
end
|
|
224
220
|
|
|
225
221
|
it "returns the object id as an array" do
|
|
@@ -234,7 +230,7 @@ describe Mongoid::Extensions::Array do
|
|
|
234
230
|
end
|
|
235
231
|
|
|
236
232
|
let(:fk) do
|
|
237
|
-
Array.__mongoize_fk__(
|
|
233
|
+
Array.__mongoize_fk__(association, [ object_id ])
|
|
238
234
|
end
|
|
239
235
|
|
|
240
236
|
it "returns the object ids" do
|
|
@@ -251,7 +247,7 @@ describe Mongoid::Extensions::Array do
|
|
|
251
247
|
end
|
|
252
248
|
|
|
253
249
|
let(:fk) do
|
|
254
|
-
Array.__mongoize_fk__(
|
|
250
|
+
Array.__mongoize_fk__(association, object_id.to_s)
|
|
255
251
|
end
|
|
256
252
|
|
|
257
253
|
it "returns the object id in an array" do
|
|
@@ -266,7 +262,7 @@ describe Mongoid::Extensions::Array do
|
|
|
266
262
|
end
|
|
267
263
|
|
|
268
264
|
let(:fk) do
|
|
269
|
-
Array.__mongoize_fk__(
|
|
265
|
+
Array.__mongoize_fk__(association, string)
|
|
270
266
|
end
|
|
271
267
|
|
|
272
268
|
it "returns the string in an array" do
|
|
@@ -277,7 +273,7 @@ describe Mongoid::Extensions::Array do
|
|
|
277
273
|
context "when the string is blank" do
|
|
278
274
|
|
|
279
275
|
let(:fk) do
|
|
280
|
-
Array.__mongoize_fk__(
|
|
276
|
+
Array.__mongoize_fk__(association, "")
|
|
281
277
|
end
|
|
282
278
|
|
|
283
279
|
it "returns an empty array" do
|
|
@@ -289,7 +285,7 @@ describe Mongoid::Extensions::Array do
|
|
|
289
285
|
context "when provided nil" do
|
|
290
286
|
|
|
291
287
|
let(:fk) do
|
|
292
|
-
Array.__mongoize_fk__(
|
|
288
|
+
Array.__mongoize_fk__(association, nil)
|
|
293
289
|
end
|
|
294
290
|
|
|
295
291
|
it "returns an empty array" do
|
|
@@ -306,7 +302,7 @@ describe Mongoid::Extensions::Array do
|
|
|
306
302
|
end
|
|
307
303
|
|
|
308
304
|
let(:fk) do
|
|
309
|
-
Array.__mongoize_fk__(
|
|
305
|
+
Array.__mongoize_fk__(association, [ object_id.to_s ])
|
|
310
306
|
end
|
|
311
307
|
|
|
312
308
|
it "returns the object id in an array" do
|
|
@@ -321,7 +317,7 @@ describe Mongoid::Extensions::Array do
|
|
|
321
317
|
end
|
|
322
318
|
|
|
323
319
|
let(:fk) do
|
|
324
|
-
Array.__mongoize_fk__(
|
|
320
|
+
Array.__mongoize_fk__(association, [ string ])
|
|
325
321
|
end
|
|
326
322
|
|
|
327
323
|
it "returns the string in an array" do
|
|
@@ -332,7 +328,7 @@ describe Mongoid::Extensions::Array do
|
|
|
332
328
|
context "when the strings are blank" do
|
|
333
329
|
|
|
334
330
|
let(:fk) do
|
|
335
|
-
Array.__mongoize_fk__(
|
|
331
|
+
Array.__mongoize_fk__(association, [ "", "" ])
|
|
336
332
|
end
|
|
337
333
|
|
|
338
334
|
it "returns an empty array" do
|
|
@@ -344,7 +340,7 @@ describe Mongoid::Extensions::Array do
|
|
|
344
340
|
context "when provided nils" do
|
|
345
341
|
|
|
346
342
|
let(:fk) do
|
|
347
|
-
Array.__mongoize_fk__(
|
|
343
|
+
Array.__mongoize_fk__(association, [ nil, nil, nil ])
|
|
348
344
|
end
|
|
349
345
|
|
|
350
346
|
it "returns an empty array" do
|
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
|
3
3
|
describe Mongoid::Extensions::BigDecimal do
|
|
4
4
|
|
|
5
5
|
let(:big_decimal) do
|
|
6
|
-
BigDecimal("123456.789")
|
|
6
|
+
BigDecimal.new("123456.789")
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
describe ".demongoize" do
|
|
@@ -26,7 +26,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it "returns a BigDecimal" do
|
|
29
|
-
expect(BigDecimal.demongoize(string)).to eq(BigDecimal(string))
|
|
29
|
+
expect(BigDecimal.demongoize(string)).to eq(BigDecimal.new(string))
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -37,7 +37,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
it "returns a BigDecimal" do
|
|
40
|
-
expect(BigDecimal.demongoize(string)).to eq(BigDecimal(string))
|
|
40
|
+
expect(BigDecimal.demongoize(string)).to eq(BigDecimal.new(string))
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
@@ -48,7 +48,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it "returns a BigDecimal" do
|
|
51
|
-
expect(BigDecimal.demongoize(string)).to eq(BigDecimal(string))
|
|
51
|
+
expect(BigDecimal.demongoize(string)).to eq(BigDecimal.new(string))
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
@@ -184,7 +184,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
184
184
|
context "when the value is the BigDecimal zero" do
|
|
185
185
|
|
|
186
186
|
let(:big_decimal) do
|
|
187
|
-
BigDecimal("0.0")
|
|
187
|
+
BigDecimal.new("0.0")
|
|
188
188
|
end
|
|
189
189
|
|
|
190
190
|
it "returns a BigDecimal" do
|
|
@@ -195,7 +195,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
195
195
|
context "when the value is the BigDecimal negative zero" do
|
|
196
196
|
|
|
197
197
|
let(:big_decimal) do
|
|
198
|
-
BigDecimal("-0.0")
|
|
198
|
+
BigDecimal.new("-0.0")
|
|
199
199
|
end
|
|
200
200
|
|
|
201
201
|
it "returns a BigDecimal" do
|
|
@@ -326,7 +326,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
326
326
|
context "when the value is BigDecimal NaN" do
|
|
327
327
|
|
|
328
328
|
let(:nan) do
|
|
329
|
-
BigDecimal("NaN")
|
|
329
|
+
BigDecimal.new("NaN")
|
|
330
330
|
end
|
|
331
331
|
|
|
332
332
|
it "returns a String" do
|
|
@@ -337,7 +337,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
337
337
|
context "when the value is BigDecimal Infinity" do
|
|
338
338
|
|
|
339
339
|
let(:infinity) do
|
|
340
|
-
BigDecimal("Infinity")
|
|
340
|
+
BigDecimal.new("Infinity")
|
|
341
341
|
end
|
|
342
342
|
|
|
343
343
|
it "returns a String" do
|
|
@@ -348,7 +348,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
348
348
|
context "when the value is BigDecimal negative Infinity" do
|
|
349
349
|
|
|
350
350
|
let(:neg_infinity) do
|
|
351
|
-
BigDecimal("-Infinity")
|
|
351
|
+
BigDecimal.new("-Infinity")
|
|
352
352
|
end
|
|
353
353
|
|
|
354
354
|
it "returns a String" do
|
|
@@ -230,10 +230,27 @@ describe Mongoid::Extensions::Hash do
|
|
|
230
230
|
it "should retrieve a nested value under the provided key" do
|
|
231
231
|
expect(nested).to eq "hundred"
|
|
232
232
|
end
|
|
233
|
+
|
|
234
|
+
context 'and the value is falsey' do
|
|
235
|
+
let(:hash) do
|
|
236
|
+
{ "100" => { "name" => false } }
|
|
237
|
+
end
|
|
238
|
+
it "should retrieve the falsey nested value under the provided key" do
|
|
239
|
+
expect(nested).to eq false
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
context 'and the value is nil' do
|
|
244
|
+
let(:hash) do
|
|
245
|
+
{ "100" => { 0 => "Please don't return this value!" } }
|
|
246
|
+
end
|
|
247
|
+
it "should retrieve the nil nested value under the provided key" do
|
|
248
|
+
expect(nested).to eq nil
|
|
249
|
+
end
|
|
250
|
+
end
|
|
233
251
|
end
|
|
234
252
|
|
|
235
253
|
context "when the hash key is an integer" do
|
|
236
|
-
|
|
237
254
|
let(:hash) do
|
|
238
255
|
{ 100 => { "name" => "hundred" } }
|
|
239
256
|
end
|
|
@@ -39,14 +39,10 @@ describe Mongoid::Extensions::Object do
|
|
|
39
39
|
|
|
40
40
|
context "when the related model uses object ids" do
|
|
41
41
|
|
|
42
|
-
let(:
|
|
42
|
+
let(:association) do
|
|
43
43
|
Game.relations["person"]
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
let(:constraint) do
|
|
47
|
-
metadata.constraint
|
|
48
|
-
end
|
|
49
|
-
|
|
50
46
|
context "when provided an object id" do
|
|
51
47
|
|
|
52
48
|
let(:object_id) do
|
|
@@ -54,7 +50,7 @@ describe Mongoid::Extensions::Object do
|
|
|
54
50
|
end
|
|
55
51
|
|
|
56
52
|
let(:fk) do
|
|
57
|
-
Object.__mongoize_fk__(
|
|
53
|
+
Object.__mongoize_fk__(association, object_id)
|
|
58
54
|
end
|
|
59
55
|
|
|
60
56
|
it "returns the object id" do
|
|
@@ -71,7 +67,7 @@ describe Mongoid::Extensions::Object do
|
|
|
71
67
|
end
|
|
72
68
|
|
|
73
69
|
let(:fk) do
|
|
74
|
-
Object.__mongoize_fk__(
|
|
70
|
+
Object.__mongoize_fk__(association, object_id.to_s)
|
|
75
71
|
end
|
|
76
72
|
|
|
77
73
|
it "returns the object id" do
|
|
@@ -86,7 +82,7 @@ describe Mongoid::Extensions::Object do
|
|
|
86
82
|
end
|
|
87
83
|
|
|
88
84
|
let(:fk) do
|
|
89
|
-
Object.__mongoize_fk__(
|
|
85
|
+
Object.__mongoize_fk__(association, string)
|
|
90
86
|
end
|
|
91
87
|
|
|
92
88
|
it "returns the string" do
|
|
@@ -97,7 +93,7 @@ describe Mongoid::Extensions::Object do
|
|
|
97
93
|
context "when the string is blank" do
|
|
98
94
|
|
|
99
95
|
let(:fk) do
|
|
100
|
-
Object.__mongoize_fk__(
|
|
96
|
+
Object.__mongoize_fk__(association, "")
|
|
101
97
|
end
|
|
102
98
|
|
|
103
99
|
it "returns nil" do
|
|
@@ -109,7 +105,7 @@ describe Mongoid::Extensions::Object do
|
|
|
109
105
|
context "when provided nil" do
|
|
110
106
|
|
|
111
107
|
let(:fk) do
|
|
112
|
-
Object.__mongoize_fk__(
|
|
108
|
+
Object.__mongoize_fk__(association, nil)
|
|
113
109
|
end
|
|
114
110
|
|
|
115
111
|
it "returns nil" do
|
|
@@ -120,7 +116,7 @@ describe Mongoid::Extensions::Object do
|
|
|
120
116
|
context "when provided an empty array" do
|
|
121
117
|
|
|
122
118
|
let(:fk) do
|
|
123
|
-
Object.__mongoize_fk__(
|
|
119
|
+
Object.__mongoize_fk__(association, [])
|
|
124
120
|
end
|
|
125
121
|
|
|
126
122
|
it "returns an empty array" do
|
|
@@ -139,6 +139,13 @@ describe Mongoid::Extensions::Range do
|
|
|
139
139
|
expect(("a".."z").mongoize).to eq({ "min" => "a", "max" => "z" })
|
|
140
140
|
end
|
|
141
141
|
end
|
|
142
|
+
|
|
143
|
+
context 'when the value is a string' do
|
|
144
|
+
|
|
145
|
+
it 'returns a string' do
|
|
146
|
+
expect(Range.mongoize('3')).to eq('3')
|
|
147
|
+
end
|
|
148
|
+
end
|
|
142
149
|
end
|
|
143
150
|
|
|
144
151
|
describe "#resizable?" do
|
|
@@ -35,29 +35,6 @@ describe Mongoid::Extensions::Regexp do
|
|
|
35
35
|
it "returns the provided value as a regex" do
|
|
36
36
|
expect(value).to eq(/[^abc]/)
|
|
37
37
|
end
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
context "when the string is empty" do
|
|
41
|
-
|
|
42
|
-
let(:value) do
|
|
43
|
-
Regexp.mongoize("")
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "returns an empty regex" do
|
|
47
|
-
expect(value).to eq(//)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
context "when the value is nil" do
|
|
53
|
-
|
|
54
|
-
let(:value) do
|
|
55
|
-
Regexp.mongoize(nil)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "returns the nil" do
|
|
59
|
-
expect(value).to be_nil
|
|
60
|
-
end
|
|
61
38
|
end
|
|
62
39
|
end
|
|
63
40
|
|