mongoid 7.2.6 → 7.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/Rakefile +16 -0
  4. data/lib/config/locales/en.yml +2 -2
  5. data/lib/mongoid/association/accessors.rb +13 -1
  6. data/lib/mongoid/association/constrainable.rb +1 -1
  7. data/lib/mongoid/association/depending.rb +4 -4
  8. data/lib/mongoid/association/embedded/batchable.rb +1 -1
  9. data/lib/mongoid/association/embedded/embedded_in.rb +1 -1
  10. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +10 -3
  11. data/lib/mongoid/association/nested/many.rb +1 -1
  12. data/lib/mongoid/association/nested/one.rb +4 -2
  13. data/lib/mongoid/association/proxy.rb +6 -1
  14. data/lib/mongoid/association/referenced/auto_save.rb +2 -2
  15. data/lib/mongoid/association/referenced/has_many/enumerable.rb +490 -496
  16. data/lib/mongoid/association/referenced/has_many/proxy.rb +2 -2
  17. data/lib/mongoid/association/referenced/has_one/nested_builder.rb +2 -2
  18. data/lib/mongoid/atomic.rb +26 -2
  19. data/lib/mongoid/attributes/projector.rb +120 -0
  20. data/lib/mongoid/attributes.rb +24 -13
  21. data/lib/mongoid/cacheable.rb +2 -2
  22. data/lib/mongoid/clients/factory.rb +22 -8
  23. data/lib/mongoid/clients.rb +1 -1
  24. data/lib/mongoid/config.rb +19 -2
  25. data/lib/mongoid/contextual/aggregable/mongo.rb +10 -8
  26. data/lib/mongoid/copyable.rb +1 -1
  27. data/lib/mongoid/criteria/findable.rb +1 -1
  28. data/lib/mongoid/criteria/queryable/expandable.rb +0 -24
  29. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
  30. data/lib/mongoid/criteria/queryable/extensions.rb +0 -4
  31. data/lib/mongoid/criteria/queryable/mergeable.rb +46 -20
  32. data/lib/mongoid/criteria/queryable/selectable.rb +8 -8
  33. data/lib/mongoid/criteria.rb +4 -5
  34. data/lib/mongoid/document.rb +1 -15
  35. data/lib/mongoid/errors/delete_restriction.rb +8 -9
  36. data/lib/mongoid/evolvable.rb +1 -1
  37. data/lib/mongoid/extensions/boolean.rb +1 -2
  38. data/lib/mongoid/extensions/false_class.rb +1 -1
  39. data/lib/mongoid/extensions/hash.rb +2 -2
  40. data/lib/mongoid/extensions/true_class.rb +1 -1
  41. data/lib/mongoid/fields.rb +43 -5
  42. data/lib/mongoid/inspectable.rb +1 -1
  43. data/lib/mongoid/matcher/bits.rb +41 -0
  44. data/lib/mongoid/matcher/bits_all_clear.rb +20 -0
  45. data/lib/mongoid/matcher/bits_all_set.rb +20 -0
  46. data/lib/mongoid/matcher/bits_any_clear.rb +20 -0
  47. data/lib/mongoid/matcher/bits_any_set.rb +20 -0
  48. data/lib/mongoid/matcher/expression.rb +4 -0
  49. data/lib/mongoid/matcher/field_operator.rb +6 -0
  50. data/lib/mongoid/matcher/mod.rb +17 -0
  51. data/lib/mongoid/matcher/type.rb +99 -0
  52. data/lib/mongoid/matcher.rb +7 -0
  53. data/lib/mongoid/persistable/deletable.rb +1 -2
  54. data/lib/mongoid/persistable/destroyable.rb +8 -2
  55. data/lib/mongoid/persistable/updatable.rb +27 -2
  56. data/lib/mongoid/query_cache.rb +35 -29
  57. data/lib/mongoid/selectable.rb +5 -7
  58. data/lib/mongoid/shardable.rb +21 -5
  59. data/lib/mongoid/touchable.rb +33 -4
  60. data/lib/mongoid/version.rb +1 -1
  61. data/spec/integration/associations/embeds_many_spec.rb +44 -0
  62. data/spec/integration/associations/has_one_spec.rb +48 -0
  63. data/spec/integration/criteria/date_field_spec.rb +1 -1
  64. data/spec/integration/document_spec.rb +9 -0
  65. data/spec/integration/matcher_operator_data/bits_all_clear.yml +159 -0
  66. data/spec/integration/matcher_operator_data/bits_all_set.yml +159 -0
  67. data/spec/integration/matcher_operator_data/bits_any_clear.yml +159 -0
  68. data/spec/integration/matcher_operator_data/bits_any_set.yml +159 -0
  69. data/spec/integration/matcher_operator_data/comment.yml +22 -0
  70. data/spec/integration/matcher_operator_data/in.yml +16 -0
  71. data/spec/integration/matcher_operator_data/mod.yml +55 -0
  72. data/spec/integration/matcher_operator_data/type.yml +70 -0
  73. data/spec/integration/matcher_operator_data/type_array.yml +16 -0
  74. data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
  75. data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
  76. data/spec/integration/matcher_operator_data/type_code.yml +26 -0
  77. data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
  78. data/spec/integration/matcher_operator_data/type_date.yml +39 -0
  79. data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
  80. data/spec/integration/matcher_operator_data/type_decimal.yml +40 -0
  81. data/spec/integration/matcher_operator_data/type_double.yml +15 -0
  82. data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
  83. data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
  84. data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
  85. data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
  86. data/spec/integration/matcher_operator_data/type_null.yml +23 -0
  87. data/spec/integration/matcher_operator_data/type_object.yml +23 -0
  88. data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
  89. data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
  90. data/spec/integration/matcher_operator_data/type_string.yml +15 -0
  91. data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
  92. data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
  93. data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
  94. data/spec/lite_spec_helper.rb +2 -0
  95. data/spec/mongoid/association/depending_spec.rb +391 -352
  96. data/spec/mongoid/association/nested/one_spec.rb +18 -14
  97. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +25 -8
  98. data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +1 -1
  99. data/spec/mongoid/association/referenced/has_many/binding_spec.rb +1 -1
  100. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +245 -93
  101. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +6 -6
  102. data/spec/mongoid/association/referenced/has_one_models.rb +8 -0
  103. data/spec/mongoid/atomic/paths_spec.rb +64 -12
  104. data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
  105. data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
  106. data/spec/mongoid/attributes/projector_spec.rb +41 -0
  107. data/spec/mongoid/attributes_spec.rb +98 -6
  108. data/spec/mongoid/clients/factory_spec.rb +48 -0
  109. data/spec/mongoid/config_spec.rb +106 -1
  110. data/spec/mongoid/contextual/mongo_spec.rb +2 -2
  111. data/spec/mongoid/criteria/modifiable_spec.rb +1 -1
  112. data/spec/mongoid/criteria/queryable/expandable_spec.rb +0 -73
  113. data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +1 -1
  114. data/spec/mongoid/criteria/queryable/mergeable_spec.rb +105 -7
  115. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +229 -24
  116. data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +39 -0
  117. data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -565
  118. data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +590 -0
  119. data/spec/mongoid/criteria_projection_spec.rb +411 -0
  120. data/spec/mongoid/criteria_spec.rb +0 -275
  121. data/spec/mongoid/document_spec.rb +13 -13
  122. data/spec/mongoid/errors/delete_restriction_spec.rb +1 -1
  123. data/spec/mongoid/extensions/false_class_spec.rb +1 -1
  124. data/spec/mongoid/extensions/string_spec.rb +5 -5
  125. data/spec/mongoid/extensions/true_class_spec.rb +1 -1
  126. data/spec/mongoid/fields/localized_spec.rb +4 -4
  127. data/spec/mongoid/fields_spec.rb +4 -4
  128. data/spec/mongoid/inspectable_spec.rb +12 -4
  129. data/spec/mongoid/persistable/deletable_spec.rb +175 -1
  130. data/spec/mongoid/persistable/destroyable_spec.rb +191 -3
  131. data/spec/mongoid/persistable/savable_spec.rb +3 -5
  132. data/spec/mongoid/persistable/upsertable_spec.rb +1 -1
  133. data/spec/mongoid/query_cache_middleware_spec.rb +8 -0
  134. data/spec/mongoid/reloadable_spec.rb +18 -1
  135. data/spec/mongoid/shardable_spec.rb +44 -0
  136. data/spec/mongoid/touchable_spec.rb +122 -16
  137. data/spec/mongoid/touchable_spec_models.rb +54 -0
  138. data/spec/mongoid/validatable_spec.rb +1 -1
  139. data/spec/spec_helper.rb +6 -2
  140. data/spec/support/client_registry.rb +9 -0
  141. data/spec/support/models/bolt.rb +8 -0
  142. data/spec/support/models/hole.rb +13 -0
  143. data/spec/support/models/mop.rb +0 -1
  144. data/spec/support/models/nut.rb +8 -0
  145. data/spec/support/models/person.rb +6 -0
  146. data/spec/support/models/sealer.rb +8 -0
  147. data/spec/support/models/shirt.rb +12 -0
  148. data/spec/support/models/spacer.rb +8 -0
  149. data/spec/support/models/threadlocker.rb +8 -0
  150. data/spec/support/models/washer.rb +8 -0
  151. data.tar.gz.sig +0 -0
  152. metadata +97 -3
  153. metadata.gz.sig +0 -0
  154. data/spec/support/cluster_config.rb +0 -158
