mongoid 7.6.3 → 8.0.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.
Files changed (341) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +5 -0
  3. data/README.md +3 -3
  4. data/Rakefile +21 -85
  5. data/lib/config/locales/en.yml +46 -56
  6. data/lib/mongoid/association/accessors.rb +32 -3
  7. data/lib/mongoid/association/bindable.rb +48 -0
  8. data/lib/mongoid/association/builders.rb +4 -2
  9. data/lib/mongoid/association/depending.rb +4 -8
  10. data/lib/mongoid/association/eager_loadable.rb +29 -7
  11. data/lib/mongoid/association/embedded/batchable.rb +28 -5
  12. data/lib/mongoid/association/embedded/embedded_in/binding.rb +24 -2
  13. data/lib/mongoid/association/embedded/embedded_in.rb +2 -1
  14. data/lib/mongoid/association/embedded/embeds_many/binding.rb +1 -0
  15. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +1 -1
  16. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +40 -18
  17. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +18 -4
  18. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +21 -2
  19. data/lib/mongoid/association/macros.rb +2 -1
  20. data/lib/mongoid/association/many.rb +5 -0
  21. data/lib/mongoid/association/nested/many.rb +5 -39
  22. data/lib/mongoid/association/nested/nested_buildable.rb +0 -14
  23. data/lib/mongoid/association/proxy.rb +12 -0
  24. data/lib/mongoid/association/referenced/auto_save.rb +3 -2
  25. data/lib/mongoid/association/referenced/belongs_to/binding.rb +1 -0
  26. data/lib/mongoid/association/referenced/belongs_to/buildable.rb +1 -1
  27. data/lib/mongoid/association/referenced/belongs_to.rb +1 -1
  28. data/lib/mongoid/association/referenced/counter_cache.rb +8 -8
  29. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +64 -11
  30. data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +4 -1
  31. data/lib/mongoid/association/referenced/has_many/enumerable.rb +10 -18
  32. data/lib/mongoid/association/referenced/has_many/proxy.rb +12 -110
  33. data/lib/mongoid/association/referenced/has_one/buildable.rb +1 -1
  34. data/lib/mongoid/association/referenced/has_one/proxy.rb +8 -11
  35. data/lib/mongoid/association/referenced/syncable.rb +2 -2
  36. data/lib/mongoid/association/relatable.rb +38 -4
  37. data/lib/mongoid/attributes/processing.rb +9 -2
  38. data/lib/mongoid/attributes/readonly.rb +3 -33
  39. data/lib/mongoid/attributes.rb +30 -27
  40. data/lib/mongoid/cacheable.rb +2 -2
  41. data/lib/mongoid/changeable.rb +41 -24
  42. data/lib/mongoid/clients/factory.rb +0 -4
  43. data/lib/mongoid/clients/options.rb +4 -0
  44. data/lib/mongoid/clients/sessions.rb +2 -14
  45. data/lib/mongoid/config.rb +15 -73
  46. data/lib/mongoid/contextual/aggregable/memory.rb +22 -20
  47. data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
  48. data/lib/mongoid/contextual/map_reduce.rb +2 -2
  49. data/lib/mongoid/contextual/memory.rb +63 -47
  50. data/lib/mongoid/contextual/mongo.rb +173 -287
  51. data/lib/mongoid/contextual/none.rb +23 -56
  52. data/lib/mongoid/copyable.rb +32 -8
  53. data/lib/mongoid/criteria/includable.rb +24 -20
  54. data/lib/mongoid/criteria/marshalable.rb +10 -2
  55. data/lib/mongoid/criteria/queryable/extensions/array.rb +2 -15
  56. data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +25 -4
  57. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
  58. data/lib/mongoid/criteria/queryable/extensions/date.rb +6 -1
  59. data/lib/mongoid/criteria/queryable/extensions/date_time.rb +6 -1
  60. data/lib/mongoid/criteria/queryable/extensions/hash.rb +0 -16
  61. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
  62. data/lib/mongoid/criteria/queryable/extensions/object.rb +2 -1
  63. data/lib/mongoid/criteria/queryable/extensions/range.rb +13 -5
  64. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +1 -1
  65. data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -1
  66. data/lib/mongoid/criteria/queryable/extensions/time.rb +6 -1
  67. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +6 -1
  68. data/lib/mongoid/criteria/queryable/mergeable.rb +0 -12
  69. data/lib/mongoid/criteria/queryable/optional.rb +3 -9
  70. data/lib/mongoid/criteria/queryable/options.rb +1 -1
  71. data/lib/mongoid/criteria/queryable/selectable.rb +9 -145
  72. data/lib/mongoid/criteria/queryable/selector.rb +90 -5
  73. data/lib/mongoid/criteria/queryable/smash.rb +39 -6
  74. data/lib/mongoid/criteria/queryable/storable.rb +1 -1
  75. data/lib/mongoid/criteria/queryable.rb +11 -6
  76. data/lib/mongoid/criteria/scopable.rb +1 -7
  77. data/lib/mongoid/criteria.rb +2 -73
  78. data/lib/mongoid/deprecable.rb +36 -0
  79. data/lib/mongoid/deprecation.rb +25 -0
  80. data/lib/mongoid/document.rb +88 -43
  81. data/lib/mongoid/equality.rb +4 -4
  82. data/lib/mongoid/errors/document_not_found.rb +6 -2
  83. data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +23 -0
  84. data/lib/mongoid/errors/invalid_field.rb +5 -1
  85. data/lib/mongoid/errors/invalid_field_type.rb +26 -0
  86. data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -1
  87. data/lib/mongoid/errors.rb +2 -3
  88. data/lib/mongoid/extensions/array.rb +8 -6
  89. data/lib/mongoid/extensions/big_decimal.rb +29 -10
  90. data/lib/mongoid/extensions/binary.rb +42 -0
  91. data/lib/mongoid/extensions/boolean.rb +8 -2
  92. data/lib/mongoid/extensions/date.rb +26 -20
  93. data/lib/mongoid/extensions/date_time.rb +1 -1
  94. data/lib/mongoid/extensions/float.rb +4 -5
  95. data/lib/mongoid/extensions/hash.rb +13 -32
  96. data/lib/mongoid/extensions/integer.rb +4 -5
  97. data/lib/mongoid/extensions/object.rb +2 -0
  98. data/lib/mongoid/extensions/range.rb +41 -10
  99. data/lib/mongoid/extensions/regexp.rb +11 -4
  100. data/lib/mongoid/extensions/set.rb +11 -4
  101. data/lib/mongoid/extensions/string.rb +2 -13
  102. data/lib/mongoid/extensions/symbol.rb +3 -14
  103. data/lib/mongoid/extensions/time.rb +27 -16
  104. data/lib/mongoid/extensions/time_with_zone.rb +1 -2
  105. data/lib/mongoid/extensions.rb +1 -0
  106. data/lib/mongoid/factory.rb +42 -7
  107. data/lib/mongoid/fields/foreign_key.rb +7 -0
  108. data/lib/mongoid/fields/validators/macro.rb +3 -9
  109. data/lib/mongoid/fields.rb +49 -7
  110. data/lib/mongoid/findable.rb +21 -16
  111. data/lib/mongoid/indexable/specification.rb +1 -1
  112. data/lib/mongoid/indexable/validators/options.rb +4 -1
  113. data/lib/mongoid/interceptable.rb +69 -9
  114. data/lib/mongoid/matchable.rb +1 -6
  115. data/lib/mongoid/matcher/eq_impl_with_regexp.rb +5 -3
  116. data/lib/mongoid/matcher/regex.rb +9 -8
  117. data/lib/mongoid/matcher.rb +0 -1
  118. data/lib/mongoid/persistable/creatable.rb +14 -5
  119. data/lib/mongoid/persistable/updatable.rb +12 -5
  120. data/lib/mongoid/persistence_context.rb +8 -42
  121. data/lib/mongoid/query_cache.rb +6 -258
  122. data/lib/mongoid/railties/controller_runtime.rb +1 -1
  123. data/lib/mongoid/reloadable.rb +7 -4
  124. data/lib/mongoid/scopable.rb +9 -11
  125. data/lib/mongoid/selectable.rb +1 -2
  126. data/lib/mongoid/shardable.rb +11 -35
  127. data/lib/mongoid/stateful.rb +27 -1
  128. data/lib/mongoid/threaded.rb +0 -3
  129. data/lib/mongoid/timestamps/created.rb +1 -1
  130. data/lib/mongoid/timestamps/updated.rb +1 -1
  131. data/lib/mongoid/touchable.rb +2 -3
  132. data/lib/mongoid/traversable.rb +1 -0
  133. data/lib/mongoid/validatable/uniqueness.rb +2 -1
  134. data/lib/mongoid/version.rb +1 -5
  135. data/lib/mongoid/warnings.rb +3 -5
  136. data/lib/mongoid.rb +1 -0
  137. data/spec/config/mongoid.yml +16 -0
  138. data/spec/integration/app_spec.rb +8 -20
  139. data/spec/integration/associations/belongs_to_spec.rb +18 -0
  140. data/spec/integration/associations/embedded_spec.rb +15 -0
  141. data/spec/integration/associations/embeds_many_spec.rb +15 -2
  142. data/spec/integration/associations/embeds_one_spec.rb +18 -0
  143. data/spec/integration/associations/foreign_key_spec.rb +9 -0
  144. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +21 -0
  145. data/spec/integration/associations/has_one_spec.rb +97 -1
  146. data/spec/integration/associations/scope_option_spec.rb +1 -1
  147. data/spec/integration/callbacks_models.rb +95 -1
  148. data/spec/integration/callbacks_spec.rb +226 -4
  149. data/spec/integration/criteria/range_spec.rb +95 -1
  150. data/spec/integration/discriminator_key_spec.rb +115 -76
  151. data/spec/integration/dots_and_dollars_spec.rb +277 -0
  152. data/spec/integration/i18n_fallbacks_spec.rb +1 -15
  153. data/spec/integration/matcher_examples_spec.rb +20 -13
  154. data/spec/integration/matcher_operator_data/regex.yml +0 -21
  155. data/spec/integration/matcher_operator_data/type_decimal.yml +3 -2
  156. data/spec/integration/matcher_operator_spec.rb +3 -5
  157. data/spec/integration/persistence/range_field_spec.rb +350 -0
  158. data/spec/mongoid/association/counter_cache_spec.rb +1 -1
  159. data/spec/mongoid/association/depending_spec.rb +9 -9
  160. data/spec/mongoid/association/eager_spec.rb +2 -1
  161. data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +2 -1
  162. data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +54 -0
  163. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +69 -9
  164. data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +112 -0
  165. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +198 -8
  166. data/spec/mongoid/association/embedded/embeds_many_models.rb +36 -0
  167. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +12 -0
  168. data/spec/mongoid/association/embedded/embeds_many_spec.rb +68 -0
  169. data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +25 -0
  170. data/spec/mongoid/association/embedded/embeds_one_models.rb +19 -0
  171. data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -0
  172. data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +2 -1
  173. data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +54 -0
  174. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +15 -0
  175. data/spec/mongoid/association/referenced/belongs_to_models.rb +11 -0
  176. data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -2
  177. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +36 -99
  178. data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +25 -0
  179. data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +35 -2
  180. data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +109 -0
  181. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +2 -56
  182. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +60 -239
  183. data/spec/mongoid/association/referenced/has_many_models.rb +3 -1
  184. data/spec/mongoid/association/referenced/has_many_spec.rb +25 -0
  185. data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +2 -2
  186. data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +107 -1
  187. data/spec/mongoid/association/referenced/has_one_models.rb +16 -0
  188. data/spec/mongoid/association/syncable_spec.rb +14 -0
  189. data/spec/mongoid/atomic/paths_spec.rb +0 -14
  190. data/spec/mongoid/attributes/nested_spec.rb +73 -198
  191. data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
  192. data/spec/mongoid/attributes/projector_spec.rb +1 -5
  193. data/spec/mongoid/attributes/readonly_spec.rb +0 -387
  194. data/spec/mongoid/attributes_spec.rb +480 -27
  195. data/spec/mongoid/cacheable_spec.rb +3 -3
  196. data/spec/mongoid/changeable_spec.rb +130 -31
  197. data/spec/mongoid/clients/factory_spec.rb +22 -60
  198. data/spec/mongoid/clients/sessions_spec.rb +0 -38
  199. data/spec/mongoid/clients_spec.rb +2 -2
  200. data/spec/mongoid/config_spec.rb +52 -15
  201. data/spec/mongoid/contextual/aggregable/memory_spec.rb +371 -231
  202. data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
  203. data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +62 -0
  204. data/spec/mongoid/contextual/map_reduce_spec.rb +2 -16
  205. data/spec/mongoid/contextual/memory_spec.rb +467 -156
  206. data/spec/mongoid/contextual/mongo_spec.rb +566 -426
  207. data/spec/mongoid/contextual/none_spec.rb +8 -34
  208. data/spec/mongoid/copyable_spec.rb +451 -2
  209. data/spec/mongoid/criteria/findable_spec.rb +86 -210
  210. data/spec/mongoid/criteria/includable_spec.rb +1492 -0
  211. data/spec/mongoid/criteria/includable_spec_models.rb +54 -0
  212. data/spec/mongoid/criteria/marshalable_spec.rb +18 -1
  213. data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +7 -19
  214. data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +134 -26
  215. data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +1 -2
  216. data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +11 -0
  217. data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +11 -0
  218. data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +1 -2
  219. data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +0 -15
  220. data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +73 -7
  221. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +11 -0
  222. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +11 -0
  223. data/spec/mongoid/criteria/queryable/optional_spec.rb +0 -484
  224. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +28 -7
  225. data/spec/mongoid/criteria/queryable/selectable_spec.rb +77 -85
  226. data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +0 -200
  227. data/spec/mongoid/criteria/queryable/selector_spec.rb +16 -77
  228. data/spec/mongoid/criteria/queryable/storable_spec.rb +0 -72
  229. data/spec/mongoid/criteria_spec.rb +463 -1214
  230. data/spec/mongoid/document_fields_spec.rb +173 -24
  231. data/spec/mongoid/document_spec.rb +32 -41
  232. data/spec/mongoid/equality_spec.rb +12 -12
  233. data/spec/mongoid/errors/document_not_found_spec.rb +29 -2
  234. data/spec/mongoid/errors/invalid_field_spec.rb +1 -1
  235. data/spec/mongoid/errors/invalid_field_type_spec.rb +55 -0
  236. data/spec/mongoid/errors/mongoid_error_spec.rb +3 -1
  237. data/spec/mongoid/errors/no_environment_spec.rb +3 -3
  238. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +1 -1
  239. data/spec/mongoid/extensions/array_spec.rb +16 -2
  240. data/spec/mongoid/extensions/big_decimal_spec.rb +697 -212
  241. data/spec/mongoid/extensions/binary_spec.rb +44 -9
  242. data/spec/mongoid/extensions/boolean_spec.rb +68 -82
  243. data/spec/mongoid/extensions/date_class_mongoize_spec.rb +7 -3
  244. data/spec/mongoid/extensions/date_spec.rb +71 -1
  245. data/spec/mongoid/extensions/date_time_spec.rb +15 -9
  246. data/spec/mongoid/extensions/float_spec.rb +48 -76
  247. data/spec/mongoid/extensions/hash_spec.rb +30 -236
  248. data/spec/mongoid/extensions/integer_spec.rb +45 -66
  249. data/spec/mongoid/extensions/range_spec.rb +255 -54
  250. data/spec/mongoid/extensions/regexp_spec.rb +58 -33
  251. data/spec/mongoid/extensions/set_spec.rb +106 -0
  252. data/spec/mongoid/extensions/string_spec.rb +53 -25
  253. data/spec/mongoid/extensions/symbol_spec.rb +18 -25
  254. data/spec/mongoid/extensions/time_spec.rb +634 -66
  255. data/spec/mongoid/extensions/time_with_zone_spec.rb +17 -31
  256. data/spec/mongoid/factory_spec.rb +61 -1
  257. data/spec/mongoid/fields_spec.rb +321 -50
  258. data/spec/mongoid/findable_spec.rb +64 -43
  259. data/spec/mongoid/indexable/specification_spec.rb +2 -2
  260. data/spec/mongoid/indexable_spec.rb +16 -19
  261. data/spec/mongoid/interceptable_spec.rb +584 -5
  262. data/spec/mongoid/interceptable_spec_models.rb +235 -4
  263. data/spec/mongoid/matcher/extract_attribute_spec.rb +1 -5
  264. data/spec/mongoid/mongoizable_spec.rb +285 -0
  265. data/spec/mongoid/persistable/creatable_spec.rb +2 -2
  266. data/spec/mongoid/persistable/deletable_spec.rb +2 -2
  267. data/spec/mongoid/persistable/destroyable_spec.rb +2 -2
  268. data/spec/mongoid/persistable/upsertable_spec.rb +14 -0
  269. data/spec/mongoid/persistence_context_spec.rb +24 -0
  270. data/spec/mongoid/query_cache_middleware_spec.rb +0 -18
  271. data/spec/mongoid/query_cache_spec.rb +1 -156
  272. data/spec/mongoid/reloadable_spec.rb +35 -2
  273. data/spec/mongoid/scopable_spec.rb +38 -150
  274. data/spec/mongoid/serializable_spec.rb +14 -7
  275. data/spec/mongoid/shardable_models.rb +0 -14
  276. data/spec/mongoid/shardable_spec.rb +61 -153
  277. data/spec/mongoid/stateful_spec.rb +28 -0
  278. data/spec/mongoid/timestamps_spec.rb +390 -0
  279. data/spec/mongoid/timestamps_spec_models.rb +67 -0
  280. data/spec/mongoid/touchable_spec.rb +116 -0
  281. data/spec/mongoid/touchable_spec_models.rb +12 -8
  282. data/spec/mongoid/traversable_spec.rb +4 -11
  283. data/spec/mongoid/validatable/presence_spec.rb +1 -1
  284. data/spec/mongoid/validatable/uniqueness_spec.rb +60 -31
  285. data/spec/mongoid/warnings_spec.rb +35 -0
  286. data/spec/mongoid_spec.rb +1 -7
  287. data/spec/rails/controller_extension/controller_runtime_spec.rb +2 -2
  288. data/spec/rails/mongoid_spec.rb +4 -16
  289. data/spec/shared/lib/mrss/cluster_config.rb +40 -5
  290. data/spec/shared/lib/mrss/constraints.rb +46 -7
  291. data/spec/shared/lib/mrss/docker_runner.rb +21 -17
  292. data/spec/shared/lib/mrss/eg_config_utils.rb +31 -0
  293. data/spec/shared/lib/mrss/event_subscriber.rb +5 -15
  294. data/spec/shared/lib/mrss/lite_constraints.rb +2 -10
  295. data/spec/shared/lib/mrss/server_version_registry.rb +29 -18
  296. data/spec/shared/lib/mrss/spec_organizer.rb +3 -32
  297. data/spec/shared/lib/mrss/utils.rb +6 -28
  298. data/spec/shared/share/Dockerfile.erb +114 -38
  299. data/spec/shared/shlib/distro.sh +0 -10
  300. data/spec/shared/shlib/server.sh +83 -64
  301. data/spec/shared/shlib/set_env.sh +81 -16
  302. data/spec/spec_helper.rb +0 -8
  303. data/spec/support/constraints.rb +24 -0
  304. data/spec/support/expectations.rb +17 -20
  305. data/spec/support/macros.rb +30 -0
  306. data/spec/support/models/augmentation.rb +12 -0
  307. data/spec/support/models/band.rb +3 -0
  308. data/spec/support/models/catalog.rb +24 -0
  309. data/spec/support/models/circus.rb +3 -0
  310. data/spec/support/models/{delete_all_tag.rb → fanatic.rb} +3 -2
  311. data/spec/support/models/implant.rb +9 -0
  312. data/spec/support/models/label.rb +2 -0
  313. data/spec/support/models/passport.rb +9 -0
  314. data/spec/support/models/person.rb +1 -0
  315. data/spec/support/models/player.rb +2 -0
  316. data/spec/support/models/powerup.rb +12 -0
  317. data/spec/support/models/registry.rb +1 -0
  318. data/spec/support/models/school.rb +14 -0
  319. data/spec/support/models/shield.rb +18 -0
  320. data/spec/support/models/student.rb +14 -0
  321. data/spec/support/models/weapon.rb +12 -0
  322. data.tar.gz.sig +0 -0
  323. metadata +1838 -1820
  324. metadata.gz.sig +0 -0
  325. data/lib/mongoid/errors/eager_load.rb +0 -23
  326. data/lib/mongoid/errors/in_memory_regexp_timeout.rb +0 -26
  327. data/lib/mongoid/errors/invalid_value.rb +0 -17
  328. data/lib/mongoid/field_readable.rb +0 -70
  329. data/lib/mongoid/matcher/regexp_budget.rb +0 -389
  330. data/spec/integration/matcher_regexp_timeout_spec.rb +0 -215
  331. data/spec/integration/query_operator_guard_spec.rb +0 -94
  332. data/spec/mongoid/attributes/readonly_dotted_spec.rb +0 -286
  333. data/spec/mongoid/errors/eager_load_spec.rb +0 -31
  334. data/spec/mongoid/matcher/regexp_budget_spec.rb +0 -576
  335. data/spec/shared/CANDIDATE.md +0 -28
  336. data/spec/shared/lib/mrss/release/candidate.rb +0 -287
  337. data/spec/shared/lib/mrss/release/product_data.rb +0 -144
  338. data/spec/shared/lib/tasks/candidate.rake +0 -64
  339. data/spec/support/models/delete_all_account.rb +0 -10
  340. data/spec/support/models/delete_all_item.rb +0 -9
  341. data/spec/support/models/delete_all_scoped_item.rb +0 -11
