mongoid 7.5.4 → 8.1.9

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 (446) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -3
  3. data/README.md +6 -6
  4. data/Rakefile +44 -46
  5. data/lib/config/locales/en.yml +92 -43
  6. data/lib/mongoid/association/accessors.rb +44 -11
  7. data/lib/mongoid/association/bindable.rb +50 -2
  8. data/lib/mongoid/association/builders.rb +5 -3
  9. data/lib/mongoid/association/constrainable.rb +0 -1
  10. data/lib/mongoid/association/eager_loadable.rb +32 -7
  11. data/lib/mongoid/association/embedded/batchable.rb +34 -11
  12. data/lib/mongoid/association/embedded/cyclic.rb +1 -1
  13. data/lib/mongoid/association/embedded/embedded_in/binding.rb +24 -2
  14. data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -2
  15. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +4 -3
  16. data/lib/mongoid/association/embedded/embedded_in.rb +3 -2
  17. data/lib/mongoid/association/embedded/embeds_many/binding.rb +1 -0
  18. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +4 -3
  19. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +85 -46
  20. data/lib/mongoid/association/embedded/embeds_many.rb +2 -2
  21. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +19 -5
  22. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +24 -5
  23. data/lib/mongoid/association/embedded/embeds_one.rb +3 -3
  24. data/lib/mongoid/association/macros.rb +8 -1
  25. data/lib/mongoid/association/many.rb +11 -7
  26. data/lib/mongoid/association/nested/many.rb +5 -4
  27. data/lib/mongoid/association/nested/nested_buildable.rb +4 -4
  28. data/lib/mongoid/association/nested/one.rb +45 -7
  29. data/lib/mongoid/association/one.rb +2 -2
  30. data/lib/mongoid/association/options.rb +9 -9
  31. data/lib/mongoid/association/proxy.rb +15 -4
  32. data/lib/mongoid/association/referenced/auto_save.rb +4 -3
  33. data/lib/mongoid/association/referenced/belongs_to/binding.rb +1 -0
  34. data/lib/mongoid/association/referenced/belongs_to/buildable.rb +1 -1
  35. data/lib/mongoid/association/referenced/belongs_to/proxy.rb +5 -6
  36. data/lib/mongoid/association/referenced/belongs_to.rb +2 -2
  37. data/lib/mongoid/association/referenced/counter_cache.rb +10 -10
  38. data/lib/mongoid/association/referenced/eager.rb +2 -2
  39. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +70 -13
  40. data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +6 -3
  41. data/lib/mongoid/association/referenced/has_many/enumerable.rb +22 -30
  42. data/lib/mongoid/association/referenced/has_many/proxy.rb +40 -21
  43. data/lib/mongoid/association/referenced/has_many.rb +3 -3
  44. data/lib/mongoid/association/referenced/has_one/buildable.rb +1 -1
  45. data/lib/mongoid/association/referenced/has_one/nested_builder.rb +5 -5
  46. data/lib/mongoid/association/referenced/has_one/proxy.rb +9 -12
  47. data/lib/mongoid/association/referenced/has_one.rb +3 -3
  48. data/lib/mongoid/association/referenced/syncable.rb +4 -4
  49. data/lib/mongoid/association/reflections.rb +4 -4
  50. data/lib/mongoid/association/relatable.rb +44 -10
  51. data/lib/mongoid/association.rb +5 -5
  52. data/lib/mongoid/atomic/modifiers.rb +2 -2
  53. data/lib/mongoid/atomic.rb +16 -7
  54. data/lib/mongoid/attributes/dynamic.rb +4 -4
  55. data/lib/mongoid/attributes/nested.rb +6 -6
  56. data/lib/mongoid/attributes/processing.rb +37 -6
  57. data/lib/mongoid/attributes/projector.rb +2 -2
  58. data/lib/mongoid/attributes/readonly.rb +11 -6
  59. data/lib/mongoid/attributes.rb +51 -42
  60. data/lib/mongoid/changeable.rb +147 -14
  61. data/lib/mongoid/clients/options.rb +5 -1
  62. data/lib/mongoid/clients/sessions.rb +2 -14
  63. data/lib/mongoid/clients/storage_options.rb +2 -5
  64. data/lib/mongoid/clients/validators/storage.rb +3 -15
  65. data/lib/mongoid/collection_configurable.rb +58 -0
  66. data/lib/mongoid/composable.rb +2 -0
  67. data/lib/mongoid/config/defaults.rb +60 -0
  68. data/lib/mongoid/config/options.rb +3 -0
  69. data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
  70. data/lib/mongoid/config/validators/client.rb +6 -6
  71. data/lib/mongoid/config/validators.rb +1 -0
  72. data/lib/mongoid/config.rb +153 -18
  73. data/lib/mongoid/contextual/aggregable/memory.rb +24 -16
  74. data/lib/mongoid/contextual/aggregable/mongo.rb +5 -5
  75. data/lib/mongoid/contextual/aggregable/none.rb +1 -1
  76. data/lib/mongoid/contextual/atomic.rb +1 -1
  77. data/lib/mongoid/contextual/geo_near.rb +7 -7
  78. data/lib/mongoid/contextual/map_reduce.rb +2 -2
  79. data/lib/mongoid/contextual/memory.rb +285 -58
  80. data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
  81. data/lib/mongoid/contextual/mongo.rb +540 -346
  82. data/lib/mongoid/contextual/none.rb +193 -20
  83. data/lib/mongoid/contextual/queryable.rb +1 -1
  84. data/lib/mongoid/contextual.rb +14 -2
  85. data/lib/mongoid/copyable.rb +32 -8
  86. data/lib/mongoid/criteria/findable.rb +8 -5
  87. data/lib/mongoid/criteria/includable.rb +27 -22
  88. data/lib/mongoid/criteria/marshalable.rb +10 -2
  89. data/lib/mongoid/criteria/permission.rb +1 -1
  90. data/lib/mongoid/criteria/queryable/aggregable.rb +2 -2
  91. data/lib/mongoid/criteria/queryable/extensions/array.rb +3 -16
  92. data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +25 -4
  93. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +2 -2
  94. data/lib/mongoid/criteria/queryable/extensions/date.rb +6 -1
  95. data/lib/mongoid/criteria/queryable/extensions/date_time.rb +6 -1
  96. data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -17
  97. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +15 -9
  98. data/lib/mongoid/criteria/queryable/extensions/object.rb +2 -1
  99. data/lib/mongoid/criteria/queryable/extensions/range.rb +13 -5
  100. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +3 -3
  101. data/lib/mongoid/criteria/queryable/extensions/set.rb +1 -1
  102. data/lib/mongoid/criteria/queryable/extensions/string.rb +4 -14
  103. data/lib/mongoid/criteria/queryable/extensions/symbol.rb +4 -12
  104. data/lib/mongoid/criteria/queryable/extensions/time.rb +6 -1
  105. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +6 -1
  106. data/lib/mongoid/criteria/queryable/key.rb +4 -4
  107. data/lib/mongoid/criteria/queryable/mergeable.rb +1 -1
  108. data/lib/mongoid/criteria/queryable/optional.rb +11 -17
  109. data/lib/mongoid/criteria/queryable/options.rb +2 -2
  110. data/lib/mongoid/criteria/queryable/pipeline.rb +1 -1
  111. data/lib/mongoid/criteria/queryable/selectable.rb +48 -39
  112. data/lib/mongoid/criteria/queryable/selector.rb +92 -7
  113. data/lib/mongoid/criteria/queryable/smash.rb +40 -7
  114. data/lib/mongoid/criteria/queryable.rb +12 -7
  115. data/lib/mongoid/criteria/scopable.rb +2 -2
  116. data/lib/mongoid/criteria/translator.rb +45 -0
  117. data/lib/mongoid/criteria.rb +20 -40
  118. data/lib/mongoid/deprecable.rb +37 -0
  119. data/lib/mongoid/deprecation.rb +25 -0
  120. data/lib/mongoid/document.rb +135 -36
  121. data/lib/mongoid/equality.rb +9 -8
  122. data/lib/mongoid/errors/create_collection_failure.rb +33 -0
  123. data/lib/mongoid/errors/document_not_found.rb +10 -6
  124. data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
  125. data/lib/mongoid/errors/immutable_attribute.rb +26 -0
  126. data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
  127. data/lib/mongoid/errors/invalid_config_option.rb +1 -1
  128. data/lib/mongoid/errors/invalid_dependent_strategy.rb +1 -1
  129. data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +23 -0
  130. data/lib/mongoid/errors/invalid_field.rb +6 -2
  131. data/lib/mongoid/errors/invalid_field_type.rb +26 -0
  132. data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
  133. data/lib/mongoid/errors/invalid_relation.rb +1 -1
  134. data/lib/mongoid/errors/invalid_relation_option.rb +1 -1
  135. data/lib/mongoid/errors/invalid_session_use.rb +1 -1
  136. data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
  137. data/lib/mongoid/errors/invalid_storage_parent.rb +2 -0
  138. data/lib/mongoid/errors/mongoid_error.rb +3 -3
  139. data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -1
  140. data/lib/mongoid/errors/no_client_database.rb +1 -1
  141. data/lib/mongoid/errors/no_client_hosts.rb +1 -1
  142. data/lib/mongoid/errors/readonly_attribute.rb +1 -1
  143. data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -1
  144. data/lib/mongoid/errors/unknown_attribute.rb +1 -1
  145. data/lib/mongoid/errors.rb +6 -3
  146. data/lib/mongoid/extensions/array.rb +9 -7
  147. data/lib/mongoid/extensions/big_decimal.rb +33 -10
  148. data/lib/mongoid/extensions/binary.rb +42 -0
  149. data/lib/mongoid/extensions/boolean.rb +8 -2
  150. data/lib/mongoid/extensions/date.rb +26 -20
  151. data/lib/mongoid/extensions/date_time.rb +1 -1
  152. data/lib/mongoid/extensions/false_class.rb +1 -1
  153. data/lib/mongoid/extensions/float.rb +7 -4
  154. data/lib/mongoid/extensions/hash.rb +38 -9
  155. data/lib/mongoid/extensions/integer.rb +7 -4
  156. data/lib/mongoid/extensions/module.rb +1 -1
  157. data/lib/mongoid/extensions/object.rb +10 -8
  158. data/lib/mongoid/extensions/range.rb +41 -10
  159. data/lib/mongoid/extensions/regexp.rb +11 -4
  160. data/lib/mongoid/extensions/set.rb +11 -4
  161. data/lib/mongoid/extensions/string.rb +11 -22
  162. data/lib/mongoid/extensions/symbol.rb +4 -15
  163. data/lib/mongoid/extensions/time.rb +29 -16
  164. data/lib/mongoid/extensions/time_with_zone.rb +1 -2
  165. data/lib/mongoid/extensions/true_class.rb +1 -1
  166. data/lib/mongoid/extensions.rb +1 -0
  167. data/lib/mongoid/factory.rb +55 -7
  168. data/lib/mongoid/fields/foreign_key.rb +11 -4
  169. data/lib/mongoid/fields/localized.rb +19 -4
  170. data/lib/mongoid/fields/standard.rb +17 -7
  171. data/lib/mongoid/fields/validators/macro.rb +3 -9
  172. data/lib/mongoid/fields.rb +142 -28
  173. data/lib/mongoid/findable.rb +54 -24
  174. data/lib/mongoid/indexable/specification.rb +2 -2
  175. data/lib/mongoid/indexable/validators/options.rb +6 -2
  176. data/lib/mongoid/interceptable.rb +187 -16
  177. data/lib/mongoid/matchable.rb +1 -1
  178. data/lib/mongoid/matcher/eq_impl.rb +1 -1
  179. data/lib/mongoid/matcher/type.rb +1 -1
  180. data/lib/mongoid/matcher.rb +48 -14
  181. data/lib/mongoid/persistable/creatable.rb +19 -9
  182. data/lib/mongoid/persistable/deletable.rb +2 -2
  183. data/lib/mongoid/persistable/destroyable.rb +1 -1
  184. data/lib/mongoid/persistable/savable.rb +14 -2
  185. data/lib/mongoid/persistable/unsettable.rb +2 -2
  186. data/lib/mongoid/persistable/updatable.rb +69 -12
  187. data/lib/mongoid/persistable/upsertable.rb +21 -2
  188. data/lib/mongoid/persistable.rb +6 -3
  189. data/lib/mongoid/persistence_context.rb +6 -4
  190. data/lib/mongoid/query_cache.rb +13 -261
  191. data/lib/mongoid/railties/controller_runtime.rb +1 -1
  192. data/lib/mongoid/railties/database.rake +7 -2
  193. data/lib/mongoid/reloadable.rb +10 -8
  194. data/lib/mongoid/scopable.rb +15 -13
  195. data/lib/mongoid/selectable.rb +1 -2
  196. data/lib/mongoid/serializable.rb +17 -13
  197. data/lib/mongoid/stateful.rb +57 -10
  198. data/lib/mongoid/tasks/database.rake +12 -0
  199. data/lib/mongoid/tasks/database.rb +20 -2
  200. data/lib/mongoid/threaded/lifecycle.rb +5 -5
  201. data/lib/mongoid/threaded.rb +42 -12
  202. data/lib/mongoid/timestamps/created.rb +9 -2
  203. data/lib/mongoid/timestamps/updated.rb +2 -2
  204. data/lib/mongoid/touchable.rb +3 -4
  205. data/lib/mongoid/traversable.rb +41 -5
  206. data/lib/mongoid/utils.rb +22 -0
  207. data/lib/mongoid/validatable/associated.rb +98 -17
  208. data/lib/mongoid/validatable/localizable.rb +1 -1
  209. data/lib/mongoid/validatable/macros.rb +5 -7
  210. data/lib/mongoid/validatable/presence.rb +2 -2
  211. data/lib/mongoid/validatable/uniqueness.rb +9 -8
  212. data/lib/mongoid/validatable.rb +17 -6
  213. data/lib/mongoid/version.rb +1 -1
  214. data/lib/mongoid/warnings.rb +19 -4
  215. data/lib/mongoid.rb +17 -3
  216. data/spec/config/mongoid.yml +16 -0
  217. data/spec/integration/app_spec.rb +24 -19
  218. data/spec/integration/associations/belongs_to_spec.rb +18 -0
  219. data/spec/integration/associations/embedded_spec.rb +15 -0
  220. data/spec/integration/associations/embeds_many_spec.rb +15 -2
  221. data/spec/integration/associations/embeds_one_spec.rb +18 -0
  222. data/spec/integration/associations/foreign_key_spec.rb +9 -0
  223. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +61 -0
  224. data/spec/integration/associations/has_one_spec.rb +97 -1
  225. data/spec/integration/associations/scope_option_spec.rb +1 -1
  226. data/spec/integration/callbacks_models.rb +132 -1
  227. data/spec/integration/callbacks_spec.rb +381 -4
  228. data/spec/integration/criteria/range_spec.rb +95 -1
  229. data/spec/integration/discriminator_key_spec.rb +118 -80
  230. data/spec/integration/dots_and_dollars_spec.rb +277 -0
  231. data/spec/integration/i18n_fallbacks_spec.rb +3 -32
  232. data/spec/integration/matcher_examples_spec.rb +20 -13
  233. data/spec/integration/matcher_operator_data/type_decimal.yml +3 -2
  234. data/spec/integration/matcher_operator_spec.rb +3 -5
  235. data/spec/integration/persistence/range_field_spec.rb +350 -0
  236. data/spec/mongoid/association/counter_cache_spec.rb +1 -1
  237. data/spec/mongoid/association/depending_spec.rb +9 -9
  238. data/spec/mongoid/association/eager_spec.rb +26 -3
  239. data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +2 -1
  240. data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +54 -0
  241. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +96 -9
  242. data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +112 -0
  243. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +290 -65
  244. data/spec/mongoid/association/embedded/embeds_many_models.rb +37 -0
  245. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +16 -0
  246. data/spec/mongoid/association/embedded/embeds_many_spec.rb +68 -0
  247. data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +25 -0
  248. data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +15 -2
  249. data/spec/mongoid/association/embedded/embeds_one_models.rb +19 -0
  250. data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -0
  251. data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +2 -1
  252. data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +54 -0
  253. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +19 -0
  254. data/spec/mongoid/association/referenced/belongs_to_models.rb +11 -0
  255. data/spec/mongoid/association/referenced/belongs_to_spec.rb +4 -20
  256. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +186 -229
  257. data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +25 -0
  258. data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +35 -2
  259. data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +109 -0
  260. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +2 -56
  261. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +215 -177
  262. data/spec/mongoid/association/referenced/has_many_models.rb +3 -1
  263. data/spec/mongoid/association/referenced/has_many_spec.rb +25 -0
  264. data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +2 -2
  265. data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +107 -1
  266. data/spec/mongoid/association/referenced/has_one_models.rb +16 -0
  267. data/spec/mongoid/association/syncable_spec.rb +15 -1
  268. data/spec/mongoid/association_spec.rb +60 -0
  269. data/spec/mongoid/atomic/paths_spec.rb +0 -14
  270. data/spec/mongoid/attributes/nested_spec.rb +80 -11
  271. data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
  272. data/spec/mongoid/attributes/projector_spec.rb +1 -5
  273. data/spec/mongoid/attributes/readonly_spec.rb +19 -0
  274. data/spec/mongoid/attributes_spec.rb +526 -33
  275. data/spec/mongoid/changeable_spec.rb +429 -37
  276. data/spec/mongoid/clients/factory_spec.rb +23 -30
  277. data/spec/mongoid/clients/sessions_spec.rb +0 -38
  278. data/spec/mongoid/clients_spec.rb +149 -15
  279. data/spec/mongoid/collection_configurable_spec.rb +158 -0
  280. data/spec/mongoid/config/defaults_spec.rb +160 -0
  281. data/spec/mongoid/config_spec.rb +214 -31
  282. data/spec/mongoid/contextual/aggregable/memory_spec.rb +396 -158
  283. data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
  284. data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +62 -0
  285. data/spec/mongoid/contextual/map_reduce_spec.rb +2 -16
  286. data/spec/mongoid/contextual/memory_spec.rb +850 -88
  287. data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
  288. data/spec/mongoid/contextual/mongo_spec.rb +2256 -1005
  289. data/spec/mongoid/contextual/none_spec.rb +60 -21
  290. data/spec/mongoid/copyable_spec.rb +453 -11
  291. data/spec/mongoid/criteria/findable_spec.rb +86 -210
  292. data/spec/mongoid/criteria/includable_spec.rb +1492 -0
  293. data/spec/mongoid/criteria/includable_spec_models.rb +54 -0
  294. data/spec/mongoid/criteria/marshalable_spec.rb +18 -1
  295. data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +7 -19
  296. data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +134 -26
  297. data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +11 -0
  298. data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +11 -0
  299. data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +0 -15
  300. data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +73 -7
  301. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +4 -69
  302. data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +0 -59
  303. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +11 -0
  304. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +11 -0
  305. data/spec/mongoid/criteria/queryable/optional_spec.rb +15 -484
  306. data/spec/mongoid/criteria/queryable/options_spec.rb +1 -1
  307. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +469 -0
  308. data/spec/mongoid/criteria/queryable/selectable_spec.rb +107 -86
  309. data/spec/mongoid/criteria/queryable/selector_spec.rb +15 -3
  310. data/spec/mongoid/criteria/translator_spec.rb +132 -0
  311. data/spec/mongoid/criteria_projection_spec.rb +1 -5
  312. data/spec/mongoid/criteria_spec.rb +469 -1205
  313. data/spec/mongoid/document_fields_spec.rb +173 -24
  314. data/spec/mongoid/document_spec.rb +59 -41
  315. data/spec/mongoid/equality_spec.rb +6 -0
  316. data/spec/mongoid/errors/document_not_found_spec.rb +29 -2
  317. data/spec/mongoid/errors/invalid_field_spec.rb +1 -1
  318. data/spec/mongoid/errors/invalid_field_type_spec.rb +55 -0
  319. data/spec/mongoid/errors/mongoid_error_spec.rb +3 -1
  320. data/spec/mongoid/errors/no_environment_spec.rb +3 -3
  321. data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
  322. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +1 -1
  323. data/spec/mongoid/extensions/array_spec.rb +16 -2
  324. data/spec/mongoid/extensions/big_decimal_spec.rb +712 -212
  325. data/spec/mongoid/extensions/binary_spec.rb +44 -9
  326. data/spec/mongoid/extensions/boolean_spec.rb +68 -82
  327. data/spec/mongoid/extensions/date_class_mongoize_spec.rb +7 -3
  328. data/spec/mongoid/extensions/date_spec.rb +71 -1
  329. data/spec/mongoid/extensions/date_time_spec.rb +15 -9
  330. data/spec/mongoid/extensions/float_spec.rb +53 -74
  331. data/spec/mongoid/extensions/hash_spec.rb +33 -3
  332. data/spec/mongoid/extensions/integer_spec.rb +50 -64
  333. data/spec/mongoid/extensions/range_spec.rb +255 -54
  334. data/spec/mongoid/extensions/regexp_spec.rb +58 -33
  335. data/spec/mongoid/extensions/set_spec.rb +106 -0
  336. data/spec/mongoid/extensions/string_spec.rb +53 -25
  337. data/spec/mongoid/extensions/symbol_spec.rb +18 -25
  338. data/spec/mongoid/extensions/time_spec.rb +639 -106
  339. data/spec/mongoid/extensions/time_with_zone_spec.rb +24 -83
  340. data/spec/mongoid/factory_spec.rb +61 -1
  341. data/spec/mongoid/fields/localized_spec.rb +80 -37
  342. data/spec/mongoid/fields_spec.rb +503 -87
  343. data/spec/mongoid/findable_spec.rb +450 -58
  344. data/spec/mongoid/indexable/specification_spec.rb +2 -2
  345. data/spec/mongoid/indexable_spec.rb +55 -30
  346. data/spec/mongoid/interceptable_spec.rb +904 -22
  347. data/spec/mongoid/interceptable_spec_models.rb +189 -22
  348. data/spec/mongoid/matcher/extract_attribute_spec.rb +1 -5
  349. data/spec/mongoid/mongoizable_spec.rb +285 -0
  350. data/spec/mongoid/persistable/creatable_spec.rb +2 -2
  351. data/spec/mongoid/persistable/deletable_spec.rb +28 -8
  352. data/spec/mongoid/persistable/destroyable_spec.rb +28 -8
  353. data/spec/mongoid/persistable/incrementable_spec.rb +37 -0
  354. data/spec/mongoid/persistable/logical_spec.rb +37 -0
  355. data/spec/mongoid/persistable/poppable_spec.rb +36 -0
  356. data/spec/mongoid/persistable/pullable_spec.rb +72 -0
  357. data/spec/mongoid/persistable/pushable_spec.rb +72 -0
  358. data/spec/mongoid/persistable/renamable_spec.rb +36 -0
  359. data/spec/mongoid/persistable/savable_spec.rb +96 -0
  360. data/spec/mongoid/persistable/settable_spec.rb +37 -0
  361. data/spec/mongoid/persistable/unsettable_spec.rb +36 -0
  362. data/spec/mongoid/persistable/updatable_spec.rb +20 -28
  363. data/spec/mongoid/persistable/upsertable_spec.rb +89 -1
  364. data/spec/mongoid/persistence_context_spec.rb +31 -57
  365. data/spec/mongoid/query_cache_middleware_spec.rb +0 -18
  366. data/spec/mongoid/query_cache_spec.rb +56 -215
  367. data/spec/mongoid/reloadable_spec.rb +83 -6
  368. data/spec/mongoid/scopable_spec.rb +91 -1
  369. data/spec/mongoid/serializable_spec.rb +25 -39
  370. data/spec/mongoid/shardable_spec.rb +4 -4
  371. data/spec/mongoid/stateful_spec.rb +150 -8
  372. data/spec/mongoid/tasks/database_rake_spec.rb +74 -0
  373. data/spec/mongoid/tasks/database_spec.rb +127 -0
  374. data/spec/mongoid/timestamps/created_spec.rb +23 -0
  375. data/spec/mongoid/timestamps_spec.rb +392 -4
  376. data/spec/mongoid/timestamps_spec_models.rb +67 -0
  377. data/spec/mongoid/touchable_spec.rb +390 -2
  378. data/spec/mongoid/touchable_spec_models.rb +14 -8
  379. data/spec/mongoid/traversable_spec.rb +13 -35
  380. data/spec/mongoid/validatable/associated_spec.rb +27 -34
  381. data/spec/mongoid/validatable/presence_spec.rb +1 -1
  382. data/spec/mongoid/validatable/uniqueness_spec.rb +58 -31
  383. data/spec/mongoid/warnings_spec.rb +35 -0
  384. data/spec/mongoid_spec.rb +34 -16
  385. data/spec/rails/controller_extension/controller_runtime_spec.rb +2 -2
  386. data/spec/rails/mongoid_spec.rb +4 -16
  387. data/spec/spec_helper.rb +5 -0
  388. data/spec/support/constraints.rb +24 -0
  389. data/spec/support/immutable_ids.rb +118 -0
  390. data/spec/support/macros.rb +78 -0
  391. data/spec/support/models/artist.rb +0 -1
  392. data/spec/support/models/augmentation.rb +12 -0
  393. data/spec/support/models/band.rb +5 -0
  394. data/spec/support/models/book.rb +1 -0
  395. data/spec/support/models/building.rb +2 -0
  396. data/spec/support/models/catalog.rb +24 -0
  397. data/spec/support/models/circus.rb +3 -0
  398. data/spec/support/models/cover.rb +10 -0
  399. data/spec/support/models/fanatic.rb +8 -0
  400. data/spec/support/models/implant.rb +9 -0
  401. data/spec/support/models/label.rb +2 -0
  402. data/spec/support/models/lat_lng.rb +6 -0
  403. data/spec/support/models/name.rb +10 -0
  404. data/spec/support/models/passport.rb +9 -0
  405. data/spec/support/models/person.rb +2 -0
  406. data/spec/support/models/player.rb +2 -0
  407. data/spec/support/models/powerup.rb +12 -0
  408. data/spec/support/models/product.rb +1 -0
  409. data/spec/support/models/purse.rb +9 -0
  410. data/spec/support/models/registry.rb +1 -0
  411. data/spec/support/models/school.rb +14 -0
  412. data/spec/support/models/shield.rb +18 -0
  413. data/spec/support/models/student.rb +14 -0
  414. data/spec/support/models/weapon.rb +12 -0
  415. metadata +98 -96
  416. checksums.yaml.gz.sig +0 -0
  417. data/lib/mongoid/errors/eager_load.rb +0 -23
  418. data/lib/mongoid/errors/invalid_value.rb +0 -17
  419. data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -60
  420. data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -60
  421. data/spec/mongoid/errors/eager_load_spec.rb +0 -31
  422. data/spec/shared/LICENSE +0 -20
  423. data/spec/shared/bin/get-mongodb-download-url +0 -17
  424. data/spec/shared/bin/s3-copy +0 -45
  425. data/spec/shared/bin/s3-upload +0 -69
  426. data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
  427. data/spec/shared/lib/mrss/cluster_config.rb +0 -231
  428. data/spec/shared/lib/mrss/constraints.rb +0 -378
  429. data/spec/shared/lib/mrss/docker_runner.rb +0 -291
  430. data/spec/shared/lib/mrss/eg_config_utils.rb +0 -51
  431. data/spec/shared/lib/mrss/event_subscriber.rb +0 -210
  432. data/spec/shared/lib/mrss/lite_constraints.rb +0 -238
  433. data/spec/shared/lib/mrss/server_version_registry.rb +0 -120
  434. data/spec/shared/lib/mrss/session_registry.rb +0 -69
  435. data/spec/shared/lib/mrss/session_registry_legacy.rb +0 -60
  436. data/spec/shared/lib/mrss/spec_organizer.rb +0 -179
  437. data/spec/shared/lib/mrss/utils.rb +0 -15
  438. data/spec/shared/share/Dockerfile.erb +0 -325
  439. data/spec/shared/share/haproxy-1.conf +0 -16
  440. data/spec/shared/share/haproxy-2.conf +0 -17
  441. data/spec/shared/shlib/config.sh +0 -27
  442. data/spec/shared/shlib/distro.sh +0 -74
  443. data/spec/shared/shlib/server.sh +0 -392
  444. data/spec/shared/shlib/set_env.sh +0 -169
  445. data.tar.gz.sig +0 -0
  446. metadata.gz.sig +0 -3
