mongoid 7.2.1 → 7.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/mongoid/attributes.rb +8 -1
  5. data/lib/mongoid/matcher.rb +19 -43
  6. data/lib/mongoid/matcher/elem_match.rb +2 -1
  7. data/lib/mongoid/matcher/expression.rb +5 -14
  8. data/lib/mongoid/matcher/field_expression.rb +4 -5
  9. data/lib/mongoid/reloadable.rb +5 -0
  10. data/lib/mongoid/version.rb +1 -1
  11. data/lib/rails/generators/mongoid/config/config_generator.rb +8 -1
  12. data/spec/integration/app_spec.rb +136 -82
  13. data/spec/integration/document_spec.rb +21 -0
  14. data/spec/integration/matcher_operator_data/elem_match.yml +46 -0
  15. data/spec/integration/matcher_operator_data/implicit_traversal.yml +96 -0
  16. data/spec/lite_spec_helper.rb +2 -3
  17. data/spec/mongoid/attributes_spec.rb +241 -0
  18. data/spec/mongoid/contextual/atomic_spec.rb +17 -4
  19. data/spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml +104 -0
  20. data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +68 -88
  21. data/spec/mongoid/matcher/extract_attribute_spec.rb +3 -13
  22. data/spec/mongoid/persistable/settable_spec.rb +30 -0
  23. data/spec/shared/bin/get-mongodb-download-url +17 -0
  24. data/spec/shared/lib/mrss/cluster_config.rb +11 -1
  25. data/spec/shared/lib/mrss/constraints.rb +18 -2
  26. data/spec/shared/lib/mrss/docker_runner.rb +3 -0
  27. data/spec/shared/lib/mrss/lite_constraints.rb +16 -0
  28. data/spec/shared/lib/mrss/server_version_registry.rb +79 -33
  29. data/spec/shared/lib/mrss/spec_organizer.rb +3 -0
  30. data/spec/shared/lib/mrss/utils.rb +15 -0
  31. data/spec/shared/share/Dockerfile.erb +13 -11
  32. data/spec/shared/shlib/server.sh +29 -9
  33. data/spec/support/spec_config.rb +8 -0
  34. metadata +8 -2
  35. 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
- it "sets existing fields" do
757
- expect(depeche_mode.reload.name).to eq("Recoil")
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
- it "sets non existent fields" do
761
- expect(smiths.reload.name).to eq("Recoil")
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
- exists: true
7
- value: foo
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
- exists: true
20
- value: 2
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
- exists: true
28
- value:
29
- foo:
30
- bar:
31
- 2
32
- expanded: false
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
- exists: true
44
- value:
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
- exists: true
53
- value:
54
- foo:
55
- bar:
56
- - 2
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
- exists: true
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
- exists: true
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
- exists: false
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
- exists: false
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
- exists: false
109
- value: ~
110
- expanded: false
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
- exists: true
121
- value: 2
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
- exists: true
129
- value:
130
- two: 2
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
- exists: true
138
- value: 4
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
- exists: false
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
- exists: false
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
- exists: true
170
- value: [Steve]
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
- exists: true
178
- value:
179
- authors:
180
- - name: Steve
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
- exists: true
188
- value:
189
- authors:
190
- - name: Boris
191
- - name: Pasha
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
- exists: true
201
- value: 1
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
- exists: false
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
- exists: false
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
- exists: false
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
- exists: false
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
- exists: true
246
- value: [2]
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
- exists: false
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(:expected_exists) { spec['exists'] }
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 exists flag' do
33
- actual[0].should == expected_exists
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