mongoid 6.4.8 → 7.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Rakefile +0 -26
- data/lib/config/locales/en.yml +17 -21
- data/lib/mongoid.rb +2 -2
- data/lib/mongoid/association.rb +150 -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/association/embedded.rb +4 -0
- data/lib/mongoid/{relations → association}/embedded/batchable.rb +27 -53
- data/lib/mongoid/association/embedded/cyclic.rb +109 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +154 -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/embeds_many.rb +210 -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_one.rb +173 -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/macros.rb +204 -0
- data/lib/mongoid/{relations → association}/many.rb +18 -52
- data/lib/mongoid/{relations → association}/marshalable.rb +6 -4
- data/lib/mongoid/association/nested.rb +15 -0
- 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/{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.rb +7 -0
- data/lib/mongoid/association/referenced/auto_save.rb +79 -0
- data/lib/mongoid/association/referenced/belongs_to.rb +248 -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/counter_cache.rb +163 -0
- data/lib/mongoid/association/referenced/eager.rb +159 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +290 -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_many.rb +273 -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 +479 -0
- data/lib/mongoid/association/referenced/has_many/proxy.rb +577 -0
- data/lib/mongoid/association/referenced/has_one.rb +204 -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/syncable.rb +170 -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/atomic.rb +6 -6
- data/lib/mongoid/atomic/modifiers.rb +8 -12
- data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
- data/lib/mongoid/attributes.rb +2 -1
- 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/clients.rb +0 -2
- data/lib/mongoid/clients/options.rb +1 -1
- data/lib/mongoid/clients/storage_options.rb +0 -1
- data/lib/mongoid/composable.rb +3 -4
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +3 -6
- data/lib/mongoid/contextual/map_reduce.rb +3 -7
- data/lib/mongoid/contextual/memory.rb +5 -10
- data/lib/mongoid/contextual/mongo.rb +10 -27
- data/lib/mongoid/copyable.rb +6 -6
- data/lib/mongoid/criteria.rb +1 -2
- data/lib/mongoid/criteria/includable.rb +14 -14
- data/lib/mongoid/criteria/modifiable.rb +8 -14
- data/lib/mongoid/criteria/queryable/mergeable.rb +1 -3
- data/lib/mongoid/criteria/queryable/pipeline.rb +10 -5
- data/lib/mongoid/criteria/queryable/selectable.rb +10 -34
- data/lib/mongoid/document.rb +6 -6
- data/lib/mongoid/errors.rb +3 -1
- 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/extensions/array.rb +5 -5
- data/lib/mongoid/extensions/big_decimal.rb +1 -1
- 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/factory.rb +4 -3
- data/lib/mongoid/fields.rb +1 -1
- 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/indexable.rb +8 -5
- data/lib/mongoid/interceptable.rb +5 -5
- data/lib/mongoid/matchable.rb +0 -3
- data/lib/mongoid/persistable.rb +4 -5
- data/lib/mongoid/persistable/creatable.rb +2 -4
- data/lib/mongoid/persistable/deletable.rb +9 -10
- data/lib/mongoid/persistable/destroyable.rb +5 -1
- 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 -2
- data/lib/mongoid/persistence_context.rb +4 -9
- data/lib/mongoid/query_cache.rb +18 -65
- 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 +3 -3
- data/lib/mongoid/tasks/database.rb +2 -3
- data/lib/mongoid/threaded.rb +0 -74
- data/lib/mongoid/traversable.rb +2 -2
- data/lib/mongoid/validatable.rb +8 -8
- data/lib/mongoid/validatable/presence.rb +2 -2
- data/lib/mongoid/validatable/uniqueness.rb +4 -4
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +3 -4
- data/spec/app/models/animal.rb +2 -1
- data/spec/app/models/band.rb +0 -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/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 → association}/embedded/dirty_spec.rb +0 -0
- data/spec/mongoid/{relations/bindings/embedded/in_spec.rb → association/embedded/embedded_in/binding_spec.rb} +13 -13
- data/spec/mongoid/{relations/builders/embedded/in_spec.rb → association/embedded/embedded_in/buildable_spec.rb} +9 -9
- data/spec/mongoid/{relations/embedded/in_spec.rb → association/embedded/embedded_in/proxy_spec.rb} +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 -93
- 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} +11 -11
- data/spec/mongoid/{relations/targets → association/referenced/has_many}/enumerable_spec.rb +1 -109
- 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 +17 -17
- data/spec/mongoid/atomic_spec.rb +17 -17
- data/spec/mongoid/attributes/nested_spec.rb +14 -12
- data/spec/mongoid/attributes/readonly_spec.rb +80 -125
- data/spec/mongoid/clients/factory_spec.rb +28 -52
- data/spec/mongoid/clients/options_spec.rb +65 -69
- data/spec/mongoid/config_spec.rb +24 -0
- data/spec/mongoid/contextual/geo_near_spec.rb +0 -1
- data/spec/mongoid/contextual/mongo_spec.rb +4 -112
- 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/pipeline_spec.rb +12 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +6 -74
- 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/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 +18 -11
- 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 +21 -2
- data/spec/mongoid/matchable_spec.rb +1 -26
- data/spec/mongoid/persistable/deletable_spec.rb +0 -19
- data/spec/mongoid/persistable/destroyable_spec.rb +0 -19
- data/spec/mongoid/persistable/incrementable_spec.rb +6 -6
- data/spec/mongoid/persistable/savable_spec.rb +3 -3
- data/spec/mongoid/persistable/settable_spec.rb +1 -35
- data/spec/mongoid/persistable/updatable_spec.rb +2 -2
- data/spec/mongoid/persistable_spec.rb +16 -16
- data/spec/mongoid/persistence_context_spec.rb +0 -14
- data/spec/mongoid/positional_spec.rb +10 -10
- data/spec/mongoid/query_cache_spec.rb +18 -87
- data/spec/mongoid/relations/proxy_spec.rb +124 -124
- data/spec/mongoid/scopable_spec.rb +0 -13
- 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 +7 -83
- metadata +586 -611
- metadata.gz.sig +2 -5
- data/lib/mongoid/clients/sessions.rb +0 -113
- data/lib/mongoid/errors/invalid_session_use.rb +0 -24
- data/lib/mongoid/matchable/nor.rb +0 -37
- data/lib/mongoid/railties/controller_runtime.rb +0 -86
- data/lib/mongoid/relations.rb +0 -148
- data/lib/mongoid/relations/accessors.rb +0 -267
- data/lib/mongoid/relations/auto_save.rb +0 -94
- data/lib/mongoid/relations/bindings.rb +0 -9
- 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/builder.rb +0 -57
- data/lib/mongoid/relations/builders.rb +0 -106
- 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/cascading.rb +0 -56
- 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/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.rb +0 -2
- data/lib/mongoid/relations/targets/enumerable.rb +0 -493
- data/lib/mongoid/relations/touchable.rb +0 -97
- 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/clients/sessions_spec.rb +0 -334
- 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
@@ -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
|
@@ -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
|
|
@@ -277,77 +277,49 @@ describe Mongoid::Extensions::String do
|
|
277
277
|
context "when the string is an integer" do
|
278
278
|
|
279
279
|
it "returns true" do
|
280
|
-
expect("1234"
|
280
|
+
expect("1234").to be_numeric
|
281
281
|
end
|
282
282
|
end
|
283
283
|
|
284
284
|
context "when string is a float" do
|
285
285
|
|
286
286
|
it "returns true" do
|
287
|
-
expect("1234.123"
|
287
|
+
expect("1234.123").to be_numeric
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
291
291
|
context "when the string is has exponents" do
|
292
292
|
|
293
293
|
it "returns true" do
|
294
|
-
expect("1234.123123E4"
|
294
|
+
expect("1234.123123E4").to be_numeric
|
295
295
|
end
|
296
296
|
end
|
297
297
|
|
298
298
|
context "when the string is non numeric" do
|
299
299
|
|
300
300
|
it "returns false" do
|
301
|
-
expect("blah"
|
301
|
+
expect("blah").to_not be_numeric
|
302
302
|
end
|
303
303
|
end
|
304
304
|
|
305
305
|
context "when the string is NaN" do
|
306
306
|
|
307
307
|
it "returns true" do
|
308
|
-
expect("NaN"
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
context "when the string is NaN and junk in front" do
|
313
|
-
|
314
|
-
it "returns false" do
|
315
|
-
expect("a\nNaN".numeric?).to eq(false)
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
context "when the string is NaN and whitespace at end" do
|
320
|
-
|
321
|
-
it "returns false" do
|
322
|
-
expect("NaN\n".numeric?).to eq(false)
|
308
|
+
expect("NaN").to be_numeric
|
323
309
|
end
|
324
310
|
end
|
325
311
|
|
326
312
|
context "when the string is Infinity" do
|
327
313
|
|
328
314
|
it "returns true" do
|
329
|
-
expect("Infinity"
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
context "when the string contains Infinity and junk in front" do
|
334
|
-
|
335
|
-
it "returns false" do
|
336
|
-
expect("a\nInfinity".numeric?).to eq(false)
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
context "when the string contains Infinity and whitespace at end" do
|
341
|
-
|
342
|
-
it "returns false" do
|
343
|
-
expect("Infinity\n".numeric?).to eq(false)
|
315
|
+
expect("Infinity").to be_numeric
|
344
316
|
end
|
345
317
|
end
|
346
318
|
|
347
319
|
context "when the string is -Infinity" do
|
348
320
|
|
349
321
|
it "returns true" do
|
350
|
-
expect("-Infinity"
|
322
|
+
expect("-Infinity").to be_numeric
|
351
323
|
end
|
352
324
|
end
|
353
325
|
end
|
@@ -88,17 +88,6 @@ describe Mongoid::Factory do
|
|
88
88
|
expect(person.title).to eq("Sir")
|
89
89
|
end
|
90
90
|
end
|
91
|
-
|
92
|
-
context "when the type is a symbol" do
|
93
|
-
|
94
|
-
let(:person) do
|
95
|
-
described_class.build(Person, {:_type => "Doctor"})
|
96
|
-
end
|
97
|
-
|
98
|
-
it "instantiates the subclass" do
|
99
|
-
expect(person.class).to eq(Doctor)
|
100
|
-
end
|
101
|
-
end
|
102
91
|
end
|
103
92
|
|
104
93
|
describe ".from_db" do
|
@@ -192,5 +181,23 @@ describe Mongoid::Factory do
|
|
192
181
|
expect(document.title).to eq("Sir")
|
193
182
|
end
|
194
183
|
end
|
184
|
+
|
185
|
+
context 'when type does not correspond to a Class name' do
|
186
|
+
|
187
|
+
let(:attributes) do
|
188
|
+
{ "title" => "Sir", "_type" => "invalid_class_name" }
|
189
|
+
end
|
190
|
+
|
191
|
+
let(:person) do
|
192
|
+
described_class.from_db(Person, attributes)
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'raises a exception' do
|
196
|
+
expect {
|
197
|
+
person
|
198
|
+
}.to raise_exception(Mongoid::Errors::UnknownModel)
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
195
202
|
end
|
196
203
|
end
|
@@ -7,7 +7,7 @@ describe Mongoid::Fields::ForeignKey do
|
|
7
7
|
let(:field) do
|
8
8
|
described_class.new(
|
9
9
|
:vals,
|
10
|
-
|
10
|
+
association: Person.relations["preferences"],
|
11
11
|
type: Array,
|
12
12
|
default: [],
|
13
13
|
identity: true
|
@@ -68,7 +68,7 @@ describe Mongoid::Fields::ForeignKey do
|
|
68
68
|
let(:field) do
|
69
69
|
described_class.new(
|
70
70
|
:vals,
|
71
|
-
|
71
|
+
association: Person.relations["posts"],
|
72
72
|
type: Array,
|
73
73
|
default: default,
|
74
74
|
identity: true
|
@@ -89,7 +89,7 @@ describe Mongoid::Fields::ForeignKey do
|
|
89
89
|
let(:field) do
|
90
90
|
described_class.new(
|
91
91
|
:vals,
|
92
|
-
|
92
|
+
association: Person.relations["posts"],
|
93
93
|
type: Array,
|
94
94
|
default: [],
|
95
95
|
identity: true
|
@@ -103,14 +103,14 @@ describe Mongoid::Fields::ForeignKey do
|
|
103
103
|
|
104
104
|
describe "#evolve" do
|
105
105
|
|
106
|
-
let(:
|
106
|
+
let(:association) do
|
107
107
|
Person.reflect_on_association(:preferences)
|
108
108
|
end
|
109
109
|
|
110
110
|
context "when provided a document" do
|
111
111
|
|
112
112
|
let(:field) do
|
113
|
-
described_class.new(:person_id, type: Object,
|
113
|
+
described_class.new(:person_id, type: Object, association: association)
|
114
114
|
end
|
115
115
|
|
116
116
|
let(:game) do
|
@@ -129,7 +129,7 @@ describe Mongoid::Fields::ForeignKey do
|
|
129
129
|
context "when the type is an array" do
|
130
130
|
|
131
131
|
let(:field) do
|
132
|
-
described_class.new(:preference_ids, type: Array, default: [],
|
132
|
+
described_class.new(:preference_ids, type: Array, default: [], association: association)
|
133
133
|
end
|
134
134
|
|
135
135
|
context "when providing a single value" do
|
@@ -197,12 +197,12 @@ describe Mongoid::Fields::ForeignKey do
|
|
197
197
|
|
198
198
|
context "when the relation stores ids as strings" do
|
199
199
|
|
200
|
-
let!(:
|
200
|
+
let!(:association) do
|
201
201
|
Agent.reflect_on_association(:accounts)
|
202
202
|
end
|
203
203
|
|
204
204
|
let!(:field) do
|
205
|
-
described_class.new(:account_ids, type: Array, default: [],
|
205
|
+
described_class.new(:account_ids, type: Array, default: [], association: association)
|
206
206
|
end
|
207
207
|
|
208
208
|
let(:id_one) do
|
@@ -260,12 +260,12 @@ describe Mongoid::Fields::ForeignKey do
|
|
260
260
|
|
261
261
|
context "when the type is an object" do
|
262
262
|
|
263
|
-
let(:
|
263
|
+
let(:association) do
|
264
264
|
Game.reflect_on_association(:person)
|
265
265
|
end
|
266
266
|
|
267
267
|
let(:field) do
|
268
|
-
described_class.new(:person_id, type: Object,
|
268
|
+
described_class.new(:person_id, type: Object, association: association)
|
269
269
|
end
|
270
270
|
|
271
271
|
context "when providing a single value" do
|
@@ -312,12 +312,12 @@ describe Mongoid::Fields::ForeignKey do
|
|
312
312
|
|
313
313
|
context "when the relation stores string ids" do
|
314
314
|
|
315
|
-
let(:
|
315
|
+
let(:association) do
|
316
316
|
Comment.reflect_on_association(:account)
|
317
317
|
end
|
318
318
|
|
319
319
|
let(:field) do
|
320
|
-
described_class.new(:person_id, type: Object,
|
320
|
+
described_class.new(:person_id, type: Object, association: association)
|
321
321
|
end
|
322
322
|
|
323
323
|
context "when the value is an id string" do
|
@@ -384,12 +384,12 @@ describe Mongoid::Fields::ForeignKey do
|
|
384
384
|
|
385
385
|
context "when the relation stores ids as strings" do
|
386
386
|
|
387
|
-
let(:
|
387
|
+
let(:association) do
|
388
388
|
Comment.reflect_on_association(:account)
|
389
389
|
end
|
390
390
|
|
391
391
|
let(:field) do
|
392
|
-
described_class.new(:person_id, type: Object,
|
392
|
+
described_class.new(:person_id, type: Object, association: association)
|
393
393
|
end
|
394
394
|
|
395
395
|
let(:id_one) do
|
@@ -445,14 +445,14 @@ describe Mongoid::Fields::ForeignKey do
|
|
445
445
|
end
|
446
446
|
end
|
447
447
|
|
448
|
-
context "when the
|
448
|
+
context "when the association is polymoprhic" do
|
449
449
|
|
450
|
-
let(:
|
450
|
+
let(:association) do
|
451
451
|
Agent.reflect_on_association(:names)
|
452
452
|
end
|
453
453
|
|
454
454
|
let(:field) do
|
455
|
-
described_class.new(:nameable_id, type: Object,
|
455
|
+
described_class.new(:nameable_id, type: Object, association: association)
|
456
456
|
end
|
457
457
|
|
458
458
|
let(:value) do
|
@@ -464,7 +464,7 @@ describe Mongoid::Fields::ForeignKey do
|
|
464
464
|
end
|
465
465
|
|
466
466
|
it "does not change the foreign key" do
|
467
|
-
expect(evolved).to
|
467
|
+
expect(evolved).to eq(BSON::ObjectId.from_string(value))
|
468
468
|
end
|
469
469
|
end
|
470
470
|
end
|
@@ -500,12 +500,8 @@ describe Mongoid::Fields::ForeignKey do
|
|
500
500
|
|
501
501
|
context "when the array is object ids" do
|
502
502
|
|
503
|
-
let(:
|
504
|
-
|
505
|
-
inverse_class_name: "Game",
|
506
|
-
name: :person,
|
507
|
-
relation: Mongoid::Relations::Referenced::In
|
508
|
-
)
|
503
|
+
let(:association) do
|
504
|
+
Game.relations["person"]
|
509
505
|
end
|
510
506
|
|
511
507
|
let(:field) do
|
@@ -514,7 +510,7 @@ describe Mongoid::Fields::ForeignKey do
|
|
514
510
|
type: Array,
|
515
511
|
default: [],
|
516
512
|
identity: true,
|
517
|
-
|
513
|
+
association: association,
|
518
514
|
overwrite: true
|
519
515
|
)
|
520
516
|
end
|
@@ -589,12 +585,8 @@ describe Mongoid::Fields::ForeignKey do
|
|
589
585
|
|
590
586
|
context "when the array is object ids" do
|
591
587
|
|
592
|
-
let(:
|
593
|
-
|
594
|
-
inverse_class_name: "Game",
|
595
|
-
name: :person,
|
596
|
-
relation: Mongoid::Relations::Referenced::In
|
597
|
-
)
|
588
|
+
let(:association) do
|
589
|
+
Game.relations['person']
|
598
590
|
end
|
599
591
|
|
600
592
|
let(:field) do
|
@@ -603,7 +595,7 @@ describe Mongoid::Fields::ForeignKey do
|
|
603
595
|
type: Object,
|
604
596
|
default: nil,
|
605
597
|
identity: true,
|
606
|
-
|
598
|
+
association: association,
|
607
599
|
overwrite: true
|
608
600
|
)
|
609
601
|
end
|