@@ -388,6 +388,86 @@ describe Mongoid::Interceptable do
388
388
  end
389
389
  end
390
390
  end
391
+
392
+ context 'with embedded grandchildren' do
393
+ IS = InterceptableSpec
394
+
395
+ config_override :prevent_multiple_calls_of_embedded_callbacks, true
396
+
397
+ context 'when creating' do
398
+ let(:registry) { IS::CallbackRegistry.new(only: %i[ before_save ]) }
399
+
400
+ let(:expected_calls) do
401
+ [
402
+ # the parent
403
+ [ IS::CbParent, :before_save ],
404
+
405
+ # the immediate child of the parent
406
+ [ IS::CbCascadedNode, :before_save ],
407
+
408
+ # the grandchild of the parent
409
+ [ IS::CbCascadedNode, :before_save ],
410
+ ]
411
+ end
412
+
413
+ let!(:parent) do
414
+ parent = IS::CbParent.new(registry)
415
+ child = IS::CbCascadedNode.new(registry)
416
+ grandchild = IS::CbCascadedNode.new(registry)
417
+
418
+ child.cb_cascaded_nodes = [ grandchild ]
419
+ parent.cb_cascaded_nodes = [ child ]
420
+
421
+ parent.tap(&:save)
422
+ end
423
+
424
+ it 'should cascade callbacks to grandchildren' do
425
+ expect(registry.calls).to be == expected_calls
426
+ end
427
+ end
428
+
429
+ context 'when updating' do
430
+ let(:registry) { IS::CallbackRegistry.new(only: %i[ before_update ]) }
431
+
432
+ let(:expected_calls) do
433
+ [
434
+ # the parent
435
+ [ IS::CbParent, :before_update ],
436
+
437
+ # the immediate child of the parent
438
+ [ IS::CbCascadedNode, :before_update ],
439
+
440
+ # the grandchild of the parent
441
+ [ IS::CbCascadedNode, :before_update ],
442
+ ]
443
+ end
444
+
445
+ let!(:parent) do
446
+ parent = IS::CbParent.new(nil)
447
+ child = IS::CbCascadedNode.new(nil)
448
+ grandchild = IS::CbCascadedNode.new(nil)
449
+
450
+ child.cb_cascaded_nodes = [ grandchild ]
451
+ parent.cb_cascaded_nodes = [ child ]
452
+
453
+ parent.save
454
+
455
+ parent.callback_registry = registry
456
+ child.callback_registry = registry
457
+ grandchild.callback_registry = registry
458
+
459
+ parent.name = 'updated'
460
+ child.name = 'updated'
461
+ grandchild.name = 'updated'
462
+
463
+ parent.tap(&:save)
464
+ end
465
+
466
+ it 'should cascade callbacks to grandchildren' do
467
+ expect(registry.calls).to be == expected_calls
468
+ end
469
+ end
470
+ end
391
471
  end