@@ -0,0 +1,159 @@
1
+ - name: existing field - matches with int
2
+ document:
3
+ a: 54
4
+ binaryValueofA: "00110110"
5
+ query:
6
+ a:
7
+ $bitsAnyClear: 35
8
+ matches: true
9
+ min_server_version: 3.2
10
+
11
+ - name: existing field - does not match with int
12
+ document:
13
+ a: 7
14
+ binaryValueofA: "00000011"
15
+ query:
16
+ a:
17
+ $bitsAnyClear: 35
18
+ matches: true
19
+ min_server_version: 3.2
20
+
21
+ - name: existing field - matches with binData
22
+ document:
23
+ a: 16
24
+ binaryValueofA: "00001000"
25
+ query:
26
+ a:
27
+ $bitsAnyClear: !ruby/object:BSON::Binary
28
+ data: !binary |-
29
+ IW==
30
+ type: :generic
31
+ matches: true
32
+ min_server_version: 3.2
33
+
34
+ - name: existing field - does not match with binData
35
+ document:
36
+ a: 55
37
+ binaryValueofA: "00110111"
38
+ query:
39
+ a:
40
+ $bitsAnyClear: !ruby/object:BSON::Binary
41
+ data: !binary |-
42
+ IW==
43
+ type: :generic
44
+ matches: false
45
+ min_server_version: 3.2
46
+
47
+ - name: existing binData field matches
48
+ document:
49
+ a: !ruby/object:BSON::Binary
50
+ data: !binary |-
51
+ FA==
52
+ type: :generic
53
+ query:
54
+ a:
55
+ $bitsAnyClear: 35
56
+ matches: true
57
+ min_server_version: 3.2
58
+
59
+ - name: existing binData field does not match
60
+ document:
61
+ a: !ruby/object:BSON::Binary
62
+ data: !binary |-
63
+ IW==
64
+ type: :generic
65
+ query:
66
+ a:
67
+ $bitsAnyClear: 32
68
+ matches: false
69
+ min_server_version: 3.2
70
+
71
+ - name: existing field - matches with array
72
+ document:
73
+ a: 20
74
+ binaryValueofA: "00010100"
75
+ query:
76
+ a:
77
+ $bitsAnyClear: [0, 2]
78
+ matches: true
79
+ min_server_version: 3.2
80
+
81
+ - name: existing field - does not match with array
82
+ document:
83
+ a: 20
84
+ binaryValueofA: "00010100"
85
+ query:
86
+ a:
87
+ $bitsAnyClear: [2, 4]
88
+ matches: false
89
+ min_server_version: 3.2
90
+
91
+ - name: float condition representable as an integer
92
+ document:
93
+ a: 54
94
+ binaryValueofA: "00110110"
95
+ query:
96
+ a:
97
+ $bitsAnyClear: 35.0
98
+ matches: true
99
+ min_server_version: 3.2
100
+
101
+ - name: float condition not representable as an integer
102
+ document:
103
+ a: 54
104
+ binaryValueofA: "00110110"
105
+ query:
106
+ a:
107
+ $bitsAnyClear: 35.1
108
+ error: true
109
+ min_server_version: 3.2
110
+
111
+ - name: string condition
112
+ document:
113
+ a: 54
114
+ binaryValueofA: "00110110"
115
+ query:
116
+ a:
117
+ $bitsAnyClear: 'hello'
118
+ error: true
119
+ min_server_version: 3.2
120
+
121
+ - name: empty array condition
122
+ document:
123
+ a: 54
124
+ binaryValueofA: "00110110"
125
+ query:
126
+ a:
127
+ $bitsAnyClear: []
128
+ matches: false
129
+ min_server_version: 3.2
130
+
131
+ - name: integer 0 condition
132
+ document:
133
+ a: 54
134
+ binaryValueofA: "00110110"
135
+ query:
136
+ a:
137
+ $bitsAnyClear: 0
138
+ matches: false
139
+ min_server_version: 3.2
140
+
141
+ - name: negative integer condition
142
+ document:
143
+ a: 54
144
+ binaryValueofA: "00110110"
145
+ query:
146
+ a:
147
+ $bitsAnyClear: -1
148
+ error: true
149
+ min_server_version: 3.2
150
+
151
+ - name: negative float condition
152
+ document:
153
+ a: 54
154
+ binaryValueofA: "00110110"
155
+ query:
156
+ a:
157
+ $bitsAnyClear: -1.0
158
+ error: true
159
+ min_server_version: 3.2
@@ -0,0 +1,159 @@
1
+ - name: existing field - matches with int
2
+ document:
3
+ a: 54
4
+ binaryValueofA: "00110110"
5
+ query:
6
+ a:
7
+ $bitsAnySet: 35
8
+ matches: true
9
+ min_server_version: 3.2
10
+
11
+ - name: existing field - does not match with int
12
+ document:
13
+ a: 16
14
+ binaryValueofA: "00000100"
15
+ query:
16
+ a:
17
+ $bitsAllSet: 35
18
+ matches: false
19
+ min_server_version: 3.2
20
+
21
+ - name: existing field - matches with binData
22
+ document:
23
+ a: 54
24
+ binaryValueofA: "00110110"
25
+ query:
26
+ a:
27
+ $bitsAnySet: !ruby/object:BSON::Binary
28
+ data: !binary |-
29
+ IW==
30
+ type: :generic
31
+ matches: true
32
+ min_server_version: 3.2
33
+
34
+ - name: existing field - does not match with binData
35
+ document:
36
+ a: 16
37
+ binaryValueofA: "00001000"
38
+ query:
39
+ a:
40
+ $bitsAnySet: !ruby/object:BSON::Binary
41
+ data: !binary |-
42
+ IW==
43
+ type: :generic
44
+ matches: false
45
+ min_server_version: 3.2
46
+
47
+ - name: existing binData field matches
48
+ document:
49
+ a: !ruby/object:BSON::Binary
50
+ data: !binary |-
51
+ IW==
52
+ type: :generic
53
+ query:
54
+ a:
55
+ $bitsAnySet: 37
56
+ matches: true
57
+ min_server_version: 3.2
58
+
59
+ - name: existing binData field does not match
60
+ document:
61
+ a: !ruby/object:BSON::Binary
62
+ data: !binary |-
63
+ IW==
64
+ type: :generic
65
+ query:
66
+ a:
67
+ $bitsAnySet: 20
68
+ matches: false
69
+ min_server_version: 3.2
70
+
71
+ - name: existing field - matches with array
72
+ document:
73
+ a: 20
74
+ binaryValueofA: "00010100"
75
+ query:
76
+ a:
77
+ $bitsAnySet: [0, 2]
78
+ matches: true
79
+ min_server_version: 3.2
80
+
81
+ - name: existing field - does not match with array
82
+ document:
83
+ a: 20
84
+ binaryValueofA: "00010100"
85
+ query:
86
+ a:
87
+ $bitsAnySet: [0, 3]
88
+ matches: false
89
+ min_server_version: 3.2
90
+
91
+ - name: float condition representable as an integer
92
+ document:
93
+ a: 54
94
+ binaryValueofA: "00110110"
95
+ query:
96
+ a:
97
+ $bitsAnySet: 35
98
+ matches: true
99
+ min_server_version: 3.2
100
+
101
+ - name: float condition not representable as an integer
102
+ document:
103
+ a: 54
104
+ binaryValueofA: "00110110"
105
+ query:
106
+ a:
107
+ $bitsAnySet: 35.1
108
+ error: true
109
+ min_server_version: 3.2
110
+
111
+ - name: string condition
112
+ document:
113
+ a: 54
114
+ binaryValueofA: "00110110"
115
+ query:
116
+ a:
117
+ $bitsAnySet: hello
118
+ error: true
119
+ min_server_version: 3.2
120
+
121
+ - name: empty array condition
122
+ document:
123
+ a: 54
124
+ binaryValueofA: "00110110"
125
+ query:
126
+ a:
127
+ $bitsAnySet: []
128
+ matches: false
129
+ min_server_version: 3.2
130
+
131
+ - name: integer 0 condition
132
+ document:
133
+ a: 54
134
+ binaryValueofA: "00110110"
135
+ query:
136
+ a:
137
+ $bitsAnySet: 0
138
+ matches: false
139
+ min_server_version: 3.2
140
+
141
+ - name: negative integer condition
142
+ document:
143
+ a: 54
144
+ binaryValueofA: "00110110"
145
+ query:
146
+ a:
147
+ $bitsAnySet: -1
148
+ error: true
149
+ min_server_version: 3.2
150
+
151
+ - name: negative float condition
152
+ document:
153
+ a: 54
154
+ binaryValueofA: "00110110"
155
+ query:
156
+ a:
157
+ $bitsAnySet: -1.0
158
+ error: true
159
+ min_server_version: 3.2
@@ -0,0 +1,22 @@
1
+ - name: matches
2
+ document:
3
+ name: Angel Share
4
+ query:
5
+ name: Angel Share
6
+ $comment: "foo"
7
+ matches: true
8
+
9
+ - name: null query is accepted
10
+ document:
11
+ pi: 3.14
12
+ query:
13
+ $comment: "hello"
14
+ matches: true
15
+
16
+ - name: does not match
17
+ document:
18
+ name: Angel Share
19
+ query:
20
+ name: Angel Foo
21
+ $comment: "foo"
22
+ matches: false
@@ -192,3 +192,19 @@
192
192
  end: 20
