mongoid 7.2.1 → 7.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +1 -1
- data/Rakefile +16 -0
- data/lib/config/locales/en.yml +2 -2
- data/lib/mongoid/association/accessors.rb +13 -1
- data/lib/mongoid/association/constrainable.rb +1 -1
- data/lib/mongoid/association/depending.rb +4 -4
- data/lib/mongoid/association/embedded/batchable.rb +1 -1
- data/lib/mongoid/association/embedded/embedded_in.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +10 -3
- data/lib/mongoid/association/nested/many.rb +1 -1
- data/lib/mongoid/association/nested/one.rb +4 -2
- data/lib/mongoid/association/proxy.rb +6 -1
- data/lib/mongoid/association/referenced/auto_save.rb +2 -2
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +493 -495
- data/lib/mongoid/association/referenced/has_many/proxy.rb +2 -2
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +2 -2
- data/lib/mongoid/attributes.rb +32 -14
- data/lib/mongoid/attributes/projector.rb +120 -0
- data/lib/mongoid/cacheable.rb +2 -2
- data/lib/mongoid/clients.rb +1 -1
- data/lib/mongoid/clients/factory.rb +22 -8
- data/lib/mongoid/config.rb +19 -2
- data/lib/mongoid/contextual/aggregable/mongo.rb +10 -8
- data/lib/mongoid/copyable.rb +1 -1
- data/lib/mongoid/criteria.rb +4 -5
- data/lib/mongoid/criteria/findable.rb +1 -1
- data/lib/mongoid/criteria/queryable/expandable.rb +0 -24
- data/lib/mongoid/criteria/queryable/extensions.rb +0 -4
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
- data/lib/mongoid/criteria/queryable/mergeable.rb +46 -20
- data/lib/mongoid/criteria/queryable/selectable.rb +8 -8
- data/lib/mongoid/document.rb +1 -15
- data/lib/mongoid/errors/delete_restriction.rb +8 -9
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/evolvable.rb +1 -1
- data/lib/mongoid/extensions/boolean.rb +1 -2
- data/lib/mongoid/extensions/false_class.rb +1 -1
- data/lib/mongoid/extensions/hash.rb +2 -2
- data/lib/mongoid/extensions/true_class.rb +1 -1
- data/lib/mongoid/fields.rb +43 -5
- data/lib/mongoid/inspectable.rb +1 -1
- data/lib/mongoid/matcher.rb +26 -43
- data/lib/mongoid/matcher/bits.rb +41 -0
- data/lib/mongoid/matcher/bits_all_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_all_set.rb +20 -0
- data/lib/mongoid/matcher/bits_any_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_any_set.rb +20 -0
- data/lib/mongoid/matcher/elem_match.rb +2 -1
- data/lib/mongoid/matcher/expression.rb +9 -14
- data/lib/mongoid/matcher/field_expression.rb +4 -5
- data/lib/mongoid/matcher/field_operator.rb +6 -0
- data/lib/mongoid/matcher/mod.rb +17 -0
- data/lib/mongoid/matcher/type.rb +99 -0
- data/lib/mongoid/persistable/deletable.rb +1 -2
- data/lib/mongoid/persistable/destroyable.rb +8 -2
- data/lib/mongoid/persistable/updatable.rb +27 -2
- data/lib/mongoid/query_cache.rb +35 -29
- data/lib/mongoid/reloadable.rb +5 -0
- data/lib/mongoid/selectable.rb +5 -7
- data/lib/mongoid/shardable.rb +21 -5
- data/lib/mongoid/touchable.rb +23 -4
- data/lib/mongoid/validatable/associated.rb +1 -1
- data/lib/mongoid/validatable/presence.rb +3 -3
- data/lib/mongoid/validatable/uniqueness.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/config_generator.rb +8 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +1 -1
- data/spec/integration/app_spec.rb +139 -82
- data/spec/integration/associations/embeds_many_spec.rb +44 -0
- data/spec/integration/associations/has_one_spec.rb +48 -0
- data/spec/integration/criteria/date_field_spec.rb +1 -1
- data/spec/integration/document_spec.rb +30 -0
- data/spec/integration/matcher_operator_data/bits_all_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_all_set.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_set.yml +159 -0
- data/spec/integration/matcher_operator_data/comment.yml +22 -0
- data/spec/integration/matcher_operator_data/elem_match.yml +46 -0
- data/spec/integration/matcher_operator_data/implicit_traversal.yml +96 -0
- data/spec/integration/matcher_operator_data/in.yml +16 -0
- data/spec/integration/matcher_operator_data/mod.yml +55 -0
- data/spec/integration/matcher_operator_data/type.yml +70 -0
- data/spec/integration/matcher_operator_data/type_array.yml +16 -0
- data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
- data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
- data/spec/integration/matcher_operator_data/type_code.yml +26 -0
- data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
- data/spec/integration/matcher_operator_data/type_date.yml +39 -0
- data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
- data/spec/integration/matcher_operator_data/type_decimal.yml +40 -0
- data/spec/integration/matcher_operator_data/type_double.yml +15 -0
- data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
- data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
- data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_null.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
- data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
- data/spec/integration/matcher_operator_data/type_string.yml +15 -0
- data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
- data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
- data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
- data/spec/lite_spec_helper.rb +4 -3
- data/spec/mongoid/association/depending_spec.rb +391 -352
- data/spec/mongoid/association/nested/one_spec.rb +18 -14
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +25 -8
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +1 -1
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +1 -1
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +1 -1
- data/spec/mongoid/association/referenced/has_one_models.rb +8 -0
- data/spec/mongoid/atomic/paths_spec.rb +64 -12
- data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
- data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
- data/spec/mongoid/attributes/projector_spec.rb +41 -0
- data/spec/mongoid/attributes_spec.rb +333 -0
- data/spec/mongoid/clients/factory_spec.rb +48 -0
- data/spec/mongoid/config_spec.rb +32 -0
- data/spec/mongoid/contextual/atomic_spec.rb +17 -4
- data/spec/mongoid/contextual/mongo_spec.rb +2 -2
- data/spec/mongoid/criteria/modifiable_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +0 -73
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +105 -7
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +229 -24
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +39 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -565
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +590 -0
- data/spec/mongoid/criteria_projection_spec.rb +411 -0
- data/spec/mongoid/criteria_spec.rb +0 -275
- data/spec/mongoid/document_fields_spec.rb +26 -0
- data/spec/mongoid/document_query_spec.rb +51 -0
- data/spec/mongoid/document_spec.rb +13 -13
- data/spec/mongoid/errors/delete_restriction_spec.rb +1 -1
- data/spec/mongoid/errors/mongoid_error_spec.rb +20 -8
- data/spec/mongoid/extensions/false_class_spec.rb +1 -1
- data/spec/mongoid/extensions/string_spec.rb +5 -5
- data/spec/mongoid/extensions/true_class_spec.rb +1 -1
- data/spec/mongoid/fields/localized_spec.rb +4 -4
- data/spec/mongoid/fields_spec.rb +4 -4
- data/spec/mongoid/inspectable_spec.rb +12 -4
- data/spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml +104 -0
- data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +68 -88
- data/spec/mongoid/matcher/extract_attribute_spec.rb +3 -13
- data/spec/mongoid/persistable/deletable_spec.rb +175 -1
- data/spec/mongoid/persistable/destroyable_spec.rb +191 -3
- data/spec/mongoid/persistable/savable_spec.rb +3 -5
- data/spec/mongoid/persistable/settable_spec.rb +30 -0
- data/spec/mongoid/persistable/upsertable_spec.rb +1 -1
- data/spec/mongoid/persistable_spec.rb +2 -2
- data/spec/mongoid/query_cache_middleware_spec.rb +8 -0
- data/spec/mongoid/reloadable_spec.rb +18 -1
- data/spec/mongoid/shardable_spec.rb +44 -0
- data/spec/mongoid/touchable_spec.rb +104 -16
- data/spec/mongoid/touchable_spec_models.rb +52 -0
- data/spec/mongoid/validatable_spec.rb +1 -1
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/cluster_config.rb +19 -4
- data/spec/shared/lib/mrss/constraints.rb +46 -8
- data/spec/shared/lib/mrss/docker_runner.rb +10 -1
- data/spec/shared/lib/mrss/lite_constraints.rb +16 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +79 -33
- data/spec/shared/lib/mrss/spec_organizer.rb +32 -2
- data/spec/shared/lib/mrss/utils.rb +15 -0
- data/spec/shared/share/Dockerfile.erb +122 -29
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/server.sh +58 -11
- data/spec/shared/shlib/set_env.sh +4 -1
- data/spec/spec_helper.rb +7 -3
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/models/bolt.rb +8 -0
- data/spec/support/models/hole.rb +13 -0
- data/spec/support/models/mop.rb +9 -0
- data/spec/support/models/nut.rb +8 -0
- data/spec/support/models/person.rb +6 -0
- data/spec/support/models/sealer.rb +8 -0
- data/spec/support/models/shirt.rb +12 -0
- data/spec/support/models/spacer.rb +8 -0
- data/spec/support/models/threadlocker.rb +8 -0
- data/spec/support/models/washer.rb +8 -0
- data/spec/support/spec_config.rb +8 -0
- metadata +636 -528
- metadata.gz.sig +0 -0
- data/spec/support/cluster_config.rb +0 -158
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
name: foo
|
|
4
4
|
key: name
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
expanded: false
|
|
6
|
+
result:
|
|
7
|
+
- foo
|
|
9
8
|
|
|
10
9
|
- name: scalar leaf
|
|
11
10
|
document: &foo-bar-foo-bar-2
|
|
@@ -16,20 +15,26 @@
|
|
|
16
15
|
2
|
|
17
16
|
key: foo.bar.foo.bar
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
expanded: false
|
|
18
|
+
result:
|
|
19
|
+
- 2
|
|
22
20
|
|
|
23
21
|
- name: scalar non-leaf
|
|
24
22
|
document: *foo-bar-foo-bar-2
|
|
25
23
|
key: foo.bar
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
result:
|
|
26
|
+
-
|
|
27
|
+
foo:
|
|
28
|
+
bar:
|
|
29
|
+
2
|
|
30
|
+
|
|
31
|
+
- name: null leaf
|
|
32
|
+
document:
|
|
33
|
+
name:
|
|
34
|
+
key: name
|
|
35
|
+
|
|
36
|
+
result:
|
|
37
|
+
- ~
|
|
33
38
|
|
|
34
39
|
- name: array leaf
|
|
35
40
|
document: &foo-bar-foo-bar-array-2
|
|
@@ -40,21 +45,18 @@
|
|
|
40
45
|
- 2
|
|
41
46
|
key: foo.bar.foo.bar
|
|
42
47
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- 2
|
|
46
|
-
expanded: false
|
|
48
|
+
result:
|
|
49
|
+
- [2]
|
|
47
50
|
|
|
48
51
|
- name: scalar non-leaf
|
|
49
52
|
document: *foo-bar-foo-bar-array-2
|
|
50
53
|
key: foo.bar
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
expanded: false
|
|
55
|
+
result:
|
|
56
|
+
-
|
|
57
|
+
foo:
|
|
58
|
+
bar:
|
|
59
|
+
- 2
|
|
58
60
|
|
|
59
61
|
- name: array non-leaf
|
|
60
62
|
document: &foo-bar-array-foo-bar-2
|
|
@@ -66,30 +68,24 @@
|
|
|
66
68
|
2
|
|
67
69
|
key: foo.bar.foo.bar
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
value:
|
|
71
|
+
result:
|
|
71
72
|
- 2
|
|
72
|
-
expanded: true
|
|
73
73
|
|
|
74
74
|
- name: array non-leaf with non-leaf query
|
|
75
75
|
document: *foo-bar-array-foo-bar-2
|
|
76
76
|
key: foo.bar
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
value:
|
|
78
|
+
result:
|
|
80
79
|
-
|
|
81
80
|
foo:
|
|
82
81
|
bar:
|
|
83
82
|
2
|
|
84
|
-
expanded: true
|
|
85
83
|
|
|
86
84
|
- name: array non-leaf with query for missing non-leaf key
|
|
87
85
|
document: *foo-bar-array-foo-bar-2
|
|
88
86
|
key: foo.missing
|
|
89
87
|
|
|
90
|
-
|
|
91
|
-
value: []
|
|
92
|
-
expanded: true
|
|
88
|
+
result: []
|
|
93
89
|
|
|
94
90
|
- name: path past end of document
|
|
95
91
|
document: &foo-hello-world
|
|
@@ -97,17 +93,23 @@
|
|
|
97
93
|
hello: world
|
|
98
94
|
key: foo.bar.foo.bar
|
|
99
95
|
|
|
100
|
-
|
|
101
|
-
value: ~
|
|
102
|
-
expanded: false
|
|
96
|
+
result: []
|
|
103
97
|
|
|
104
98
|
- name: query for missing leaf key
|
|
105
99
|
document: *foo-hello-world
|
|
106
100
|
key: foo.bar
|
|
107
101
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
102
|
+
result: []
|
|
103
|
+
|
|
104
|
+
- name: numeric path component when traversing hash
|
|
105
|
+
document:
|
|
106
|
+
foo:
|
|
107
|
+
"10":
|
|
108
|
+
42
|
|
109
|
+
key: "foo.10"
|
|
110
|
+
|
|
111
|
+
result:
|
|
112
|
+
- 42
|
|
111
113
|
|
|
112
114
|
- name: array index - hash leaf
|
|
113
115
|
document: &foo-one-two
|
|
@@ -117,42 +119,35 @@
|
|
|
117
119
|
bar: [3, 4]
|
|
118
120
|
key: foo.1.two
|
|
119
121
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
expanded: false
|
|
122
|
+
result:
|
|
123
|
+
- 2
|
|
123
124
|
|
|
124
125
|
- name: array index - hash non-leaf
|
|
125
126
|
document: *foo-one-two
|
|
126
127
|
key: foo.1
|
|
127
128
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
expanded: false
|
|
129
|
+
result:
|
|
130
|
+
-
|
|
131
|
+
two: 2
|
|
132
132
|
|
|
133
133
|
- name: array index - scalar leaf
|
|
134
134
|
document: *foo-one-two
|
|
135
135
|
key: bar.1
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
expanded: false
|
|
137
|
+
result:
|
|
138
|
+
- 4
|
|
140
139
|
|
|
141
140
|
- name: array index - scalar leaf - missing
|
|
142
141
|
document: *foo-one-two
|
|
143
142
|
key: bar.2
|
|
144
143
|
|
|
145
|
-
|
|
146
|
-
value: ~
|
|
147
|
-
expanded: false
|
|
144
|
+
result: []
|
|
148
145
|
|
|
149
146
|
- name: array index - scalar leaf - missing with further hash subscription
|
|
150
147
|
document: *foo-one-two
|
|
151
148
|
key: bar.2.any
|
|
152
149
|
|
|
153
|
-
|
|
154
|
-
value: ~
|
|
155
|
-
expanded: false
|
|
150
|
+
result: []
|
|
156
151
|
|
|
157
152
|
- name: non-sequential nested arrays - hash leaf - one value
|
|
158
153
|
document: &books-authors
|
|
@@ -166,30 +161,27 @@
|
|
|
166
161
|
- name: Pasha
|
|
167
162
|
key: books.0.authors.name
|
|
168
163
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
expanded: true
|
|
164
|
+
result:
|
|
165
|
+
- Steve
|
|
172
166
|
|
|
173
167
|
- name: non-sequential nested arrays - hash non-leaf - one value
|
|
174
168
|
document: *books-authors
|
|
175
169
|
key: books.0
|
|
176
170
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
expanded: false
|
|
171
|
+
result:
|
|
172
|
+
-
|
|
173
|
+
authors:
|
|
174
|
+
- name: Steve
|
|
182
175
|
|
|
183
176
|
- name: non-sequential nested arrays - hash non-leaf - multiple values
|
|
184
177
|
document: *books-authors
|
|
185
178
|
key: books.1
|
|
186
179
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
expanded: false
|
|
180
|
+
result:
|
|
181
|
+
-
|
|
182
|
+
authors:
|
|
183
|
+
- name: Boris
|
|
184
|
+
- name: Pasha
|
|
193
185
|
|
|
194
186
|
- name: sequential nested arrays - numerically indexed leaf
|
|
195
187
|
document: &groups
|
|
@@ -197,41 +189,32 @@
|
|
|
197
189
|
- [1]
|
|
198
190
|
key: groups.0.0
|
|
199
191
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
expanded: false
|
|
192
|
+
result:
|
|
193
|
+
- 1
|
|
203
194
|
|
|
204
195
|
- name: sequential nested arrays - numerically indexed leaf - missing
|
|
205
196
|
document: *groups
|
|
206
197
|
key: groups.0.1
|
|
207
198
|
|
|
208
|
-
|
|
209
|
-
value: ~
|
|
210
|
-
expanded: false
|
|
199
|
+
result: []
|
|
211
200
|
|
|
212
201
|
- name: sequential nested arrays - missing hash path through non-leaf
|
|
213
202
|
document: *groups
|
|
214
203
|
key: groups.missing
|
|
215
204
|
|
|
216
|
-
|
|
217
|
-
value: []
|
|
218
|
-
expanded: true
|
|
205
|
+
result: []
|
|
219
206
|
|
|
220
207
|
- name: sequential nested arrays - missing hash path through leaf
|
|
221
208
|
document: *groups
|
|
222
209
|
key: groups.0.missing
|
|
223
210
|
|
|
224
|
-
|
|
225
|
-
value: []
|
|
226
|
-
expanded: true
|
|
211
|
+
result: []
|
|
227
212
|
|
|
228
213
|
- name: sequential nested arrays - missing hash path past leaf
|
|
229
214
|
document: *groups
|
|
230
215
|
key: groups.0.0.missing
|
|
231
216
|
|
|
232
|
-
|
|
233
|
-
value: ~
|
|
234
|
-
expanded: false
|
|
217
|
+
result: []
|
|
235
218
|
|
|
236
219
|
- name: mix of arrays and hashes in an array
|
|
237
220
|
document:
|
|
@@ -242,9 +225,8 @@
|
|
|
242
225
|
- bar: 2
|
|
243
226
|
key: foo.bar
|
|
244
227
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
expanded: true
|
|
228
|
+
result:
|
|
229
|
+
- 2
|
|
248
230
|
|
|
249
231
|
- name: numeric index through a primitive value not supporting subscription operator
|
|
250
232
|
document:
|
|
@@ -254,6 +236,4 @@
|
|
|
254
236
|
key:
|
|
255
237
|
occupants.0.age.0
|
|
256
238
|
|
|
257
|
-
|
|
258
|
-
value: ~
|
|
259
|
-
expanded: false
|
|
239
|
+
result: []
|
|
@@ -25,20 +25,10 @@ describe 'Matcher.extract_attribute' do
|
|
|
25
25
|
Mongoid::Matcher.extract_attribute(document, key)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
let(:
|
|
29
|
-
let(:expected_value) { spec['value'] }
|
|
30
|
-
let(:expected_expanded) { spec['expanded'] }
|
|
28
|
+
let(:expected) { spec.fetch('result') }
|
|
31
29
|
|
|
32
|
-
it 'has the expected
|
|
33
|
-
actual
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it 'has the expected value' do
|
|
37
|
-
actual[1].should == expected_value
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it 'has the expected expanded flag' do
|
|
41
|
-
actual[2].should == expected_expanded
|
|
30
|
+
it 'has the expected result' do
|
|
31
|
+
actual.should == expected
|
|
42
32
|
end
|
|
43
33
|
end
|
|
44
34
|
end
|
|
@@ -8,7 +8,7 @@ describe Mongoid::Persistable::Deletable do
|
|
|
8
8
|
describe "#delete" do
|
|
9
9
|
|
|
10
10
|
let!(:person) do
|
|
11
|
-
Person.create
|
|
11
|
+
Person.create!
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
context "when deleting a readonly document" do
|
|
@@ -24,6 +24,20 @@ describe Mongoid::Persistable::Deletable do
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
context 'when deleting a document that was not saved' do
|
|
28
|
+
let(:unsaved_person) { Person.new(id: person.id) }
|
|
29
|
+
|
|
30
|
+
before do
|
|
31
|
+
unsaved_person.delete
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'deletes the matching document from the database' do
|
|
35
|
+
lambda do
|
|
36
|
+
person.reload
|
|
37
|
+
end.should raise_error(Mongoid::Errors::DocumentNotFound)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
27
41
|
context "when removing a root document" do
|
|
28
42
|
|
|
29
43
|
let!(:deleted) do
|
|
@@ -259,6 +273,86 @@ describe Mongoid::Persistable::Deletable do
|
|
|
259
273
|
expect(Browser.count).to eq(1)
|
|
260
274
|
end
|
|
261
275
|
end
|
|
276
|
+
|
|
277
|
+
context 'when there are dependent documents' do
|
|
278
|
+
context 'has_one' do
|
|
279
|
+
|
|
280
|
+
context 'dependent: :destroy' do
|
|
281
|
+
let!(:parent) do
|
|
282
|
+
Hole.create!(bolt: Bolt.create!)
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
it 'does not destroy dependent documents' do
|
|
286
|
+
Bolt.count.should == 1
|
|
287
|
+
parent.delete
|
|
288
|
+
Bolt.count.should == 1
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
context 'dependent: :delete_all' do
|
|
293
|
+
let!(:parent) do
|
|
294
|
+
Hole.create!(threadlocker: Threadlocker.create!)
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
it 'does not destroy dependent documents' do
|
|
298
|
+
Threadlocker.count.should == 1
|
|
299
|
+
parent.delete
|
|
300
|
+
Threadlocker.count.should == 1
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
context 'dependent: :restrict_with_exception' do
|
|
305
|
+
let!(:parent) do
|
|
306
|
+
Hole.create!(sealer: Sealer.create!)
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
it 'does not destroy dependent documents' do
|
|
310
|
+
Sealer.count.should == 1
|
|
311
|
+
parent.delete
|
|
312
|
+
Sealer.count.should == 1
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
context 'has_many' do
|
|
318
|
+
|
|
319
|
+
context 'dependent: :destroy' do
|
|
320
|
+
let!(:parent) do
|
|
321
|
+
Hole.create!(nuts: [Nut.create!])
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
it 'does not destroy dependent documents' do
|
|
325
|
+
Nut.count.should == 1
|
|
326
|
+
parent.delete
|
|
327
|
+
Nut.count.should == 1
|
|
328
|
+
end
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
context 'dependent: :delete_all' do
|
|
332
|
+
let!(:parent) do
|
|
333
|
+
Hole.create!(washers: [Washer.create!])
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
it 'does not destroy dependent documents' do
|
|
337
|
+
Washer.count.should == 1
|
|
338
|
+
parent.delete
|
|
339
|
+
Washer.count.should == 1
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
context 'dependent: :restrict_with_exception' do
|
|
344
|
+
let!(:parent) do
|
|
345
|
+
Hole.create!(spacers: [Spacer.create!])
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
it 'does not destroy dependent documents' do
|
|
349
|
+
Spacer.count.should == 1
|
|
350
|
+
parent.delete
|
|
351
|
+
Spacer.count.should == 1
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
end
|
|
262
356
|
end
|
|
263
357
|
|
|
264
358
|
describe "#delete_all" do
|
|
@@ -337,5 +431,85 @@ describe Mongoid::Persistable::Deletable do
|
|
|
337
431
|
end
|
|
338
432
|
end
|
|
339
433
|
end
|
|
434
|
+
|
|
435
|
+
context 'when there are dependent documents' do
|
|
436
|
+
context 'has_one' do
|
|
437
|
+
|
|
438
|
+
context 'dependent: :destroy' do
|
|
439
|
+
let!(:parent) do
|
|
440
|
+
Hole.create!(bolt: Bolt.create!)
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
it 'does not destroy dependent documents' do
|
|
444
|
+
Bolt.count.should == 1
|
|
445
|
+
Hole.delete_all
|
|
446
|
+
Bolt.count.should == 1
|
|
447
|
+
end
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
context 'dependent: :delete_all' do
|
|
451
|
+
let!(:parent) do
|
|
452
|
+
Hole.create!(threadlocker: Threadlocker.create!)
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
it 'does not destroy dependent documents' do
|
|
456
|
+
Threadlocker.count.should == 1
|
|
457
|
+
Hole.delete_all
|
|
458
|
+
Threadlocker.count.should == 1
|
|
459
|
+
end
|
|
460
|
+
end
|
|
461
|
+
|
|
462
|
+
context 'dependent: :restrict_with_exception' do
|
|
463
|
+
let!(:parent) do
|
|
464
|
+
Hole.create!(sealer: Sealer.create!)
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
it 'does not destroy dependent documents' do
|
|
468
|
+
Sealer.count.should == 1
|
|
469
|
+
Hole.delete_all
|
|
470
|
+
Sealer.count.should == 1
|
|
471
|
+
end
|
|
472
|
+
end
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
context 'has_many' do
|
|
476
|
+
|
|
477
|
+
context 'dependent: :destroy' do
|
|
478
|
+
let!(:parent) do
|
|
479
|
+
Hole.create!(nuts: [Nut.create!])
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
it 'does not destroy dependent documents' do
|
|
483
|
+
Nut.count.should == 1
|
|
484
|
+
Hole.delete_all
|
|
485
|
+
Nut.count.should == 1
|
|
486
|
+
end
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
context 'dependent: :delete_all' do
|
|
490
|
+
let!(:parent) do
|
|
491
|
+
Hole.create!(washers: [Washer.create!])
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
it 'does not destroy dependent documents' do
|
|
495
|
+
Washer.count.should == 1
|
|
496
|
+
Hole.delete_all
|
|
497
|
+
Washer.count.should == 1
|
|
498
|
+
end
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
context 'dependent: :restrict_with_exception' do
|
|
502
|
+
let!(:parent) do
|
|
503
|
+
Hole.create!(spacers: [Spacer.create!])
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
it 'does not destroy dependent documents' do
|
|
507
|
+
Spacer.count.should == 1
|
|
508
|
+
Hole.delete_all
|
|
509
|
+
Spacer.count.should == 1
|
|
510
|
+
end
|
|
511
|
+
end
|
|
512
|
+
end
|
|
513
|
+
end
|
|
340
514
|
end
|
|
341
515
|
end
|