392
472
 
393
473
  describe ".before_destroy" do
@@ -580,10 +660,24 @@ describe Mongoid::Interceptable do
580
660
  end
581
661
 
582
662
  context "when saving the root" do
663
+ context 'with prevent_multiple_calls_of_embedded_callbacks enabled' do
664
+ config_override :prevent_multiple_calls_of_embedded_callbacks, true
665
+ config_override :around_callbacks_for_embeds, true
583
666
 
584
- it "only executes the callbacks once for each embed" do
585
- expect(note).to receive(:update_saved).twice
586
- band.save!
667
+ it "executes the callbacks only once for each document" do
668
+ expect(note).to receive(:update_saved).once
669
+ band.save!
670
+ end
671
+ end
672
+
673
+ context 'with prevent_multiple_calls_of_embedded_callbacks disabled' do
674
+ config_override :prevent_multiple_calls_of_embedded_callbacks, false
675
+ config_override :around_callbacks_for_embeds, true
676
+
677
+ it "executes the callbacks once for each ember" do
678
+ expect(note).to receive(:update_saved).twice
679
+ band.save!
680
+ end
587
681
  end
588
682
  end
589
683
  end
@@ -1746,8 +1840,12 @@ describe Mongoid::Interceptable do
1746
1840
  [InterceptableSpec::CbChild, :after_validation],
