mongoid 9.0.11 → 9.0.12

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/lib/config/locales/en.yml +45 -0
  3. data/lib/mongoid/association/depending.rb +8 -4
  4. data/lib/mongoid/association/nested/many.rb +34 -5
  5. data/lib/mongoid/association/nested/nested_buildable.rb +14 -0
  6. data/lib/mongoid/association/referenced/has_many/proxy.rb +100 -1
  7. data/lib/mongoid/association/relatable.rb +17 -0
  8. data/lib/mongoid/collection_configurable.rb +8 -0
  9. data/lib/mongoid/config/encryption.rb +36 -18
  10. data/lib/mongoid/config.rb +56 -9
  11. data/lib/mongoid/contextual/aggregable/memory.rb +5 -2
  12. data/lib/mongoid/contextual/memory.rb +18 -7
  13. data/lib/mongoid/criteria/queryable/mergeable.rb +4 -0
  14. data/lib/mongoid/criteria/queryable/selectable.rb +109 -0
  15. data/lib/mongoid/encryptable.rb +46 -0
  16. data/lib/mongoid/errors/in_memory_regexp_timeout.rb +26 -0
  17. data/lib/mongoid/errors/no_encryption_schema.rb +28 -0
  18. data/lib/mongoid/errors.rb +2 -0
  19. data/lib/mongoid/field_readable.rb +70 -0
  20. data/lib/mongoid/indexable.rb +39 -27
  21. data/lib/mongoid/matchable.rb +6 -1
  22. data/lib/mongoid/matcher/eq_impl_with_regexp.rb +4 -9
  23. data/lib/mongoid/matcher/regex.rb +9 -13
  24. data/lib/mongoid/matcher/regexp_budget.rb +383 -0
  25. data/lib/mongoid/matcher.rb +1 -0
  26. data/lib/mongoid/persistence_context.rb +35 -0
  27. data/lib/mongoid/search_indexable.rb +14 -7
  28. data/lib/mongoid/tasks/database.rb +23 -9
  29. data/lib/mongoid/threaded.rb +37 -0
  30. data/lib/mongoid/version.rb +1 -1
  31. data/spec/integration/app_spec.rb +7 -0
  32. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +17 -2
  33. data/spec/integration/dots_and_dollars_spec.rb +12 -2
  34. data/spec/integration/encryption_spec.rb +149 -0
  35. data/spec/integration/matcher_operator_data/regex.yml +21 -0
  36. data/spec/integration/matcher_regexp_timeout_spec.rb +215 -0
  37. data/spec/integration/query_operator_guard_spec.rb +89 -0
  38. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +48 -0
  39. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +145 -0
  40. data/spec/mongoid/attributes/nested_spec.rb +204 -10
  41. data/spec/mongoid/config/defaults_spec.rb +18 -0
  42. data/spec/mongoid/config/encryption_spec.rb +228 -0
  43. data/spec/mongoid/contextual/aggregable/memory_spec.rb +91 -0
  44. data/spec/mongoid/contextual/memory_spec.rb +177 -0
  45. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +2 -0
  46. data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +200 -0
  47. data/spec/mongoid/criteria_spec.rb +2 -0
  48. data/spec/mongoid/encryptable_spec.rb +61 -0
  49. data/spec/mongoid/matcher/regexp_budget_spec.rb +570 -0
  50. data/spec/mongoid/tasks/database_spec.rb +18 -0
  51. data/spec/support/crypt/models.rb +157 -0
  52. metadata +14 -2
@@ -47,4 +47,161 @@ module Crypt
47
47
  field :vin, type: String, encrypt: true
48
48
  field :make, type: String
49
49
  end
