mongoid 6.4.2 → 7.0.3
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
- data/README.md +1 -1
- data/lib/config/locales/en.yml +17 -0
- data/lib/mongoid/association/accessors.rb +339 -0
- data/lib/mongoid/{relations/binding.rb → association/bindable.rb} +32 -52
- data/lib/mongoid/association/builders.rb +92 -0
- data/lib/mongoid/{relations/constraint.rb → association/constrainable.rb} +11 -22
- data/lib/mongoid/association/depending.rb +137 -0
- data/lib/mongoid/{relations/eager.rb → association/eager_loadable.rb} +11 -11
- data/lib/mongoid/{relations → association}/embedded/batchable.rb +19 -19
- data/lib/mongoid/association/embedded/cyclic.rb +109 -0
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +56 -0
- data/lib/mongoid/{relations/builders/embedded/in.rb → association/embedded/embedded_in/buildable.rb} +12 -6
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +121 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +154 -0
- data/lib/mongoid/{relations/bindings/embedded/many.rb → association/embedded/embeds_many/binding.rb} +11 -9
- data/lib/mongoid/{relations/builders/embedded/many.rb → association/embedded/embeds_many/buildable.rb} +13 -7
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +552 -0
- data/lib/mongoid/association/embedded/embeds_many.rb +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 +19 -49
- data/lib/mongoid/{relations → association}/marshalable.rb +6 -4
- data/lib/mongoid/association/nested/many.rb +200 -0
- data/lib/mongoid/association/nested/nested_buildable.rb +72 -0
- data/lib/mongoid/association/nested/one.rb +127 -0
- data/lib/mongoid/association/nested.rb +15 -0
- data/lib/mongoid/{relations → association}/one.rb +6 -6
- data/lib/mongoid/association/options.rb +152 -0
- data/lib/mongoid/{relations → association}/proxy.rb +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 +162 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +71 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +40 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +52 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +312 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +290 -0
- data/lib/mongoid/{relations/bindings/referenced/many.rb → association/referenced/has_many/binding.rb} +6 -5
- data/lib/mongoid/association/referenced/has_many/buildable.rb +38 -0
- data/lib/mongoid/association/referenced/has_many/eager.rb +43 -0
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +510 -0
- data/lib/mongoid/association/referenced/has_many/proxy.rb +578 -0
- data/lib/mongoid/association/referenced/has_many.rb +275 -0
- data/lib/mongoid/{relations/bindings/referenced/one.rb → association/referenced/has_one/binding.rb} +11 -8
- data/lib/mongoid/association/referenced/has_one/buildable.rb +60 -0
- data/lib/mongoid/association/referenced/has_one/eager.rb +35 -0
- data/lib/mongoid/{relations/builders/nested_attributes/one.rb → association/referenced/has_one/nested_builder.rb} +9 -9
- data/lib/mongoid/association/referenced/has_one/proxy.rb +113 -0
- data/lib/mongoid/association/referenced/has_one.rb +204 -0
- data/lib/mongoid/association/referenced/syncable.rb +170 -0
- data/lib/mongoid/association/referenced.rb +7 -0
- data/lib/mongoid/{relations → association}/reflections.rb +21 -17
- data/lib/mongoid/association/relatable.rb +509 -0
- data/lib/mongoid/{relations.rb → association.rb} +57 -56
- data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
- data/lib/mongoid/atomic.rb +4 -4
- data/lib/mongoid/attributes/dynamic.rb +2 -2
- data/lib/mongoid/attributes/nested.rb +22 -11
- data/lib/mongoid/attributes/processing.rb +2 -2
- data/lib/mongoid/attributes/readonly.rb +2 -4
- data/lib/mongoid/attributes.rb +22 -13
- data/lib/mongoid/changeable.rb +1 -1
- data/lib/mongoid/clients/options.rb +7 -5
- data/lib/mongoid/composable.rb +4 -4
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/geo_near.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +21 -3
- data/lib/mongoid/contextual/mongo.rb +10 -8
- data/lib/mongoid/copyable.rb +7 -6
- data/lib/mongoid/criteria/includable.rb +14 -14
- data/lib/mongoid/criteria/modifiable.rb +8 -14
- data/lib/mongoid/criteria/options.rb +2 -2
- 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 +37 -7
- data/lib/mongoid/criteria.rb +2 -2
- data/lib/mongoid/document.rb +15 -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 +1 -0
- 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 +4 -1
- 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/eq.rb +22 -0
- data/lib/mongoid/matchable/ne.rb +1 -1
- data/lib/mongoid/matchable.rb +3 -1
- data/lib/mongoid/persistable/deletable.rb +7 -6
- data/lib/mongoid/persistable/incrementable.rb +1 -1
- data/lib/mongoid/persistable/logical.rb +1 -1
- data/lib/mongoid/persistable/settable.rb +57 -12
- data/lib/mongoid/persistable.rb +4 -5
- data/lib/mongoid/persistence_context.rb +20 -5
- data/lib/mongoid/query_cache.rb +8 -4
- data/lib/mongoid/railtie.rb +17 -0
- data/lib/mongoid/railties/controller_runtime.rb +86 -0
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +4 -4
- data/lib/mongoid/shardable.rb +1 -1
- data/lib/mongoid/threaded.rb +36 -0
- data/lib/mongoid/touchable.rb +102 -0
- 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/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/minim.rb +7 -0
- data/spec/app/models/person.rb +5 -2
- data/spec/app/models/shipment_address.rb +1 -0
- data/spec/app/models/store_as_dup_test3.rb +7 -0
- data/spec/app/models/store_as_dup_test4.rb +7 -0
- data/spec/app/models/updatable.rb +7 -0
- data/spec/app/models/vertex.rb +6 -0
- data/spec/app/models/wiki_page.rb +1 -1
- data/spec/config/mongoid.yml +13 -3
- data/spec/integration/associations/belongs_to_spec.rb +13 -0
- data/spec/lite_spec_helper.rb +56 -0
- data/spec/mongoid/{relations → association}/accessors_spec.rb +40 -1
- data/spec/mongoid/{relations → association}/auto_save_spec.rb +60 -12
- data/spec/mongoid/{relations → association}/builders_spec.rb +1 -1
- data/spec/mongoid/association/constrainable_spec.rb +115 -0
- data/spec/mongoid/{relations → association}/counter_cache_spec.rb +1 -1
- data/spec/mongoid/association/depending_spec.rb +866 -0
- data/spec/mongoid/{relations → association}/eager_spec.rb +12 -12
- data/spec/mongoid/{relations → association/embedded}/cyclic_spec.rb +1 -1
- data/spec/mongoid/{relations/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} +124 -182
- 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 +66 -34
- data/spec/mongoid/{relations/bindings/referenced/in_spec.rb → association/referenced/belongs_to/binding_spec.rb} +7 -7
- data/spec/mongoid/{relations/builders/referenced/in_spec.rb → association/referenced/belongs_to/buildable_spec.rb} +46 -79
- data/spec/mongoid/{relations/eager/belongs_to_spec.rb → association/referenced/belongs_to/eager_spec.rb} +33 -14
- data/spec/mongoid/{relations/referenced/in_spec.rb → association/referenced/belongs_to/proxy_spec.rb} +57 -91
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2006 -0
- data/spec/mongoid/{relations/bindings/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +121 -0
- data/spec/mongoid/{relations/eager/has_and_belongs_to_many_spec.rb → association/referenced/has_and_belongs_to_many/eager_spec.rb} +26 -7
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +56 -0
- data/spec/mongoid/{relations/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/proxy_spec.rb} +107 -98
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +26 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +1027 -0
- data/spec/mongoid/{relations/bindings/referenced/many_spec.rb → association/referenced/has_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +119 -0
- data/spec/mongoid/{relations/eager/has_many_spec.rb → association/referenced/has_many/eager_spec.rb} +26 -11
- data/spec/mongoid/{relations/targets → association/referenced/has_many}/enumerable_spec.rb +122 -1
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +23 -0
- data/spec/mongoid/{relations/referenced/many_spec.rb → association/referenced/has_many/proxy_spec.rb} +28 -93
- data/spec/mongoid/association/referenced/has_many_models.rb +37 -0
- data/spec/mongoid/association/referenced/has_many_spec.rb +1225 -0
- data/spec/mongoid/{relations/bindings/referenced/one_spec.rb → association/referenced/has_one/binding_spec.rb} +4 -4
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +113 -0
- data/spec/mongoid/{relations/eager/has_one_spec.rb → association/referenced/has_one/eager_spec.rb} +10 -10
- data/spec/mongoid/{relations/referenced/one_spec.rb → association/referenced/has_one/proxy_spec.rb} +9 -109
- data/spec/mongoid/association/referenced/has_one_models.rb +48 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +1350 -0
- data/spec/mongoid/{relations → association}/reflections_spec.rb +1 -12
- data/spec/mongoid/{relations/synchronization_spec.rb → association/syncable_spec.rb} +4 -2
- data/spec/mongoid/{relations_spec.rb → association_spec.rb} +1 -1
- data/spec/mongoid/atomic/modifiers_spec.rb +2 -2
- data/spec/mongoid/atomic_spec.rb +4 -4
- data/spec/mongoid/attributes/nested_spec.rb +29 -11
- data/spec/mongoid/attributes/readonly_spec.rb +80 -125
- data/spec/mongoid/attributes_spec.rb +38 -2
- data/spec/mongoid/clients/factory_spec.rb +24 -18
- data/spec/mongoid/clients/options_spec.rb +58 -44
- data/spec/mongoid/clients/sessions_spec.rb +1 -1
- data/spec/mongoid/clients/transactions_spec.rb +369 -0
- data/spec/mongoid/clients_spec.rb +68 -8
- data/spec/mongoid/config_spec.rb +27 -1
- data/spec/mongoid/contextual/memory_spec.rb +19 -0
- data/spec/mongoid/contextual/mongo_spec.rb +33 -5
- data/spec/mongoid/copyable_spec.rb +90 -6
- data/spec/mongoid/copyable_spec_models.rb +17 -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 +42 -3
- data/spec/mongoid/criteria/queryable/selector_spec.rb +2 -2
- data/spec/mongoid/criteria/scopable_spec.rb +81 -0
- data/spec/mongoid/criteria_spec.rb +33 -18
- data/spec/mongoid/document_spec.rb +83 -4
- 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 +23 -0
- 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/eq_spec.rb +48 -0
- 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 +95 -10
- data/spec/mongoid/persistable_spec.rb +21 -6
- data/spec/mongoid/persistence_context_spec.rb +1 -1
- data/spec/mongoid/query_cache_spec.rb +61 -22
- data/spec/mongoid/relations/proxy_spec.rb +124 -124
- data/spec/mongoid/scopable_spec.rb +13 -0
- data/spec/mongoid/shardable_spec.rb +32 -12
- data/spec/mongoid/threaded_spec.rb +68 -0
- data/spec/mongoid/{relations/touchable_spec.rb → touchable_spec.rb} +40 -1
- data/spec/mongoid/validatable/associated_spec.rb +1 -1
- data/spec/mongoid/validatable/presence_spec.rb +7 -6
- data/spec/mongoid/validatable_spec.rb +1 -1
- data/spec/rails/controller_extension/controller_runtime_spec.rb +110 -0
- data/spec/spec_helper.rb +51 -25
- data/spec/support/constraints.rb +101 -0
- data/spec/support/macros.rb +20 -0
- data/spec/support/spec_config.rb +39 -0
- metadata +602 -582
- checksums.yaml.gz.sig +0 -2
- data/lib/mongoid/relations/accessors.rb +0 -267
- data/lib/mongoid/relations/auto_save.rb +0 -94
- data/lib/mongoid/relations/bindings/embedded/in.rb +0 -59
- data/lib/mongoid/relations/bindings/referenced/in.rb +0 -65
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +0 -70
- data/lib/mongoid/relations/bindings.rb +0 -9
- data/lib/mongoid/relations/builder.rb +0 -57
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +0 -199
- data/lib/mongoid/relations/builders/referenced/in.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +0 -39
- data/lib/mongoid/relations/builders/referenced/one.rb +0 -26
- data/lib/mongoid/relations/builders.rb +0 -106
- data/lib/mongoid/relations/cascading/delete.rb +0 -44
- data/lib/mongoid/relations/cascading/destroy.rb +0 -43
- data/lib/mongoid/relations/cascading/nullify.rb +0 -35
- data/lib/mongoid/relations/cascading/restrict.rb +0 -39
- data/lib/mongoid/relations/cascading.rb +0 -56
- data/lib/mongoid/relations/conversions.rb +0 -34
- data/lib/mongoid/relations/counter_cache.rb +0 -160
- data/lib/mongoid/relations/cyclic.rb +0 -107
- data/lib/mongoid/relations/eager/base.rb +0 -153
- data/lib/mongoid/relations/eager/belongs_to.rb +0 -31
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +0 -47
- data/lib/mongoid/relations/eager/has_many.rb +0 -38
- data/lib/mongoid/relations/eager/has_one.rb +0 -30
- data/lib/mongoid/relations/embedded/in.rb +0 -241
- data/lib/mongoid/relations/embedded/many.rb +0 -683
- data/lib/mongoid/relations/embedded/one.rb +0 -235
- data/lib/mongoid/relations/macros.rb +0 -367
- data/lib/mongoid/relations/metadata.rb +0 -1179
- data/lib/mongoid/relations/nested_builder.rb +0 -74
- data/lib/mongoid/relations/options.rb +0 -49
- data/lib/mongoid/relations/polymorphic.rb +0 -39
- data/lib/mongoid/relations/referenced/in.rb +0 -304
- data/lib/mongoid/relations/referenced/many.rb +0 -812
- data/lib/mongoid/relations/referenced/many_to_many.rb +0 -479
- data/lib/mongoid/relations/referenced/one.rb +0 -290
- data/lib/mongoid/relations/synchronization.rb +0 -169
- data/lib/mongoid/relations/targets/enumerable.rb +0 -493
- data/lib/mongoid/relations/targets.rb +0 -2
- data/lib/mongoid/relations/touchable.rb +0 -97
- data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +0 -184
- data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +0 -201
- data/spec/mongoid/relations/builders/referenced/many_spec.rb +0 -137
- data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +0 -178
- data/spec/mongoid/relations/builders/referenced/one_spec.rb +0 -111
- data/spec/mongoid/relations/cascading/delete_spec.rb +0 -101
- data/spec/mongoid/relations/cascading/destroy_spec.rb +0 -47
- data/spec/mongoid/relations/cascading/nullify_spec.rb +0 -32
- data/spec/mongoid/relations/cascading/restrict_spec.rb +0 -68
- data/spec/mongoid/relations/cascading_spec.rb +0 -355
- data/spec/mongoid/relations/constraint_spec.rb +0 -75
- data/spec/mongoid/relations/conversions_spec.rb +0 -128
- data/spec/mongoid/relations/metadata_spec.rb +0 -1985
- data/spec/mongoid/relations/options_spec.rb +0 -35
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
- /data/spec/mongoid/{relations → association}/embedded/dirty_spec.rb +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
|
-
describe Mongoid::
|
|
3
|
+
describe Mongoid::Association::Reflections do
|
|
4
4
|
|
|
5
5
|
class TestClass
|
|
6
6
|
include Mongoid::Document
|
|
@@ -20,17 +20,6 @@ describe Mongoid::Relations::Reflections do
|
|
|
20
20
|
klass.embeds_many(:addresses)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
context "when the name exists" do
|
|
24
|
-
|
|
25
|
-
let(:relation) do
|
|
26
|
-
klass.reflect_on_association(:addresses)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "returns the association metadata" do
|
|
30
|
-
expect(relation.macro).to eq(:embeds_many)
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
23
|
context "when the name does not exist" do
|
|
35
24
|
|
|
36
25
|
let(:relation) do
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe "Syncable Association" do
|
|
4
4
|
|
|
5
5
|
before(:all) do
|
|
6
6
|
Mongoid.raise_not_found_error = true
|
|
7
7
|
Person._synced(Person.relations["preferences"])
|
|
8
|
+
Person.has_and_belongs_to_many :preferences
|
|
9
|
+
Preference.has_and_belongs_to_many :people
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
after(:all) do
|
|
@@ -27,7 +29,7 @@ describe Mongoid::Relations::Synchronization do
|
|
|
27
29
|
field :_synced?
|
|
28
30
|
end
|
|
29
31
|
end
|
|
30
|
-
|
|
32
|
+
|
|
31
33
|
let(:model_syncable?) do
|
|
32
34
|
class TestModel
|
|
33
35
|
include Mongoid::Document
|
|
@@ -212,7 +212,7 @@ describe Mongoid::Atomic::Modifiers do
|
|
|
212
212
|
it "adds the push all modifiers" do
|
|
213
213
|
expect(modifiers).to eq(
|
|
214
214
|
{ "$push" =>
|
|
215
|
-
|
|
215
|
+
{ "addresses" => { '$each' => [
|
|
216
216
|
{ "street" => "Oxford St" }
|
|
217
217
|
] }
|
|
218
218
|
}
|
|
@@ -303,7 +303,7 @@ describe Mongoid::Atomic::Modifiers do
|
|
|
303
303
|
conflicts: { "$push" =>
|
|
304
304
|
{ "addresses" => { '$each' => [
|
|
305
305
|
{ "street" => "Oxford St" }
|
|
306
|
-
]
|
|
306
|
+
]}
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
}
|
data/spec/mongoid/atomic_spec.rb
CHANGED
|
@@ -76,13 +76,13 @@ describe Mongoid::Atomic do
|
|
|
76
76
|
person.addresses.build(street: "Oxford St")
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
it "returns a $set and $push for modifications" do
|
|
79
|
+
it "returns a $set and $push with $each for modifications" do
|
|
80
80
|
expect(person.atomic_updates).to eq(
|
|
81
81
|
{
|
|
82
82
|
"$set" => { "title" => "Sir" },
|
|
83
|
-
"$push" => { "addresses" => {
|
|
83
|
+
"$push" => { "addresses" => { "$each" => [
|
|
84
84
|
{ "_id" => "oxford-st", "street" => "Oxford St" }
|
|
85
|
-
]} }
|
|
85
|
+
] } }
|
|
86
86
|
}
|
|
87
87
|
)
|
|
88
88
|
end
|
|
@@ -271,7 +271,7 @@ describe Mongoid::Atomic do
|
|
|
271
271
|
"_id" => location.id,
|
|
272
272
|
"name" => "Home"
|
|
273
273
|
]
|
|
274
|
-
}]
|
|
274
|
+
}]}
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
}
|
|
@@ -12,10 +12,12 @@ describe Mongoid::Attributes::Nested do
|
|
|
12
12
|
|
|
13
13
|
before do
|
|
14
14
|
Person.accepts_nested_attributes_for :favorites
|
|
15
|
+
Person.accepts_nested_attributes_for :children
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
after do
|
|
18
19
|
Person.send(:undef_method, :favorites_attributes=)
|
|
20
|
+
Person.send(:undef_method, :children_attributes=)
|
|
19
21
|
Person.nested_attributes.clear
|
|
20
22
|
end
|
|
21
23
|
|
|
@@ -23,9 +25,18 @@ describe Mongoid::Attributes::Nested do
|
|
|
23
25
|
expect(person).to respond_to(:favorites_attributes=)
|
|
24
26
|
end
|
|
25
27
|
|
|
28
|
+
it "does not autosave if the association is embedded" do
|
|
29
|
+
expect(person).not_to respond_to(:autosave_documents_for_favorites)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "autosaves if the association is not embedded" do
|
|
33
|
+
expect(person).to respond_to(:autosave_documents_for_children)
|
|
34
|
+
end
|
|
35
|
+
|
|
26
36
|
it "adds the method name to the nested attributes list" do
|
|
27
37
|
expect(Person.nested_attributes).to eq({
|
|
28
|
-
"favorites_attributes" => "favorites_attributes="
|
|
38
|
+
"favorites_attributes" => "favorites_attributes=",
|
|
39
|
+
"children_attributes" => "children_attributes="
|
|
29
40
|
})
|
|
30
41
|
end
|
|
31
42
|
end
|
|
@@ -41,12 +52,12 @@ describe Mongoid::Attributes::Nested do
|
|
|
41
52
|
Account.nested_attributes.clear
|
|
42
53
|
end
|
|
43
54
|
|
|
44
|
-
let(:
|
|
55
|
+
let(:association) do
|
|
45
56
|
Account.reflect_on_association(:alerts)
|
|
46
57
|
end
|
|
47
58
|
|
|
48
59
|
it "keeps autosave set to false" do
|
|
49
|
-
expect(
|
|
60
|
+
expect(association).to_not be_autosave
|
|
50
61
|
end
|
|
51
62
|
end
|
|
52
63
|
end
|
|
@@ -202,11 +213,12 @@ describe Mongoid::Attributes::Nested do
|
|
|
202
213
|
context "when the relation is a referenced in" do
|
|
203
214
|
|
|
204
215
|
before do
|
|
205
|
-
Post.accepts_nested_attributes_for :person
|
|
216
|
+
Post.accepts_nested_attributes_for :person, autosave: false
|
|
206
217
|
end
|
|
207
218
|
|
|
208
219
|
after do
|
|
209
|
-
Post.
|
|
220
|
+
Post.send(:undef_method, :person_attributes=)
|
|
221
|
+
Post.nested_attributes.clear
|
|
210
222
|
end
|
|
211
223
|
|
|
212
224
|
let(:post) do
|
|
@@ -4381,12 +4393,11 @@ describe Mongoid::Attributes::Nested do
|
|
|
4381
4393
|
|
|
4382
4394
|
context "when nesting multiple levels and parent is timestamped" do
|
|
4383
4395
|
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
end
|
|
4396
|
+
around do |example|
|
|
4397
|
+
original_relations = Location.relations
|
|
4398
|
+
Location.embedded_in :address, touch: true
|
|
4399
|
+
example.run
|
|
4400
|
+
Location.relations = original_relations
|
|
4390
4401
|
end
|
|
4391
4402
|
|
|
4392
4403
|
after do
|
|
@@ -4766,6 +4777,13 @@ describe Mongoid::Attributes::Nested do
|
|
|
4766
4777
|
user.update_attributes(params)
|
|
4767
4778
|
end
|
|
4768
4779
|
|
|
4780
|
+
around do |example|
|
|
4781
|
+
original_relations = User.relations
|
|
4782
|
+
User.has_many :posts, foreign_key: :author_id, validate: false, autosave: true
|
|
4783
|
+
example.run
|
|
4784
|
+
user.relations = original_relations
|
|
4785
|
+
end
|
|
4786
|
+
|
|
4769
4787
|
let(:post) do
|
|
4770
4788
|
user.posts.first
|
|
4771
4789
|
end
|
|
@@ -96,30 +96,14 @@ describe Mongoid::Attributes::Readonly do
|
|
|
96
96
|
context "when updating via the setter" do
|
|
97
97
|
|
|
98
98
|
it "does not update the first field" do
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
102
|
-
expect(person.title).to eq("sir")
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "does not update the second field" do
|
|
106
|
-
expect {
|
|
107
|
-
person.aliased_timestamp = Time.at(43)
|
|
108
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
109
|
-
expect(person.aliased_timestamp).to eq(Time.at(42))
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
it "does not persist the first field" do
|
|
113
|
-
expect {
|
|
114
|
-
person.title = 'mr'
|
|
115
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
99
|
+
person.title = 'mr'
|
|
100
|
+
person.save
|
|
116
101
|
expect(person.reload.title).to eq("sir")
|
|
117
102
|
end
|
|
118
103
|
|
|
119
|
-
it "does not
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
104
|
+
it "does not update the second field" do
|
|
105
|
+
person.aliased_timestamp = Time.at(43)
|
|
106
|
+
person.save
|
|
123
107
|
expect(person.reload.aliased_timestamp).to eq(Time.at(42))
|
|
124
108
|
end
|
|
125
109
|
end
|
|
@@ -128,19 +112,20 @@ describe Mongoid::Attributes::Readonly do
|
|
|
128
112
|
|
|
129
113
|
context 'with single field operation' do
|
|
130
114
|
|
|
131
|
-
it "
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
115
|
+
it "updates the field" do
|
|
116
|
+
person.inc(score: 1)
|
|
117
|
+
person.save
|
|
118
|
+
expect(person.reload.score).to eq(2)
|
|
135
119
|
end
|
|
136
120
|
end
|
|
137
121
|
|
|
138
122
|
context 'with multiple fields operation' do
|
|
139
123
|
|
|
140
|
-
it "
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
124
|
+
it "updates the fields" do
|
|
125
|
+
person.inc(score: 1, age: 1)
|
|
126
|
+
person.save
|
|
127
|
+
expect(person.reload.score).to eq(2)
|
|
128
|
+
expect(person.reload.age).to eq(101)
|
|
144
129
|
end
|
|
145
130
|
end
|
|
146
131
|
end
|
|
@@ -149,21 +134,20 @@ describe Mongoid::Attributes::Readonly do
|
|
|
149
134
|
|
|
150
135
|
context 'with single field operation' do
|
|
151
136
|
|
|
152
|
-
it "
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
137
|
+
it "does the update" do
|
|
138
|
+
person.bit(score: { or: 13 })
|
|
139
|
+
person.save
|
|
140
|
+
expect(person.reload.score).to eq(13)
|
|
156
141
|
end
|
|
157
142
|
end
|
|
158
143
|
|
|
159
144
|
context 'with multiple fields operation' do
|
|
160
145
|
|
|
161
|
-
it "
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}.to raise_error(Mongoid::Errors::ReadonlyAttribute)
|
|
146
|
+
it "udpates the attribute" do
|
|
147
|
+
person.bit(age: {and: 13}, score: {or: 13})
|
|
148
|
+
person.save
|
|
149
|
+
expect(person.reload.score).to eq(13)
|
|
150
|
+
expect(person.reload.age).to eq(4)
|
|
167
151
|
end
|
|
168
152
|
end
|
|
169
153
|
end
|
|
@@ -171,30 +155,14 @@ describe Mongoid::Attributes::Readonly do
|
|
|
171
155
|
context "when updating via []=" do
|
|
172
156
|
|
|
173
157
|
it "does not update the first field" do
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
177
|
-
expect(person.title).to eq("sir")
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
it "does not update the second field" do
|
|
181
|
-
expect {
|
|
182
|
-
person[:aliased_timestamp] = Time.at(43)
|
|
183
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
184
|
-
expect(person.aliased_timestamp).to eq(Time.at(42))
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
it "does not persist the first field" do
|
|
188
|
-
expect {
|
|
189
|
-
person[:title] = "mr"
|
|
190
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
158
|
+
person[:title] = "mr"
|
|
159
|
+
person.save
|
|
191
160
|
expect(person.reload.title).to eq("sir")
|
|
192
161
|
end
|
|
193
162
|
|
|
194
|
-
it "does not
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
163
|
+
it "does not update the second field" do
|
|
164
|
+
person[:aliased_timestamp] = Time.at(43)
|
|
165
|
+
person.save
|
|
198
166
|
expect(person.reload.aliased_timestamp).to eq(Time.at(42))
|
|
199
167
|
end
|
|
200
168
|
end
|
|
@@ -202,30 +170,14 @@ describe Mongoid::Attributes::Readonly do
|
|
|
202
170
|
context "when updating via write_attribute" do
|
|
203
171
|
|
|
204
172
|
it "does not update the first field" do
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
208
|
-
expect(person.title).to eq("sir")
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
it "does not update the second field" do
|
|
212
|
-
expect {
|
|
213
|
-
person.write_attribute(:aliased_timestamp, Time.at(43))
|
|
214
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
215
|
-
expect(person.aliased_timestamp).to eq(Time.at(42))
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
it "does not persist the first field" do
|
|
219
|
-
expect {
|
|
220
|
-
person.write_attribute(:title, "mr")
|
|
221
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
173
|
+
person.write_attribute(:title, "mr")
|
|
174
|
+
person.save
|
|
222
175
|
expect(person.reload.title).to eq("sir")
|
|
223
176
|
end
|
|
224
177
|
|
|
225
|
-
it "does not
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
178
|
+
it "does not update the second field" do
|
|
179
|
+
person.write_attribute(:aliased_timestamp, Time.at(43))
|
|
180
|
+
person.save
|
|
229
181
|
expect(person.reload.aliased_timestamp).to eq(Time.at(42))
|
|
230
182
|
end
|
|
231
183
|
end
|
|
@@ -233,30 +185,14 @@ describe Mongoid::Attributes::Readonly do
|
|
|
233
185
|
context "when updating via update_attributes" do
|
|
234
186
|
|
|
235
187
|
it "does not update the first field" do
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
239
|
-
expect(person.title).to eq("sir")
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
it "does not update the second field" do
|
|
243
|
-
expect {
|
|
244
|
-
person.update_attributes(title: "mr", aliased_timestamp: Time.at(43))
|
|
245
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
246
|
-
expect(person.aliased_timestamp).to eq(Time.at(42))
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
it "does not persist the first field" do
|
|
250
|
-
expect {
|
|
251
|
-
person.update_attributes(title: "mr", aliased_timestamp: Time.at(43))
|
|
252
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
188
|
+
person.update_attributes(title: "mr", aliased_timestamp: Time.at(43))
|
|
189
|
+
person.save
|
|
253
190
|
expect(person.reload.title).to eq("sir")
|
|
254
191
|
end
|
|
255
192
|
|
|
256
|
-
it "does not
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
193
|
+
it "does not update the second field" do
|
|
194
|
+
person.update_attributes(title: "mr", aliased_timestamp: Time.at(43))
|
|
195
|
+
person.save
|
|
260
196
|
expect(person.reload.aliased_timestamp).to eq(Time.at(42))
|
|
261
197
|
end
|
|
262
198
|
end
|
|
@@ -264,30 +200,14 @@ describe Mongoid::Attributes::Readonly do
|
|
|
264
200
|
context "when updating via update_attributes!" do
|
|
265
201
|
|
|
266
202
|
it "does not update the first field" do
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
270
|
-
expect(person.title).to eq("sir")
|
|
271
|
-
end
|
|
272
|
-
|
|
273
|
-
it "does not update the second field" do
|
|
274
|
-
expect {
|
|
275
|
-
person.update_attributes!(title: "mr", aliased_timestamp: Time.at(43))
|
|
276
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
277
|
-
expect(person.aliased_timestamp).to eq(Time.at(42))
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
it "does not persist the first field" do
|
|
281
|
-
expect {
|
|
282
|
-
person.update_attributes!(title: "mr", aliased_timestamp: Time.at(43))
|
|
283
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
203
|
+
person.update_attributes!(title: "mr", aliased_timestamp: Time.at(43))
|
|
204
|
+
person.save
|
|
284
205
|
expect(person.reload.title).to eq("sir")
|
|
285
206
|
end
|
|
286
207
|
|
|
287
|
-
it "does not
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
208
|
+
it "does not update the second field" do
|
|
209
|
+
person.update_attributes!(title: "mr", aliased_timestamp: Time.at(43))
|
|
210
|
+
person.save
|
|
291
211
|
expect(person.reload.aliased_timestamp).to eq(Time.at(42))
|
|
292
212
|
end
|
|
293
213
|
end
|
|
@@ -297,7 +217,7 @@ describe Mongoid::Attributes::Readonly do
|
|
|
297
217
|
it "raises an error" do
|
|
298
218
|
expect {
|
|
299
219
|
person.update_attribute(:title, "mr")
|
|
300
|
-
}.to
|
|
220
|
+
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
301
221
|
end
|
|
302
222
|
end
|
|
303
223
|
|
|
@@ -306,9 +226,44 @@ describe Mongoid::Attributes::Readonly do
|
|
|
306
226
|
it "raises an error" do
|
|
307
227
|
expect {
|
|
308
228
|
person.remove_attribute(:title)
|
|
309
|
-
}.to
|
|
229
|
+
}.to raise_exception(Mongoid::Errors::ReadonlyAttribute)
|
|
310
230
|
end
|
|
311
231
|
end
|
|
312
232
|
end
|
|
233
|
+
|
|
234
|
+
context 'when a foreign_key is defined as readonly' do
|
|
235
|
+
|
|
236
|
+
let(:attributes) do
|
|
237
|
+
:mother_id
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
context 'when the relation exists' do
|
|
241
|
+
|
|
242
|
+
let(:mother) do
|
|
243
|
+
Person.create
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
let(:child) do
|
|
247
|
+
Person.create(mother: mother)
|
|
248
|
+
Person.find_by(mother: mother)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
it 'the relation can still be accessed' do
|
|
252
|
+
expect(child.mother).to eq(mother)
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
context 'when the relation does not exist' do
|
|
257
|
+
|
|
258
|
+
let(:child) do
|
|
259
|
+
Person.create
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
it 'the relation is nil' do
|
|
263
|
+
expect(child.mother).to be_nil
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
end
|
|
313
268
|
end
|
|
314
269
|
end
|
|
@@ -42,7 +42,7 @@ describe Mongoid::Attributes do
|
|
|
42
42
|
context "accessing via []" do
|
|
43
43
|
|
|
44
44
|
it "does not raise an error" do
|
|
45
|
-
expect(from_db["desc"]).to eq("
|
|
45
|
+
expect(from_db["desc"]).to eq("test")
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -150,6 +150,17 @@ describe Mongoid::Attributes do
|
|
|
150
150
|
|
|
151
151
|
describe "#[]" do
|
|
152
152
|
|
|
153
|
+
context 'when the document has a custom attribute type' do
|
|
154
|
+
|
|
155
|
+
let(:bar) do
|
|
156
|
+
Bar.create(lat_lng: LatLng.new(52.30, 13.25))
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it 'returns the demongoized version of the attribute' do
|
|
160
|
+
expect(bar.reload[:lat_lng]).to be_a(LatLng)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
153
164
|
context "when the document is a new record" do
|
|
154
165
|
|
|
155
166
|
let(:person) do
|
|
@@ -165,7 +176,7 @@ describe Mongoid::Attributes do
|
|
|
165
176
|
context "when passing just the name" do
|
|
166
177
|
|
|
167
178
|
it "returns the full value" do
|
|
168
|
-
expect(person[:desc]).to eq("
|
|
179
|
+
expect(person[:desc]).to eq("testing")
|
|
169
180
|
end
|
|
170
181
|
end
|
|
171
182
|
|
|
@@ -268,6 +279,20 @@ describe Mongoid::Attributes do
|
|
|
268
279
|
|
|
269
280
|
describe "#[]=" do
|
|
270
281
|
|
|
282
|
+
context 'when the document has a custom attribute type' do
|
|
283
|
+
|
|
284
|
+
let(:bar) do
|
|
285
|
+
Bar.new.tap do |b|
|
|
286
|
+
b[:lat_lng] = LatLng.new(52.30, 13.25)
|
|
287
|
+
b.save
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
it 'sets the demongoized version of the attribute' do
|
|
292
|
+
expect(bar.reload.lat_lng).to be_a(LatLng)
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
|
|
271
296
|
let(:person) do
|
|
272
297
|
Person.new
|
|
273
298
|
end
|
|
@@ -768,6 +793,17 @@ describe Mongoid::Attributes do
|
|
|
768
793
|
|
|
769
794
|
describe "#read_attribute" do
|
|
770
795
|
|
|
796
|
+
context 'when the document has a custom attribute type' do
|
|
797
|
+
|
|
798
|
+
let(:bar) do
|
|
799
|
+
Bar.create(lat_lng: LatLng.new(52.30, 13.25))
|
|
800
|
+
end
|
|
801
|
+
|
|
802
|
+
it 'returns the demongoized version of the attribute' do
|
|
803
|
+
expect(bar.reload.read_attribute(:lat_lng)).to be_a(LatLng)
|
|
804
|
+
end
|
|
805
|
+
end
|
|
806
|
+
|
|
771
807
|
context "when the document is a new record" do
|
|
772
808
|
|
|
773
809
|
let(:person) do
|