mongoid 7.2.1 → 7.2.2
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/lib/mongoid/attributes.rb +8 -1
- data/lib/mongoid/matcher.rb +19 -43
- data/lib/mongoid/matcher/elem_match.rb +2 -1
- data/lib/mongoid/matcher/expression.rb +5 -14
- data/lib/mongoid/matcher/field_expression.rb +4 -5
- data/lib/mongoid/reloadable.rb +5 -0
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/config_generator.rb +8 -1
- data/spec/integration/app_spec.rb +136 -82
- data/spec/integration/document_spec.rb +21 -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/lite_spec_helper.rb +2 -3
- data/spec/mongoid/attributes_spec.rb +241 -0
- data/spec/mongoid/contextual/atomic_spec.rb +17 -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/settable_spec.rb +30 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/lib/mrss/cluster_config.rb +11 -1
- data/spec/shared/lib/mrss/constraints.rb +18 -2
- data/spec/shared/lib/mrss/docker_runner.rb +3 -0
- 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 +3 -0
- data/spec/shared/lib/mrss/utils.rb +15 -0
- data/spec/shared/share/Dockerfile.erb +13 -11
- data/spec/shared/shlib/server.sh +29 -9
- data/spec/support/spec_config.rb +8 -0
- metadata +8 -2
- metadata.gz.sig +0 -0
@@ -753,12 +753,25 @@ describe Mongoid::Contextual::Atomic do
|
|
753
753
|
context.set(name: "Recoil")
|
754
754
|
end
|
755
755
|
|
756
|
-
|
757
|
-
|
756
|
+
shared_examples 'writes as expected' do
|
757
|
+
it "sets existing fields" do
|
758
|
+
expect(depeche_mode.reload.name).to eq("Recoil")
|
759
|
+
end
|
760
|
+
|
761
|
+
it "sets non existent fields" do
|
762
|
+
expect(smiths.reload.name).to eq("Recoil")
|
763
|
+
end
|
758
764
|
end
|
759
765
|
|
760
|
-
|
761
|
-
|
766
|
+
include_examples 'writes as expected'
|
767
|
+
|
768
|
+
context 'when fields being set have been projected out' do
|
769
|
+
|
770
|
+
let(:criteria) do
|
771
|
+
Band.only(:genres)
|
772
|
+
end
|
773
|
+
|
774
|
+
include_examples 'writes as expected'
|
762
775
|
end
|
763
776
|
end
|
764
777
|
|
@@ -0,0 +1,104 @@
|
|
1
|
+
- name: string key - matches
|
2
|
+
document:
|
3
|
+
# Document field names in MongoDB are always strings.
|
4
|
+
'42': foo
|
5
|
+
# The paths are also always strings.
|
6
|
+
key: '42'
|
7
|
+
|
8
|
+
result:
|
9
|
+
- foo
|
10
|
+
|
11
|
+
- name: string key - does not match
|
12
|
+
document:
|
13
|
+
# Document field names in MongoDB are always strings.
|
14
|
+
'42': foo
|
15
|
+
# The paths are also always strings.
|
16
|
+
key: '4'
|
17
|
+
|
18
|
+
result: []
|
19
|
+
|
20
|
+
- name: array value - matches
|
21
|
+
document:
|
22
|
+
'42':
|
23
|
+
- foo
|
24
|
+
key: '42'
|
25
|
+
|
26
|
+
result:
|
27
|
+
- ['foo']
|
28
|
+
|
29
|
+
- name: subfield of numeric key - matches
|
30
|
+
document:
|
31
|
+
'42':
|
32
|
+
foo: bar
|
33
|
+
key: 42.foo
|
34
|
+
|
35
|
+
result:
|
36
|
+
- bar
|
37
|
+
|
38
|
+
- name: numeric key under array
|
39
|
+
document:
|
40
|
+
a:
|
41
|
+
-
|
42
|
+
'42': bar
|
43
|
+
|
44
|
+
key: a.42
|
45
|
+
|
46
|
+
result:
|
47
|
+
- bar
|
48
|
+
|
49
|
+
- name: multiple values under numeric key under array
|
50
|
+
document: &numeric-key-under-array
|
51
|
+
a:
|
52
|
+
-
|
53
|
+
'42': bar
|
54
|
+
-
|
55
|
+
'42': foo
|
56
|
+
|
57
|
+
key: a.42
|
58
|
+
|
59
|
+
result:
|
60
|
+
- bar
|
61
|
+
- foo
|
62
|
+
|
63
|
+
- name: array indexing with values under numeric key under array
|
64
|
+
document: *numeric-key-under-array
|
65
|
+
|
66
|
+
key: a.1
|
67
|
+
|
68
|
+
result:
|
69
|
+
-
|
70
|
+
'42': foo
|
71
|
+
|
72
|
+
- name: multiple values under array under numeric key
|
73
|
+
document:
|
74
|
+
a:
|
75
|
+
'42':
|
76
|
+
-
|
77
|
+
foo: bar
|
78
|
+
-
|
79
|
+
foo: baq
|
80
|
+
|
81
|
+
key: a.42.foo
|
82
|
+
|
83
|
+
result:
|
84
|
+
- bar
|
85
|
+
- baq
|
86
|
+
|
87
|
+
- name: path component interpretable as both array index and hash key
|
88
|
+
document:
|
89
|
+
a:
|
90
|
+
-
|
91
|
+
'1': bar
|
92
|
+
-
|
93
|
+
'1': foo
|
94
|
+
|
95
|
+
key: a.1
|
96
|
+
|
97
|
+
result:
|
98
|
+
# The order of these results isn't guaranteed:
|
99
|
+
# 1 interpreted as the array index:
|
100
|
+
-
|
101
|
+
'1': foo
|
102
|
+
# 1 interpreted as hash key:
|
103
|
+
- bar
|
104
|
+
- foo
|
@@ -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
|