50
+
51
+ # An encrypted model whose database name is a callable resolving to a
52
+ # constant. The callable form of :database is supported by store_in, but the
53
+ # encryption schema map is keyed by namespace and built once, so this model's
54
+ # namespace is not known when the map is generated.
55
+ class DynamicCar
56
+ include Mongoid::Document
57
+
58
+ store_in database: -> { 'vehicles_dynamic' }
59
+
60
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q==', deterministic: true
61
+
62
+ field :vin, type: String, encrypt: true
63
+ end
64
+
65
+ # An encrypted model using the documented multi-tenant idiom, where the
66
+ # database name is only known once a tenant is selected. There is no correct
67
+ # value to resolve at client construction time.
68
+ class TenantCar
69
+ include Mongoid::Document
70
+
71
+ # The fallback keeps this model usable by tasks that iterate every model,
72
+ # such as Mongoid::Tasks::Database.create_collections. Mongoid raises
73
+ # NoMethodError when a callable :database resolves to nil.
74
+ store_in database: -> { Thread.current[:tenant_database] || 'vehicles_no_tenant' }
75
+
76
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q==', deterministic: true
77
+
78
+ field :vin, type: String, encrypt: true
79
+ end
80
+
81
+ # An encrypted model that is embedded by more than one parent, and more than
82
+ # once by the same parent.
83
+ class Token
84
+ include Mongoid::Document
85
+
86
+ field :value, type: String, encrypt: { deterministic: true }
87
+
88
+ embedded_in :tokenized, polymorphic: true
89
+ end
90
+
91
+ # A parent whose encrypted data lives entirely in an embedded model: it has
92
+ # no encrypted field of its own and no encrypt_with.
93
+ class Wallet
94
+ include Mongoid::Document
95
+
96
+ embeds_one :token, class_name: 'Crypt::Token', as: :tokenized
97
+ end
98
+
99
+ # Two parents embedding the same encrypted model.
100
+ class Vault
101
+ include Mongoid::Document
102
+
103
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q=='
104
+
105
+ embeds_one :token, class_name: 'Crypt::Token', as: :tokenized
106
+ end
107
+
108
+ class Chest
109
+ include Mongoid::Document
110
+
111
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q=='
112
+
113
+ embeds_one :token, class_name: 'Crypt::Token', as: :tokenized
114
+ end
115
+
116
+ # A parent embedding the same encrypted model through two relations.
117
+ class Ledger
118
+ include Mongoid::Document
119
+
120
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q=='
121
+
122
+ embeds_one :primary_token, class_name: 'Crypt::Token', as: :tokenized
123
+ embeds_one :backup_token, class_name: 'Crypt::Token', as: :tokenized
124
+ end
125
+
126
+ # Three levels of nesting, where the middle level has no encrypted field of
127
+ # its own.
128
+ class Owner
129
+ include Mongoid::Document
130
+
131
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q=='
132
+
133
+ embeds_one :account, class_name: 'Crypt::Account'
134
+ end
135
+
136
+ class Account
137
+ include Mongoid::Document
138
+
139
+ embedded_in :owner, class_name: 'Crypt::Owner'
140
+ embeds_one :credential, class_name: 'Crypt::Credential'
141
+ end
142
+
143
+ class Credential
144
+ include Mongoid::Document
145
+
146
+ field :secret, type: String, encrypt: { deterministic: true }
147
+
148
+ embedded_in :account, class_name: 'Crypt::Account'
149
+ end
150
+
151
+ # A model that embeds itself. The walk over embedded relations has to stop
152
+ # here, or generating the map never terminates.
153
+ class Comment
154
+ include Mongoid::Document
155
+
156
+ field :body, type: String, encrypt: { deterministic: true }
157
+
158
+ embedded_in :commentable, polymorphic: true
159
+ embeds_one :reply, class_name: 'Crypt::Comment', as: :commentable
160
+ end
161
+
162
+ class Article
163
+ include Mongoid::Document
164
+
165
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q=='
166
+
167
+ embeds_one :comment, class_name: 'Crypt::Comment', as: :commentable
168
+ end
169
+
170
+ # A parent with no encrypted field of its own: the encrypted field lives on
171
+ # the embedded model. Used by the integration specs, so the embedded model
172
+ # carries a key id.
173
+ class Folder
174
+ include Mongoid::Document
175
+
176
+ embeds_one :note, class_name: 'Crypt::Note'
177
+ end
178
+
179
+ class Note
180
+ include Mongoid::Document
181
+
182
+ encrypt_with key_id: 'grolrnFVSSW9Gq04Q87R9Q==', deterministic: true
183
+
184
+ field :text, type: String, encrypt: true
185
+
186
+ embedded_in :folder, class_name: 'Crypt::Folder'
187
+ end
188
+
189
+ # A model naming an embedded class that is never defined. The association
190
+ # cannot be used, so nothing is ever embedded through it, but every model in
191
+ # the application is walked when the schema map is generated.
192
+ class Drawer
193
+ include Mongoid::Document
194
+
195
+ embeds_one :missing_note, class_name: 'Crypt::MissingNote'
196
+ end
197
+
198
+ # The same, on a model that is encrypted itself, so the walk descends into
199
+ # its relations.
200
+ class Cabinet
201
+ include Mongoid::Document
202
+
203
+ field :label, type: String, encrypt: { deterministic: true }
204
+
205
+ embeds_one :missing_note, class_name: 'Crypt::MissingNote'
206
+ end
50
207
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.0.11
4
+ version: 9.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - The MongoDB Ruby Team
@@ -292,6 +292,7 @@ files:
292
292
  - lib/mongoid/errors/empty_config_file.rb
293
293
  - lib/mongoid/errors/immutable_attribute.rb
294
294
  - lib/mongoid/errors/in_memory_collation_not_supported.rb
295
+ - lib/mongoid/errors/in_memory_regexp_timeout.rb
295
296
  - lib/mongoid/errors/invalid_around_callback.rb
296
297
  - lib/mongoid/errors/invalid_async_query_executor.rb
297
298
  - lib/mongoid/errors/invalid_auto_encryption_configuration.rb
@@ -335,6 +336,7 @@ files:
335
336
  - lib/mongoid/errors/no_client_hosts.rb
336
337
  - lib/mongoid/errors/no_clients_config.rb
337
338
  - lib/mongoid/errors/no_default_client.rb
339
+ - lib/mongoid/errors/no_encryption_schema.rb
338
340
  - lib/mongoid/errors/no_environment.rb
339
341
  - lib/mongoid/errors/no_map_reduce_output.rb