193
193
  excl: false
194
194
  error: true
195
+
196
+ - name: scalar field - symbol operator - matches
197
+ document:
198
+ count: 10
199
+ query:
200
+ count:
201
+ :$in: [10, 11]
202
+ matches: true
203
+
204
+ - name: scalar field - symbol operator - does not match
205
+ document:
206
+ count: 8
207
+ query:
208
+ count:
209
+ :$in: [10, 11]
210
+ matches: false
@@ -0,0 +1,55 @@
1
+ - name: existing field - matches
2
+ document:
3
+ pi: 8
4
+ query:
5
+ pi:
6
+ $mod: [5, 3]
7
+ matches: true
8
+
9
+ - name: existing field - does not match
10
+ document:
11
+ pi: 9
12
+ query:
13
+ pi:
14
+ $mod: [5, 3]
15
+ matches: false
16
+
17
+ - name: invalid condition
18
+ document:
19
+ pi: 9
20
+ query:
21
+ pi:
22
+ $mod: 5
23
+ error: true
24
+
25
+ - name: invalid field
26
+ document:
27
+ pi: [1, 2]
28
+ query:
29
+ pi:
30
+ $mod: 5
31
+ error: true
32
+
33
+ - name: array too short
34
+ document:
35
+ pi: 3
36
+ query:
37
+ pi:
38
+ $mod: [5]
39
+ error: true
40
+
41
+ - name: empty array
42
+ document:
43
+ pi: 3
44
+ query:
45
+ pi:
46
+ $mod: []
47
+ error: true
48
+
49
+ - name: array too long
50
+ document:
51
+ pi: 3
52
+ query:
53
+ pi:
54
+ $mod: [1, 2, 3]
55
+ error: true
@@ -0,0 +1,70 @@
1
+ - name: type is 0
2
+ document:
3
+ pi: 3.14
4
+ query:
5
+ pi:
6
+ $type: 0
7
+ error: true
8
+ min_server_version: 4.2
9
+
10
+ - name: type is too negative
11
+ document:
12
+ pi: 3.14
13
+ query:
14
+ pi:
15
+ $type: -2
16
+ error: true
17
+ min_server_version: 3.2
18
+
19
+ - name: type is too large
20
+ document:
21
+ pi: 3.14
22
+ query:
23
+ pi:
24
+ $type: 42
25
+ error: true
26
+ min_server_version: 3.2
27
+
28
+ - name: array argument for type - matches
29
+ document:
30
+ pi: 3.14
31
+ query:
32
+ pi:
33
+ $type: [1]
34
+ matches: true
35
+ min_server_version: 3.6
36
+
37
+ - name: array argument for type - does not match
38
+ document:
39
+ pi: 3.14
40
+ query:
41
+ pi:
42
+ $type: [2]
43
+ matches: false
44
+ min_server_version: 3.6
45
+
46
+ - name: hash argument
47
+ document:
48
+ pi: 3
49
+ query:
50
+ pi:
51
+ $type: {}
52
+ error: true
53
+
54
+ - name: array with multiple elements - matches
55
+ document:
56
+ pi: 3.14
57
+ query:
58
+ pi:
59
+ $type: [1, 2]
60
+ matches: true
61
+ min_server_version: 3.6
62
+
63
+ - name: array with multiple elements - does not match
64
+ document:
65
+ pi: 3.14
66
+ query:
67
+ pi:
68
+ $type: [2, 3]
69
+ matches: false
70
+ min_server_version: 3.6