mongoid 6.4.8 → 7.0.0.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.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
|
@@ -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
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
|
-
describe Mongoid::
|
|
3
|
+
describe Mongoid::Association::Touchable do
|
|
4
4
|
|
|
5
5
|
describe "#touch" do
|
|
6
6
|
|
|
7
7
|
context "when the document is embedded" do
|
|
8
8
|
|
|
9
|
+
before do
|
|
10
|
+
Label.send(:include, Mongoid::Association::Touchable::InstanceMethods)
|
|
11
|
+
end
|
|
12
|
+
|
|
9
13
|
let(:band) do
|
|
10
14
|
Band.create(name: "Placebo")
|
|
11
15
|
end
|
|
@@ -29,6 +33,11 @@ describe Mongoid::Relations::Touchable do
|
|
|
29
33
|
|
|
30
34
|
context "when no relations have touch options" do
|
|
31
35
|
|
|
36
|
+
before do
|
|
37
|
+
Person.send(:include, Mongoid::Association::Touchable::InstanceMethods)
|
|
38
|
+
Agent.send(:include, Mongoid::Association::Touchable::InstanceMethods)
|
|
39
|
+
end
|
|
40
|
+
|
|
32
41
|
context "when no updated at is defined" do
|
|
33
42
|
|
|
34
43
|
let(:person) do
|
|
@@ -209,6 +218,11 @@ describe Mongoid::Relations::Touchable do
|
|
|
209
218
|
|
|
210
219
|
context "when the relation is a parent of an embedded doc" do
|
|
211
220
|
|
|
221
|
+
before do
|
|
222
|
+
Page.send(:include, Mongoid::Association::Touchable::InstanceMethods)
|
|
223
|
+
Edit.send(:include, Mongoid::Association::Touchable::InstanceMethods)
|
|
224
|
+
end
|
|
225
|
+
|
|
212
226
|
let(:page) do
|
|
213
227
|
WikiPage.create(title: "test")
|
|
214
228
|
end
|
|
@@ -229,6 +243,10 @@ describe Mongoid::Relations::Touchable do
|
|
|
229
243
|
|
|
230
244
|
context "when the parent of embedded doc has cascade callbacks" do
|
|
231
245
|
|
|
246
|
+
before do
|
|
247
|
+
Band.send(:include, Mongoid::Association::Touchable::InstanceMethods)
|
|
248
|
+
end
|
|
249
|
+
|
|
232
250
|
let!(:book) do
|
|
233
251
|
Book.new
|
|
234
252
|
end
|
|
@@ -211,10 +211,10 @@ describe Mongoid::Atomic::Modifiers do
|
|
|
211
211
|
|
|
212
212
|
it "adds the push all modifiers" do
|
|
213
213
|
expect(modifiers).to eq(
|
|
214
|
-
{ "$
|
|
215
|
-
|
|
214
|
+
{ "$pushAll" =>
|
|
215
|
+
{ "addresses" => [
|
|
216
216
|
{ "street" => "Oxford St" }
|
|
217
|
-
]
|
|
217
|
+
]
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
)
|
|
@@ -238,11 +238,11 @@ describe Mongoid::Atomic::Modifiers do
|
|
|
238
238
|
|
|
239
239
|
it "adds the push all modifiers" do
|
|
240
240
|
expect(modifiers).to eq(
|
|
241
|
-
{ "$
|
|
242
|
-
{ "addresses" =>
|
|
241
|
+
{ "$pushAll" =>
|
|
242
|
+
{ "addresses" => [
|
|
243
243
|
{ "street" => "Hobrechtstr." },
|
|
244
244
|
{ "street" => "Pflugerstr." }
|
|
245
|
-
]
|
|
245
|
+
]
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
)
|
|
@@ -270,10 +270,10 @@ describe Mongoid::Atomic::Modifiers do
|
|
|
270
270
|
it "adds the push all modifiers to the conflicts hash" do
|
|
271
271
|
expect(modifiers).to eq(
|
|
272
272
|
{ "$set" => { "addresses.0.street" => "Bond" },
|
|
273
|
-
conflicts: { "$
|
|
274
|
-
{ "addresses" =>
|
|
273
|
+
conflicts: { "$pushAll" =>
|
|
274
|
+
{ "addresses" => [
|
|
275
275
|
{ "street" => "Oxford St" }
|
|
276
|
-
]
|
|
276
|
+
]
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
}
|
|
@@ -300,10 +300,10 @@ describe Mongoid::Atomic::Modifiers do
|
|
|
300
300
|
expect(modifiers).to eq(
|
|
301
301
|
{ "$pullAll" => {
|
|
302
302
|
"addresses" => { "street" => "Bond St" }},
|
|
303
|
-
conflicts: { "$
|
|
304
|
-
{ "addresses" =>
|
|
303
|
+
conflicts: { "$pushAll" =>
|
|
304
|
+
{ "addresses" => [
|
|
305
305
|
{ "street" => "Oxford St" }
|
|
306
|
-
]
|
|
306
|
+
]
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
}
|
|
@@ -328,12 +328,12 @@ describe Mongoid::Atomic::Modifiers do
|
|
|
328
328
|
|
|
329
329
|
it "adds the push all modifiers to the conflicts hash" do
|
|
330
330
|
expect(modifiers).to eq(
|
|
331
|
-
{ "$
|
|
332
|
-
"addresses.0.locations" =>
|
|
333
|
-
conflicts: { "$
|
|
334
|
-
{ "addresses" =>
|
|
331
|
+
{ "$pushAll" => {
|
|
332
|
+
"addresses.0.locations" => [{ "street" => "Bond St" }]},
|
|
333
|
+
conflicts: { "$pushAll" =>
|
|
334
|
+
{ "addresses" => [
|
|
335
335
|
{ "street" => "Oxford St" }
|
|
336
|
-
]
|
|
336
|
+
]
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
}
|
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 $
|
|
79
|
+
it "returns a $set and $pushAll for modifications" do
|
|
80
80
|
expect(person.atomic_updates).to eq(
|
|
81
81
|
{
|
|
82
82
|
"$set" => { "title" => "Sir" },
|
|
83
|
-
"$
|
|
83
|
+
"$pushAll" => { "addresses" => [
|
|
84
84
|
{ "_id" => "oxford-st", "street" => "Oxford St" }
|
|
85
|
-
]}
|
|
85
|
+
]}
|
|
86
86
|
}
|
|
87
87
|
)
|
|
88
88
|
end
|
|
@@ -197,8 +197,8 @@ describe Mongoid::Atomic do
|
|
|
197
197
|
"addresses.0.street" => "Bond St"
|
|
198
198
|
},
|
|
199
199
|
conflicts: {
|
|
200
|
-
"$
|
|
201
|
-
"addresses.0.locations" =>
|
|
200
|
+
"$pushAll" => {
|
|
201
|
+
"addresses.0.locations" => [{ "_id" => location.id, "name" => "Home" }]
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
}
|
|
@@ -215,8 +215,8 @@ describe Mongoid::Atomic do
|
|
|
215
215
|
"addresses.0.street" => "Bond St"
|
|
216
216
|
},
|
|
217
217
|
conflicts: {
|
|
218
|
-
"$
|
|
219
|
-
"addresses.0.locations" =>
|
|
218
|
+
"$pushAll" => {
|
|
219
|
+
"addresses.0.locations" => [{ "_id" => location.id, "name" => "Home" }]
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
}
|
|
@@ -263,15 +263,15 @@ describe Mongoid::Atomic do
|
|
|
263
263
|
"addresses.0.street" => "Bond St"
|
|
264
264
|
},
|
|
265
265
|
conflicts: {
|
|
266
|
-
"$
|
|
267
|
-
"addresses" =>
|
|
266
|
+
"$pushAll" => {
|
|
267
|
+
"addresses" => [{
|
|
268
268
|
"_id" => new_address.id,
|
|
269
269
|
"street" => "Another",
|
|
270
270
|
"locations" => [
|
|
271
271
|
"_id" => location.id,
|
|
272
272
|
"name" => "Home"
|
|
273
273
|
]
|
|
274
|
-
}]
|
|
274
|
+
}]
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
}
|
|
@@ -310,15 +310,15 @@ describe Mongoid::Atomic do
|
|
|
310
310
|
"$set" => {
|
|
311
311
|
"title" => "Sir"
|
|
312
312
|
},
|
|
313
|
-
"$
|
|
314
|
-
"addresses" =>
|
|
313
|
+
"$pushAll" => {
|
|
314
|
+
"addresses" => [{
|
|
315
315
|
"_id" => new_address.id,
|
|
316
316
|
"street" => "Ipanema",
|
|
317
317
|
"locations" => [
|
|
318
318
|
"_id" => location.id,
|
|
319
319
|
"name" => "Home"
|
|
320
320
|
]
|
|
321
|
-
}]
|
|
321
|
+
}]
|
|
322
322
|
},
|
|
323
323
|
conflicts: {
|
|
324
324
|
"$set" => { "addresses.0.street"=>"Bond St" }
|
|
@@ -339,21 +339,21 @@ describe Mongoid::Atomic do
|
|
|
339
339
|
address.locations.build(name: "Home")
|
|
340
340
|
end
|
|
341
341
|
|
|
342
|
-
it "returns the proper $sets and $
|
|
342
|
+
it "returns the proper $sets and $pushAlls for all levels" do
|
|
343
343
|
expect(person.atomic_updates).to eq(
|
|
344
344
|
{
|
|
345
345
|
"$set" => {
|
|
346
346
|
"title" => "Sir",
|
|
347
347
|
},
|
|
348
|
-
"$
|
|
349
|
-
"addresses" =>
|
|
348
|
+
"$pushAll" => {
|
|
349
|
+
"addresses" => [{
|
|
350
350
|
"_id" => address.id,
|
|
351
351
|
"street" => "Another",
|
|
352
352
|
"locations" => [
|
|
353
353
|
"_id" => location.id,
|
|
354
354
|
"name" => "Home"
|
|
355
355
|
]
|
|
356
|
-
}]
|
|
356
|
+
}]
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
)
|
|
@@ -41,12 +41,12 @@ describe Mongoid::Attributes::Nested do
|
|
|
41
41
|
Account.nested_attributes.clear
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
let(:
|
|
44
|
+
let(:association) do
|
|
45
45
|
Account.reflect_on_association(:alerts)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it "keeps autosave set to false" do
|
|
49
|
-
expect(
|
|
49
|
+
expect(association).to_not be_autosave
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
end
|
|
@@ -205,10 +205,6 @@ describe Mongoid::Attributes::Nested do
|
|
|
205
205
|
Post.accepts_nested_attributes_for :person
|
|
206
206
|
end
|
|
207
207
|
|
|
208
|
-
after do
|
|
209
|
-
Post.reset_callbacks(:save)
|
|
210
|
-
end
|
|
211
|
-
|
|
212
208
|
let(:post) do
|
|
213
209
|
Post.new(person_attributes: { title: "Sir" })
|
|
214
210
|
end
|
|
@@ -4381,12 +4377,11 @@ describe Mongoid::Attributes::Nested do
|
|
|
4381
4377
|
|
|
4382
4378
|
context "when nesting multiple levels and parent is timestamped" do
|
|
4383
4379
|
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
end
|
|
4380
|
+
around do |example|
|
|
4381
|
+
original_relations = Location.relations
|
|
4382
|
+
Location.embedded_in :address, touch: true
|
|
4383
|
+
example.run
|
|
4384
|
+
Location.relations = original_relations
|
|
4390
4385
|
end
|
|
4391
4386
|
|
|
4392
4387
|
after do
|
|
@@ -4766,6 +4761,13 @@ describe Mongoid::Attributes::Nested do
|
|
|
4766
4761
|
user.update_attributes(params)
|
|
4767
4762
|
end
|
|
4768
4763
|
|
|
4764
|
+
around do |example|
|
|
4765
|
+
original_relations = User.relations
|
|
4766
|
+
User.has_many :posts, foreign_key: :author_id, validate: false, autosave: true
|
|
4767
|
+
example.run
|
|
4768
|
+
user.relations = original_relations
|
|
4769
|
+
end
|
|
4770
|
+
|
|
4769
4771
|
let(:post) do
|
|
4770
4772
|
user.posts.first
|
|
4771
4773
|
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
|