1747
1841
  [InterceptableSpec::CbParent, :after_validation],
1748
1842
  [InterceptableSpec::CbParent, :before_save],
1843
+ [InterceptableSpec::CbParent, :around_save_open],
1749
1844
  [InterceptableSpec::CbParent, :before_create],
1845
+ [InterceptableSpec::CbParent, :around_create_open],
1846
+ [InterceptableSpec::CbParent, :around_create_close],
1750
1847
  [InterceptableSpec::CbParent, :after_create],
1848
+ [InterceptableSpec::CbParent, :around_save_close],
1751
1849
  [InterceptableSpec::CbParent, :after_save],
1752
1850
  ]
1753
1851
  end
@@ -1767,28 +1865,812 @@ describe Mongoid::Interceptable do
1767
1865
  end
1768
1866
  end
1769
1867
 
1770
- let(:expected) do
1771
- [
1772
- [InterceptableSpec::CbParent, :before_validation],
1773
- [InterceptableSpec::CbCascadedChild, :before_validation],
1774
- [InterceptableSpec::CbCascadedChild, :after_validation],
1775
- [InterceptableSpec::CbParent, :after_validation],
1776
- [InterceptableSpec::CbParent, :before_save],
1777
- [InterceptableSpec::CbCascadedChild, :before_save],
1778
- [InterceptableSpec::CbParent, :before_create],
1779
- [InterceptableSpec::CbCascadedChild, :before_create],
1780
- [InterceptableSpec::CbParent, :after_create],
1781
- [InterceptableSpec::CbCascadedChild, :after_create],
1782
- [InterceptableSpec::CbParent, :after_save],
1783
- [InterceptableSpec::CbCascadedChild, :after_save],
1784
- ]
1868
+ context 'with around callbacks' do
1869
+ config_override :around_callbacks_for_embeds, true
1870
+
1871
+ let(:expected) do
1872
+ [
1873
+ [InterceptableSpec::CbCascadedChild, :before_validation],
1874
+ [InterceptableSpec::CbCascadedChild, :after_validation],
1875
+ [InterceptableSpec::CbParent, :before_validation],
1876
+ [InterceptableSpec::CbCascadedChild, :before_validation],
1877
+ [InterceptableSpec::CbCascadedChild, :after_validation],
1878
+
1879
+ [InterceptableSpec::CbParent, :after_validation],
1880
+ [InterceptableSpec::CbParent, :before_save],
1881
+ [InterceptableSpec::CbParent, :around_save_open],
1882
+ [InterceptableSpec::CbParent, :before_create],
1883
+ [InterceptableSpec::CbParent, :around_create_open],
1884
+
1885
+ [InterceptableSpec::CbCascadedChild, :before_save],
1886
+ [InterceptableSpec::CbCascadedChild, :around_save_open],
1887
+ [InterceptableSpec::CbCascadedChild, :before_create],
1888
+ [InterceptableSpec::CbCascadedChild, :around_create_open],
1889
+
1890
+ [InterceptableSpec::CbCascadedChild, :around_create_close],
1891
+ [InterceptableSpec::CbCascadedChild, :after_create],
1892
+ [InterceptableSpec::CbCascadedChild, :around_save_close],
1893
+ [InterceptableSpec::CbCascadedChild, :after_save],
1894
+
1895
+ [InterceptableSpec::CbParent, :around_create_close],
1896
+ [InterceptableSpec::CbParent, :after_create],
1897
+ [InterceptableSpec::CbParent, :around_save_close],
1898
+ [InterceptableSpec::CbParent, :after_save]
1899
+ ]
1900
+ end
1901
+
1902
+ it 'calls callbacks in the right order' do
1903
+ parent.save!
1904
+ expect(registry.calls).to eq expected
1905
+ end
1785
1906
  end