@@ -1,215 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'benchmark'
4
- require 'spec_helper'
5
-
6
- describe 'in-memory regexp time limit' do
7
- # See the comment in spec/mongoid/matcher/regexp_budget_spec.rb: costly to
8
- # match but bounded on every supported Ruby. A pattern relying on nested
9
- # quantifiers would hang before Ruby 3.2, where the examples that have no
10
- # interrupt available could not stop it.
11
- let(:slow_pattern) { "(?:#{(1..300).map { |i| "a#{i}" }.join('|')})Z" }
12
- let(:slow_street) { 'a' * 5_000 }
13
-
14
- let(:person) do
15
- # Address derives its _id from the street, so the streets have to differ or
16
- # the embedded association collapses to a single document.
17
- Person.new(addresses: Array.new(30) { |i| Address.new(street: "#{slow_street}#{i}") })
18
- end
19
-
20
- let(:one_address) { Person.new(addresses: [ Address.new(street: slow_street) ]) }
21
-
22
- # What one match of the fixture costs on the machine running the suite. It
23
- # varies by more than an order of magnitude between implementations - around
24
- # 6ms on MRI, 110ms on JRuby - so the examples below calibrate against a
25
- # measurement instead of hard-coding a threshold that only holds on one.
26
- let(:single_match_cost) do
27
- regexp = Regexp.new(slow_pattern)
28
- 3.times { slow_street =~ regexp }
29
- Benchmark.realtime { slow_street =~ regexp }
30
- end
31
-
32
- # Comfortably more than one match, comfortably less than twenty. The examples
33
- # only need the ordering to hold, so the margin either side is wide.
34
- let(:calibrated_limit) { single_match_cost * 5 }
35
-
36
- context 'when the limit is disabled' do
37
- config_override :in_memory_regexp_time_limit, nil
38
-
39
- it 'evaluates the query without a bound' do
40
- expect(person.addresses.where(street: { '$regex' => slow_pattern }).to_a).to eq([])
41
- end
42
- end
43
-
44
- context 'when a limit is configured' do
45
- config_override :in_memory_regexp_time_limit, nil
46
-
47
- before { Mongoid::Config.in_memory_regexp_time_limit = calibrated_limit }
48
-
49
- it 'leaves ordinary queries alone' do
50
- person = Person.new(addresses: [ Address.new(street: 'Clarkson') ])
51
- expect(person.addresses.where(street: { '$regex' => '\AClark' }).to_a.size).to eq(1)
52
- end
53
-
54
- it 'does not raise for a single document' do
55
- # The counterpart to the example below, and what makes it meaningful: one
56
- # document stays under the limit, so a scan that raises can only have got
57
- # there by accumulating cost across documents.
58
- expect do
59
- one_address.addresses.where(street: { '$regex' => slow_pattern }).to_a
60
- end.not_to raise_error
61
- end
62
-
63
- it 'raises for a scan over many documents under that same limit' do
64
- expect do
65
- person.addresses.where(street: { '$regex' => slow_pattern }).to_a
66
- end.to raise_error(Mongoid::Errors::InMemoryRegexpTimeout)
67
- end
68
-
69
- it 'raises when $in multiplies the cost within a single document' do
70
- conditions = Array.new(20) { BSON::Regexp::Raw.new(slow_pattern) }
71
-
72
- expect do
73
- one_address.addresses.where(street: { '$in' => conditions }).to_a
74
- end.to raise_error(Mongoid::Errors::InMemoryRegexpTimeout)
75
- end
76
-
77
- it 'raises through the public _matches? API' do
78
- # 20 conditions rather than one, because a single match is deliberately
79
- # kept well under the limit by the calibration above.
80
- conditions = Array.new(20) { BSON::Regexp::Raw.new(slow_pattern) }
81
-
82
- expect do
83
- person.addresses.first._matches?('street' => { '$in' => conditions })
84
- end.to raise_error(Mongoid::Errors::InMemoryRegexpTimeout)
85
- end
86
- end
87
-
88
- context 'when the pattern is pathological' do
89
- config_override :in_memory_regexp_time_limit, 0.2
90
-
91
- # The ticket's Case 1, verbatim. It backtracks exponentially and is the
92
- # reason the guard exists, so every entry point that evaluates a selector
93
- # in memory has to bound it. The subject is kept short enough that the
94
- # match still finishes on its own in a few seconds, so an entry point that
95
- # fails to bound it shows up as a failing example rather than a hung run.
96
- let(:evil_pattern) { '^(a+)+\1?$' }
97
- let(:evil_subject) { "#{'a' * 28}X" }
98
-
99
- it 'bounds a scan over an embedded association' do
100
- person = Person.new(addresses: [ Address.new(street: evil_subject) ])
101
-
102
- expect do
103
- person.addresses.where(street: { '$regex' => evil_pattern }).to_a
104
- end.to raise_error(Mongoid::Errors::InMemoryRegexpTimeout)
105
- end
106
-
107
- it 'bounds the public _matches? API' do
108
- expect do
109
- Address.new(street: evil_subject)._matches?('street' => { '$regex' => evil_pattern })
110
- end.to raise_error(Mongoid::Errors::InMemoryRegexpTimeout)
111
- end
112
-
113
- it 'bounds removal from a referenced association' do
114
- owner = Person.create!
115
- owner.posts.create!(title: evil_subject)
116
-
117
- expect do
118
- owner.posts.delete_all(title: { '$regex' => evil_pattern })
119
- end.to raise_error(Mongoid::Errors::InMemoryRegexpTimeout)
120
- end
121
-
122
- it 'deletes nothing when removal is bounded' do
123
- # The scan runs before the delete, so the error means what a caller would
124
- # take it to mean: the documents are still there.
125
- owner = Person.create!
126
- owner.posts.create!(title: evil_subject)
127
-
128
- expect do
129
- owner.posts.delete_all(title: { '$regex' => evil_pattern })
130
- end.to raise_error(Mongoid::Errors::InMemoryRegexpTimeout)
131
-
132
- expect(Post.count).to eq(1)
133
- expect(owner.reload.posts.size).to eq(1)
134
- end
135
- end
136
-
137
- context 'when the association being removed from has not been loaded' do
138
- config_override :in_memory_regexp_time_limit, 0.2
139
-
140
- let!(:owner) do
141
- person = Person.create!
142
- person.posts.create!(title: 'Testing')
143
- Person.find(person._id)
144
- end
145
-
146
- # The query that loads the association, which removal has to run before it
147
- # has anything to match against.
148
- let(:load_query) { owner.posts._target._unloaded }
149
-
150
- # A stall standing in for a slow network. It is longer than the limit, and
151
- # none of it is time spent on regular expressions.
152
- before do
153
- allow(load_query).to receive(:each).and_wrap_original do |original, *args, &block|
154
- sleep(0.3)
155
- original.call(*args, &block)
156
- end
157
- end
158
-
159
- it 'does not load it, so no query can be counted against the limit' do
160
- # On the Timeout path a deadline covering the fetch failed a slow query
161
- # with an error about regular expressions, and the asynchronous exception
162
- # could land inside the driver's socket read, leaving the connection with
163
- # unconsumed bytes. Nothing is fetched now: the scan sees only what the
164
- # association already holds.
165
- stub_const('Mongoid::Matcher::RegexpBudget::PER_REGEXP_TIMEOUT', false)
166
-
167
- expect do
168
- owner.posts.delete_all(title: { '$regex' => '\Azzz' })
169
- end.not_to raise_error
170
-
171
- expect(load_query).not_to have_received(:each)
172
- end
173
-
174
- it 'runs no pattern against documents it never loaded' do
175
- # The counterpart to the referenced-association examples below, where the
176
- # documents are in memory and the pattern is run against every one of
177
- # them. Here there is nothing to run it against, and the server applies
178
- # the same selector for the delete, so nothing is missed by not looking.
179
- expect(Mongoid::Matcher::RegexpBudget).not_to receive(:match?)
180
-
181
- owner.posts.delete_all(title: { '$regex' => '\Azzz' })
182
- end
183
-
184
- it 'still removes the documents that match' do
185
- expect(owner.posts.delete_all(title: { '$regex' => '\ATest' })).to eq(1)
186
- expect(Post.count).to eq(0)
187
- expect(owner.posts.size).to eq(0)
188
- end
189
- end
190
-
191
- context 'when removing documents from a referenced association' do
192
- config_override :in_memory_regexp_time_limit, nil
193
-
194
- let!(:owner) { Person.create! }
195
-
196
- before do
197
- 30.times { owner.posts.create!(title: slow_street) }
198
- Mongoid::Config.in_memory_regexp_time_limit = calibrated_limit
199
- end
200
-
201
- it 'raises rather than scanning every loaded document' do
202
- expect do
203
- owner.posts.delete_all(title: { '$regex' => slow_pattern })
204
- end.to raise_error(Mongoid::Errors::InMemoryRegexpTimeout)
205
- end
206
-
207
- it 'leaves the documents in place' do
208
- expect do
209
- owner.posts.delete_all(title: { '$regex' => slow_pattern })
210
- end.to raise_error(Mongoid::Errors::InMemoryRegexpTimeout)
211
-
212
- expect(Post.count).to eq(30)
213
- end
214
- end
215
- end
@@ -1,94 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'query operator injection guard' do
6
- let(:js) { 'this.name == "admin"' }
7
-
8
- let(:nested_function) do
9
- { '$expr' => { '$function' => { 'body' => 'function() { return true; }', 'args' => [], 'lang' => 'js' } } }
10
- end
11
-
12
- let(:band) { Band.create!(name: 'Depeche Mode') }
13
-
14
- context 'with default configuration' do
15
- it 'rejects unsafe operators without any opt-out' do
16
- expect(Mongoid.allow_unsafe_query_operators).to be false
17
- end
18
-
19
- context 'when querying with where' do
20
- it 'rejects a top-level $where' do
21
- expect { Band.where('$where' => js).first }.to raise_error(Mongoid::Errors::InvalidQuery)
22
- end
23
-
24
- it 'rejects a $function nested in $expr' do
25
- expect { Band.where(nested_function).first }.to raise_error(Mongoid::Errors::InvalidQuery)
26
- end
27
-
28
- it 'permits an ordinary query' do
29
- expect(Band.where(name: band.name).first).to eq(band)
30
- end
31
- end
32
-
33
- context 'when querying with find_by' do
34
- it 'rejects a top-level $where' do
35
- expect { Band.find_by('$where' => js) }.to raise_error(Mongoid::Errors::InvalidQuery)
36
- end
37
-
38
- it 'rejects a $function nested in $expr' do
39
- expect { Band.find_by(nested_function) }.to raise_error(Mongoid::Errors::InvalidQuery)
40
- end
41
- end
42
-
43
- context 'when querying with find_or_create_by' do
44
- it 'rejects a top-level $where' do
45
- expect { Band.find_or_create_by('$where' => js) }.to raise_error(Mongoid::Errors::InvalidQuery)
46
- end
47
- end
48
-
49
- context 'when querying with find_or_initialize_by' do
50
- it 'rejects a top-level $where' do
51
- expect { Band.find_or_initialize_by('$where' => js) }.to raise_error(Mongoid::Errors::InvalidQuery)
52
- end
53
- end
54
-
55
- context 'when querying an association with find_or_create_by' do
56
- it 'rejects a top-level $where' do
57
- expect do
58
- band.records.find_or_create_by('$where' => js)
59
- end.to raise_error(Mongoid::Errors::InvalidQuery)
60
- end
61
- end
62
-
63
- context 'when querying with a logical operator' do
64
- it 'rejects a $where smuggled through or' do
65
- expect { Band.or('$where' => js).first }.to raise_error(Mongoid::Errors::InvalidQuery)
66
- end
67
-
68
- it 'rejects a $where smuggled through any_of' do
69
- expect { Band.any_of('$where' => js).first }.to raise_error(Mongoid::Errors::InvalidQuery)
70
- end
71
-
72
- it 'rejects a $where smuggled through multi-criteria any_of' do
73
- expect { Band.any_of({ '$where' => js }, { name: band.name }).first }
74
- .to raise_error(Mongoid::Errors::InvalidQuery)
75
- end
76
- end
77
- end
78
-
79
- context 'when allow_unsafe_query_operators is true' do
80
- config_override :allow_unsafe_query_operators, true
81
-
82
- it 'permits a top-level $where' do
83
- expect(Band.where('$where' => "this.name == '#{band.name}'").first).to eq(band)
84
- end
85
-
86
- it 'permits a $function nested in $expr' do
87
- expect { Band.where(nested_function).first }.not_to raise_error
88
- end
89
-
90
- it 'permits a $where smuggled through or' do
91
- expect { Band.or('$where' => js).first }.not_to raise_error
92
- end
93
- end
94
- end
@@ -1,286 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'Readonly dotted attributes' do
6
- let(:model_class) do
7
- test_model do
8
- field :stored_settings, as: :settings, type: Hash
9
- field :other_settings, type: Hash
10
- attr_readonly :settings
11
- end
12
- end
13
-
14
- let(:document) do
15
- model_class.create!(settings: { 'is_admin' => false }, other_settings: { 'enabled' => false })
16
- end
17
-
18
- def expect_stored_value(field, value)
19
- expect(model_class.collection.find(_id: document.id).first[field]).to eq(value)
20
- end
21
-
22
- shared_examples 'a readonly dotted attribute' do |path, field, original_value|
23
- it 'ignores write_attribute' do
24
- document.write_attribute(path, true)
25
- document.save!
26
-
27
- expect_stored_value(field, original_value)
28
- end
29
-
30
- it 'ignores the bracket setter' do
31
- document[path.to_sym] = true
32
- document.save!
33
-
34
- expect_stored_value(field, original_value)
35
- end
36
-
37
- it 'raises ReadonlyAttribute from update_attribute' do
38
- expect do
39
- document.update_attribute(path, true)
40
- end.to raise_error(Mongoid::Errors::ReadonlyAttribute)
41
-
42
- expect_stored_value(field, original_value)
43
- end
44
- end
45
-
46
- context 'without dynamic attributes' do
47
- context 'with the database field name' do
48
- include_examples 'a readonly dotted attribute',
49
- 'stored_settings.is_admin', 'stored_settings', { 'is_admin' => false }
50
- end
51
-
52
- context 'with the field alias' do
53
- include_examples 'a readonly dotted attribute',
54
- 'settings.is_admin', 'stored_settings', { 'is_admin' => false }
55
- end
56
-
57
- context 'with a new key in the readonly field' do
58
- include_examples 'a readonly dotted attribute',
59
- 'settings.new_key', 'stored_settings', { 'is_admin' => false }
60
- end
61
-
62
- context 'with a deeply nested key' do
63
- let(:document) do
64
- model_class.create!(settings: { 'permissions' => { 'is_admin' => false } })
65
- end
66
-
67
- include_examples 'a readonly dotted attribute',
68
- 'settings.permissions.is_admin', 'stored_settings', { 'permissions' => { 'is_admin' => false } }
69
- end
70
-
71
- it 'allows the readonly field to be initialized on a new document' do
72
- expect_stored_value('stored_settings', 'is_admin' => false)
73
- end
74
-
75
- it 'allows dotted writes to an unprotected field' do
76
- document.write_attribute('other_settings.enabled', true)
77
- document.save!
78
-
79
- expect_stored_value('other_settings', 'enabled' => true)
80
- end
81
-
82
- it 'continues to protect an exact dotted readonly name' do
83
- model_class.attr_readonly('other_settings.enabled')
84
- document.write_attribute('other_settings.enabled', true)
85
- document.save!
86
-
87
- expect_stored_value('other_settings', 'enabled' => false)
88
- end
89
-
90
- it 'rejects an unknown dotted field during mass assignment' do
91
- expect do
92
- document.update('stored_settings.is_admin' => true)
93
- end.to raise_error(Mongoid::Errors::UnknownAttribute)
94
-
95
- expect_stored_value('stored_settings', 'is_admin' => false)
96
- end
97
- end
98
-
99
- context 'with dynamic attributes' do
100
- let(:model_class) do
101
- test_model do
102
- include Mongoid::Attributes::Dynamic
103
-
104
- field :stored_settings, as: :settings, type: Hash
105
- field :other_settings, type: Hash
106
- attr_readonly :settings
107
- end
108
- end
109
-
110
- context 'with the database field name' do
111
- include_examples 'a readonly dotted attribute',
112
- 'stored_settings.is_admin', 'stored_settings', { 'is_admin' => false }
113
- end
114
-
115
- context 'with the field alias' do
116
- include_examples 'a readonly dotted attribute',
117
- 'settings.is_admin', 'stored_settings', { 'is_admin' => false }
118
- end
119
-
120
- context 'with a new key in the readonly field' do
121
- include_examples 'a readonly dotted attribute',
122
- 'settings.new_key', 'stored_settings', { 'is_admin' => false }
123
-
124
- it 'ignores mass assignment' do
125
- document.update('settings.new_key' => true)
126
-
127
- expect_stored_value('stored_settings', 'is_admin' => false)
128
- end
129
- end
130
-
131
- context 'with a deeply nested key' do
132
- let(:document) do
133
- model_class.create!(settings: { 'permissions' => { 'is_admin' => false } })
134
- end
135
-
136
- include_examples 'a readonly dotted attribute',
137
- 'settings.permissions.is_admin', 'stored_settings', { 'permissions' => { 'is_admin' => false } }
138
-
139
- it 'ignores mass assignment' do
140
- document.update('settings.permissions.is_admin' => true)
141
-
142
- expect_stored_value('stored_settings', 'permissions' => { 'is_admin' => false })
143
- end
144
- end
145
-
146
- it 'ignores mass assignment using the database field name' do
147
- document.update('stored_settings.is_admin' => true)
148
-
149
- expect_stored_value('stored_settings', 'is_admin' => false)
150
- end
151
-
152
- it 'ignores mass assignment using the field alias' do
153
- document.update('settings.is_admin' => true)
154
-
155
- expect_stored_value('stored_settings', 'is_admin' => false)
156
- end
157
-
158
- it 'does not persist the dotted field through update_attribute' do
159
- begin
160
- document.update_attribute('settings.is_admin', true)
161
- rescue Mongoid::Errors::ReadonlyAttribute
162
- # update_attribute is expected to raise for readonly attributes.
163
- end
164
-
165
- expect_stored_value('stored_settings', 'is_admin' => false)
166
- end
167
- end
168
-
169
- context 'when a nested path is readonly' do
170
- let(:model_class) do
171
- test_model do
172
- field :stored_settings, as: :settings, type: Hash
173
- attr_readonly 'settings.permissions.protected'
174
- end
175
- end
176
-
177
- let(:document) do
178
- model_class.create!(settings: { 'permissions' => { 'protected' => { 'is_admin' => false } } })
179
- end
180
-
181
- include_examples 'a readonly dotted attribute',
182
- 'settings.permissions.protected.is_admin', 'stored_settings',
183
- { 'permissions' => { 'protected' => { 'is_admin' => false } } }
184
-
185
- include_examples 'a readonly dotted attribute',
186
- 'stored_settings.permissions.protected.is_admin', 'stored_settings',
187
- { 'permissions' => { 'protected' => { 'is_admin' => false } } }
188
-
189
- it 'allows the bracket setter for the top-level parent' do
190
- document[:settings] = { 'permissions' => { 'protected' => { 'is_admin' => true } } }
191
- document.save!
192
-
193
- expect_stored_value('stored_settings', 'permissions' => { 'protected' => { 'is_admin' => true } })
194
- end
195
-
196
- it 'allows mass assignment to the top-level parent' do
197
- document.update(settings: { 'permissions' => { 'protected' => { 'is_admin' => true } } })
198
-
199
- expect_stored_value('stored_settings', 'permissions' => { 'protected' => { 'is_admin' => true } })
200
- end
201
-
202
- it 'allows update_attribute on the top-level parent' do
203
- document.update_attribute('settings', 'permissions' => { 'protected' => { 'is_admin' => true } })
204
-
205
- expect_stored_value('stored_settings', 'permissions' => { 'protected' => { 'is_admin' => true } })
206
- end
207
-
208
- it 'allows removing the top-level parent' do
209
- document.remove_attribute('settings')
210
- document.save!
211
-
212
- expect_stored_value('stored_settings', nil)
213
- end
214
-
215
- it 'allows an in-place change to the parent hash' do
216
- document.settings['permissions']['protected']['is_admin'] = true
217
- document.save!
218
-
219
- expect_stored_value('stored_settings', 'permissions' => { 'protected' => { 'is_admin' => true } })
220
- end
221
-
222
- it 'allows replacing a parent inside the hash' do
223
- document.settings['permissions'] = { 'protected' => { 'is_admin' => true } }
224
- document.save!
225
-
226
- expect_stored_value('stored_settings', 'permissions' => { 'protected' => { 'is_admin' => true } })
227
- end
228
-
229
- context 'with dynamic attributes' do
230
- let(:model_class) do
231
- test_model do
232
- include Mongoid::Attributes::Dynamic
233
-
234
- field :stored_settings, as: :settings, type: Hash
235
- attr_readonly 'settings.permissions.protected'
236
- end
237
- end
238
-
239
- include_examples 'a readonly dotted attribute',
240
- 'settings.permissions.protected.is_admin', 'stored_settings',
241
- { 'permissions' => { 'protected' => { 'is_admin' => false } } }
242
-
243
- it 'ignores mass assignment to a descendant' do
244
- document.update('settings.permissions.protected.is_admin' => true)
245
-
246
- expect_stored_value('stored_settings', 'permissions' => { 'protected' => { 'is_admin' => false } })
247
- end
248
- end
249
- end
250
-
251
- context 'with a separate field whose name contains a dot' do
252
- let(:document) { model_class.create!(settings: { 'theme' => 'light' }) }
253
-
254
- context 'when the dotted field is readonly' do
255
- let(:model_class) do
256
- test_model do
257
- field :settings, type: Hash
258
- field :'settings.is_admin', type: String, default: 'literal field'
259
- attr_readonly :'settings.is_admin'
260
- end
261
- end
262
-
263
- it 'allows updating the separate field' do
264
- document.settings = { 'theme' => 'dark' }
265
- document.save!
266
-
267
- expect_stored_value('settings', 'theme' => 'dark')
268
- expect_stored_value('settings.is_admin', 'literal field')
269
- end
270
-
271
- it 'allows updating a nested hash with the same name as the dotted field' do
272
- document.write_attribute('settings.is_admin.enabled', true)
273
- document.save!
274
-
275
- expect_stored_value('settings', 'theme' => 'light', 'is_admin' => { 'enabled' => true })
276
- expect_stored_value('settings.is_admin', 'literal field')
277
- end
278
-
279
- it 'still treats the dotted field as readonly' do
280
- expect do
281
- document.update_attribute('settings.is_admin', 'new value')
282
- end.to raise_error(Mongoid::Errors::ReadonlyAttribute)
283
- end
284
- end
285
- end
286
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe Mongoid::Errors::EagerLoad do
6
-
7
- describe "#message" do
8
-
9
- let(:error) do
10
- described_class.new(:ratable)
11
- end
12
-
13
- it "contains the problem in the message" do
14
- expect(error.message).to include(
15
- "Eager loading :ratable is not supported since it is a polymorphic"
16
- )
17
- end
18
-
19
- it "contains the summary in the message" do
20
- expect(error.message).to include(
21
- "Mongoid cannot currently determine the classes it needs to eager"
22
- )
23
- end
24
-
25
- it "contains the resolution in the message" do
26
- expect(error.message).to include(
27
- "Don't attempt to perform this action and have patience"
28
- )
29
- end
30
- end
31
- end