340
342
  - lib/mongoid/errors/no_metadata.rb
@@ -382,6 +384,7 @@ files:
382
384
  - lib/mongoid/extensions/time_with_zone.rb
383
385
  - lib/mongoid/extensions/true_class.rb
384
386
  - lib/mongoid/factory.rb
387
+ - lib/mongoid/field_readable.rb
385
388
  - lib/mongoid/fields.rb
386
389
  - lib/mongoid/fields/encrypted.rb
387
390
  - lib/mongoid/fields/foreign_key.rb
@@ -429,6 +432,7 @@ files:
429
432
  - lib/mongoid/matcher/not.rb
430
433
  - lib/mongoid/matcher/or.rb
431
434
  - lib/mongoid/matcher/regex.rb
435
+ - lib/mongoid/matcher/regexp_budget.rb
432
436
  - lib/mongoid/matcher/size.rb
433
437
  - lib/mongoid/matcher/type.rb
434
438
  - lib/mongoid/model_resolver.rb
@@ -598,9 +602,11 @@ files:
598
602
  - spec/integration/matcher_operator_data/type_timestamp.yml
599
603
  - spec/integration/matcher_operator_data/type_undefined.yml
600
604
  - spec/integration/matcher_operator_spec.rb
605
+ - spec/integration/matcher_regexp_timeout_spec.rb
601
606
  - spec/integration/matcher_spec.rb
602
607
  - spec/integration/persistence/collection_options_spec.rb
603
608
  - spec/integration/persistence/range_field_spec.rb
609
+ - spec/integration/query_operator_guard_spec.rb
604
610
  - spec/integration/server_query_spec.rb
605
611
  - spec/integration/shardable_spec.rb
606
612
  - spec/integration/stringified_symbol_field_spec.rb
@@ -764,6 +770,7 @@ files:
764
770
  - spec/mongoid/document_persistence_context_spec.rb
765
771
  - spec/mongoid/document_query_spec.rb
766
772
  - spec/mongoid/document_spec.rb
773
+ - spec/mongoid/encryptable_spec.rb
767
774
  - spec/mongoid/equality_spec.rb
768
775
  - spec/mongoid/errors/ambiguous_relationship_spec.rb
769
776
  - spec/mongoid/errors/attribute_not_loaded_spec.rb
@@ -851,6 +858,7 @@ files:
851
858
  - spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml
852
859
  - spec/mongoid/matcher/extract_attribute_data/traversal.yml
853
860
  - spec/mongoid/matcher/extract_attribute_spec.rb
861
+ - spec/mongoid/matcher/regexp_budget_spec.rb
854
862
  - spec/mongoid/model_resolver_spec.rb
855
863
  - spec/mongoid/mongoizable_spec.rb
856
864
  - spec/mongoid/monkey_patches_spec.rb
@@ -1245,7 +1253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1245
1253
  - !ruby/object:Gem::Version
1246
1254
  version: 1.3.6
1247
1255
  requirements: []
1248
- rubygems_version: 4.0.10
1256
+ rubygems_version: 4.0.21
1249
1257
  specification_version: 4
1250
1258
  summary: Elegant Persistence in Ruby for MongoDB.
1251
1259
  test_files:
@@ -1346,9 +1354,11 @@ test_files:
1346
1354
  - spec/integration/matcher_operator_data/type_timestamp.yml
1347
1355
  - spec/integration/matcher_operator_data/type_undefined.yml
1348
1356
  - spec/integration/matcher_operator_spec.rb
1357
+ - spec/integration/matcher_regexp_timeout_spec.rb
1349
1358
  - spec/integration/matcher_spec.rb
1350
1359
  - spec/integration/persistence/collection_options_spec.rb
1351
1360
  - spec/integration/persistence/range_field_spec.rb
1361
+ - spec/integration/query_operator_guard_spec.rb
1352
1362
  - spec/integration/server_query_spec.rb
1353
1363
  - spec/integration/shardable_spec.rb
1354
1364
  - spec/integration/stringified_symbol_field_spec.rb
@@ -1512,6 +1522,7 @@ test_files:
1512
1522
  - spec/mongoid/document_persistence_context_spec.rb
1513
1523
  - spec/mongoid/document_query_spec.rb
1514
1524
  - spec/mongoid/document_spec.rb
1525
+ - spec/mongoid/encryptable_spec.rb
1515
1526
  - spec/mongoid/equality_spec.rb
1516
1527
  - spec/mongoid/errors/ambiguous_relationship_spec.rb
1517
1528
  - spec/mongoid/errors/attribute_not_loaded_spec.rb
@@ -1599,6 +1610,7 @@ test_files:
1599
1610
  - spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml
1600
1611
  - spec/mongoid/matcher/extract_attribute_data/traversal.yml
1601
1612
  - spec/mongoid/matcher/extract_attribute_spec.rb
1613
+ - spec/mongoid/matcher/regexp_budget_spec.rb
1602
1614
  - spec/mongoid/model_resolver_spec.rb
1603
1615
  - spec/mongoid/mongoizable_spec.rb
1604
1616
  - spec/mongoid/monkey_patches_spec.rb