1786
1907
 
1787
- it 'calls callbacks in the right order' do
1788
- pending 'MONGOID-3795'
1908
+ context 'without around callbacks' do
1909
+ config_override :around_callbacks_for_embeds, false
1789
1910
 
1790
- parent.save!
1791
- expect(registry.calls).to eq expected
1911
+ let(:expected) do
1912
+ [
1913
+ [InterceptableSpec::CbCascadedChild, :before_validation],
1914
+ [InterceptableSpec::CbCascadedChild, :after_validation],
1915
+ [InterceptableSpec::CbParent, :before_validation],
1916
+ [InterceptableSpec::CbCascadedChild, :before_validation],
1917
+ [InterceptableSpec::CbCascadedChild, :after_validation],
1918
+
1919
+ [InterceptableSpec::CbParent, :after_validation],
1920
+ [InterceptableSpec::CbParent, :before_save],
1921
+ [InterceptableSpec::CbParent, :around_save_open],
1922
+ [InterceptableSpec::CbParent, :before_create],
1923
+ [InterceptableSpec::CbParent, :around_create_open],
1924
+
1925
+ [InterceptableSpec::CbCascadedChild, :before_save],
1926
+ [InterceptableSpec::CbCascadedChild, :before_create],
1927
+
1928
+ [InterceptableSpec::CbCascadedChild, :after_create],
1929
+ [InterceptableSpec::CbCascadedChild, :after_save],
1930
+
1931
+ [InterceptableSpec::CbParent, :around_create_close],
1932
+ [InterceptableSpec::CbParent, :after_create],
1933
+ [InterceptableSpec::CbParent, :around_save_close],
1934
+ [InterceptableSpec::CbParent, :after_save]
1935
+ ]
1936
+ end
1937
+
1938
+ it 'calls callbacks in the right order' do
1939
+ parent.save!
1940
+ expect(registry.calls).to eq expected
1941
+ end
1942
+ end
1943
+ end
1944
+
1945
+ context "with associations" do
1946
+ context "has_one" do
1947
+ let(:registry) { InterceptableSpec::CallbackRegistry.new }
1948
+
1949
+ let(:parent) do
1950
+ InterceptableSpec::CbHasOneParent.new(registry).tap do |parent|
1951
+ parent.child = InterceptableSpec::CbHasOneChild.new(registry)
1952
+ end
1953
+ end
1954
+
1955
+ let(:expected) do
1956
+ [
1957
+ [InterceptableSpec::CbHasOneParent, :before_validation],
1958
+ [InterceptableSpec::CbHasOneChild, :before_validation],
1959
+ [InterceptableSpec::CbHasOneChild, :after_validation],
1960
+ [InterceptableSpec::CbHasOneParent, :after_validation],
1961
+ [InterceptableSpec::CbHasOneParent, :before_save],
1962
+
1963
+ [InterceptableSpec::CbHasOneParent, :around_save_open],
1964
+ [InterceptableSpec::CbHasOneParent, :before_create],
1965
+ [InterceptableSpec::CbHasOneParent, :around_create_open],
1966
+
1967
+ [InterceptableSpec::CbHasOneParent, :insert_into_database],
1968
+
1969
+ [InterceptableSpec::CbHasOneChild, :before_validation],
1970
+ [InterceptableSpec::CbHasOneChild, :after_validation],
1971
+ [InterceptableSpec::CbHasOneChild, :before_save],
1972
+ [InterceptableSpec::CbHasOneChild, :around_save_open],
1973
+ [InterceptableSpec::CbHasOneChild, :before_create],
1974
+ [InterceptableSpec::CbHasOneChild, :around_create_open],
1975
+
1976
+ [InterceptableSpec::CbHasOneChild, :around_create_close],
1977
+ [InterceptableSpec::CbHasOneChild, :after_create],
1978
+ [InterceptableSpec::CbHasOneChild, :around_save_close],
1979
+ [InterceptableSpec::CbHasOneChild, :after_save],
1980
+
1981
+ [InterceptableSpec::CbHasOneParent, :around_create_close],
1982
+ [InterceptableSpec::CbHasOneParent, :after_create],
1983
+ [InterceptableSpec::CbHasOneParent, :around_save_close],
1984
+ [InterceptableSpec::CbHasOneParent, :after_save],
1985
+ ]
1986
+ end
1987
+
1988
+ it 'calls callbacks in the right order' do
1989
+ parent.save!
1990
+ expect(registry.calls).to eq expected
1991
+ end
1992
+ end
1993
+
1994
+ context "embeds_one" do
1995
+ let(:registry) { InterceptableSpec::CallbackRegistry.new }
1996
+
1997
+ let(:parent) do
1998
+ InterceptableSpec::CbEmbedsOneParent.new(registry).tap do |parent|
1999
+ parent.child = InterceptableSpec::CbEmbedsOneChild.new(registry)
2000
+ end
2001
+ end
2002
+
2003
+ context "create" do
2004
+ context "with around callbacks" do
2005
+ config_override :around_callbacks_for_embeds, true
2006
+
2007
+ let(:expected) do
2008
+ [
2009
+ [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2010
+ [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2011
+ [InterceptableSpec::CbEmbedsOneParent, :before_validation],
2012
+ [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2013
+ [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2014
+ [InterceptableSpec::CbEmbedsOneParent, :after_validation],
2015
+
2016
+ [InterceptableSpec::CbEmbedsOneParent, :before_save],
2017
+ [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
2018
+ [InterceptableSpec::CbEmbedsOneParent, :before_create],
2019
+ [InterceptableSpec::CbEmbedsOneParent, :around_create_open],
2020
+
2021
+ [InterceptableSpec::CbEmbedsOneChild, :before_save],
2022
+ [InterceptableSpec::CbEmbedsOneChild, :around_save_open],
2023
+ [InterceptableSpec::CbEmbedsOneChild, :before_create],
2024
+ [InterceptableSpec::CbEmbedsOneChild, :around_create_open],
2025
+
2026
+ [InterceptableSpec::CbEmbedsOneParent, :insert_into_database],
2027
+
2028
+ [InterceptableSpec::CbEmbedsOneChild, :around_create_close],
2029
+ [InterceptableSpec::CbEmbedsOneChild, :after_create],
2030
+ [InterceptableSpec::CbEmbedsOneChild, :around_save_close],
2031
+ [InterceptableSpec::CbEmbedsOneChild, :after_save],
2032
+
2033
+ [InterceptableSpec::CbEmbedsOneParent, :around_create_close],
2034
+ [InterceptableSpec::CbEmbedsOneParent, :after_create],
2035
+ [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
2036
+ [InterceptableSpec::CbEmbedsOneParent, :after_save]
2037
+ ]
2038
+ end
2039
+
2040
+ it 'calls callbacks in the right order' do
2041
+ parent.save!
2042
+ expect(registry.calls).to eq expected
2043
+ end
2044
+ end
2045
+
2046
+ context "without around callbacks" do
2047
+ config_override :around_callbacks_for_embeds, false
2048
+
2049
+ let(:expected) do
2050
+ [
2051
+ [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2052
+ [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2053
+ [InterceptableSpec::CbEmbedsOneParent, :before_validation],
2054
+ [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2055
+ [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2056
+ [InterceptableSpec::CbEmbedsOneParent, :after_validation],
2057
+
2058
+ [InterceptableSpec::CbEmbedsOneParent, :before_save],
2059
+ [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
2060
+ [InterceptableSpec::CbEmbedsOneParent, :before_create],
2061
+ [InterceptableSpec::CbEmbedsOneParent, :around_create_open],
2062
+
2063
+ [InterceptableSpec::CbEmbedsOneChild, :before_save],
2064
+ [InterceptableSpec::CbEmbedsOneChild, :before_create],
2065
+
2066
+ [InterceptableSpec::CbEmbedsOneParent, :insert_into_database],
2067
+
2068
+ [InterceptableSpec::CbEmbedsOneChild, :after_create],
2069
+ [InterceptableSpec::CbEmbedsOneChild, :after_save],
2070
+
2071
+ [InterceptableSpec::CbEmbedsOneParent, :around_create_close],
2072
+ [InterceptableSpec::CbEmbedsOneParent, :after_create],
2073
+ [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
2074
+ [InterceptableSpec::CbEmbedsOneParent, :after_save]
2075
+ ]
2076
+ end
2077
+
2078
+ it 'calls callbacks in the right order' do
2079
+ parent.save!
2080
+ expect(registry.calls).to eq expected
2081
+ end
2082
+ end
2083
+ end
2084
+
2085
+ context "update" do
2086
+ context "with around callbacks" do
2087
+ config_override :around_callbacks_for_embeds, true
2088
+
2089
+ let(:expected) do
2090
+ [
2091
+ [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2092
+ [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2093
+ [InterceptableSpec::CbEmbedsOneParent, :before_validation],
2094
+ [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2095
+ [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2096
+ [InterceptableSpec::CbEmbedsOneParent, :after_validation],
2097
+
2098
+ [InterceptableSpec::CbEmbedsOneParent, :before_save],
2099
+ [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
2100
+ [InterceptableSpec::CbEmbedsOneParent, :before_update],
2101
+ [InterceptableSpec::CbEmbedsOneParent, :around_update_open],
2102
+
2103
+ [InterceptableSpec::CbEmbedsOneChild, :before_save],
2104
+ [InterceptableSpec::CbEmbedsOneChild, :around_save_open],
2105
+ [InterceptableSpec::CbEmbedsOneChild, :before_update],
2106
+ [InterceptableSpec::CbEmbedsOneChild, :around_update_open],
2107
+
2108
+ [InterceptableSpec::CbEmbedsOneChild, :around_update_close],
2109
+ [InterceptableSpec::CbEmbedsOneChild, :after_update],
2110
+ [InterceptableSpec::CbEmbedsOneChild, :around_save_close],
2111
+ [InterceptableSpec::CbEmbedsOneChild, :after_save],
2112
+
2113
+ [InterceptableSpec::CbEmbedsOneParent, :around_update_close],
2114
+ [InterceptableSpec::CbEmbedsOneParent, :after_update],
2115
+ [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
2116
+ [InterceptableSpec::CbEmbedsOneParent, :after_save]
2117
+ ]
2118
+ end
2119
+
2120
+ it 'calls callbacks in the right order' do
2121
+ parent.callback_registry = nil
2122
+ parent.child.callback_registry = nil
2123
+ parent.save!
2124
+
2125
+ parent.callback_registry = registry
2126
+ parent.child.callback_registry = registry
2127
+ parent.name = "name"
2128
+ parent.child.age = 10
2129
+
2130
+ parent.save!
2131
+ expect(registry.calls).to eq expected
2132
+ end
2133
+ end
2134
+
2135
+ context "without around callbacks" do
2136
+ config_override :around_callbacks_for_embeds, false
2137
+
2138
+ let(:expected) do
2139
+ [
2140
+ [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2141
+ [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2142
+ [InterceptableSpec::CbEmbedsOneParent, :before_validation],
2143
+ [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2144
+ [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2145
+ [InterceptableSpec::CbEmbedsOneParent, :after_validation],
2146
+
2147
+ [InterceptableSpec::CbEmbedsOneParent, :before_save],
2148
+ [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
2149
+ [InterceptableSpec::CbEmbedsOneParent, :before_update],
2150
+ [InterceptableSpec::CbEmbedsOneParent, :around_update_open],
2151
+
2152
+ [InterceptableSpec::CbEmbedsOneChild, :before_save],
2153
+ [InterceptableSpec::CbEmbedsOneChild, :before_update],
2154
+
2155
+ [InterceptableSpec::CbEmbedsOneChild, :after_update],
2156
+ [InterceptableSpec::CbEmbedsOneChild, :after_save],
2157
+
2158
+ [InterceptableSpec::CbEmbedsOneParent, :around_update_close],
2159
+ [InterceptableSpec::CbEmbedsOneParent, :after_update],
2160
+ [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
2161
+ [InterceptableSpec::CbEmbedsOneParent, :after_save]
2162
+ ]
2163
+ end
2164
+
2165
+ it 'calls callbacks in the right order' do
2166
+ parent.callback_registry = nil
2167
+ parent.child.callback_registry = nil
2168
+ parent.save!
2169
+
2170
+ parent.callback_registry = registry
2171
+ parent.child.callback_registry = registry
2172
+ parent.name = "name"
2173
+ parent.child.age = 10
2174
+
2175
+ parent.save!
2176
+ expect(registry.calls).to eq expected
2177
+ end
2178
+ end
2179
+ end
2180
+ end
2181
+
2182
+ context "has_many" do
2183
+ let(:registry) { InterceptableSpec::CallbackRegistry.new }
2184
+
2185
+ let(:parent) do
2186
+ InterceptableSpec::CbHasManyParent.new(registry).tap do |parent|
2187
+ parent.children = [
2188
+ InterceptableSpec::CbHasManyChild.new(registry),
2189
+ InterceptableSpec::CbHasManyChild.new(registry)
2190
+ ]
2191
+ end
2192
+ end
2193
+
2194
+ let(:expected) do
2195
+ [
2196
+ [InterceptableSpec::CbHasManyParent, :before_validation],
2197
+ [InterceptableSpec::CbHasManyChild, :before_validation],
2198
+ [InterceptableSpec::CbHasManyChild, :after_validation],
2199
+ [InterceptableSpec::CbHasManyChild, :before_validation],
2200
+ [InterceptableSpec::CbHasManyChild, :after_validation],
2201
+ [InterceptableSpec::CbHasManyParent, :after_validation],
2202
+
2203
+ [InterceptableSpec::CbHasManyParent, :before_save],
2204
+ [InterceptableSpec::CbHasManyParent, :around_save_open],
2205
+ [InterceptableSpec::CbHasManyParent, :before_create],
2206
+ [InterceptableSpec::CbHasManyParent, :around_create_open],
2207
+
2208
+ [InterceptableSpec::CbHasManyParent, :insert_into_database],
2209
+
2210
+ [InterceptableSpec::CbHasManyChild, :before_validation],
2211
+ [InterceptableSpec::CbHasManyChild, :after_validation],
2212
+ [InterceptableSpec::CbHasManyChild, :before_save],
2213
+ [InterceptableSpec::CbHasManyChild, :around_save_open],
2214
+ [InterceptableSpec::CbHasManyChild, :before_create],
2215
+ [InterceptableSpec::CbHasManyChild, :around_create_open],
2216
+ [InterceptableSpec::CbHasManyChild, :around_create_close],
2217
+ [InterceptableSpec::CbHasManyChild, :after_create],
2218
+ [InterceptableSpec::CbHasManyChild, :around_save_close],
2219
+ [InterceptableSpec::CbHasManyChild, :after_save],
2220
+
2221
+ [InterceptableSpec::CbHasManyChild, :before_validation],
2222
+ [InterceptableSpec::CbHasManyChild, :after_validation],
2223
+ [InterceptableSpec::CbHasManyChild, :before_save],
2224
+ [InterceptableSpec::CbHasManyChild, :around_save_open],
2225
+ [InterceptableSpec::CbHasManyChild, :before_create],
2226
+ [InterceptableSpec::CbHasManyChild, :around_create_open],
2227
+ [InterceptableSpec::CbHasManyChild, :around_create_close],
2228
+ [InterceptableSpec::CbHasManyChild, :after_create],
2229
+ [InterceptableSpec::CbHasManyChild, :around_save_close],
2230
+ [InterceptableSpec::CbHasManyChild, :after_save],
2231
+
2232
+ [InterceptableSpec::CbHasManyParent, :around_create_close],
2233
+ [InterceptableSpec::CbHasManyParent, :after_create],
2234
+ [InterceptableSpec::CbHasManyParent, :around_save_close],
2235
+ [InterceptableSpec::CbHasManyParent, :after_save]
2236
+ ]
2237
+ end
2238
+
2239
+ it 'calls callbacks in the right order' do
2240
+ parent.save!
2241
+ expect(registry.calls).to eq expected
2242
+ end
2243
+ end
2244
+
2245
+ context "embeds_many" do
2246
+ let(:registry) { InterceptableSpec::CallbackRegistry.new }
2247
+
2248
+ let(:parent) do
2249
+ InterceptableSpec::CbEmbedsManyParent.new(registry).tap do |parent|
2250
+ parent.children = [
2251
+ InterceptableSpec::CbEmbedsManyChild.new(registry),
2252
+ InterceptableSpec::CbEmbedsManyChild.new(registry),
2253
+ ]
2254
+ end
2255
+ end
2256
+
2257
+ context "with around callbacks" do
2258
+ config_override :around_callbacks_for_embeds, true
2259
+
2260
+ let(:expected) do
2261
+ [
2262
+ [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2263
+ [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2264
+ [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2265
+ [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2266
+ [InterceptableSpec::CbEmbedsManyParent, :before_validation],
2267
+ [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2268
+ [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2269
+ [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2270
+ [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2271
+ [InterceptableSpec::CbEmbedsManyParent, :after_validation],
2272
+
2273
+ [InterceptableSpec::CbEmbedsManyParent, :before_save],
2274
+ [InterceptableSpec::CbEmbedsManyParent, :around_save_open],
2275
+ [InterceptableSpec::CbEmbedsManyParent, :before_create],
2276
+ [InterceptableSpec::CbEmbedsManyParent, :around_create_open],
2277
+
2278
+ [InterceptableSpec::CbEmbedsManyChild, :before_save],
2279
+ [InterceptableSpec::CbEmbedsManyChild, :around_save_open],
2280
+ [InterceptableSpec::CbEmbedsManyChild, :before_save],
2281
+
2282
+ [InterceptableSpec::CbEmbedsManyChild, :around_save_open],
2283
+ [InterceptableSpec::CbEmbedsManyChild, :before_create],
2284
+ [InterceptableSpec::CbEmbedsManyChild, :around_create_open],
2285
+
2286
+ [InterceptableSpec::CbEmbedsManyChild, :before_create],
2287
+ [InterceptableSpec::CbEmbedsManyChild, :around_create_open],
2288
+
2289
+ [InterceptableSpec::CbEmbedsManyParent, :insert_into_database],
2290
+
2291
+ [InterceptableSpec::CbEmbedsManyChild, :around_create_close],
2292
+ [InterceptableSpec::CbEmbedsManyChild, :after_create],
2293
+
2294
+ [InterceptableSpec::CbEmbedsManyChild, :around_create_close],
2295
+ [InterceptableSpec::CbEmbedsManyChild, :after_create],
2296
+
2297
+ [InterceptableSpec::CbEmbedsManyChild, :around_save_close],
2298
+ [InterceptableSpec::CbEmbedsManyChild, :after_save],
2299
+
2300
+ [InterceptableSpec::CbEmbedsManyChild, :around_save_close],
2301
+ [InterceptableSpec::CbEmbedsManyChild, :after_save],
2302
+
2303
+ [InterceptableSpec::CbEmbedsManyParent, :around_create_close],
2304
+ [InterceptableSpec::CbEmbedsManyParent, :after_create],
2305
+ [InterceptableSpec::CbEmbedsManyParent, :around_save_close],
2306
+ [InterceptableSpec::CbEmbedsManyParent, :after_save]
2307
+ ]
2308
+ end
2309
+
2310
+ it 'calls callbacks in the right order' do
2311
+ parent.save!
2312
+ expect(registry.calls).to eq expected
2313
+ end
2314
+ end
2315
+
2316
+ context "without around callbacks" do
2317
+ config_override :around_callbacks_for_embeds, false
2318
+
2319
+ let(:expected) do
2320
+ [
2321
+ [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2322
+ [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2323
+ [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2324
+ [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2325
+ [InterceptableSpec::CbEmbedsManyParent, :before_validation],
2326
+ [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2327
+ [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2328
+ [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2329
+ [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2330
+ [InterceptableSpec::CbEmbedsManyParent, :after_validation],
2331
+
2332
+ [InterceptableSpec::CbEmbedsManyParent, :before_save],
2333
+ [InterceptableSpec::CbEmbedsManyParent, :around_save_open],
2334
+ [InterceptableSpec::CbEmbedsManyParent, :before_create],
2335
+ [InterceptableSpec::CbEmbedsManyParent, :around_create_open],
2336
+
2337
+ [InterceptableSpec::CbEmbedsManyChild, :before_save],
2338
+ [InterceptableSpec::CbEmbedsManyChild, :before_save],
2339
+
2340
+ [InterceptableSpec::CbEmbedsManyChild, :before_create],
2341
+
2342
+ [InterceptableSpec::CbEmbedsManyChild, :before_create],
2343
+
2344
+ [InterceptableSpec::CbEmbedsManyParent, :insert_into_database],
2345
+
2346
+ [InterceptableSpec::CbEmbedsManyChild, :after_create],
2347
+
2348
+ [InterceptableSpec::CbEmbedsManyChild, :after_create],
2349
+
2350
+ [InterceptableSpec::CbEmbedsManyChild, :after_save],
2351
+
2352
+ [InterceptableSpec::CbEmbedsManyChild, :after_save],
2353
+
2354
+ [InterceptableSpec::CbEmbedsManyParent, :around_create_close],
2355
+ [InterceptableSpec::CbEmbedsManyParent, :after_create],
2356
+ [InterceptableSpec::CbEmbedsManyParent, :around_save_close],
2357
+ [InterceptableSpec::CbEmbedsManyParent, :after_save]
2358
+ ]
2359
+ end
2360
+
2361
+ it 'calls callbacks in the right order' do
2362
+ parent.save!
2363
+ expect(registry.calls).to eq expected
2364
+ end
2365
+ end
2366
+ end
2367
+ end
2368
+
2369
+ context "when accessing parent document from callbacks" do
2370
+ shared_examples 'accesses the correct parent' do
2371
+ it "accesses the correct parent in after_find" do
2372
+ expect(from_db.after_find_player).to eq(player._id)
2373
+ end
2374
+
2375
+ it "accesses the correct parent in after_initialize" do
2376
+ expect(from_db.after_initialize_player).to eq(player._id)
2377
+ end
2378
+
2379
+ it "accesses the correct parent in default" do
2380
+ expect(from_db.after_default_player).to eq(player._id)
2381
+ end
2382
+
2383
+ it "accesses the correct parent in unpersisted after_initialize" do
2384
+ expect(unpersisted.after_initialize_player).to eq(player._id)
2385
+ end
2386
+ end
2387
+
2388
+ context "when using create methods" do
2389
+
2390
+ context "when the child is an embeds_many association" do
2391
+ let!(:player) do
2392
+ Player.create!.tap do |player|
2393
+ player.implants.create!
2394
+ end
2395
+ end
2396
+
2397
+ let(:unpersisted) { player.implants.first }
2398
+
2399
+ before do
2400
+ # The default is originally set when creating this document, and it is
2401
+ # subsequently persisted to the database. Therefore when we retrieve
2402
+ # this document from the database, this field is already set, and
2403
+ # the default Proc is not called. This unset is needed to allow the
2404
+ # default Proc to be called when the document is retrieved from the
2405
+ # database.
2406
+ Player.find(player.id).implants.first.unset(:after_default_player)
2407
+ end
2408
+
2409
+ let(:from_db) do
2410
+ Player.find(player.id).implants.first
2411
+ end
2412
+
2413
+ include_examples 'accesses the correct parent'
2414
+ end
2415
+
2416
+ context "when the child is an embeds_one association" do
2417
+ let!(:player) do
2418
+ Player.create!.tap do |player|
2419
+ player.create_augmentation
2420
+ end
2421
+ end
2422
+
2423
+ let(:unpersisted) { player.augmentation }
2424
+
2425
+ before do
2426
+ Player.find(player.id).augmentation.unset(:after_default_player)
2427
+ end
2428
+
2429
+ let(:from_db) do
2430
+ Player.find(player.id).augmentation
2431
+ end
2432
+
2433
+ include_examples 'accesses the correct parent'
2434
+ end
2435
+
2436
+ context "when the child is a has_many association" do
2437
+ let!(:player) do
2438
+ Player.create!.tap do |player|
2439
+ player.weapons.create!
2440
+ end
2441
+ end
2442
+
2443
+ let(:unpersisted) { player.weapons.first }
2444
+
2445
+ before do
2446
+ Player.find(player.id).weapons.first.unset(:after_default_player)
2447
+ end
2448
+
2449
+ let(:from_db) do
2450
+ Player.find(player.id).weapons.first
2451
+ end
2452
+
2453
+ include_examples 'accesses the correct parent'
2454
+ end
2455
+
2456
+ context "when the child is a has_one association" do
2457
+ let!(:player) do
2458
+ Player.create!.tap do |player|
2459
+ player.create_powerup
2460
+ player.save!
2461
+ end
2462
+ end
2463
+
2464
+ let(:unpersisted) { player.powerup }
2465
+
2466
+ before do
2467
+ Player.find(player.id).powerup.unset(:after_default_player)
2468
+ end
2469
+
2470
+ let(:from_db) do
2471
+ Player.find(player.id).powerup
2472
+ end
2473
+
2474
+ include_examples 'accesses the correct parent'
2475
+ end
2476
+
2477
+ context "when the child is a has_and_belongs_to_many association" do
2478
+ let!(:player) do
2479
+ Player.create!.tap do |player|
2480
+ player.shields.create!
2481
+ end
2482
+ end
2483
+
2484
+ let(:unpersisted) { player.shields.first }
2485
+
2486
+ before do
2487
+ Player.find(player.id).shields.unset(:after_default_player)
2488
+ end
2489
+
2490
+ let(:from_db) do
2491
+ Player.find(player.id).shields.first
2492
+ end
2493
+
2494
+ include_examples 'accesses the correct parent'
2495
+ end
2496
+ end
2497
+
2498
+ context "when using build methods" do
2499
+
2500
+ context "when the child is an embeds_many association" do
2501
+ let!(:player) do
2502
+ Player.create!.tap do |player|
2503
+ player.implants.build
2504
+ player.implants.first.save!
2505
+ end
2506
+ end
2507
+
2508
+ let(:unpersisted) { player.implants.first }
2509
+
2510
+ before do
2511
+ Player.find(player.id).implants.first.unset(:after_default_player)
2512
+ end
2513
+
2514
+ let(:from_db) do
2515
+ Player.find(player.id).implants.first
2516
+ end
2517
+
2518
+ include_examples 'accesses the correct parent'
2519
+ end
2520
+
2521
+ context "when the child is an embeds_one association" do
2522
+ let!(:player) do
2523
+ Player.create!.tap do |player|
2524
+ player.build_augmentation
2525
+ player.save!
2526
+ end
2527
+ end
2528
+
2529
+ let(:unpersisted) { player.augmentation }
2530
+
2531
+ before do
2532
+ Player.find(player.id).augmentation.unset(:after_default_player)
2533
+ end
2534
+
2535
+ let(:from_db) do
2536
+ Player.find(player.id).augmentation
2537
+ end
2538
+
2539
+ include_examples 'accesses the correct parent'
2540
+ end
2541
+
2542
+ context "when the child is a has_many association" do
2543
+ let!(:player) do
2544
+ Player.create!.tap do |player|
2545
+ player.weapons.build
2546
+ player.weapons.first.save!
2547
+ end
2548
+ end
2549
+
2550
+ let(:unpersisted) { player.weapons.first }
2551
+
2552
+ before do
2553
+ Player.find(player.id).weapons.first.unset(:after_default_player)
2554
+ end
2555
+
2556
+ let(:from_db) do
2557
+ Player.find(player.id).weapons.first
2558
+ end
2559
+
2560
+ include_examples 'accesses the correct parent'
2561
+ end
2562
+
2563
+ context "when the child is a has_one association" do
2564
+ let!(:player) do
2565
+ Player.create!.tap do |player|
2566
+ player.build_powerup
2567
+ player.powerup.save!
2568
+ end
2569
+ end
2570
+
2571
+ let(:unpersisted) { player.powerup }
2572
+
2573
+ before do
2574
+ Player.find(player.id).powerup.unset(:after_default_player)
2575
+ end
2576
+
2577
+ let(:from_db) do
2578
+ Player.find(player.id).powerup
2579
+ end
2580
+
2581
+ include_examples 'accesses the correct parent'
2582
+ end
2583
+
2584
+ context "when the child is a has_and_belongs_to_many association" do
2585
+ let!(:player) do
2586
+ Player.create!.tap do |player|
2587
+ player.shields.build
2588
+ player.shields.first.save!
2589
+ end
2590
+ end
2591
+
2592
+ let(:unpersisted) { player.shields.first }
2593
+
2594
+ before do
2595
+ Player.find(player.id).shields.unset(:after_default_player)
2596
+ end
2597
+
2598
+ let(:from_db) do
2599
+ Player.find(player.id).shields.first
2600
+ end
2601
+
2602
+ include_examples 'accesses the correct parent'
2603
+ end
2604
+ end
2605
+ end
2606
+
2607
+ context "when accessing associations in defaults" do
2608
+ context "when not using autobuilding" do
2609
+ let(:band) { InterceptableBand.create(name: "Molejo") }
2610
+ let(:song) { band.songs.create(name: "Cilada") }
2611
+
2612
+ it "assigns the default correctly" do
2613
+ expect(song.band_name).to eq("Molejo")
2614
+ end
2615
+ end
2616
+
2617
+ context "when using autobuilding" do
2618
+ before do
2619
+ InterceptablePlane.create!.tap do |plane|
2620
+ plane.wings.create!
2621
+ end
2622
+ end
2623
+
2624
+ let(:plane) { InterceptablePlane.first }
2625
+ let(:wing) { InterceptableWing.first }
2626
+ let(:engine) { wing.engine }
2627
+
2628
+ it "sets the defaults correctly" do
2629
+ expect(wing._id).to eq("hello-wing")
2630
+ expect(wing.p_id).to eq(plane._id.to_s)
2631
+ expect(wing.e_id).to eq(engine._id.to_s)
2632
+ expect(engine._id).to eq("hello-engine-#{wing.id}")
2633
+ end
2634
+ end
2635
+ end
2636
+
2637
+ # This case is rather niche. The _ids method used to use the `.only` method
2638
+ # to get only the _ids for an association, which was causing a
2639
+ # MissingAttributeError to be raised when accessing another association. This
2640
+ # was fixed by using `.pluck` over `.only`. Look at MONGOID-5306 for a more
2641
+ # detailed explanation.
2642
+ context "when accessing _ids in validate and access an association in after_initialize" do
2643
+ it "doesn't raise a MissingAttributeError" do
2644
+ company = InterceptableCompany.create!
2645
+ shop = InterceptableShop.create!(company: company)
2646
+ user = InterceptableUser.new
2647
+ user.company = company
2648
+ expect do
2649
+ user.save!
2650
+ end.to_not raise_error(ActiveModel::MissingAttributeError)
2651
+ end
2652
+ end
2653
+
2654
+ context "when around callbacks for embedded are disabled" do
2655
+ config_override :around_callbacks_for_embeds, false
2656
+
2657
+ context "when around callback is defined" do
2658
+ let(:registry) { InterceptableSpec::CallbackRegistry.new }
2659
+
2660
+ let(:parent) do
2661
+ InterceptableSpec::CbEmbedsOneParent.new(registry).tap do |parent|
2662
+ parent.child = InterceptableSpec::CbEmbedsOneChild.new(registry)
2663
+ end
2664
+ end
2665
+
2666
+ before do
2667
+ expect(Mongoid.logger).to receive(:warn).with(/Around callbacks are disabled for embedded documents/).twice.and_call_original
2668
+ expect(Mongoid.logger).to receive(:warn).with(/To enable around callbacks for embedded documents/).twice.and_call_original
2669
+ end
2670
+
2671
+ it "logs a warning" do
2672
+ parent.save!
2673
+ end
1792
2674
  end
1793
2675
  end
1794
2676
  end