mongoid 9.0.11 → 9.1.0

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 (997) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -8
  3. data/README.md +5 -11
  4. data/Rakefile +35 -38
  5. data/lib/config/locales/en.yml +11 -0
  6. data/lib/mongoid/association/accessors.rb +19 -26
  7. data/lib/mongoid/association/bindable.rb +43 -45
  8. data/lib/mongoid/association/builders.rb +18 -15
  9. data/lib/mongoid/association/constrainable.rb +3 -5
  10. data/lib/mongoid/association/depending.rb +34 -38
  11. data/lib/mongoid/association/eager.rb +47 -13
  12. data/lib/mongoid/association/eager_loadable.rb +152 -24
  13. data/lib/mongoid/association/embedded/batchable.rb +28 -30
  14. data/lib/mongoid/association/embedded/cyclic.rb +8 -11
  15. data/lib/mongoid/association/embedded/eager.rb +1 -6
  16. data/lib/mongoid/association/embedded/embedded_in/binding.rb +6 -9
  17. data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -3
  18. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -0
  19. data/lib/mongoid/association/embedded/embedded_in.rb +25 -22
  20. data/lib/mongoid/association/embedded/embeds_many/binding.rb +0 -2
  21. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +2 -3
  22. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +1 -1
  23. data/lib/mongoid/association/embedded/embeds_many.rb +24 -21
  24. data/lib/mongoid/association/embedded/embeds_one/binding.rb +0 -2
  25. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +2 -6
  26. data/lib/mongoid/association/embedded/embeds_one.rb +20 -18
  27. data/lib/mongoid/association/embedded.rb +0 -1
  28. data/lib/mongoid/association/macros.rb +3 -7
  29. data/lib/mongoid/association/many.rb +75 -3
  30. data/lib/mongoid/association/marshalable.rb +0 -3
  31. data/lib/mongoid/association/nested/many.rb +18 -13
  32. data/lib/mongoid/association/nested/nested_buildable.rb +6 -9
  33. data/lib/mongoid/association/nested/one.rb +4 -7
  34. data/lib/mongoid/association/nested.rb +1 -3
  35. data/lib/mongoid/association/one.rb +0 -3
  36. data/lib/mongoid/association/options.rb +8 -7
  37. data/lib/mongoid/association/referenced/auto_save.rb +0 -2
  38. data/lib/mongoid/association/referenced/belongs_to/binding.rb +11 -15
  39. data/lib/mongoid/association/referenced/belongs_to/buildable.rb +23 -5
  40. data/lib/mongoid/association/referenced/belongs_to/eager.rb +1 -3
  41. data/lib/mongoid/association/referenced/belongs_to.rb +48 -43
  42. data/lib/mongoid/association/referenced/counter_cache.rb +5 -10
  43. data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +0 -2
  44. data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +8 -4
  45. data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +0 -3
  46. data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +52 -47
  47. data/lib/mongoid/association/referenced/has_many/binding.rb +0 -2
  48. data/lib/mongoid/association/referenced/has_many/buildable.rb +11 -5
  49. data/lib/mongoid/association/referenced/has_many/eager.rb +0 -3
  50. data/lib/mongoid/association/referenced/has_many/enumerable.rb +107 -38
  51. data/lib/mongoid/association/referenced/has_many/proxy.rb +10 -6
  52. data/lib/mongoid/association/referenced/has_many.rb +30 -24
  53. data/lib/mongoid/association/referenced/has_one/binding.rb +0 -2
  54. data/lib/mongoid/association/referenced/has_one/buildable.rb +11 -9
  55. data/lib/mongoid/association/referenced/has_one/eager.rb +0 -3
  56. data/lib/mongoid/association/referenced/has_one.rb +26 -21
  57. data/lib/mongoid/association/referenced/syncable.rb +30 -34
  58. data/lib/mongoid/association/referenced.rb +0 -1
  59. data/lib/mongoid/association/reflections.rb +0 -3
  60. data/lib/mongoid/association/relatable.rb +69 -66
  61. data/lib/mongoid/association.rb +12 -15
  62. data/lib/mongoid/atomic/modifiers.rb +65 -25
  63. data/lib/mongoid/atomic/paths/embedded/many.rb +4 -7
  64. data/lib/mongoid/atomic/paths/embedded/one.rb +2 -4
  65. data/lib/mongoid/atomic/paths/embedded.rb +3 -6
  66. data/lib/mongoid/atomic/paths/root.rb +1 -4
  67. data/lib/mongoid/atomic/paths.rb +2 -3
  68. data/lib/mongoid/atomic.rb +0 -3
  69. data/lib/mongoid/attributes/dynamic.rb +6 -7
  70. data/lib/mongoid/attributes/nested.rb +8 -10
  71. data/lib/mongoid/attributes/projector.rb +7 -20
  72. data/lib/mongoid/attributes/readonly.rb +6 -11
  73. data/lib/mongoid/attributes.rb +18 -34
  74. data/lib/mongoid/cacheable.rb +24 -6
  75. data/lib/mongoid/clients/factory.rb +12 -15
  76. data/lib/mongoid/clients/options.rb +2 -5
  77. data/lib/mongoid/clients/sessions.rb +50 -60
  78. data/lib/mongoid/clients/storage_options.rb +1 -4
  79. data/lib/mongoid/clients/validators/storage.rb +2 -3
  80. data/lib/mongoid/clients/validators.rb +1 -2
  81. data/lib/mongoid/clients.rb +8 -11
  82. data/lib/mongoid/collection_configurable.rb +10 -14
  83. data/lib/mongoid/composable.rb +30 -34
  84. data/lib/mongoid/config/defaults.rb +7 -4
  85. data/lib/mongoid/config/encryption.rb +1 -3
  86. data/lib/mongoid/config/environment.rb +7 -16
  87. data/lib/mongoid/config/introspection.rb +14 -16
  88. data/lib/mongoid/config/options.rb +16 -10
  89. data/lib/mongoid/config/validators/async_query_executor.rb +3 -6
  90. data/lib/mongoid/config/validators/client.rb +12 -15
  91. data/lib/mongoid/config/validators/option.rb +3 -5
  92. data/lib/mongoid/config/validators.rb +3 -4
  93. data/lib/mongoid/config.rb +132 -42
  94. data/lib/mongoid/contextual/aggregable/memory.rb +2 -4
  95. data/lib/mongoid/contextual/aggregable/mongo.rb +20 -22
  96. data/lib/mongoid/contextual/aggregable/none.rb +2 -4
  97. data/lib/mongoid/contextual/aggregable.rb +5 -7
  98. data/lib/mongoid/contextual/atomic.rb +20 -24
  99. data/lib/mongoid/contextual/command.rb +0 -3
  100. data/lib/mongoid/contextual/map_reduce.rb +12 -16
  101. data/lib/mongoid/contextual/memory.rb +72 -65
  102. data/lib/mongoid/contextual/mongo/documents_loader.rb +2 -3
  103. data/lib/mongoid/contextual/mongo.rb +169 -85
  104. data/lib/mongoid/contextual/none.rb +9 -9
  105. data/lib/mongoid/contextual/queryable.rb +1 -4
  106. data/lib/mongoid/contextual.rb +18 -7
  107. data/lib/mongoid/copyable.rb +7 -9
  108. data/lib/mongoid/criteria/findable.rb +5 -7
  109. data/lib/mongoid/criteria/includable.rb +37 -8
  110. data/lib/mongoid/criteria/inspectable.rb +2 -5
  111. data/lib/mongoid/criteria/marshalable.rb +4 -8
  112. data/lib/mongoid/criteria/modifiable.rb +3 -11
  113. data/lib/mongoid/criteria/options.rb +0 -3
  114. data/lib/mongoid/criteria/permission.rb +34 -37
  115. data/lib/mongoid/criteria/queryable/aggregable.rb +9 -10
  116. data/lib/mongoid/criteria/queryable/expandable.rb +4 -9
  117. data/lib/mongoid/criteria/queryable/extensions/array.rb +7 -10
  118. data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +3 -5
  119. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -4
  120. data/lib/mongoid/criteria/queryable/extensions/date.rb +2 -6
  121. data/lib/mongoid/criteria/queryable/extensions/date_time.rb +3 -7
  122. data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -4
  123. data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +20 -11
  124. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +15 -11
  125. data/lib/mongoid/criteria/queryable/extensions/object.rb +7 -8
  126. data/lib/mongoid/criteria/queryable/extensions/range.rb +6 -9
  127. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +10 -12
  128. data/lib/mongoid/criteria/queryable/extensions/set.rb +4 -6
  129. data/lib/mongoid/criteria/queryable/extensions/string.rb +5 -9
  130. data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -7
  131. data/lib/mongoid/criteria/queryable/extensions/time.rb +2 -6
  132. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +2 -12
  133. data/lib/mongoid/criteria/queryable/extensions.rb +18 -21
  134. data/lib/mongoid/criteria/queryable/key.rb +12 -18
  135. data/lib/mongoid/criteria/queryable/macroable.rb +0 -3
  136. data/lib/mongoid/criteria/queryable/mergeable.rb +31 -39
  137. data/lib/mongoid/criteria/queryable/optional.rb +17 -18
  138. data/lib/mongoid/criteria/queryable/options.rb +20 -9
  139. data/lib/mongoid/criteria/queryable/pipeline.rb +6 -9
  140. data/lib/mongoid/criteria/queryable/selectable.rb +131 -193
  141. data/lib/mongoid/criteria/queryable/selector.rb +20 -29
  142. data/lib/mongoid/criteria/queryable/smash.rb +1 -6
  143. data/lib/mongoid/criteria/queryable/storable.rb +20 -39
  144. data/lib/mongoid/criteria/queryable.rb +25 -15
  145. data/lib/mongoid/criteria/scopable.rb +5 -11
  146. data/lib/mongoid/criteria/translator.rb +5 -8
  147. data/lib/mongoid/criteria.rb +109 -54
  148. data/lib/mongoid/deprecable.rb +1 -4
  149. data/lib/mongoid/deprecation.rb +2 -6
  150. data/lib/mongoid/document.rb +1 -1
  151. data/lib/mongoid/encryptable.rb +1 -2
  152. data/lib/mongoid/equality.rb +4 -5
  153. data/lib/mongoid/errors/ambiguous_relationship.rb +2 -5
  154. data/lib/mongoid/errors/attribute_not_loaded.rb +1 -4
  155. data/lib/mongoid/errors/callback.rb +1 -4
  156. data/lib/mongoid/errors/create_collection_failure.rb +8 -11
  157. data/lib/mongoid/errors/criteria_argument_required.rb +2 -5
  158. data/lib/mongoid/errors/delete_restriction.rb +1 -4
  159. data/lib/mongoid/errors/document_not_destroyed.rb +1 -4
  160. data/lib/mongoid/errors/document_not_found.rb +16 -21
  161. data/lib/mongoid/errors/drop_collection_failure.rb +7 -10
  162. data/lib/mongoid/errors/empty_config_file.rb +1 -4
  163. data/lib/mongoid/errors/immutable_attribute.rb +1 -4
  164. data/lib/mongoid/errors/in_memory_collation_not_supported.rb +1 -4
  165. data/lib/mongoid/errors/invalid_async_query_executor.rb +2 -5
  166. data/lib/mongoid/errors/invalid_auto_encryption_configuration.rb +2 -5
  167. data/lib/mongoid/errors/invalid_collection.rb +1 -3
  168. data/lib/mongoid/errors/invalid_config_file.rb +1 -4
  169. data/lib/mongoid/errors/invalid_config_option.rb +2 -5
  170. data/lib/mongoid/errors/invalid_dependent_strategy.rb +6 -10
  171. data/lib/mongoid/errors/invalid_discriminator_key_target.rb +2 -4
  172. data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +1 -4
  173. data/lib/mongoid/errors/invalid_elem_match_operator.rb +5 -9
  174. data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +1 -4
  175. data/lib/mongoid/errors/invalid_estimated_count_scoping.rb +1 -4
  176. data/lib/mongoid/errors/invalid_expression_operator.rb +3 -7
  177. data/lib/mongoid/errors/invalid_field.rb +2 -5
  178. data/lib/mongoid/errors/invalid_field_operator.rb +5 -9
  179. data/lib/mongoid/errors/invalid_field_option.rb +2 -5
  180. data/lib/mongoid/errors/invalid_field_type.rb +1 -4
  181. data/lib/mongoid/errors/invalid_find.rb +1 -4
  182. data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +1 -4
  183. data/lib/mongoid/errors/invalid_includes.rb +3 -6
  184. data/lib/mongoid/errors/invalid_index.rb +1 -4
  185. data/lib/mongoid/errors/invalid_options.rb +1 -4
  186. data/lib/mongoid/errors/invalid_path.rb +1 -4
  187. data/lib/mongoid/errors/invalid_persistence_option.rb +4 -7
  188. data/lib/mongoid/errors/invalid_query.rb +6 -11
  189. data/lib/mongoid/errors/invalid_relation.rb +10 -13
  190. data/lib/mongoid/errors/invalid_relation_option.rb +4 -7
  191. data/lib/mongoid/errors/invalid_scope.rb +1 -4
  192. data/lib/mongoid/errors/invalid_session_nesting.rb +0 -3
  193. data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +2 -4
  194. data/lib/mongoid/errors/invalid_storage_options.rb +1 -4
  195. data/lib/mongoid/errors/invalid_time.rb +1 -4
  196. data/lib/mongoid/errors/invalid_transaction_nesting.rb +0 -3
  197. data/lib/mongoid/errors/inverse_not_found.rb +1 -4
  198. data/lib/mongoid/errors/mixed_client_configuration.rb +1 -4
  199. data/lib/mongoid/errors/mixed_relations.rb +1 -3
  200. data/lib/mongoid/errors/mongoid_error.rb +7 -11
  201. data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -4
  202. data/lib/mongoid/errors/no_client_config.rb +1 -4
  203. data/lib/mongoid/errors/no_client_database.rb +1 -4
  204. data/lib/mongoid/errors/no_client_hosts.rb +1 -4
  205. data/lib/mongoid/errors/no_clients_config.rb +1 -4
  206. data/lib/mongoid/errors/no_default_client.rb +1 -4
  207. data/lib/mongoid/errors/no_environment.rb +1 -4
  208. data/lib/mongoid/errors/no_map_reduce_output.rb +1 -4
  209. data/lib/mongoid/errors/no_metadata.rb +1 -4
  210. data/lib/mongoid/errors/no_parent.rb +1 -4
  211. data/lib/mongoid/errors/readonly_attribute.rb +1 -4
  212. data/lib/mongoid/errors/readonly_document.rb +1 -4
  213. data/lib/mongoid/errors/rollback.rb +0 -2
  214. data/lib/mongoid/errors/scope_overwrite.rb +2 -4
  215. data/lib/mongoid/errors/sessions_not_supported.rb +0 -3
  216. data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -3
  217. data/lib/mongoid/errors/transaction_error.rb +0 -3
  218. data/lib/mongoid/errors/transactions_not_supported.rb +0 -3
  219. data/lib/mongoid/errors/unknown_attribute.rb +1 -4
  220. data/lib/mongoid/errors/unknown_model.rb +1 -4
  221. data/lib/mongoid/errors/unregistered_class.rb +1 -1
  222. data/lib/mongoid/errors/unsaved_document.rb +1 -3
  223. data/lib/mongoid/errors/unsupported_isolation_level.rb +22 -0
  224. data/lib/mongoid/errors/unsupported_javascript.rb +1 -4
  225. data/lib/mongoid/errors/validations.rb +3 -5
  226. data/lib/mongoid/errors.rb +72 -72
  227. data/lib/mongoid/evolvable.rb +0 -3
  228. data/lib/mongoid/extensions/array.rb +5 -7
  229. data/lib/mongoid/extensions/big_decimal.rb +6 -7
  230. data/lib/mongoid/extensions/binary.rb +3 -6
  231. data/lib/mongoid/extensions/boolean.rb +4 -7
  232. data/lib/mongoid/extensions/bson_document.rb +28 -0
  233. data/lib/mongoid/extensions/date.rb +10 -14
  234. data/lib/mongoid/extensions/date_time.rb +2 -6
  235. data/lib/mongoid/extensions/decimal128.rb +1 -5
  236. data/lib/mongoid/extensions/false_class.rb +3 -5
  237. data/lib/mongoid/extensions/float.rb +5 -10
  238. data/lib/mongoid/extensions/hash.rb +5 -10
  239. data/lib/mongoid/extensions/integer.rb +5 -10
  240. data/lib/mongoid/extensions/module.rb +1 -4
  241. data/lib/mongoid/extensions/nil_class.rb +0 -1
  242. data/lib/mongoid/extensions/object.rb +9 -14
  243. data/lib/mongoid/extensions/object_id.rb +2 -6
  244. data/lib/mongoid/extensions/range.rb +14 -15
  245. data/lib/mongoid/extensions/raw_value.rb +0 -3
  246. data/lib/mongoid/extensions/regexp.rb +3 -6
  247. data/lib/mongoid/extensions/set.rb +3 -4
  248. data/lib/mongoid/extensions/string.rb +8 -12
  249. data/lib/mongoid/extensions/symbol.rb +3 -7
  250. data/lib/mongoid/extensions/time.rb +24 -26
  251. data/lib/mongoid/extensions/time_with_zone.rb +4 -7
  252. data/lib/mongoid/extensions/true_class.rb +3 -5
  253. data/lib/mongoid/extensions.rb +26 -26
  254. data/lib/mongoid/factory.rb +5 -9
  255. data/lib/mongoid/fields/encrypted.rb +0 -1
  256. data/lib/mongoid/fields/foreign_key.rb +9 -10
  257. data/lib/mongoid/fields/localized.rb +12 -12
  258. data/lib/mongoid/fields/standard.rb +5 -7
  259. data/lib/mongoid/fields/validators/macro.rb +23 -34
  260. data/lib/mongoid/fields/validators.rb +1 -2
  261. data/lib/mongoid/fields.rb +151 -58
  262. data/lib/mongoid/findable.rb +82 -53
  263. data/lib/mongoid/indexable/specification.rb +20 -6
  264. data/lib/mongoid/indexable/validators/options.rb +33 -40
  265. data/lib/mongoid/indexable.rb +26 -25
  266. data/lib/mongoid/inspectable.rb +4 -7
  267. data/lib/mongoid/interceptable.rb +41 -40
  268. data/lib/mongoid/loadable.rb +17 -18
  269. data/lib/mongoid/loggable.rb +4 -8
  270. data/lib/mongoid/matchable.rb +0 -2
  271. data/lib/mongoid/matcher/all.rb +2 -5
  272. data/lib/mongoid/matcher/and.rb +0 -3
  273. data/lib/mongoid/matcher/bits.rb +13 -8
  274. data/lib/mongoid/matcher/bits_all_clear.rb +1 -3
  275. data/lib/mongoid/matcher/bits_all_set.rb +1 -3
  276. data/lib/mongoid/matcher/bits_any_clear.rb +1 -3
  277. data/lib/mongoid/matcher/bits_any_set.rb +1 -3
  278. data/lib/mongoid/matcher/elem_match.rb +13 -15
  279. data/lib/mongoid/matcher/elem_match_expression.rb +0 -3
  280. data/lib/mongoid/matcher/eq.rb +0 -3
  281. data/lib/mongoid/matcher/eq_impl.rb +12 -17
  282. data/lib/mongoid/matcher/eq_impl_with_regexp.rb +4 -7
  283. data/lib/mongoid/matcher/exists.rb +1 -4
  284. data/lib/mongoid/matcher/expression.rb +5 -10
  285. data/lib/mongoid/matcher/expression_operator.rb +1 -3
  286. data/lib/mongoid/matcher/field_expression.rb +10 -13
  287. data/lib/mongoid/matcher/field_operator.rb +4 -6
  288. data/lib/mongoid/matcher/gt.rb +0 -3
  289. data/lib/mongoid/matcher/gte.rb +0 -3
  290. data/lib/mongoid/matcher/in.rb +9 -12
  291. data/lib/mongoid/matcher/lt.rb +0 -3
  292. data/lib/mongoid/matcher/lte.rb +0 -3
  293. data/lib/mongoid/matcher/mod.rb +4 -8
  294. data/lib/mongoid/matcher/ne.rb +0 -3
  295. data/lib/mongoid/matcher/nin.rb +0 -3
  296. data/lib/mongoid/matcher/nor.rb +1 -6
  297. data/lib/mongoid/matcher/not.rb +0 -3
  298. data/lib/mongoid/matcher/or.rb +0 -3
  299. data/lib/mongoid/matcher/regex.rb +11 -14
  300. data/lib/mongoid/matcher/size.rb +2 -5
  301. data/lib/mongoid/matcher/type.rb +32 -37
  302. data/lib/mongoid/matcher.rb +7 -15
  303. data/lib/mongoid/model_resolver.rb +1 -0
  304. data/lib/mongoid/persistable/creatable.rb +23 -7
  305. data/lib/mongoid/persistable/deletable.rb +6 -7
  306. data/lib/mongoid/persistable/destroyable.rb +2 -6
  307. data/lib/mongoid/persistable/incrementable.rb +1 -3
  308. data/lib/mongoid/persistable/logical.rb +3 -5
  309. data/lib/mongoid/persistable/maxable.rb +2 -4
  310. data/lib/mongoid/persistable/minable.rb +2 -4
  311. data/lib/mongoid/persistable/multipliable.rb +1 -3
  312. data/lib/mongoid/persistable/poppable.rb +2 -4
  313. data/lib/mongoid/persistable/pullable.rb +3 -5
  314. data/lib/mongoid/persistable/pushable.rb +5 -7
  315. data/lib/mongoid/persistable/renamable.rb +1 -3
  316. data/lib/mongoid/persistable/savable.rb +0 -3
  317. data/lib/mongoid/persistable/settable.rb +4 -13
  318. data/lib/mongoid/persistable/unsettable.rb +1 -3
  319. data/lib/mongoid/persistable/updatable.rb +16 -24
  320. data/lib/mongoid/persistable/upsertable.rb +8 -10
  321. data/lib/mongoid/persistable.rb +28 -27
  322. data/lib/mongoid/persistence_context.rb +34 -41
  323. data/lib/mongoid/pluckable.rb +0 -2
  324. data/lib/mongoid/positional.rb +5 -11
  325. data/lib/mongoid/railtie.rb +16 -22
  326. data/lib/mongoid/railties/console_sandbox.rb +6 -8
  327. data/lib/mongoid/railties/controller_runtime.rb +7 -11
  328. data/lib/mongoid/railties/database.rake +42 -44
  329. data/lib/mongoid/scopable.rb +23 -31
  330. data/lib/mongoid/search_indexable.rb +330 -0
  331. data/lib/mongoid/selectable.rb +1 -3
  332. data/lib/mongoid/serializable.rb +6 -8
  333. data/lib/mongoid/shardable.rb +8 -17
  334. data/lib/mongoid/stateful.rb +5 -10
  335. data/lib/mongoid/stringified_symbol.rb +5 -9
  336. data/lib/mongoid/tasks/database.rake +31 -32
  337. data/lib/mongoid/tasks/database.rb +28 -30
  338. data/lib/mongoid/tasks/encryption.rb +10 -15
  339. data/lib/mongoid/threaded/lifecycle.rb +6 -9
  340. data/lib/mongoid/threaded.rb +132 -32
  341. data/lib/mongoid/timestamps/created/short.rb +2 -3
  342. data/lib/mongoid/timestamps/created.rb +1 -2
  343. data/lib/mongoid/timestamps/short.rb +0 -1
  344. data/lib/mongoid/timestamps/timeless.rb +8 -13
  345. data/lib/mongoid/timestamps/updated/short.rb +2 -3
  346. data/lib/mongoid/timestamps/updated.rb +2 -5
  347. data/lib/mongoid/timestamps.rb +4 -6
  348. data/lib/mongoid/touchable.rb +19 -11
  349. data/lib/mongoid/traversable.rb +3 -2
  350. data/lib/mongoid/validatable/associated.rb +1 -5
  351. data/lib/mongoid/validatable/format.rb +0 -2
  352. data/lib/mongoid/validatable/length.rb +0 -2
  353. data/lib/mongoid/validatable/localizable.rb +0 -3
  354. data/lib/mongoid/validatable/macros.rb +0 -2
  355. data/lib/mongoid/validatable/numericality.rb +24 -3
  356. data/lib/mongoid/validatable/presence.rb +8 -10
  357. data/lib/mongoid/validatable/queryable.rb +0 -3
  358. data/lib/mongoid/validatable/uniqueness.rb +12 -14
  359. data/lib/mongoid/validatable.rb +15 -20
  360. data/lib/mongoid/version.rb +1 -1
  361. data/lib/mongoid/warnings.rb +10 -11
  362. data/lib/mongoid.rb +30 -34
  363. data/lib/rails/generators/mongoid/config/config_generator.rb +2 -4
  364. data/lib/rails/generators/mongoid/config/templates/mongoid.rb +4 -5
  365. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +2 -2
  366. data/lib/rails/generators/mongoid/model/model_generator.rb +5 -8
  367. data/lib/rails/generators/mongoid_generator.rb +6 -10
  368. data/lib/rails/mongoid.rb +1 -3
  369. data/spec/integration/active_job_spec.rb +1 -2
  370. data/spec/integration/app_spec.rb +142 -178
  371. data/spec/integration/associations/belongs_to_spec.rb +30 -28
  372. data/spec/integration/associations/embedded_dirty_spec.rb +0 -1
  373. data/spec/integration/associations/embedded_spec.rb +41 -43
  374. data/spec/integration/associations/embeds_many_spec.rb +46 -29
  375. data/spec/integration/associations/embeds_one_spec.rb +2 -1
  376. data/spec/integration/associations/foreign_key_spec.rb +10 -11
  377. data/spec/integration/associations/foreign_key_spec_models.rb +8 -9
  378. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +16 -13
  379. data/spec/integration/associations/has_many_spec.rb +17 -18
  380. data/spec/integration/associations/has_one_spec.rb +42 -45
  381. data/spec/integration/associations/nested_attributes_assignment_spec.rb +36 -39
  382. data/spec/integration/associations/reverse_population_spec.rb +4 -5
  383. data/spec/integration/associations/reverse_population_spec_models.rb +0 -1
  384. data/spec/integration/associations/scope_option_spec.rb +18 -20
  385. data/spec/integration/atomic/modifiers_spec.rb +72 -52
  386. data/spec/integration/bson_regexp_raw_spec.rb +2 -3
  387. data/spec/integration/caching_spec.rb +68 -0
  388. data/spec/integration/callbacks_models.rb +11 -9
  389. data/spec/integration/callbacks_spec.rb +78 -80
  390. data/spec/integration/contextual/empty_spec.rb +19 -20
  391. data/spec/integration/criteria/alias_query_spec.rb +12 -19
  392. data/spec/integration/criteria/date_field_spec.rb +1 -2
  393. data/spec/integration/criteria/default_scope_spec.rb +23 -18
  394. data/spec/integration/criteria/logical_spec.rb +18 -19
  395. data/spec/integration/criteria/range_spec.rb +77 -86
  396. data/spec/integration/criteria/raw_value_spec.rb +122 -109
  397. data/spec/integration/criteria/time_with_zone_spec.rb +33 -24
  398. data/spec/integration/discriminator_key_spec.rb +85 -85
  399. data/spec/integration/discriminator_value_spec.rb +70 -73
  400. data/spec/integration/document_spec.rb +9 -10
  401. data/spec/integration/dots_and_dollars_spec.rb +104 -119
  402. data/spec/integration/encryption_spec.rb +8 -11
  403. data/spec/integration/i18n_fallbacks_spec.rb +7 -8
  404. data/spec/integration/isolation_state_spec.rb +241 -0
  405. data/spec/integration/matcher_examples_spec.rb +145 -168
  406. data/spec/integration/matcher_operator_data/in.yml +6 -6
  407. data/spec/integration/matcher_operator_spec.rb +16 -26
  408. data/spec/integration/matcher_spec.rb +31 -32
  409. data/spec/integration/persistence/collection_options_spec.rb +0 -2
  410. data/spec/integration/persistence/range_field_spec.rb +24 -2
  411. data/spec/integration/server_query_spec.rb +43 -37
  412. data/spec/integration/shardable_spec.rb +10 -11
  413. data/spec/integration/stringified_symbol_field_spec.rb +28 -43
  414. data/spec/lite_spec_helper.rb +11 -12
  415. data/spec/mongoid/association/accessors_spec.rb +197 -285
  416. data/spec/mongoid/association/auto_save_spec.rb +62 -93
  417. data/spec/mongoid/association/builders_spec.rb +121 -74
  418. data/spec/mongoid/association/constrainable_spec.rb +9 -22
  419. data/spec/mongoid/association/counter_cache_spec.rb +71 -104
  420. data/spec/mongoid/association/depending_spec.rb +166 -208
  421. data/spec/mongoid/association/eager_spec.rb +416 -80
  422. data/spec/mongoid/association/embedded/cyclic_spec.rb +36 -48
  423. data/spec/mongoid/association/embedded/dirty_spec.rb +15 -20
  424. data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +36 -54
  425. data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +8 -15
  426. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +135 -175
  427. data/spec/mongoid/association/embedded/embedded_in_spec.rb +25 -127
  428. data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +9 -14
  429. data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +38 -51
  430. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +1151 -1340
  431. data/spec/mongoid/association/embedded/embeds_many_models.rb +17 -17
  432. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +11 -11
  433. data/spec/mongoid/association/embedded/embeds_many_spec.rb +25 -138
  434. data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +15 -23
  435. data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +18 -26
  436. data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +204 -273
  437. data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +0 -1
  438. data/spec/mongoid/association/embedded/embeds_one_models.rb +0 -1
  439. data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +5 -6
  440. data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -143
  441. data/spec/mongoid/association/macros_spec.rb +213 -300
  442. data/spec/mongoid/association/nested/many_spec.rb +51 -73
  443. data/spec/mongoid/association/nested/one_spec.rb +56 -80
  444. data/spec/mongoid/association/options_spec.rb +187 -310
  445. data/spec/mongoid/association/polymorphic_spec.rb +35 -53
  446. data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +55 -76
  447. data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +36 -41
  448. data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +81 -101
  449. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +258 -345
  450. data/spec/mongoid/association/referenced/belongs_to_models.rb +4 -3
  451. data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +3 -4
  452. data/spec/mongoid/association/referenced/belongs_to_spec.rb +91 -294
  453. data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +42 -56
  454. data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +41 -32
  455. data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +36 -42
  456. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +8 -9
  457. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +771 -975
  458. data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +9 -9
  459. data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +5 -6
  460. data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +59 -177
  461. data/spec/mongoid/association/referenced/has_many/binding_spec.rb +29 -43
  462. data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +53 -53
  463. data/spec/mongoid/association/referenced/has_many/eager_spec.rb +104 -67
  464. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +431 -675
  465. data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -2
  466. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +173 -11
  467. data/spec/mongoid/association/referenced/has_many_models.rb +1 -2
  468. data/spec/mongoid/association/referenced/has_many_query_spec.rb +3 -4
  469. data/spec/mongoid/association/referenced/has_many_spec.rb +44 -188
  470. data/spec/mongoid/association/referenced/has_one/binding_spec.rb +26 -38
  471. data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +28 -29
  472. data/spec/mongoid/association/referenced/has_one/eager_spec.rb +29 -42
  473. data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +270 -332
  474. data/spec/mongoid/association/referenced/has_one_models.rb +1 -2
  475. data/spec/mongoid/association/referenced/has_one_query_spec.rb +3 -4
  476. data/spec/mongoid/association/referenced/has_one_spec.rb +40 -188
  477. data/spec/mongoid/association/reflections_spec.rb +14 -24
  478. data/spec/mongoid/association/syncable_spec.rb +102 -125
  479. data/spec/mongoid/association_spec.rb +47 -70
  480. data/spec/mongoid/atomic/modifiers_spec.rb +184 -197
  481. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +39 -52
  482. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +35 -49
  483. data/spec/mongoid/atomic/paths/root_spec.rb +9 -15
  484. data/spec/mongoid/atomic/paths_spec.rb +81 -117
  485. data/spec/mongoid/atomic_spec.rb +156 -171
  486. data/spec/mongoid/attributes/dynamic_spec.rb +5 -6
  487. data/spec/mongoid/attributes/nested_spec.rb +1219 -1692
  488. data/spec/mongoid/attributes/nested_spec_models.rb +8 -9
  489. data/spec/mongoid/attributes/projector_spec.rb +2 -6
  490. data/spec/mongoid/attributes/readonly_spec.rb +73 -97
  491. data/spec/mongoid/attributes_spec.rb +669 -826
  492. data/spec/mongoid/cacheable_spec.rb +74 -44
  493. data/spec/mongoid/changeable_spec.rb +591 -733
  494. data/spec/mongoid/clients/factory_spec.rb +122 -154
  495. data/spec/mongoid/clients/options_spec.rb +40 -59
  496. data/spec/mongoid/clients/sessions_spec.rb +25 -44
  497. data/spec/mongoid/clients/transactions_spec.rb +33 -50
  498. data/spec/mongoid/clients/transactions_spec_models.rb +3 -4
  499. data/spec/mongoid/clients_spec.rb +265 -355
  500. data/spec/mongoid/collection_configurable_spec.rb +9 -12
  501. data/spec/mongoid/composable_spec.rb +2 -9
  502. data/spec/mongoid/config/defaults_spec.rb +24 -31
  503. data/spec/mongoid/config/encryption_spec.rb +54 -57
  504. data/spec/mongoid/config/environment_spec.rb +30 -40
  505. data/spec/mongoid/config/introspection_spec.rb +42 -37
  506. data/spec/mongoid/config/options_spec.rb +14 -21
  507. data/spec/mongoid/config_spec.rb +145 -195
  508. data/spec/mongoid/contextual/aggregable/memory_spec.rb +98 -135
  509. data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +4 -7
  510. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +149 -187
  511. data/spec/mongoid/contextual/aggregable/none_spec.rb +14 -16
  512. data/spec/mongoid/contextual/atomic_spec.rb +223 -271
  513. data/spec/mongoid/contextual/map_reduce_spec.rb +110 -138
  514. data/spec/mongoid/contextual/memory_spec.rb +706 -854
  515. data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +12 -13
  516. data/spec/mongoid/contextual/mongo_spec.rb +1008 -1213
  517. data/spec/mongoid/contextual/none_spec.rb +54 -59
  518. data/spec/mongoid/contextual/short_circuit_spec.rb +139 -0
  519. data/spec/mongoid/copyable_spec.rb +254 -300
  520. data/spec/mongoid/copyable_spec_models.rb +0 -1
  521. data/spec/mongoid/criteria/findable_spec.rb +322 -387
  522. data/spec/mongoid/criteria/includable_spec.rb +421 -372
  523. data/spec/mongoid/criteria/includable_spec_models.rb +16 -7
  524. data/spec/mongoid/criteria/inspectable_spec.rb +11 -14
  525. data/spec/mongoid/criteria/marshalable_spec.rb +11 -14
  526. data/spec/mongoid/criteria/modifiable_spec.rb +366 -512
  527. data/spec/mongoid/criteria/options_spec.rb +2 -7
  528. data/spec/mongoid/criteria/queryable/aggregable_spec.rb +112 -141
  529. data/spec/mongoid/criteria/queryable/expandable_spec.rb +8 -11
  530. data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +127 -184
  531. data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +123 -60
  532. data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +84 -117
  533. data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +44 -65
  534. data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +86 -108
  535. data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +94 -33
  536. data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +103 -138
  537. data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +95 -34
  538. data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +25 -38
  539. data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +26 -28
  540. data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +32 -54
  541. data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +136 -130
  542. data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +16 -24
  543. data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +15 -24
  544. data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +12 -19
  545. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +46 -63
  546. data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +28 -42
  547. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +73 -96
  548. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +71 -92
  549. data/spec/mongoid/criteria/queryable/key_spec.rb +32 -36
  550. data/spec/mongoid/criteria/queryable/mergeable_spec.rb +44 -49
  551. data/spec/mongoid/criteria/queryable/optional_spec.rb +373 -486
  552. data/spec/mongoid/criteria/queryable/options_spec.rb +172 -123
  553. data/spec/mongoid/criteria/queryable/pipeline_spec.rb +65 -87
  554. data/spec/mongoid/criteria/queryable/queryable_spec.rb +41 -53
  555. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +576 -680
  556. data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +7 -11
  557. data/spec/mongoid/criteria/queryable/selectable_spec.rb +807 -998
  558. data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +154 -191
  559. data/spec/mongoid/criteria/queryable/selector_spec.rb +294 -390
  560. data/spec/mongoid/criteria/queryable/smash_spec.rb +6 -11
  561. data/spec/mongoid/criteria/queryable/storable_spec.rb +54 -81
  562. data/spec/mongoid/criteria/queryable_mql_spec.rb +92 -0
  563. data/spec/mongoid/criteria/scopable_spec.rb +102 -138
  564. data/spec/mongoid/criteria/translator_spec.rb +59 -60
  565. data/spec/mongoid/criteria_projection_spec.rb +81 -99
  566. data/spec/mongoid/criteria_spec.rb +935 -950
  567. data/spec/mongoid/document_fields_spec.rb +28 -30
  568. data/spec/mongoid/document_persistence_context_spec.rb +13 -15
  569. data/spec/mongoid/document_query_spec.rb +9 -12
  570. data/spec/mongoid/document_spec.rb +317 -409
  571. data/spec/mongoid/equality_spec.rb +69 -102
  572. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +8 -11
  573. data/spec/mongoid/errors/attribute_not_loaded_spec.rb +7 -10
  574. data/spec/mongoid/errors/callback_spec.rb +8 -11
  575. data/spec/mongoid/errors/delete_restriction_spec.rb +5 -8
  576. data/spec/mongoid/errors/document_not_destroyed_spec.rb +7 -10
  577. data/spec/mongoid/errors/document_not_found_spec.rb +51 -61
  578. data/spec/mongoid/errors/invalid_collection_spec.rb +9 -13
  579. data/spec/mongoid/errors/invalid_config_file_spec.rb +8 -11
  580. data/spec/mongoid/errors/invalid_config_option_spec.rb +8 -11
  581. data/spec/mongoid/errors/invalid_field_option_spec.rb +7 -10
  582. data/spec/mongoid/errors/invalid_field_spec.rb +10 -11
  583. data/spec/mongoid/errors/invalid_field_type_spec.rb +9 -12
  584. data/spec/mongoid/errors/invalid_find_spec.rb +8 -11
  585. data/spec/mongoid/errors/invalid_includes_spec.rb +9 -13
  586. data/spec/mongoid/errors/invalid_index_spec.rb +8 -11
  587. data/spec/mongoid/errors/invalid_options_spec.rb +8 -11
  588. data/spec/mongoid/errors/invalid_path_spec.rb +7 -10
  589. data/spec/mongoid/errors/invalid_relation_spec.rb +15 -16
  590. data/spec/mongoid/errors/invalid_scope_spec.rb +8 -11
  591. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -6
  592. data/spec/mongoid/errors/invalid_storage_options_spec.rb +8 -11
  593. data/spec/mongoid/errors/invalid_time_spec.rb +8 -11
  594. data/spec/mongoid/errors/inverse_not_found_spec.rb +9 -12
  595. data/spec/mongoid/errors/mixed_client_configuration_spec.rb +9 -12
  596. data/spec/mongoid/errors/mixed_relations_spec.rb +8 -11
  597. data/spec/mongoid/errors/mongoid_error_spec.rb +21 -24
  598. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +6 -9
  599. data/spec/mongoid/errors/no_client_config_spec.rb +7 -10
  600. data/spec/mongoid/errors/no_client_database_spec.rb +9 -12
  601. data/spec/mongoid/errors/no_client_hosts_spec.rb +9 -12
  602. data/spec/mongoid/errors/no_clients_config_spec.rb +7 -10
  603. data/spec/mongoid/errors/no_environment_spec.rb +8 -11
  604. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +8 -11
  605. data/spec/mongoid/errors/no_metadata_spec.rb +7 -10
  606. data/spec/mongoid/errors/no_parent_spec.rb +7 -10
  607. data/spec/mongoid/errors/readonly_attribute_spec.rb +7 -10
  608. data/spec/mongoid/errors/readonly_document_spec.rb +6 -9
  609. data/spec/mongoid/errors/scope_overwrite_spec.rb +9 -12
  610. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +9 -12
  611. data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -8
  612. data/spec/mongoid/errors/unsaved_document_spec.rb +8 -11
  613. data/spec/mongoid/errors/unsupported_javascript_spec.rb +9 -12
  614. data/spec/mongoid/errors/validations_spec.rb +11 -14
  615. data/spec/mongoid/extensions/array_spec.rb +70 -92
  616. data/spec/mongoid/extensions/big_decimal_spec.rb +233 -313
  617. data/spec/mongoid/extensions/binary_spec.rb +21 -32
  618. data/spec/mongoid/extensions/boolean_spec.rb +52 -75
  619. data/spec/mongoid/extensions/date_class_mongoize_spec.rb +43 -54
  620. data/spec/mongoid/extensions/date_spec.rb +26 -38
  621. data/spec/mongoid/extensions/date_time_spec.rb +22 -32
  622. data/spec/mongoid/extensions/decimal128_spec.rb +12 -18
  623. data/spec/mongoid/extensions/false_class_spec.rb +10 -17
  624. data/spec/mongoid/extensions/float_spec.rb +40 -61
  625. data/spec/mongoid/extensions/hash_spec.rb +46 -64
  626. data/spec/mongoid/extensions/integer_spec.rb +40 -61
  627. data/spec/mongoid/extensions/module_spec.rb +13 -18
  628. data/spec/mongoid/extensions/nil_class_spec.rb +2 -5
  629. data/spec/mongoid/extensions/object_id_spec.rb +159 -247
  630. data/spec/mongoid/extensions/object_spec.rb +31 -47
  631. data/spec/mongoid/extensions/range_spec.rb +112 -115
  632. data/spec/mongoid/extensions/raw_value_spec.rb +10 -12
  633. data/spec/mongoid/extensions/regexp_spec.rb +23 -36
  634. data/spec/mongoid/extensions/set_spec.rb +38 -49
  635. data/spec/mongoid/extensions/string_spec.rb +118 -167
  636. data/spec/mongoid/extensions/stringified_symbol_spec.rb +29 -43
  637. data/spec/mongoid/extensions/symbol_spec.rb +12 -20
  638. data/spec/mongoid/extensions/time_spec.rb +160 -202
  639. data/spec/mongoid/extensions/time_with_zone_spec.rb +79 -105
  640. data/spec/mongoid/extensions/true_class_spec.rb +10 -17
  641. data/spec/mongoid/factory_spec.rb +125 -148
  642. data/spec/mongoid/fields/foreign_key_spec.rb +124 -169
  643. data/spec/mongoid/fields/localized_spec.rb +140 -185
  644. data/spec/mongoid/fields/standard_spec.rb +43 -59
  645. data/spec/mongoid/fields_spec.rb +751 -620
  646. data/spec/mongoid/findable_spec.rb +260 -228
  647. data/spec/mongoid/indexable/specification_spec.rb +42 -58
  648. data/spec/mongoid/indexable_spec.rb +260 -264
  649. data/spec/mongoid/inspectable_spec.rb +45 -55
  650. data/spec/mongoid/interceptable_spec.rb +784 -922
  651. data/spec/mongoid/interceptable_spec_models.rb +35 -35
  652. data/spec/mongoid/loading_spec.rb +47 -43
  653. data/spec/mongoid/loggable_spec.rb +3 -6
  654. data/spec/mongoid/matcher/extract_attribute_spec.rb +2 -6
  655. data/spec/mongoid/mongoizable_spec.rb +81 -90
  656. data/spec/mongoid/monkey_patches_spec.rb +4 -0
  657. data/spec/mongoid/persistable/creatable_spec.rb +181 -220
  658. data/spec/mongoid/persistable/deletable_spec.rb +139 -179
  659. data/spec/mongoid/persistable/destroyable_spec.rb +135 -164
  660. data/spec/mongoid/persistable/incrementable_spec.rb +65 -84
  661. data/spec/mongoid/persistable/logical_spec.rb +48 -61
  662. data/spec/mongoid/persistable/maxable_spec.rb +45 -44
  663. data/spec/mongoid/persistable/minable_spec.rb +45 -44
  664. data/spec/mongoid/persistable/multipliable_spec.rb +54 -69
  665. data/spec/mongoid/persistable/poppable_spec.rb +47 -60
  666. data/spec/mongoid/persistable/pullable_spec.rb +79 -103
  667. data/spec/mongoid/persistable/pushable_spec.rb +106 -131
  668. data/spec/mongoid/persistable/renamable_spec.rb +52 -65
  669. data/spec/mongoid/persistable/savable_spec.rb +152 -189
  670. data/spec/mongoid/persistable/settable_spec.rb +121 -145
  671. data/spec/mongoid/persistable/unsettable_spec.rb +56 -73
  672. data/spec/mongoid/persistable/updatable_spec.rb +185 -232
  673. data/spec/mongoid/persistable/upsertable_spec.rb +66 -77
  674. data/spec/mongoid/persistable_spec.rb +132 -139
  675. data/spec/mongoid/persistence_context_spec.rb +31 -89
  676. data/spec/mongoid/positional_spec.rb +67 -79
  677. data/spec/mongoid/railties/bson_object_id_serializer_spec.rb +0 -3
  678. data/spec/mongoid/railties/console_sandbox_spec.rb +0 -1
  679. data/spec/mongoid/relations/proxy_spec.rb +0 -1
  680. data/spec/mongoid/reloadable_spec.rb +250 -145
  681. data/spec/mongoid/scopable_spec.rb +319 -398
  682. data/spec/mongoid/search_indexable_spec.rb +446 -41
  683. data/spec/mongoid/selectable_spec.rb +36 -51
  684. data/spec/mongoid/serializable_spec.rb +269 -312
  685. data/spec/mongoid/shardable_models.rb +5 -5
  686. data/spec/mongoid/shardable_spec.rb +44 -46
  687. data/spec/mongoid/stateful_spec.rb +55 -75
  688. data/spec/mongoid/tasks/database_rake_spec.rb +138 -141
  689. data/spec/mongoid/tasks/database_spec.rb +80 -80
  690. data/spec/mongoid/tasks/encryption_spec.rb +22 -20
  691. data/spec/mongoid/threaded_spec.rb +57 -83
  692. data/spec/mongoid/timestamps/created/short_spec.rb +12 -16
  693. data/spec/mongoid/timestamps/created_spec.rb +16 -20
  694. data/spec/mongoid/timestamps/timeless_spec.rb +31 -43
  695. data/spec/mongoid/timestamps/updated/short_spec.rb +21 -28
  696. data/spec/mongoid/timestamps/updated_spec.rb +18 -25
  697. data/spec/mongoid/timestamps_spec.rb +171 -188
  698. data/spec/mongoid/timestamps_spec_models.rb +12 -13
  699. data/spec/mongoid/touchable_spec.rb +330 -294
  700. data/spec/mongoid/touchable_spec_models.rb +35 -37
  701. data/spec/mongoid/traversable_spec.rb +435 -471
  702. data/spec/mongoid/validatable/associated_spec.rb +42 -60
  703. data/spec/mongoid/validatable/format_spec.rb +24 -34
  704. data/spec/mongoid/validatable/length_spec.rb +62 -86
  705. data/spec/mongoid/validatable/numericality_spec.rb +114 -23
  706. data/spec/mongoid/validatable/presence_spec.rb +149 -203
  707. data/spec/mongoid/validatable/uniqueness_spec.rb +632 -830
  708. data/spec/mongoid/validatable_spec.rb +71 -103
  709. data/spec/mongoid/warnings_spec.rb +5 -9
  710. data/spec/mongoid_spec.rb +25 -41
  711. data/spec/rails/controller_extension/controller_runtime_spec.rb +45 -49
  712. data/spec/rails/mongoid_spec.rb +15 -15
  713. data/spec/shared/lib/mrss/cluster_config.rb +5 -40
  714. data/spec/shared/lib/mrss/constraints.rb +7 -46
  715. data/spec/shared/lib/mrss/docker_runner.rb +10 -21
  716. data/spec/shared/lib/mrss/eg_config_utils.rb +0 -31
  717. data/spec/shared/lib/mrss/release/candidate.rb +18 -12
  718. data/spec/shared/lib/mrss/server_version_registry.rb +1 -5
  719. data/spec/shared/share/Dockerfile.erb +6 -8
  720. data/spec/shared/shlib/server.sh +0 -50
  721. data/spec/shared/shlib/set_env.sh +4 -10
  722. data/spec/spec_helper.rb +54 -31
  723. data/spec/support/authorization.rb +0 -1
  724. data/spec/support/client_registry.rb +1 -2
  725. data/spec/support/constraints.rb +8 -25
  726. data/spec/support/crypt/models.rb +7 -8
  727. data/spec/support/crypt.rb +6 -9
  728. data/spec/support/expectations.rb +21 -7
  729. data/spec/support/feature_sandbox.rb +1 -4
  730. data/spec/support/helpers.rb +0 -1
  731. data/spec/support/immutable_ids.rb +20 -21
  732. data/spec/support/macros.rb +1 -3
  733. data/spec/support/models/account.rb +4 -5
  734. data/spec/support/models/acolyte.rb +5 -5
  735. data/spec/support/models/actor.rb +3 -3
  736. data/spec/support/models/actress.rb +0 -1
  737. data/spec/support/models/address.rb +11 -11
  738. data/spec/support/models/address_component.rb +1 -1
  739. data/spec/support/models/address_number.rb +1 -1
  740. data/spec/support/models/agency.rb +1 -1
  741. data/spec/support/models/agent.rb +1 -1
  742. data/spec/support/models/album.rb +1 -2
  743. data/spec/support/models/alert.rb +1 -1
  744. data/spec/support/models/animal.rb +4 -5
  745. data/spec/support/models/answer.rb +1 -1
  746. data/spec/support/models/appointment.rb +2 -2
  747. data/spec/support/models/armrest.rb +0 -1
  748. data/spec/support/models/array_field.rb +0 -1
  749. data/spec/support/models/article.rb +0 -1
  750. data/spec/support/models/artist.rb +16 -12
  751. data/spec/support/models/artwork.rb +1 -1
  752. data/spec/support/models/audible_sound.rb +0 -1
  753. data/spec/support/models/audio.rb +2 -2
  754. data/spec/support/models/augmentation.rb +1 -2
  755. data/spec/support/models/author.rb +1 -1
  756. data/spec/support/models/baby.rb +1 -1
  757. data/spec/support/models/band.rb +0 -1
  758. data/spec/support/models/bar.rb +2 -2
  759. data/spec/support/models/basic.rb +0 -1
  760. data/spec/support/models/bed.rb +0 -1
  761. data/spec/support/models/big_palette.rb +0 -1
  762. data/spec/support/models/birthday.rb +3 -5
  763. data/spec/support/models/bolt.rb +0 -1
  764. data/spec/support/models/bomb.rb +1 -1
  765. data/spec/support/models/book.rb +1 -1
  766. data/spec/support/models/breed.rb +1 -1
  767. data/spec/support/models/browser.rb +1 -2
  768. data/spec/support/models/building.rb +0 -1
  769. data/spec/support/models/building_address.rb +1 -1
  770. data/spec/support/models/bus.rb +1 -1
  771. data/spec/support/models/business.rb +2 -2
  772. data/spec/support/models/callback_test.rb +1 -1
  773. data/spec/support/models/canvas.rb +5 -6
  774. data/spec/support/models/car.rb +0 -1
  775. data/spec/support/models/cat.rb +0 -2
  776. data/spec/support/models/catalog.rb +0 -1
  777. data/spec/support/models/category.rb +1 -1
  778. data/spec/support/models/child.rb +1 -1
  779. data/spec/support/models/child_doc.rb +5 -6
  780. data/spec/support/models/church.rb +1 -1
  781. data/spec/support/models/circle.rb +0 -1
  782. data/spec/support/models/circuit.rb +2 -2
  783. data/spec/support/models/circus.rb +0 -1
  784. data/spec/support/models/code.rb +2 -1
  785. data/spec/support/models/coding/pull_request.rb +0 -1
  786. data/spec/support/models/coding.rb +0 -1
  787. data/spec/support/models/comment.rb +0 -1
  788. data/spec/support/models/company.rb +0 -1
  789. data/spec/support/models/consumption_period.rb +0 -1
  790. data/spec/support/models/contextable_item.rb +1 -1
  791. data/spec/support/models/contractor.rb +1 -1
  792. data/spec/support/models/cookie.rb +0 -1
  793. data/spec/support/models/country_code.rb +2 -3
  794. data/spec/support/models/courier_job.rb +2 -2
  795. data/spec/support/models/cover.rb +0 -1
  796. data/spec/support/models/crate.rb +0 -1
  797. data/spec/support/models/customer.rb +0 -1
  798. data/spec/support/models/customer_address.rb +0 -1
  799. data/spec/support/models/deed.rb +1 -1
  800. data/spec/support/models/definition.rb +1 -1
  801. data/spec/support/models/delegating_patient.rb +0 -1
  802. data/spec/support/models/description.rb +0 -1
  803. data/spec/support/models/dictionary.rb +1 -1
  804. data/spec/support/models/division.rb +2 -2
  805. data/spec/support/models/doctor.rb +0 -1
  806. data/spec/support/models/dog.rb +2 -2
  807. data/spec/support/models/dokument.rb +1 -1
  808. data/spec/support/models/draft.rb +0 -1
  809. data/spec/support/models/dragon.rb +1 -1
  810. data/spec/support/models/driver.rb +2 -2
  811. data/spec/support/models/drug.rb +1 -1
  812. data/spec/support/models/dungeon.rb +1 -1
  813. data/spec/support/models/edit.rb +1 -1
  814. data/spec/support/models/email.rb +1 -1
  815. data/spec/support/models/employer.rb +1 -2
  816. data/spec/support/models/entry.rb +1 -1
  817. data/spec/support/models/eraser.rb +0 -1
  818. data/spec/support/models/even.rb +1 -1
  819. data/spec/support/models/event.rb +3 -4
  820. data/spec/support/models/exhibition.rb +1 -1
  821. data/spec/support/models/exhibitor.rb +1 -1
  822. data/spec/support/models/explosion.rb +1 -1
  823. data/spec/support/models/eye.rb +0 -1
  824. data/spec/support/models/eye_bowl.rb +2 -3
  825. data/spec/support/models/face.rb +2 -3
  826. data/spec/support/models/fanatic.rb +1 -1
  827. data/spec/support/models/favorite.rb +1 -1
  828. data/spec/support/models/filesystem.rb +1 -1
  829. data/spec/support/models/fire_hydrant.rb +1 -1
  830. data/spec/support/models/firefox.rb +0 -1
  831. data/spec/support/models/fish.rb +0 -1
  832. data/spec/support/models/folder.rb +0 -2
  833. data/spec/support/models/folder_item.rb +1 -3
  834. data/spec/support/models/fruits.rb +9 -5
  835. data/spec/support/models/game.rb +3 -4
  836. data/spec/support/models/ghost.rb +0 -1
  837. data/spec/support/models/guitar.rb +0 -1
  838. data/spec/support/models/hole.rb +0 -1
  839. data/spec/support/models/home.rb +1 -1
  840. data/spec/support/models/house.rb +2 -2
  841. data/spec/support/models/html_writer.rb +0 -1
  842. data/spec/support/models/id_key.rb +3 -3
  843. data/spec/support/models/idnodef.rb +0 -1
  844. data/spec/support/models/image.rb +0 -1
  845. data/spec/support/models/implant.rb +1 -2
  846. data/spec/support/models/instrument.rb +2 -3
  847. data/spec/support/models/item.rb +2 -2
  848. data/spec/support/models/jar.rb +1 -2
  849. data/spec/support/models/kaleidoscope.rb +1 -1
  850. data/spec/support/models/kangaroo.rb +1 -1
  851. data/spec/support/models/label.rb +2 -2
  852. data/spec/support/models/language.rb +1 -1
  853. data/spec/support/models/lat_lng.rb +0 -1
  854. data/spec/support/models/league.rb +1 -1
  855. data/spec/support/models/learner.rb +0 -1
  856. data/spec/support/models/line_item.rb +1 -1
  857. data/spec/support/models/location.rb +1 -1
  858. data/spec/support/models/login.rb +1 -2
  859. data/spec/support/models/manufacturer.rb +0 -1
  860. data/spec/support/models/meat.rb +1 -1
  861. data/spec/support/models/membership.rb +1 -1
  862. data/spec/support/models/message.rb +1 -2
  863. data/spec/support/models/minim.rb +0 -1
  864. data/spec/support/models/mixed_drink.rb +1 -1
  865. data/spec/support/models/modifier_models.rb +25 -0
  866. data/spec/support/models/mop.rb +0 -1
  867. data/spec/support/models/movie.rb +1 -1
  868. data/spec/support/models/my_hash.rb +1 -2
  869. data/spec/support/models/name.rb +4 -5
  870. data/spec/support/models/name_only.rb +0 -1
  871. data/spec/support/models/node.rb +1 -1
  872. data/spec/support/models/note.rb +3 -3
  873. data/spec/support/models/nut.rb +0 -1
  874. data/spec/support/models/odd.rb +1 -1
  875. data/spec/support/models/order.rb +1 -1
  876. data/spec/support/models/ordered_post.rb +1 -1
  877. data/spec/support/models/ordered_preference.rb +1 -1
  878. data/spec/support/models/oscar.rb +1 -1
  879. data/spec/support/models/other_owner_object.rb +0 -1
  880. data/spec/support/models/override.rb +3 -11
  881. data/spec/support/models/ownable.rb +1 -1
  882. data/spec/support/models/owner.rb +1 -1
  883. data/spec/support/models/pack.rb +0 -1
  884. data/spec/support/models/page.rb +3 -3
  885. data/spec/support/models/page_question.rb +1 -1
  886. data/spec/support/models/palette.rb +2 -2
  887. data/spec/support/models/parent.rb +2 -2
  888. data/spec/support/models/parent_doc.rb +1 -1
  889. data/spec/support/models/passport.rb +0 -1
  890. data/spec/support/models/patient.rb +2 -2
  891. data/spec/support/models/pdf_writer.rb +0 -1
  892. data/spec/support/models/pencil.rb +0 -1
  893. data/spec/support/models/person.rb +32 -28
  894. data/spec/support/models/pet.rb +1 -1
  895. data/spec/support/models/pet_owner.rb +1 -1
  896. data/spec/support/models/phone.rb +1 -2
  897. data/spec/support/models/piano.rb +0 -1
  898. data/spec/support/models/pizza.rb +1 -1
  899. data/spec/support/models/player.rb +5 -5
  900. data/spec/support/models/post.rb +12 -12
  901. data/spec/support/models/post_genre.rb +1 -1
  902. data/spec/support/models/powerup.rb +1 -2
  903. data/spec/support/models/preference.rb +2 -2
  904. data/spec/support/models/princess.rb +1 -1
  905. data/spec/support/models/product.rb +3 -3
  906. data/spec/support/models/profile.rb +2 -1
  907. data/spec/support/models/pronunciation.rb +1 -1
  908. data/spec/support/models/pub.rb +2 -2
  909. data/spec/support/models/publication/encyclopedia.rb +0 -1
  910. data/spec/support/models/publication/review.rb +0 -1
  911. data/spec/support/models/publication.rb +0 -1
  912. data/spec/support/models/purchase.rb +1 -1
  913. data/spec/support/models/purchased_item.rb +1 -1
  914. data/spec/support/models/question.rb +2 -2
  915. data/spec/support/models/quiz.rb +1 -1
  916. data/spec/support/models/rating.rb +1 -1
  917. data/spec/support/models/record.rb +2 -3
  918. data/spec/support/models/registry.rb +1 -1
  919. data/spec/support/models/role.rb +1 -1
  920. data/spec/support/models/root_category.rb +1 -1
  921. data/spec/support/models/sandbox/app/models/app_models_message.rb +0 -1
  922. data/spec/support/models/sandbox/lib/models/lib_models_message.rb +0 -1
  923. data/spec/support/models/sandbox/sandbox_message.rb +0 -1
  924. data/spec/support/models/sandbox/sandbox_user.rb +0 -1
  925. data/spec/support/models/sandbox/subdir/sandbox_comment.rb +0 -1
  926. data/spec/support/models/sandwich.rb +1 -1
  927. data/spec/support/models/scheduler.rb +0 -1
  928. data/spec/support/models/school.rb +0 -1
  929. data/spec/support/models/scribe.rb +1 -1
  930. data/spec/support/models/sealer.rb +0 -1
  931. data/spec/support/models/seat.rb +0 -1
  932. data/spec/support/models/seo.rb +1 -1
  933. data/spec/support/models/series.rb +1 -1
  934. data/spec/support/models/server.rb +1 -1
  935. data/spec/support/models/service.rb +2 -2
  936. data/spec/support/models/shape.rb +3 -3
  937. data/spec/support/models/shelf.rb +1 -1
  938. data/spec/support/models/shield.rb +2 -2
  939. data/spec/support/models/shipment_address.rb +0 -1
  940. data/spec/support/models/shipping_container.rb +1 -1
  941. data/spec/support/models/shipping_pack.rb +0 -1
  942. data/spec/support/models/shirt.rb +0 -1
  943. data/spec/support/models/shop.rb +2 -2
  944. data/spec/support/models/short_agent.rb +0 -1
  945. data/spec/support/models/short_quiz.rb +1 -1
  946. data/spec/support/models/simple.rb +1 -1
  947. data/spec/support/models/slave.rb +1 -1
  948. data/spec/support/models/song.rb +1 -2
  949. data/spec/support/models/sound.rb +2 -2
  950. data/spec/support/models/spacer.rb +0 -1
  951. data/spec/support/models/square.rb +0 -1
  952. data/spec/support/models/staff.rb +0 -1
  953. data/spec/support/models/store_as_dup_test1.rb +2 -2
  954. data/spec/support/models/store_as_dup_test2.rb +1 -1
  955. data/spec/support/models/store_as_dup_test3.rb +2 -2
  956. data/spec/support/models/store_as_dup_test4.rb +1 -1
  957. data/spec/support/models/strategy.rb +0 -1
  958. data/spec/support/models/student.rb +1 -2
  959. data/spec/support/models/sub_item.rb +0 -1
  960. data/spec/support/models/subscription.rb +2 -2
  961. data/spec/support/models/survey.rb +2 -2
  962. data/spec/support/models/symptom.rb +2 -2
  963. data/spec/support/models/system_role.rb +2 -3
  964. data/spec/support/models/tag.rb +2 -2
  965. data/spec/support/models/target.rb +1 -1
  966. data/spec/support/models/template.rb +1 -1
  967. data/spec/support/models/thing.rb +1 -1
  968. data/spec/support/models/threadlocker.rb +0 -1
  969. data/spec/support/models/title.rb +0 -1
  970. data/spec/support/models/tool.rb +3 -3
  971. data/spec/support/models/topping.rb +1 -1
  972. data/spec/support/models/toy.rb +0 -1
  973. data/spec/support/models/track.rb +1 -1
  974. data/spec/support/models/translation.rb +1 -1
  975. data/spec/support/models/tree.rb +2 -3
  976. data/spec/support/models/truck.rb +0 -1
  977. data/spec/support/models/updatable.rb +0 -1
  978. data/spec/support/models/user.rb +3 -4
  979. data/spec/support/models/user_account.rb +3 -3
  980. data/spec/support/models/validation_callback.rb +4 -4
  981. data/spec/support/models/vehicle.rb +2 -3
  982. data/spec/support/models/version.rb +1 -1
  983. data/spec/support/models/vertex.rb +0 -1
  984. data/spec/support/models/vet_visit.rb +1 -1
  985. data/spec/support/models/video.rb +2 -2
  986. data/spec/support/models/video_game.rb +0 -1
  987. data/spec/support/models/washer.rb +0 -1
  988. data/spec/support/models/weapon.rb +1 -2
  989. data/spec/support/models/wiki_page.rb +2 -3
  990. data/spec/support/models/word.rb +2 -2
  991. data/spec/support/models/word_origin.rb +1 -2
  992. data/spec/support/models/writer.rb +3 -3
  993. data/spec/support/rails_mock.rb +7 -12
  994. data/spec/support/shared/time.rb +0 -1
  995. data/spec/support/sinatra_mock.rb +4 -2
  996. data/spec/support/spec_config.rb +19 -18
  997. metadata +14 -2
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
- # rubocop:todo all
3
2
 
4
- require "spec_helper"
5
- require_relative './interceptable_spec_models'
3
+ require 'spec_helper'
4
+ require_relative 'interceptable_spec_models'
6
5
 
7
6
  describe Mongoid::Interceptable do
8
-
9
7
  before do
10
8
  # The find and initialize callbacks I added were causing failures
11
9
  # because they were causing updates when we were asserting no updates
@@ -19,109 +17,102 @@ describe Mongoid::Interceptable do
19
17
 
20
18
  attr_reader :before_save_called, :after_save_called
21
19
 
22
- before_save do |object|
20
+ before_save do |_object|
23
21
  @before_save_called = true
24
22
  end
25
23
 
26
- after_save do |object|
24
+ after_save do |_object|
27
25
  @after_save_called = true
28
26
  end
29
27
  end
30
28
 
31
- describe ".included" do
32
-
29
+ describe '.included' do
33
30
  let(:klass) do
34
31
  TestClass
35
32
  end
36
33
 
37
- it "includes the before_create callback" do
34
+ it 'includes the before_create callback' do
38
35
  expect(klass).to respond_to(:before_create)
39
36
  end
40
37
 
41
- it "includes the after_create callback" do
38
+ it 'includes the after_create callback' do
42
39
  expect(klass).to respond_to(:after_create)
43
40
  end
44
41
 
45
- it "includes the before_destroy callback" do
42
+ it 'includes the before_destroy callback' do
46
43
  expect(klass).to respond_to(:before_destroy)
47
44
  end
48
45
 
49
- it "includes the after_destroy callback" do
46
+ it 'includes the after_destroy callback' do
50
47
  expect(klass).to respond_to(:after_destroy)
51
48
  end
52
49
 
53
- it "includes the before_save callback" do
50
+ it 'includes the before_save callback' do
54
51
  expect(klass).to respond_to(:before_save)
55
52
  end
56
53
 
57
- it "includes the after_save callback" do
54
+ it 'includes the after_save callback' do
58
55
  expect(klass).to respond_to(:after_save)
59
56
  end
60
57
 
61
- it "includes the before_update callback" do
58
+ it 'includes the before_update callback' do
62
59
  expect(klass).to respond_to(:before_update)
63
60
  end
64
61
 
65
- it "includes the after_update callback" do
62
+ it 'includes the after_update callback' do
66
63
  expect(klass).to respond_to(:after_update)
67
64
  end
68
65
 
69
- it "includes the before_validation callback" do
66
+ it 'includes the before_validation callback' do
70
67
  expect(klass).to respond_to(:before_validation)
71
68
  end
72
69
 
73
- it "includes the after_validation callback" do
70
+ it 'includes the after_validation callback' do
74
71
  expect(klass).to respond_to(:after_validation)
75
72
  end
76
73
 
77
- it "includes the after_initialize callback" do
74
+ it 'includes the after_initialize callback' do
78
75
  expect(klass).to respond_to(:after_initialize)
79
76
  end
80
77
 
81
- it "includes the after_build callback" do
78
+ it 'includes the after_build callback' do
82
79
  expect(klass).to respond_to(:after_build)
83
80
  end
84
81
  end
85
82
 
86
- describe ".after_find" do
87
-
83
+ describe '.after_find' do
88
84
  let!(:player) do
89
85
  Player.create!
90
86
  end
91
87
 
92
- context "when the callback is on a root document" do
93
-
94
- context "when when the document is instantiated" do
95
-
96
- it "does not execute the callback" do
88
+ context 'when the callback is on a root document' do
89
+ context 'when when the document is instantiated' do
90
+ it 'does not execute the callback' do
97
91
  expect(player.impressions).to eq(0)
98
92
  end
99
93
  end
100
94
 
101
- context "when the document is found via #find" do
102
-
95
+ context 'when the document is found via #find' do
103
96
  let(:from_db) do
104
97
  Player.find(player.id)
105
98
  end
106
99
 
107
- it "executes the callback" do
100
+ it 'executes the callback' do
108
101
  expect(from_db.impressions).to eq(1)
109
102
  end
110
103
  end
111
104
 
112
- context "when the document is found in a criteria" do
113
-
105
+ context 'when the document is found in a criteria' do
114
106
  let(:from_db) do
115
107
  Player.where(id: player.id).first
116
108
  end
117
109
 
118
- it "executes the callback" do
110
+ it 'executes the callback' do
119
111
  expect(from_db.impressions).to eq(1)
120
112
  end
121
113
  end
122
114
 
123
- context "when the document is reloaded" do
124
-
115
+ context 'when the document is reloaded' do
125
116
  let(:from_db) do
126
117
  Player.find(player.id)
127
118
  end
@@ -130,170 +121,157 @@ describe Mongoid::Interceptable do
130
121
  from_db.reload
131
122
  end
132
123
 
133
- it "executes the callback" do
124
+ it 'executes the callback' do
134
125
  expect(from_db.impressions).to eq(1)
135
126
  end
136
127
  end
137
128
  end
138
129
 
139
- context "when the callback is on an embedded document" do
140
-
130
+ context 'when the callback is on an embedded document' do
141
131
  let!(:implant) do
142
132
  player.implants.create!
143
133
  end
144
134
 
145
- context "when when the document is instantiated" do
146
-
147
- it "does not execute the callback" do
135
+ context 'when when the document is instantiated' do
136
+ it 'does not execute the callback' do
148
137
  expect(implant.impressions).to eq(0)
149
138
  end
150
139
  end
151
140
 
152
- context "when the document is found via #find" do
153
-
141
+ context 'when the document is found via #find' do
154
142
  let(:from_db) do
155
143
  Player.find(player.id).implants.first
156
144
  end
157
145
 
158
- it "executes the callback" do
146
+ it 'executes the callback' do
159
147
  expect(from_db.impressions).to eq(1)
160
148
  end
161
149
  end
162
150
 
163
- context "when the document is found in a criteria" do
164
-
151
+ context 'when the document is found in a criteria' do
165
152
  let(:from_db) do
166
153
  Player.find(player.id).implants.find(implant.id)
167
154
  end
168
155
 
169
- it "executes the callback" do
156
+ it 'executes the callback' do
170
157
  expect(from_db.impressions).to eq(1)
171
158
  end
172
159
  end
173
160
  end
174
161
  end
175
162
 
176
- describe ".after_initialize" do
177
-
163
+ describe '.after_initialize' do
178
164
  let(:game) do
179
165
  Game.new
180
166
  end
181
167
 
182
- it "runs after document instantiation" do
183
- expect(game.name).to eq("Testing")
168
+ it 'runs after document instantiation' do
169
+ expect(game.name).to eq('Testing')
184
170
  end
185
171
 
186
172
  context 'when the document is embedded' do
187
-
188
173
  after do
189
174
  Book.destroy_all
190
175
  end
191
176
 
192
177
  let(:book) do
193
178
  book = Book.new({
194
- :pages => [
195
- {
196
- content: "Page 1",
197
- notes: [
198
- { message: "Page 1 / Note A" },
199
- { message: "Page 1 / Note B" }
200
- ]
201
- },
202
- {
203
- content: "Page 2",
204
- notes: [
205
- { message: "Page 2 / Note A" },
206
- { message: "Page 2 / Note B" }
207
- ]
208
- }
209
- ]
210
- })
179
+ pages: [
180
+ {
181
+ content: 'Page 1',
182
+ notes: [
183
+ { message: 'Page 1 / Note A' },
184
+ { message: 'Page 1 / Note B' }
185
+ ]
186
+ },
187
+ {
188
+ content: 'Page 2',
189
+ notes: [
190
+ { message: 'Page 2 / Note A' },
191
+ { message: 'Page 2 / Note B' }
192
+ ]
193
+ }
194
+ ]
195
+ })
211
196
  book.id = '123'
212
197
  book.save!
213
198
  book
214
199
  end
200
+ let(:expected_messages) do
201
+ book.reload.pages.reduce([]) do |messages, p|
202
+ messages + p.notes.reduce([]) do |msgs, n|
203
+ msgs << n.message
204
+ end
205
+ end
206
+ end
215
207
 
216
208
  let(:new_message) do
217
209
  'Note C'
218
210
  end
219
211
 
220
212
  before do
221
- book.pages.each do | page |
213
+ book.pages.each do |page|
222
214
  page.notes.destroy_all
223
215
  page.notes.new(message: new_message)
224
216
  page.save!
225
217
  end
226
218
  end
227
219
 
228
- let(:expected_messages) do
229
- book.reload.pages.reduce([]) do |messages, p|
230
- messages += p.notes.reduce([]) do |msgs, n|
231
- msgs << n.message
232
- end
233
- end
234
- end
235
-
236
220
  it 'runs the callback on the embedded documents and saves the parent document' do
237
221
  expect(expected_messages.all? { |m| m == new_message }).to be(true)
238
222
  end
239
223
  end
240
224
  end
241
225
 
242
- describe ".after_build" do
243
-
226
+ describe '.after_build' do
244
227
  let(:weapon) do
245
228
  Player.new(frags: 5).weapons.build
246
229
  end
247
230
 
248
- it "runs after document build (references_many)" do
249
- expect(weapon.name).to eq("Holy Hand Grenade (5)")
231
+ let(:augmentation) do
232
+ Player.new(frags: 5).build_augmentation
233
+ end
234
+ let(:powerup) do
235
+ Player.new(frags: 5).build_powerup
250
236
  end
251
-
252
237
  let(:implant) do
253
238
  Player.new(frags: 5).implants.build
254
239
  end
255
240
 
256
- it "runs after document build (embeds_many)" do
257
- expect(implant.name).to eq('Cochlear Implant (5)')
258
- end
259
-
260
- let(:powerup) do
261
- Player.new(frags: 5).build_powerup
241
+ it 'runs after document build (references_many)' do
242
+ expect(weapon.name).to eq('Holy Hand Grenade (5)')
262
243
  end
263
244
 
264
- it "runs after document build (references_one)" do
265
- expect(powerup.name).to eq("Quad Damage (5)")
245
+ it 'runs after document build (embeds_many)' do
246
+ expect(implant.name).to eq('Cochlear Implant (5)')
266
247
  end
267
248
 
268
- let(:augmentation) do
269
- Player.new(frags: 5).build_augmentation
249
+ it 'runs after document build (references_one)' do
250
+ expect(powerup.name).to eq('Quad Damage (5)')
270
251
  end
271
252
 
272
- it "runs after document build (embeds_one)" do
273
- expect(augmentation.name).to eq("Infolink (5)")
253
+ it 'runs after document build (embeds_one)' do
254
+ expect(augmentation.name).to eq('Infolink (5)')
274
255
  end
275
256
  end
276
257
 
277
- describe ".before_create" do
278
-
258
+ describe '.before_create' do
279
259
  let(:artist) do
280
- Artist.new(name: "Depeche Mode")
260
+ Artist.new(name: 'Depeche Mode')
281
261
  end
282
262
 
283
- context "callback returns true" do
284
-
263
+ context 'callback returns true' do
285
264
  before do
286
265
  expect(artist).to receive(:before_create_stub).once.and_return(true)
287
266
  artist.save!
288
267
  end
289
268
 
290
- it "gets saved" do
269
+ it 'gets saved' do
291
270
  expect(artist.persisted?).to be true
292
271
  end
293
272
  end
294
273
 
295
- context "callback aborts the callback chain" do
296
-
274
+ context 'callback aborts the callback chain' do
297
275
  before do
298
276
  Artist.before_create(:before_create_fail_stub)
299
277
  expect(artist).to receive(:before_create_fail_stub).once.and_call_original
@@ -304,37 +282,33 @@ describe Mongoid::Interceptable do
304
282
  Artist.reset_callbacks(:create)
305
283
  end
306
284
 
307
- it "does not get saved" do
285
+ it 'does not get saved' do
308
286
  expect(artist.persisted?).to be false
309
287
  end
310
288
  end
311
289
  end
312
290
 
313
- describe ".before_save" do
314
-
315
- context "when creating" do
316
-
291
+ describe '.before_save' do
292
+ context 'when creating' do
317
293
  let(:artist) do
318
- Artist.new(name: "Depeche Mode")
294
+ Artist.new(name: 'Depeche Mode')
319
295
  end
320
296
 
321
297
  after do
322
298
  artist.delete
323
299
  end
324
300
 
325
- context "when the callback returns true" do
326
-
301
+ context 'when the callback returns true' do
327
302
  before do
328
303
  expect(artist).to receive(:before_save_stub).once.and_return(true)
329
304
  end
330
305
 
331
- it "the save returns true" do
306
+ it 'the save returns true' do
332
307
  expect(artist.save!).to be true
333
308
  end
334
309
  end
335
310
 
336
- context "when callback halts the callback chain" do
337
-
311
+ context 'when callback halts the callback chain' do
338
312
  before do
339
313
  Artist.before_save(:before_save_fail_stub)
340
314
  end
@@ -343,18 +317,17 @@ describe Mongoid::Interceptable do
343
317
  Artist.reset_callbacks(:save)
344
318
  end
345
319
 
346
- it "the save returns false" do
320
+ it 'the save returns false' do
347
321
  expect(artist).to receive(:before_save_fail_stub).once.and_call_original
348
322
  expect(artist.save).to be false
349
323
  end
350
324
  end
351
325
  end
352
326
 
353
- context "when updating" do
354
-
327
+ context 'when updating' do
355
328
  let(:artist) do
356
- Artist.create!(name: "Depeche Mode").tap do |artist|
357
- artist.name = "The Mountain Goats"
329
+ Artist.create!(name: 'Depeche Mode').tap do |artist|
330
+ artist.name = 'The Mountain Goats'
358
331
  end
359
332
  end
360
333
 
@@ -362,19 +335,17 @@ describe Mongoid::Interceptable do
362
335
  artist.delete
363
336
  end
364
337
 
365
- context "when the callback returns true" do
366
-
338
+ context 'when the callback returns true' do
367
339
  before do
368
340
  expect(artist).to receive(:before_update_stub).once.and_return(true)
369
341
  end
370
342
 
371
- it "the save returns true" do
343
+ it 'the save returns true' do
372
344
  expect(artist.save!).to be true
373
345
  end
374
346
  end
375
347
 
376
- context "when the callback halts the callback chain" do
377
-
348
+ context 'when the callback halts the callback chain' do
378
349
  before do
379
350
  Artist.before_update(:before_update_fail_stub)
380
351
  end
@@ -383,7 +354,7 @@ describe Mongoid::Interceptable do
383
354
  Artist.reset_callbacks(:update)
384
355
  end
385
356
 
386
- it "the save returns false" do
357
+ it 'the save returns false' do
387
358
  expect(artist).to receive(:before_update_fail_stub).once.and_call_original
388
359
  expect(artist.save).to be false
389
360
  end
@@ -405,7 +376,7 @@ describe Mongoid::Interceptable do
405
376
  [ IS::CbCascadedNode, :before_save ],
406
377
 
407
378
  # the grandchild of the parent
408
- [ IS::CbCascadedNode, :before_save ],
379
+ [ IS::CbCascadedNode, :before_save ]
409
380
  ]
410
381
  end
411
382
 
@@ -420,8 +391,8 @@ describe Mongoid::Interceptable do
420
391
  parent.tap(&:save)
421
392
  end
422
393
 
423
- it 'should cascade callbacks to grandchildren' do
424
- expect(registry.calls).to be == expected_calls
394
+ it 'cascades callbacks to grandchildren' do
395
+ expect(registry.calls).to eq expected_calls
425
396
  end
426
397
  end
427
398
 
@@ -437,7 +408,7 @@ describe Mongoid::Interceptable do
437
408
  [ IS::CbCascadedNode, :before_update ],
438
409
 
439
410
  # the grandchild of the parent
440
- [ IS::CbCascadedNode, :before_update ],
411
+ [ IS::CbCascadedNode, :before_update ]
441
412
  ]
442
413
  end
443
414
 
@@ -462,40 +433,37 @@ describe Mongoid::Interceptable do
462
433
  parent.tap(&:save)
463
434
  end
464
435
 
465
- it 'should cascade callbacks to grandchildren' do
466
- expect(registry.calls).to be == expected_calls
436
+ it 'cascades callbacks to grandchildren' do
437
+ expect(registry.calls).to eq expected_calls
467
438
  end
468
439
  end
469
440
  end
470
441
  end
471
442
 
472
- describe ".before_destroy" do
473
-
443
+ describe '.before_destroy' do
474
444
  let(:artist) do
475
- Artist.create!(name: "Depeche Mode")
445
+ Artist.create!(name: 'Depeche Mode')
476
446
  end
477
447
 
478
448
  before do
479
- artist.name = "The Mountain Goats"
449
+ artist.name = 'The Mountain Goats'
480
450
  end
481
451
 
482
452
  after do
483
453
  artist.delete
484
454
  end
485
455
 
486
- context "when the callback returns true" do
487
-
456
+ context 'when the callback returns true' do
488
457
  before do
489
458
  expect(artist).to receive(:before_destroy_stub).once.and_return(true)
490
459
  end
491
460
 
492
- it "the destroy returns true" do
461
+ it 'the destroy returns true' do
493
462
  expect(artist.destroy).to be true
494
463
  end
495
464
  end
496
465
 
497
- context "when the callback halts the callback chain" do
498
-
466
+ context 'when the callback halts the callback chain' do
499
467
  before do
500
468
  Artist.before_destroy(:before_destroy_fail_stub)
501
469
  end
@@ -504,34 +472,32 @@ describe Mongoid::Interceptable do
504
472
  Artist.reset_callbacks(:destroy)
505
473
  end
506
474
 
507
- it "the destroy returns false" do
475
+ it 'the destroy returns false' do
508
476
  expect(artist).to receive(:before_destroy_fail_stub).once.and_call_original
509
477
  expect(artist.destroy).to be false
510
478
  end
511
479
  end
512
480
 
513
- context "when cascading callbacks" do
514
-
481
+ context 'when cascading callbacks' do
515
482
  let!(:moderat) do
516
- Band.create!(name: "Moderat")
483
+ Band.create!(name: 'Moderat')
517
484
  end
518
485
 
519
486
  let!(:record) do
520
- moderat.records.create!(name: "Moderat")
487
+ moderat.records.create!(name: 'Moderat')
521
488
  end
522
489
 
523
490
  before do
524
491
  moderat.destroy
525
492
  end
526
493
 
527
- it "executes the child destroy callbacks" do
494
+ it 'executes the child destroy callbacks' do
528
495
  expect(record.before_destroy_called).to be true
529
496
  end
530
497
  end
531
498
  end
532
499
 
533
- describe "#run_after_callbacks" do
534
-
500
+ describe '#run_after_callbacks' do
535
501
  let(:object) do
536
502
  TestClass.new
537
503
  end
@@ -540,17 +506,16 @@ describe Mongoid::Interceptable do
540
506
  object.run_after_callbacks(:save)
541
507
  end
542
508
 
543
- it "runs the after callbacks" do
509
+ it 'runs the after callbacks' do
544
510
  expect(object.after_save_called).to be true
545
511
  end
546
512
 
547
- it "does not run the before callbacks" do
548
- expect(object.before_save_called).to be nil
513
+ it 'does not run the before callbacks' do
514
+ expect(object.before_save_called).to be_nil
549
515
  end
550
516
  end
551
517
 
552
- describe "#run_before_callbacks" do
553
-
518
+ describe '#run_before_callbacks' do
554
519
  let(:object) do
555
520
  TestClass.new
556
521
  end
@@ -559,21 +524,18 @@ describe Mongoid::Interceptable do
559
524
  object.run_before_callbacks(:save)
560
525
  end
561
526
 
562
- it "runs the before callbacks" do
527
+ it 'runs the before callbacks' do
563
528
  expect(object.before_save_called).to be true
564
529
  end
565
530
 
566
- it "does not run the after callbacks" do
567
- expect(object.after_save_called).to be nil
531
+ it 'does not run the after callbacks' do
532
+ expect(object.after_save_called).to be_nil
568
533
  end
569
534
  end
570
535
 
571
- context "when cascading callbacks" do
572
-
573
- context "when the parent has a custom callback" do
574
-
575
- context "when the child does not have the same callback defined" do
576
-
536
+ context 'when cascading callbacks' do
537
+ context 'when the parent has a custom callback' do
538
+ context 'when the child does not have the same callback defined' do
577
539
  let(:exhibition) do
578
540
  Exhibition.new
579
541
  end
@@ -582,27 +544,32 @@ describe Mongoid::Interceptable do
582
544
  exhibition.exhibitors.build
583
545
  end
584
546
 
585
- context "when running the callbacks directly" do
586
-
547
+ context 'when running the callbacks directly' do
587
548
  before(:all) do
588
549
  Exhibition.define_model_callbacks(:rearrange)
589
- Exhibition.after_rearrange { }
550
+ Exhibition.after_rearrange {}
590
551
  end
591
552
 
592
553
  after(:all) do
593
554
  Exhibition.reset_callbacks(:rearrange)
594
555
  end
595
556
 
596
- it "does not cascade to the child" do
557
+ it 'does not cascade to the child' do
597
558
  expect(exhibition.run_callbacks(:rearrange)).to be true
598
559
  end
599
560
  end
600
561
 
601
- context "when the callbacks get triggered by a destroy" do
602
-
562
+ context 'when the callbacks get triggered by a destroy' do
603
563
  let(:band) do
604
564
  Band.new
605
565
  end
566
+ let(:attributes) do
567
+ {
568
+ records_attributes: {
569
+ '0' => { '_id' => record.id, '_destroy' => true }
570
+ }
571
+ }
572
+ end
606
573
 
607
574
  let!(:record) do
608
575
  band.records.build
@@ -618,18 +585,10 @@ describe Mongoid::Interceptable do
618
585
  after(:all) do
619
586
  # ActiveSupport may raise an error when trying to reset callbacks on all of Band's
620
587
  # descendants, regardless of whether they have a particular callback defined.
621
- begin; Band.reset_callbacks(:rearrange); rescue; end
588
+ Band.reset_callbacks(:rearrange); rescue StandardError
622
589
  end
623
590
 
624
- let(:attributes) do
625
- {
626
- records_attributes: {
627
- "0" => { "_id" => record.id, "_destroy" => true }
628
- }
629
- }
630
- end
631
-
632
- it "does not cascade to the child" do
591
+ it 'does not cascade to the child' do
633
592
  Band.accepts_nested_attributes_for :records, allow_destroy: true
634
593
  expect(band.update_attributes!(attributes)).to be true
635
594
  end
@@ -637,8 +596,7 @@ describe Mongoid::Interceptable do
637
596
  end
638
597
  end
639
598
 
640
- context "when a document can exist in more than 1 level" do
641
-
599
+ context 'when a document can exist in more than 1 level' do
642
600
  let(:band) do
643
601
  Band.new
644
602
  end
@@ -651,19 +609,18 @@ describe Mongoid::Interceptable do
651
609
  Note.new
652
610
  end
653
611
 
654
- context "when adding the document at multiple levels" do
655
-
612
+ context 'when adding the document at multiple levels' do
656
613
  before do
657
614
  band.notes.push(note)
658
615
  record.notes.push(note)
659
616
  end
660
617
 
661
- context "when saving the root" do
618
+ context 'when saving the root' do
662
619
  context 'with prevent_multiple_calls_of_embedded_callbacks enabled' do
663
620
  config_override :prevent_multiple_calls_of_embedded_callbacks, true
664
621
  config_override :around_callbacks_for_embeds, true
665
622
 
666
- it "executes the callbacks only once for each document" do
623
+ it 'executes the callbacks only once for each document' do
667
624
  expect(note).to receive(:update_saved).once
668
625
  band.save!
669
626
  end
@@ -673,7 +630,7 @@ describe Mongoid::Interceptable do
673
630
  config_override :prevent_multiple_calls_of_embedded_callbacks, false
674
631
  config_override :around_callbacks_for_embeds, true
675
632
 
676
- it "executes the callbacks once for each ember" do
633
+ it 'executes the callbacks once for each ember' do
677
634
  expect(note).to receive(:update_saved).twice
678
635
  band.save!
679
636
  end
@@ -682,8 +639,7 @@ describe Mongoid::Interceptable do
682
639
  end
683
640
  end
684
641
 
685
- context "when cascading after initialize" do
686
-
642
+ context 'when cascading after initialize' do
687
643
  let!(:person) do
688
644
  Person.create!
689
645
  end
@@ -693,73 +649,66 @@ describe Mongoid::Interceptable do
693
649
  end
694
650
 
695
651
  it "doesn't cascade the initialize" do
696
- expect_any_instance_of(Service).to receive(:after_initialize_called=).never
652
+ expect_any_instance_of(Service).not_to receive(:after_initialize_called=)
697
653
  expect(Person.find(person.id)).to eq(person)
698
654
  end
699
655
  end
700
656
 
701
- context "when attempting to cascade on a referenced relation" do
702
-
703
- it "raises an error" do
704
- expect {
657
+ context 'when attempting to cascade on a referenced relation' do
658
+ it 'raises an error' do
659
+ expect do
705
660
  Band.has_and_belongs_to_many :tags, cascade_callbacks: true
706
- }.to raise_error(Mongoid::Errors::InvalidRelationOption)
661
+ end.to raise_error(Mongoid::Errors::InvalidRelationOption)
707
662
  end
708
663
  end
709
664
 
710
- context "when the documents are embedded one level" do
711
-
712
- describe "#after_create" do
713
-
714
- context "when the child is new" do
715
-
716
- context "when the parent is new" do
717
-
665
+ context 'when the documents are embedded one level' do
666
+ describe '#after_create' do
667
+ context 'when the child is new' do
668
+ context 'when the parent is new' do
718
669
  let(:band) do
719
- Band.new(name: "Moderat")
670
+ Band.new(name: 'Moderat')
720
671
  end
721
672
 
722
673
  let!(:label) do
723
- band.build_label(name: "Mute")
674
+ band.build_label(name: 'Mute')
724
675
  end
725
676
 
726
677
  before do
727
678
  band.save!
728
679
  end
729
680
 
730
- it "executes the callback" do
681
+ it 'executes the callback' do
731
682
  expect(label.after_create_called).to be true
732
683
  end
733
684
  end
734
685
 
735
- context "when the parent is persisted" do
736
-
686
+ context 'when the parent is persisted' do
737
687
  let(:band) do
738
- Band.create!(name: "Moderat")
688
+ Band.create!(name: 'Moderat')
739
689
  end
740
690
 
741
691
  let!(:label) do
742
- band.build_label(name: "Mute")
692
+ band.build_label(name: 'Mute')
743
693
  end
744
694
 
745
695
  before do
746
696
  band.save!
747
697
  end
748
698
 
749
- it "executes the callback" do
699
+ it 'executes the callback' do
750
700
  expect(label.after_create_called).to be true
751
701
  end
752
702
  end
753
703
  end
754
704
 
755
- context "when the child is persisted" do
756
-
705
+ context 'when the child is persisted' do
757
706
  let(:band) do
758
- Band.create!(name: "Moderat")
707
+ Band.create!(name: 'Moderat')
759
708
  end
760
709
 
761
710
  let!(:label) do
762
- band.create_label(name: "Mute")
711
+ band.create_label(name: 'Mute')
763
712
  end
764
713
 
765
714
  before do
@@ -767,271 +716,249 @@ describe Mongoid::Interceptable do
767
716
  band.save!
768
717
  end
769
718
 
770
- it "does not execute the callback" do
719
+ it 'does not execute the callback' do
771
720
  expect(label.after_create_called).to be false
772
721
  end
773
722
  end
774
723
  end
775
724
 
776
- describe "#after_save" do
777
-
778
- context "when the child is new" do
779
-
780
- context "when the parent is new" do
781
-
725
+ describe '#after_save' do
726
+ context 'when the child is new' do
727
+ context 'when the parent is new' do
782
728
  let(:band) do
783
- Band.new(name: "Moderat")
729
+ Band.new(name: 'Moderat')
784
730
  end
785
731
 
786
732
  let!(:label) do
787
- band.build_label(name: "Mute")
733
+ band.build_label(name: 'Mute')
788
734
  end
789
735
 
790
736
  before do
791
737
  band.save!
792
738
  end
793
739
 
794
- it "executes the callback" do
740
+ it 'executes the callback' do
795
741
  expect(label.after_save_called).to be true
796
742
  end
797
743
  end
798
744
 
799
- context "when the parent is persisted" do
800
-
745
+ context 'when the parent is persisted' do
801
746
  let(:band) do
802
- Band.create!(name: "Moderat")
747
+ Band.create!(name: 'Moderat')
803
748
  end
804
749
 
805
750
  let!(:label) do
806
- band.build_label(name: "Mute")
751
+ band.build_label(name: 'Mute')
807
752
  end
808
753
 
809
754
  before do
810
755
  band.save!
811
756
  end
812
757
 
813
- it "executes the callback" do
758
+ it 'executes the callback' do
814
759
  expect(label.after_save_called).to be true
815
760
  end
816
761
  end
817
762
  end
818
763
 
819
- context "when the child is persisted" do
820
-
764
+ context 'when the child is persisted' do
821
765
  let(:band) do
822
- Band.create!(name: "Moderat")
766
+ Band.create!(name: 'Moderat')
823
767
  end
824
768
 
825
769
  let!(:label) do
826
- band.create_label(name: "Mute")
770
+ band.create_label(name: 'Mute')
827
771
  end
828
772
 
829
773
  before do
830
774
  band.save!
831
775
  end
832
776
 
833
- it "executes the callback" do
777
+ it 'executes the callback' do
834
778
  expect(label.after_save_called).to be true
835
779
  end
836
780
  end
837
781
  end
838
782
 
839
- describe "#after_update" do
840
-
841
- context "when the child is new" do
842
-
843
- context "when the parent is new" do
844
-
783
+ describe '#after_update' do
784
+ context 'when the child is new' do
785
+ context 'when the parent is new' do
845
786
  let(:band) do
846
- Band.new(name: "Moderat")
787
+ Band.new(name: 'Moderat')
847
788
  end
848
789
 
849
790
  let!(:label) do
850
- band.build_label(name: "Mute")
791
+ band.build_label(name: 'Mute')
851
792
  end
852
793
 
853
794
  before do
854
795
  band.save!
855
796
  end
856
797
 
857
- it "does not execute the callback" do
798
+ it 'does not execute the callback' do
858
799
  expect(label.after_update_called).to be false
859
800
  end
860
801
  end
861
802
 
862
- context "when the parent is persisted" do
863
-
803
+ context 'when the parent is persisted' do
864
804
  let(:band) do
865
- Band.create!(name: "Moderat")
805
+ Band.create!(name: 'Moderat')
866
806
  end
867
807
 
868
808
  let!(:label) do
869
- band.build_label(name: "Mute")
809
+ band.build_label(name: 'Mute')
870
810
  end
871
811
 
872
812
  before do
873
813
  band.save!
874
814
  end
875
815
 
876
- it "does not execute the callback" do
816
+ it 'does not execute the callback' do
877
817
  expect(label.after_update_called).to be false
878
818
  end
879
819
  end
880
820
  end
881
821
 
882
- context "when the child is persisted" do
883
-
822
+ context 'when the child is persisted' do
884
823
  let(:band) do
885
- Band.create!(name: "Moderat")
824
+ Band.create!(name: 'Moderat')
886
825
  end
887
826
 
888
- context "when the child is dirty" do
889
-
827
+ context 'when the child is dirty' do
890
828
  let!(:label) do
891
- band.create_label(name: "Mute")
829
+ band.create_label(name: 'Mute')
892
830
  end
893
831
 
894
832
  before do
895
- label.name = "Nothing"
833
+ label.name = 'Nothing'
896
834
  band.save!
897
835
  end
898
836
 
899
- it "executes the callback" do
837
+ it 'executes the callback' do
900
838
  expect(label.after_update_called).to be true
901
839
  end
902
840
  end
903
841
 
904
- context "when the child is not dirty" do
905
-
842
+ context 'when the child is not dirty' do
906
843
  let!(:label) do
907
- band.build_label(name: "Mute")
844
+ band.build_label(name: 'Mute')
908
845
  end
909
846
 
910
847
  before do
911
848
  band.save!
912
849
  end
913
850
 
914
- it "does not execute the callback" do
851
+ it 'does not execute the callback' do
915
852
  expect(label.after_update_called).to be false
916
853
  end
917
854
  end
918
855
  end
919
856
  end
920
857
 
921
- describe "#after_validation" do
922
-
923
- context "when the child is new" do
924
-
925
- context "when the parent is new" do
926
-
858
+ describe '#after_validation' do
859
+ context 'when the child is new' do
860
+ context 'when the parent is new' do
927
861
  let(:band) do
928
- Band.new(name: "Moderat")
862
+ Band.new(name: 'Moderat')
929
863
  end
930
864
 
931
865
  let!(:label) do
932
- band.build_label(name: "Mute")
866
+ band.build_label(name: 'Mute')
933
867
  end
934
868
 
935
869
  before do
936
870
  band.save!
937
871
  end
938
872
 
939
- it "executes the callback" do
873
+ it 'executes the callback' do
940
874
  expect(label.after_validation_called).to be true
941
875
  end
942
876
  end
943
877
 
944
- context "when the parent is persisted" do
945
-
878
+ context 'when the parent is persisted' do
946
879
  let(:band) do
947
- Band.create!(name: "Moderat")
880
+ Band.create!(name: 'Moderat')
948
881
  end
949
882
 
950
883
  let!(:label) do
951
- band.build_label(name: "Mute")
884
+ band.build_label(name: 'Mute')
952
885
  end
953
886
 
954
887
  before do
955
888
  band.save!
956
889
  end
957
890
 
958
- it "executes the callback" do
891
+ it 'executes the callback' do
959
892
  expect(label.after_validation_called).to be true
960
893
  end
961
894
  end
962
895
  end
963
896
 
964
- context "when the child is persisted" do
965
-
897
+ context 'when the child is persisted' do
966
898
  let(:band) do
967
- Band.create!(name: "Moderat")
899
+ Band.create!(name: 'Moderat')
968
900
  end
969
901
 
970
902
  let!(:label) do
971
- band.create_label(name: "Mute")
903
+ band.create_label(name: 'Mute')
972
904
  end
973
905
 
974
906
  before do
975
907
  band.save!
976
908
  end
977
909
 
978
- it "executes the callback" do
910
+ it 'executes the callback' do
979
911
  expect(label.after_validation_called).to be true
980
912
  end
981
913
  end
982
914
  end
983
915
 
984
- describe "#before_create" do
985
-
986
- context "when the child is new" do
987
-
988
- context "when the parent is new" do
989
-
916
+ describe '#before_create' do
917
+ context 'when the child is new' do
918
+ context 'when the parent is new' do
990
919
  let(:band) do
991
- Band.new(name: "Moderat")
920
+ Band.new(name: 'Moderat')
992
921
  end
993
922
 
994
923
  let!(:record) do
995
- band.records.build(name: "Moderat")
924
+ band.records.build(name: 'Moderat')
996
925
  end
997
926
 
998
927
  before do
999
928
  band.save!
1000
929
  end
1001
930
 
1002
- it "executes the callback" do
931
+ it 'executes the callback' do
1003
932
  expect(record.before_create_called).to be true
1004
933
  end
1005
934
  end
1006
935
 
1007
- context "when the parent is persisted" do
1008
-
936
+ context 'when the parent is persisted' do
1009
937
  let(:band) do
1010
- Band.create!(name: "Moderat")
938
+ Band.create!(name: 'Moderat')
1011
939
  end
1012
940
 
1013
941
  let!(:record) do
1014
- band.records.build(name: "Moderat")
942
+ band.records.build(name: 'Moderat')
1015
943
  end
1016
944
 
1017
945
  before do
1018
946
  band.save!
1019
947
  end
1020
948
 
1021
- it "executes the callback" do
949
+ it 'executes the callback' do
1022
950
  expect(record.before_create_called).to be true
1023
951
  end
1024
952
  end
1025
953
  end
1026
954
 
1027
- context "when the child is persisted" do
1028
-
955
+ context 'when the child is persisted' do
1029
956
  let(:band) do
1030
- Band.create!(name: "Moderat")
957
+ Band.create!(name: 'Moderat')
1031
958
  end
1032
959
 
1033
960
  let!(:record) do
1034
- band.records.create!(name: "Moderat")
961
+ band.records.create!(name: 'Moderat')
1035
962
  end
1036
963
 
1037
964
  before do
@@ -1039,88 +966,82 @@ describe Mongoid::Interceptable do
1039
966
  band.save!
1040
967
  end
1041
968
 
1042
- it "does not execute the callback" do
969
+ it 'does not execute the callback' do
1043
970
  expect(record.before_create_called).to be false
1044
971
  end
1045
972
  end
1046
973
  end
1047
974
 
1048
- describe "#before_save" do
1049
-
1050
- context "when the child is new" do
1051
-
1052
- context "when the parent is new" do
1053
-
975
+ describe '#before_save' do
976
+ context 'when the child is new' do
977
+ context 'when the parent is new' do
1054
978
  let(:band) do
1055
- Band.new(name: "Moderat")
979
+ Band.new(name: 'Moderat')
1056
980
  end
1057
981
 
1058
982
  let!(:record) do
1059
- band.records.build(name: "Moderat")
983
+ band.records.build(name: 'Moderat')
1060
984
  end
1061
985
 
1062
986
  before do
1063
987
  band.save!
1064
988
  end
1065
989
 
1066
- it "executes the callback" do
990
+ it 'executes the callback' do
1067
991
  expect(record.before_save_called).to be true
1068
992
  end
1069
993
 
1070
- it "persists the change" do
994
+ it 'persists the change' do
1071
995
  expect(band.reload.records.first.before_save_called).to be true
1072
996
  end
1073
997
  end
1074
998
 
1075
- context "when the parent is persisted" do
1076
-
999
+ context 'when the parent is persisted' do
1077
1000
  let(:band) do
1078
- Band.create!(name: "Moderat")
1001
+ Band.create!(name: 'Moderat')
1079
1002
  end
1080
1003
 
1081
1004
  let!(:record) do
1082
- band.records.build(name: "Moderat")
1005
+ band.records.build(name: 'Moderat')
1083
1006
  end
1084
1007
 
1085
1008
  before do
1086
1009
  band.save!
1087
1010
  end
1088
1011
 
1089
- it "executes the callback" do
1012
+ it 'executes the callback' do
1090
1013
  expect(record.before_save_called).to be true
1091
1014
  end
1092
1015
 
1093
- it "persists the change" do
1016
+ it 'persists the change' do
1094
1017
  expect(band.reload.records.first.before_save_called).to be true
1095
1018
  end
1096
1019
  end
1097
1020
  end
1098
1021
 
1099
- context "when the child is persisted" do
1100
-
1022
+ context 'when the child is persisted' do
1101
1023
  let(:band) do
1102
- Band.create!(name: "Moderat")
1024
+ Band.create!(name: 'Moderat')
1103
1025
  end
1104
1026
 
1105
1027
  let!(:record) do
1106
- band.records.create!(name: "Moderat")
1028
+ band.records.create!(name: 'Moderat')
1107
1029
  end
1108
1030
 
1109
1031
  before do
1110
1032
  band.save!
1111
1033
  end
1112
1034
 
1113
- it "executes the callback" do
1035
+ it 'executes the callback' do
1114
1036
  expect(record.before_save_called).to be true
1115
1037
  end
1116
1038
 
1117
- it "persists the change" do
1039
+ it 'persists the change' do
1118
1040
  expect(band.reload.records.first.before_save_called).to be true
1119
1041
  end
1120
1042
  end
1121
1043
 
1122
- context "when the child is created" do
1123
-
1044
+ context 'when the child is created' do
1124
1045
  let!(:band) do
1125
1046
  Band.create!
1126
1047
  end
@@ -1129,152 +1050,140 @@ describe Mongoid::Interceptable do
1129
1050
  band.create_label(name: 'Label')
1130
1051
  end
1131
1052
 
1132
- it "only executes callback once" do
1053
+ it 'only executes callback once' do
1133
1054
  expect(label.before_save_count).to be 1
1134
1055
  end
1135
1056
  end
1136
1057
  end
1137
1058
 
1138
- describe "#before_update" do
1139
-
1140
- context "when the child is new" do
1141
-
1142
- context "when the parent is new" do
1143
-
1059
+ describe '#before_update' do
1060
+ context 'when the child is new' do
1061
+ context 'when the parent is new' do
1144
1062
  let(:band) do
1145
- Band.new(name: "Moderat")
1063
+ Band.new(name: 'Moderat')
1146
1064
  end
1147
1065
 
1148
1066
  let!(:record) do
1149
- band.records.build(name: "Moderat")
1067
+ band.records.build(name: 'Moderat')
1150
1068
  end
1151
1069
 
1152
1070
  before do
1153
1071
  band.save!
1154
1072
  end
1155
1073
 
1156
- it "does not execute the callback" do
1074
+ it 'does not execute the callback' do
1157
1075
  expect(record.before_update_called).to be false
1158
1076
  end
1159
1077
  end
1160
1078
 
1161
- context "when the parent is persisted" do
1162
-
1079
+ context 'when the parent is persisted' do
1163
1080
  let(:band) do
1164
- Band.create!(name: "Moderat")
1081
+ Band.create!(name: 'Moderat')
1165
1082
  end
1166
1083
 
1167
1084
  let!(:record) do
1168
- band.records.build(name: "Moderat")
1085
+ band.records.build(name: 'Moderat')
1169
1086
  end
1170
1087
 
1171
1088
  before do
1172
1089
  band.save!
1173
1090
  end
1174
1091
 
1175
- it "does not execute the callback" do
1092
+ it 'does not execute the callback' do
1176
1093
  expect(record.before_update_called).to be false
1177
1094
  end
1178
1095
  end
1179
1096
  end
1180
1097
 
1181
- context "when the child is persisted" do
1182
-
1098
+ context 'when the child is persisted' do
1183
1099
  let(:band) do
1184
- Band.create!(name: "Moderat")
1100
+ Band.create!(name: 'Moderat')
1185
1101
  end
1186
1102
 
1187
1103
  let!(:record) do
1188
- band.records.create!(name: "Moderat")
1104
+ band.records.create!(name: 'Moderat')
1189
1105
  end
1190
1106
 
1191
- context "when the child is dirty" do
1192
-
1107
+ context 'when the child is dirty' do
1193
1108
  before do
1194
- record.name = "Nothing"
1109
+ record.name = 'Nothing'
1195
1110
  band.save!
1196
1111
  end
1197
1112
 
1198
- it "executes the callback" do
1113
+ it 'executes the callback' do
1199
1114
  expect(record.before_update_called).to be true
1200
1115
  end
1201
1116
 
1202
- it "persists the change" do
1117
+ it 'persists the change' do
1203
1118
  expect(band.reload.records.first.before_update_called).to be true
1204
1119
  end
1205
1120
  end
1206
1121
 
1207
- context "when the child is not dirty" do
1208
-
1122
+ context 'when the child is not dirty' do
1209
1123
  before do
1210
1124
  band.save!
1211
1125
  end
1212
1126
 
1213
- it "does not execute the callback" do
1127
+ it 'does not execute the callback' do
1214
1128
  expect(record.before_update_called).to be false
1215
1129
  end
1216
1130
  end
1217
1131
  end
1218
1132
  end
1219
1133
 
1220
- describe "#before_validation" do
1221
-
1222
- context "when the child is new" do
1223
-
1224
- context "when the parent is new" do
1225
-
1134
+ describe '#before_validation' do
1135
+ context 'when the child is new' do
1136
+ context 'when the parent is new' do
1226
1137
  let(:band) do
1227
- Band.new(name: "Moderat")
1138
+ Band.new(name: 'Moderat')
1228
1139
  end
1229
1140
 
1230
1141
  let!(:record) do
1231
- band.records.build(name: "Moderat")
1142
+ band.records.build(name: 'Moderat')
1232
1143
  end
1233
1144
 
1234
1145
  before do
1235
1146
  band.save!
1236
1147
  end
1237
1148
 
1238
- it "executes the callback" do
1149
+ it 'executes the callback' do
1239
1150
  expect(record.before_validation_called).to be true
1240
1151
  end
1241
1152
 
1242
- it "persists the change" do
1153
+ it 'persists the change' do
1243
1154
  expect(band.reload.records.first.before_validation_called).to be true
1244
1155
  end
1245
1156
  end
1246
1157
 
1247
- context "when the parent is persisted" do
1248
-
1158
+ context 'when the parent is persisted' do
1249
1159
  let(:band) do
1250
- Band.create!(name: "Moderat")
1160
+ Band.create!(name: 'Moderat')
1251
1161
  end
1252
1162
 
1253
1163
  let!(:record) do
1254
- band.records.build(name: "Moderat")
1164
+ band.records.build(name: 'Moderat')
1255
1165
  end
1256
1166
 
1257
1167
  before do
1258
1168
  band.save!
1259
1169
  end
1260
1170
 
1261
- it "executes the callback" do
1171
+ it 'executes the callback' do
1262
1172
  expect(record.before_validation_called).to be true
1263
1173
  end
1264
1174
 
1265
- it "persists the change" do
1175
+ it 'persists the change' do
1266
1176
  expect(band.reload.records.first.before_validation_called).to be true
1267
1177
  end
1268
1178
  end
1269
1179
 
1270
1180
  context 'when the parent is updated' do
1271
-
1272
1181
  let(:band) do
1273
- Band.create!(name: "Moderat")
1182
+ Band.create!(name: 'Moderat')
1274
1183
  end
1275
1184
 
1276
1185
  before do
1277
- band.update(records: [ { name: 'Black on Both Sides' }])
1186
+ band.update(records: [ { name: 'Black on Both Sides' } ])
1278
1187
  end
1279
1188
 
1280
1189
  it 'executes the callback' do
@@ -1288,13 +1197,12 @@ describe Mongoid::Interceptable do
1288
1197
  end
1289
1198
 
1290
1199
  context 'when the parent is updated' do
1291
-
1292
1200
  let(:band) do
1293
- Band.create!(name: "Moderat")
1201
+ Band.create!(name: 'Moderat')
1294
1202
  end
1295
1203
 
1296
1204
  before do
1297
- band.update(records: [ { name: 'Black on Both Sides' }])
1205
+ band.update(records: [ { name: 'Black on Both Sides' } ])
1298
1206
  end
1299
1207
 
1300
1208
  it 'executes the callback' do
@@ -1306,96 +1214,89 @@ describe Mongoid::Interceptable do
1306
1214
  end
1307
1215
  end
1308
1216
 
1309
- context "when the child is persisted" do
1310
-
1217
+ context 'when the child is persisted' do
1311
1218
  let(:band) do
1312
- Band.create!(name: "Moderat")
1219
+ Band.create!(name: 'Moderat')
1313
1220
  end
1314
1221
 
1315
1222
  let!(:record) do
1316
- band.records.create!(name: "Moderat")
1223
+ band.records.create!(name: 'Moderat')
1317
1224
  end
1318
1225
 
1319
1226
  before do
1320
1227
  band.save!
1321
1228
  end
1322
1229
 
1323
- it "executes the callback" do
1230
+ it 'executes the callback' do
1324
1231
  expect(record.before_validation_called).to be true
1325
1232
  end
1326
1233
 
1327
- it "persists the change" do
1234
+ it 'persists the change' do
1328
1235
  expect(band.reload.records.first.before_validation_called).to be true
1329
1236
  end
1330
1237
  end
1331
1238
  end
1332
1239
  end
1333
1240
 
1334
- context "when the document is embedded multiple levels" do
1335
-
1336
- describe "#before_create" do
1337
-
1338
- context "when the child is new" do
1339
-
1340
- context "when the root is new" do
1341
-
1241
+ context 'when the document is embedded multiple levels' do
1242
+ describe '#before_create' do
1243
+ context 'when the child is new' do
1244
+ context 'when the root is new' do
1342
1245
  let(:band) do
1343
- Band.new(name: "Moderat")
1246
+ Band.new(name: 'Moderat')
1344
1247
  end
1345
1248
 
1346
1249
  let!(:record) do
1347
- band.records.build(name: "Moderat")
1250
+ band.records.build(name: 'Moderat')
1348
1251
  end
1349
1252
 
1350
1253
  let!(:track) do
1351
- record.tracks.build(name: "Berlin")
1254
+ record.tracks.build(name: 'Berlin')
1352
1255
  end
1353
1256
 
1354
1257
  before do
1355
1258
  band.save!
1356
1259
  end
1357
1260
 
1358
- it "executes the callback" do
1261
+ it 'executes the callback' do
1359
1262
  expect(track.before_create_called).to be true
1360
1263
  end
1361
1264
  end
1362
1265
 
1363
- context "when the root is persisted" do
1364
-
1266
+ context 'when the root is persisted' do
1365
1267
  let(:band) do
1366
- Band.create!(name: "Moderat")
1268
+ Band.create!(name: 'Moderat')
1367
1269
  end
1368
1270
 
1369
1271
  let!(:record) do
1370
- band.records.build(name: "Moderat")
1272
+ band.records.build(name: 'Moderat')
1371
1273
  end
1372
1274
 
1373
1275
  let!(:track) do
1374
- record.tracks.build(name: "Berlin")
1276
+ record.tracks.build(name: 'Berlin')
1375
1277
  end
1376
1278
 
1377
1279
  before do
1378
1280
  band.save!
1379
1281
  end
1380
1282
 
1381
- it "executes the callback" do
1283
+ it 'executes the callback' do
1382
1284
  expect(track.before_create_called).to be true
1383
1285
  end
1384
1286
  end
1385
1287
  end
1386
1288
 
1387
- context "when the child is persisted" do
1388
-
1289
+ context 'when the child is persisted' do
1389
1290
  let(:band) do
1390
- Band.create!(name: "Moderat")
1291
+ Band.create!(name: 'Moderat')
1391
1292
  end
1392
1293
 
1393
1294
  let!(:record) do
1394
- band.records.create!(name: "Moderat")
1295
+ band.records.create!(name: 'Moderat')
1395
1296
  end
1396
1297
 
1397
1298
  let!(:track) do
1398
- record.tracks.create!(name: "Berlin")
1299
+ record.tracks.create!(name: 'Berlin')
1399
1300
  end
1400
1301
 
1401
1302
  before do
@@ -1403,180 +1304,166 @@ describe Mongoid::Interceptable do
1403
1304
  band.save!
1404
1305
  end
1405
1306
 
1406
- it "does not execute the callback" do
1307
+ it 'does not execute the callback' do
1407
1308
  expect(track.before_create_called).to be false
1408
1309
  end
1409
1310
  end
1410
1311
  end
1411
1312
 
1412
- describe "#before_save" do
1413
-
1414
- context "when the child is new" do
1415
-
1416
- context "when the root is new" do
1417
-
1313
+ describe '#before_save' do
1314
+ context 'when the child is new' do
1315
+ context 'when the root is new' do
1418
1316
  let(:band) do
1419
- Band.new(name: "Moderat")
1317
+ Band.new(name: 'Moderat')
1318
+ end
1319
+ let(:reloaded) do
1320
+ band.reload.records.first
1420
1321
  end
1421
1322
 
1422
1323
  let!(:record) do
1423
- band.records.build(name: "Moderat")
1324
+ band.records.build(name: 'Moderat')
1424
1325
  end
1425
1326
 
1426
1327
  let!(:track) do
1427
- record.tracks.build(name: "Berlin")
1328
+ record.tracks.build(name: 'Berlin')
1428
1329
  end
1429
1330
 
1430
1331
  before do
1431
1332
  band.save!
1432
1333
  end
1433
1334
 
1434
- let(:reloaded) do
1435
- band.reload.records.first
1436
- end
1437
-
1438
- it "executes the callback" do
1335
+ it 'executes the callback' do
1439
1336
  expect(track.before_save_called).to be true
1440
1337
  end
1441
1338
 
1442
- it "persists the change" do
1339
+ it 'persists the change' do
1443
1340
  expect(reloaded.tracks.first.before_save_called).to be true
1444
1341
  end
1445
1342
  end
1446
1343
 
1447
- context "when the parent is persisted" do
1448
-
1344
+ context 'when the parent is persisted' do
1449
1345
  let(:band) do
1450
- Band.create!(name: "Moderat")
1346
+ Band.create!(name: 'Moderat')
1347
+ end
1348
+ let(:reloaded) do
1349
+ band.reload.records.first
1451
1350
  end
1452
1351
 
1453
1352
  let!(:record) do
1454
- band.records.build(name: "Moderat")
1353
+ band.records.build(name: 'Moderat')
1455
1354
  end
1456
1355
 
1457
1356
  let!(:track) do
1458
- record.tracks.build(name: "Berlin")
1357
+ record.tracks.build(name: 'Berlin')
1459
1358
  end
1460
1359
 
1461
1360
  before do
1462
1361
  band.save!
1463
1362
  end
1464
1363
 
1465
- let(:reloaded) do
1466
- band.reload.records.first
1467
- end
1468
-
1469
- it "executes the callback" do
1364
+ it 'executes the callback' do
1470
1365
  expect(track.before_save_called).to be true
1471
1366
  end
1472
1367
 
1473
- it "persists the change" do
1368
+ it 'persists the change' do
1474
1369
  expect(reloaded.tracks.first.before_save_called).to be true
1475
1370
  end
1476
1371
  end
1477
1372
  end
1478
1373
 
1479
- context "when the child is persisted" do
1480
-
1374
+ context 'when the child is persisted' do
1481
1375
  let(:band) do
1482
- Band.create!(name: "Moderat")
1376
+ Band.create!(name: 'Moderat')
1377
+ end
1378
+ let(:reloaded) do
1379
+ band.reload.records.first
1483
1380
  end
1484
1381
 
1485
1382
  let!(:record) do
1486
- band.records.create!(name: "Moderat")
1383
+ band.records.create!(name: 'Moderat')
1487
1384
  end
1488
1385
 
1489
1386
  let!(:track) do
1490
- record.tracks.create!(name: "Berlin")
1387
+ record.tracks.create!(name: 'Berlin')
1491
1388
  end
1492
1389
 
1493
1390
  before do
1494
1391
  band.save!
1495
1392
  end
1496
1393
 
1497
- let(:reloaded) do
1498
- band.reload.records.first
1499
- end
1500
-
1501
- it "executes the callback" do
1394
+ it 'executes the callback' do
1502
1395
  expect(track.before_save_called).to be true
1503
1396
  end
1504
1397
 
1505
- it "persists the change" do
1398
+ it 'persists the change' do
1506
1399
  expect(reloaded.tracks.first.before_save_called).to be true
1507
1400
  end
1508
1401
  end
1509
1402
  end
1510
1403
 
1511
- describe "#before_update" do
1512
-
1513
- context "when the child is new" do
1514
-
1515
- context "when the parent is new" do
1516
-
1404
+ describe '#before_update' do
1405
+ context 'when the child is new' do
1406
+ context 'when the parent is new' do
1517
1407
  let(:band) do
1518
- Band.new(name: "Moderat")
1408
+ Band.new(name: 'Moderat')
1519
1409
  end
1520
1410
 
1521
1411
  let!(:record) do
1522
- band.records.build(name: "Moderat")
1412
+ band.records.build(name: 'Moderat')
1523
1413
  end
1524
1414
 
1525
1415
  let!(:track) do
1526
- record.tracks.build(name: "Berlin")
1416
+ record.tracks.build(name: 'Berlin')
1527
1417
  end
1528
1418
 
1529
1419
  before do
1530
1420
  band.save!
1531
1421
  end
1532
1422
 
1533
- it "does not execute the callback" do
1423
+ it 'does not execute the callback' do
1534
1424
  expect(track.before_update_called).to be false
1535
1425
  end
1536
1426
  end
1537
1427
 
1538
- context "when the parent is persisted" do
1539
-
1428
+ context 'when the parent is persisted' do
1540
1429
  let(:band) do
1541
- Band.create!(name: "Moderat")
1430
+ Band.create!(name: 'Moderat')
1542
1431
  end
1543
1432
 
1544
1433
  let!(:record) do
1545
- band.records.build(name: "Moderat")
1434
+ band.records.build(name: 'Moderat')
1546
1435
  end
1547
1436
 
1548
1437
  let!(:track) do
1549
- record.tracks.build(name: "Berlin")
1438
+ record.tracks.build(name: 'Berlin')
1550
1439
  end
1551
1440
 
1552
1441
  before do
1553
1442
  band.save!
1554
1443
  end
1555
1444
 
1556
- it "does not execute the callback" do
1445
+ it 'does not execute the callback' do
1557
1446
  expect(track.before_update_called).to be false
1558
1447
  end
1559
1448
  end
1560
1449
  end
1561
1450
 
1562
- context "when the child is persisted" do
1563
-
1451
+ context 'when the child is persisted' do
1564
1452
  let(:band) do
1565
- Band.create!(name: "Moderat")
1453
+ Band.create!(name: 'Moderat')
1566
1454
  end
1567
1455
 
1568
1456
  let!(:record) do
1569
- band.records.create!(name: "Moderat")
1457
+ band.records.create!(name: 'Moderat')
1570
1458
  end
1571
1459
 
1572
1460
  let!(:track) do
1573
- record.tracks.create!(name: "Berlin")
1461
+ record.tracks.create!(name: 'Berlin')
1574
1462
  end
1575
1463
 
1576
- context "when the child is dirty" do
1577
-
1464
+ context 'when the child is dirty' do
1578
1465
  before do
1579
- track.name = "Rusty Nails"
1466
+ track.name = 'Rusty Nails'
1580
1467
  band.save!
1581
1468
  end
1582
1469
 
@@ -1584,22 +1471,21 @@ describe Mongoid::Interceptable do
1584
1471
  band.reload.records.first
1585
1472
  end
1586
1473
 
1587
- it "executes the callback" do
1474
+ it 'executes the callback' do
1588
1475
  expect(track.before_update_called).to be true
1589
1476
  end
1590
1477
 
1591
- it "persists the change" do
1478
+ it 'persists the change' do
1592
1479
  expect(reloaded.tracks.first.before_update_called).to be true
1593
1480
  end
1594
1481
  end
1595
1482
 
1596
- context "when the child is not dirty" do
1597
-
1483
+ context 'when the child is not dirty' do
1598
1484
  before do
1599
1485
  band.save!
1600
1486
  end
1601
1487
 
1602
- it "does not execute the callback" do
1488
+ it 'does not execute the callback' do
1603
1489
  expect(track.before_update_called).to be false
1604
1490
  end
1605
1491
  end
@@ -1607,11 +1493,9 @@ describe Mongoid::Interceptable do
1607
1493
  end
1608
1494
 
1609
1495
  describe '#after_destroy' do
1610
-
1611
1496
  context 'when the parent is updated in a child after_destroy callback' do
1612
-
1613
1497
  let!(:person) do
1614
- Person.create!(ordered_posts: [OrderedPost.new])
1498
+ Person.create!(ordered_posts: [ OrderedPost.new ])
1615
1499
  end
1616
1500
 
1617
1501
  before do
@@ -1625,76 +1509,71 @@ describe Mongoid::Interceptable do
1625
1509
  end
1626
1510
  end
1627
1511
 
1628
- describe "#before_validation" do
1629
-
1630
- context "when the child is new" do
1631
-
1632
- context "when the parent is new" do
1633
-
1512
+ describe '#before_validation' do
1513
+ context 'when the child is new' do
1514
+ context 'when the parent is new' do
1634
1515
  let(:band) do
1635
- Band.new(name: "Moderat")
1516
+ Band.new(name: 'Moderat')
1636
1517
  end
1637
1518
 
1638
1519
  let!(:record) do
1639
- band.records.build(name: "Moderat")
1520
+ band.records.build(name: 'Moderat')
1640
1521
  end
1641
1522
 
1642
1523
  let!(:track) do
1643
- record.tracks.build(name: "Berlin")
1524
+ record.tracks.build(name: 'Berlin')
1644
1525
  end
1645
1526
 
1646
1527
  before do
1647
1528
  band.save!
1648
1529
  end
1649
1530
 
1650
- it "executes the callback" do
1531
+ it 'executes the callback' do
1651
1532
  expect(track.before_validation_called).to be true
1652
1533
  end
1653
1534
  end
1654
1535
 
1655
- context "when the parent is persisted" do
1656
-
1536
+ context 'when the parent is persisted' do
1657
1537
  let(:band) do
1658
- Band.create!(name: "Moderat")
1538
+ Band.create!(name: 'Moderat')
1659
1539
  end
1660
1540
 
1661
1541
  let!(:record) do
1662
- band.records.build(name: "Moderat")
1542
+ band.records.build(name: 'Moderat')
1663
1543
  end
1664
1544
 
1665
1545
  let!(:track) do
1666
- record.tracks.build(name: "Berlin")
1546
+ record.tracks.build(name: 'Berlin')
1667
1547
  end
1668
1548
 
1669
1549
  before do
1670
1550
  band.save!
1671
1551
  end
1672
1552
 
1673
- it "executes the callback" do
1553
+ it 'executes the callback' do
1674
1554
  expect(track.before_validation_called).to be true
1675
1555
  end
1676
1556
  end
1677
1557
  end
1678
1558
 
1679
- context "when the child is persisted" do
1680
-
1559
+ context 'when the child is persisted' do
1681
1560
  let(:band) do
1682
- Band.create!(name: "Moderat")
1561
+ Band.create!(name: 'Moderat')
1683
1562
  end
1684
1563
 
1685
1564
  let!(:record) do
1686
- band.records.create!(name: "Moderat")
1565
+ band.records.create!(name: 'Moderat')
1687
1566
  end
1688
1567
 
1689
1568
  let!(:track) do
1690
- record.tracks.create!(name: "Berlin")
1569
+ record.tracks.create!(name: 'Berlin')
1691
1570
  end
1692
1571
 
1693
1572
  before do
1694
1573
  band.save!
1695
1574
  end
1696
1575
 
1697
- it "executes the callback" do
1576
+ it 'executes the callback' do
1698
1577
  expect(track.before_validation_called).to be true
1699
1578
  end
1700
1579
  end
@@ -1702,17 +1581,15 @@ describe Mongoid::Interceptable do
1702
1581
  end
1703
1582
  end
1704
1583
 
1705
- context "callback on valid?" do
1706
-
1707
- it "goes in all validation callback in good order" do
1584
+ context 'callback on valid?' do
1585
+ it 'goes in all validation callback in good order' do
1708
1586
  shin = ValidationCallback.new
1709
1587
  shin.valid?
1710
- expect(shin.history).to eq([:before_validation, :validate, :after_validation])
1588
+ expect(shin.history).to eq(%i[before_validation validate after_validation])
1711
1589
  end
1712
1590
  end
1713
1591
 
1714
- context "when creating child documents in callbacks" do
1715
-
1592
+ context 'when creating child documents in callbacks' do
1716
1593
  let(:parent) do
1717
1594
  ParentDoc.new
1718
1595
  end
@@ -1721,16 +1598,15 @@ describe Mongoid::Interceptable do
1721
1598
  parent.save!
1722
1599
  end
1723
1600
 
1724
- it "does not duplicate the child documents" do
1601
+ it 'does not duplicate the child documents' do
1725
1602
  parent.children.create!(position: 1)
1726
1603
  expect(ParentDoc.find(parent.id).children.size).to eq(1)
1727
1604
  end
1728
1605
  end
1729
1606
 
1730
- context "when callbacks cancel persistence" do
1731
-
1607
+ context 'when callbacks cancel persistence' do
1732
1608
  let(:address) do
1733
- Address.new(street: "123 Sesame")
1609
+ Address.new(street: '123 Sesame')
1734
1610
  end
1735
1611
 
1736
1612
  before(:all) do
@@ -1743,81 +1619,77 @@ describe Mongoid::Interceptable do
1743
1619
  Person.reset_callbacks(:save)
1744
1620
  end
1745
1621
 
1746
- context "when creating a document" do
1747
-
1622
+ context 'when creating a document' do
1748
1623
  let(:person) do
1749
- Person.new(mode: :prevent_save, title: "Associate", addresses: [ address ])
1624
+ Person.new(mode: :prevent_save, title: 'Associate', addresses: [ address ])
1750
1625
  end
1751
1626
 
1752
- it "fails to save" do
1627
+ it 'fails to save' do
1753
1628
  expect(person).to be_valid
1754
1629
  expect(person.save).to be false
1755
1630
  end
1756
1631
 
1757
- it "is a new record" do
1632
+ it 'is a new record' do
1758
1633
  expect(person).to be_a_new_record
1759
- expect { person.save }.not_to change { person.new_record? }
1634
+ expect { person.save }.not_to(change { person.new_record? })
1760
1635
  end
1761
1636
 
1762
- it "is left dirty" do
1637
+ it 'is left dirty' do
1763
1638
  expect(person).to be_changed
1764
- expect { person.save }.not_to change { person.changed? }
1639
+ expect { person.save }.not_to(change { person.changed? })
1765
1640
  end
1766
1641
 
1767
- it "child documents are left dirty" do
1642
+ it 'child documents are left dirty' do
1768
1643
  expect(address).to be_changed
1769
- expect { person.save }.not_to change { address.changed? }
1644
+ expect { person.save }.not_to(change { address.changed? })
1770
1645
  end
1771
1646
  end
1772
1647
 
1773
- context "when updating a document" do
1774
-
1648
+ context 'when updating a document' do
1775
1649
  let(:person) do
1776
1650
  Person.create!.tap do |person|
1777
1651
  person.attributes = {
1778
1652
  mode: :prevent_save,
1779
- title: "Associate",
1653
+ title: 'Associate',
1780
1654
  addresses: [ address ]
1781
1655
  }
1782
1656
  end
1783
1657
  end
1784
1658
 
1785
- it "#save returns false" do
1659
+ it '#save returns false' do
1786
1660
  expect(person).to be_valid
1787
1661
  expect(person.save).to be false
1788
1662
  end
1789
1663
 
1790
- it "is a not a new record" do
1791
- expect(person).to_not be_a_new_record
1792
- expect { person.save }.not_to change { person.new_record? }
1664
+ it 'is a not a new record' do
1665
+ expect(person).not_to be_a_new_record
1666
+ expect { person.save }.not_to(change { person.new_record? })
1793
1667
  end
1794
1668
 
1795
- it "is left dirty" do
1669
+ it 'is left dirty' do
1796
1670
  expect(person).to be_changed
1797
- expect { person.save }.not_to change { person.changed? }
1671
+ expect { person.save }.not_to(change { person.changed? })
1798
1672
  end
1799
1673
 
1800
- it "child documents are left dirty" do
1674
+ it 'child documents are left dirty' do
1801
1675
  expect(address).to be_changed
1802
- expect { person.save }.not_to change { address.changed? }
1676
+ expect { person.save }.not_to(change { address.changed? })
1803
1677
  end
1804
1678
  end
1805
1679
  end
1806
1680
 
1807
- context "when loading a model multiple times" do
1808
-
1681
+ context 'when loading a model multiple times' do
1809
1682
  before do
1810
- load File.join(MODELS, "callback_test.rb")
1811
- load File.join(MODELS, "callback_test.rb")
1683
+ load File.join(MODELS, 'callback_test.rb')
1684
+ load File.join(MODELS, 'callback_test.rb')
1812
1685
  end
1813
1686
 
1814
1687
  let(:callback) do
1815
1688
  CallbackTest.new
1816
1689
  end
1817
1690
 
1818
- context "when saving the document" do
1819
-
1820
- it "only executes the callbacks once" do
1691
+ context 'when saving the document' do
1692
+ it 'only executes the callbacks once' do
1821
1693
  expect(callback).to receive(:execute).once
1822
1694
  callback.save
1823
1695
  end
@@ -1834,18 +1706,18 @@ describe Mongoid::Interceptable do
1834
1706
 
1835
1707
  let(:expected) do
1836
1708
  [
1837
- [InterceptableSpec::CbParent, :before_validation],
1838
- [InterceptableSpec::CbChild, :before_validation],
1839
- [InterceptableSpec::CbChild, :after_validation],
1840
- [InterceptableSpec::CbParent, :after_validation],
1841
- [InterceptableSpec::CbParent, :before_save],
1842
- [InterceptableSpec::CbParent, :around_save_open],
1843
- [InterceptableSpec::CbParent, :before_create],
1844
- [InterceptableSpec::CbParent, :around_create_open],
1845
- [InterceptableSpec::CbParent, :around_create_close],
1846
- [InterceptableSpec::CbParent, :after_create],
1847
- [InterceptableSpec::CbParent, :around_save_close],
1848
- [InterceptableSpec::CbParent, :after_save],
1709
+ [ InterceptableSpec::CbParent, :before_validation ],
1710
+ [ InterceptableSpec::CbChild, :before_validation ],
1711
+ [ InterceptableSpec::CbChild, :after_validation ],
1712
+ [ InterceptableSpec::CbParent, :after_validation ],
1713
+ [ InterceptableSpec::CbParent, :before_save ],
1714
+ [ InterceptableSpec::CbParent, :around_save_open ],
1715
+ [ InterceptableSpec::CbParent, :before_create ],
1716
+ [ InterceptableSpec::CbParent, :around_create_open ],
1717
+ [ InterceptableSpec::CbParent, :around_create_close ],
1718
+ [ InterceptableSpec::CbParent, :after_create ],
1719
+ [ InterceptableSpec::CbParent, :around_save_close ],
1720
+ [ InterceptableSpec::CbParent, :after_save ]
1849
1721
  ]
1850
1722
  end
1851
1723
 
@@ -1875,32 +1747,32 @@ describe Mongoid::Interceptable do
1875
1747
 
1876
1748
  let(:expected) do
1877
1749
  [
1878
- [InterceptableSpec::CbCascadedChild, :before_validation],
1879
- [InterceptableSpec::CbCascadedChild, :after_validation],
1880
- [InterceptableSpec::CbParent, :before_validation],
1881
- [InterceptableSpec::CbCascadedChild, :before_validation],
1882
- [InterceptableSpec::CbCascadedChild, :after_validation],
1883
-
1884
- [InterceptableSpec::CbParent, :after_validation],
1885
- [InterceptableSpec::CbParent, :before_save],
1886
- [InterceptableSpec::CbParent, :around_save_open],
1887
- [InterceptableSpec::CbParent, :before_create],
1888
- [InterceptableSpec::CbParent, :around_create_open],
1889
-
1890
- [InterceptableSpec::CbCascadedChild, :before_save],
1891
- [InterceptableSpec::CbCascadedChild, :around_save_open],
1892
- [InterceptableSpec::CbCascadedChild, :before_create],
1893
- [InterceptableSpec::CbCascadedChild, :around_create_open],
1894
-
1895
- [InterceptableSpec::CbCascadedChild, :around_create_close],
1896
- [InterceptableSpec::CbCascadedChild, :after_create],
1897
- [InterceptableSpec::CbCascadedChild, :around_save_close],
1898
- [InterceptableSpec::CbCascadedChild, :after_save],
1899
-
1900
- [InterceptableSpec::CbParent, :around_create_close],
1901
- [InterceptableSpec::CbParent, :after_create],
1902
- [InterceptableSpec::CbParent, :around_save_close],
1903
- [InterceptableSpec::CbParent, :after_save]
1750
+ [ InterceptableSpec::CbCascadedChild, :before_validation ],
1751
+ [ InterceptableSpec::CbCascadedChild, :after_validation ],
1752
+ [ InterceptableSpec::CbParent, :before_validation ],
1753
+ [ InterceptableSpec::CbCascadedChild, :before_validation ],
1754
+ [ InterceptableSpec::CbCascadedChild, :after_validation ],
1755
+
1756
+ [ InterceptableSpec::CbParent, :after_validation ],
1757
+ [ InterceptableSpec::CbParent, :before_save ],
1758
+ [ InterceptableSpec::CbParent, :around_save_open ],
1759
+ [ InterceptableSpec::CbParent, :before_create ],
1760
+ [ InterceptableSpec::CbParent, :around_create_open ],
1761
+
1762
+ [ InterceptableSpec::CbCascadedChild, :before_save ],
1763
+ [ InterceptableSpec::CbCascadedChild, :around_save_open ],
1764
+ [ InterceptableSpec::CbCascadedChild, :before_create ],
1765
+ [ InterceptableSpec::CbCascadedChild, :around_create_open ],
1766
+
1767
+ [ InterceptableSpec::CbCascadedChild, :around_create_close ],
1768
+ [ InterceptableSpec::CbCascadedChild, :after_create ],
1769
+ [ InterceptableSpec::CbCascadedChild, :around_save_close ],
1770
+ [ InterceptableSpec::CbCascadedChild, :after_save ],
1771
+
1772
+ [ InterceptableSpec::CbParent, :around_create_close ],
1773
+ [ InterceptableSpec::CbParent, :after_create ],
1774
+ [ InterceptableSpec::CbParent, :around_save_close ],
1775
+ [ InterceptableSpec::CbParent, :after_save ]
1904
1776
  ]
1905
1777
  end
1906
1778
 
@@ -1921,28 +1793,28 @@ describe Mongoid::Interceptable do
1921
1793
 
1922
1794
  let(:expected) do
1923
1795
  [
1924
- [InterceptableSpec::CbCascadedChild, :before_validation],
1925
- [InterceptableSpec::CbCascadedChild, :after_validation],
1926
- [InterceptableSpec::CbParent, :before_validation],
1927
- [InterceptableSpec::CbCascadedChild, :before_validation],
1928
- [InterceptableSpec::CbCascadedChild, :after_validation],
1929
-
1930
- [InterceptableSpec::CbParent, :after_validation],
1931
- [InterceptableSpec::CbParent, :before_save],
1932
- [InterceptableSpec::CbParent, :around_save_open],
1933
- [InterceptableSpec::CbParent, :before_create],
1934
- [InterceptableSpec::CbParent, :around_create_open],
1935
-
1936
- [InterceptableSpec::CbCascadedChild, :before_save],
1937
- [InterceptableSpec::CbCascadedChild, :before_create],
1938
-
1939
- [InterceptableSpec::CbCascadedChild, :after_create],
1940
- [InterceptableSpec::CbCascadedChild, :after_save],
1941
-
1942
- [InterceptableSpec::CbParent, :around_create_close],
1943
- [InterceptableSpec::CbParent, :after_create],
1944
- [InterceptableSpec::CbParent, :around_save_close],
1945
- [InterceptableSpec::CbParent, :after_save]
1796
+ [ InterceptableSpec::CbCascadedChild, :before_validation ],
1797
+ [ InterceptableSpec::CbCascadedChild, :after_validation ],
1798
+ [ InterceptableSpec::CbParent, :before_validation ],
1799
+ [ InterceptableSpec::CbCascadedChild, :before_validation ],
1800
+ [ InterceptableSpec::CbCascadedChild, :after_validation ],
1801
+
1802
+ [ InterceptableSpec::CbParent, :after_validation ],
1803
+ [ InterceptableSpec::CbParent, :before_save ],
1804
+ [ InterceptableSpec::CbParent, :around_save_open ],
1805
+ [ InterceptableSpec::CbParent, :before_create ],
1806
+ [ InterceptableSpec::CbParent, :around_create_open ],
1807
+
1808
+ [ InterceptableSpec::CbCascadedChild, :before_save ],
1809
+ [ InterceptableSpec::CbCascadedChild, :before_create ],
1810
+
1811
+ [ InterceptableSpec::CbCascadedChild, :after_create ],
1812
+ [ InterceptableSpec::CbCascadedChild, :after_save ],
1813
+
1814
+ [ InterceptableSpec::CbParent, :around_create_close ],
1815
+ [ InterceptableSpec::CbParent, :after_create ],
1816
+ [ InterceptableSpec::CbParent, :around_save_close ],
1817
+ [ InterceptableSpec::CbParent, :after_save ]
1946
1818
  ]
1947
1819
  end
1948
1820
 
@@ -1953,8 +1825,8 @@ describe Mongoid::Interceptable do
1953
1825
  end
1954
1826
  end
1955
1827
 
1956
- context "with associations" do
1957
- context "has_one" do
1828
+ context 'with associations' do
1829
+ context 'has_one' do
1958
1830
  let(:registry) { InterceptableSpec::CallbackRegistry.new }
1959
1831
 
1960
1832
  let(:parent) do
@@ -1965,34 +1837,34 @@ describe Mongoid::Interceptable do
1965
1837
 
1966
1838
  let(:expected) do
1967
1839
  [
1968
- [InterceptableSpec::CbHasOneParent, :before_validation],
1969
- [InterceptableSpec::CbHasOneChild, :before_validation],
1970
- [InterceptableSpec::CbHasOneChild, :after_validation],
1971
- [InterceptableSpec::CbHasOneParent, :after_validation],
1972
- [InterceptableSpec::CbHasOneParent, :before_save],
1973
-
1974
- [InterceptableSpec::CbHasOneParent, :around_save_open],
1975
- [InterceptableSpec::CbHasOneParent, :before_create],
1976
- [InterceptableSpec::CbHasOneParent, :around_create_open],
1977
-
1978
- [InterceptableSpec::CbHasOneParent, :insert_into_database],
1979
-
1980
- [InterceptableSpec::CbHasOneChild, :before_validation],
1981
- [InterceptableSpec::CbHasOneChild, :after_validation],
1982
- [InterceptableSpec::CbHasOneChild, :before_save],
1983
- [InterceptableSpec::CbHasOneChild, :around_save_open],
1984
- [InterceptableSpec::CbHasOneChild, :before_create],
1985
- [InterceptableSpec::CbHasOneChild, :around_create_open],
1986
-
1987
- [InterceptableSpec::CbHasOneChild, :around_create_close],
1988
- [InterceptableSpec::CbHasOneChild, :after_create],
1989
- [InterceptableSpec::CbHasOneChild, :around_save_close],
1990
- [InterceptableSpec::CbHasOneChild, :after_save],
1991
-
1992
- [InterceptableSpec::CbHasOneParent, :around_create_close],
1993
- [InterceptableSpec::CbHasOneParent, :after_create],
1994
- [InterceptableSpec::CbHasOneParent, :around_save_close],
1995
- [InterceptableSpec::CbHasOneParent, :after_save],
1840
+ [ InterceptableSpec::CbHasOneParent, :before_validation ],
1841
+ [ InterceptableSpec::CbHasOneChild, :before_validation ],
1842
+ [ InterceptableSpec::CbHasOneChild, :after_validation ],
1843
+ [ InterceptableSpec::CbHasOneParent, :after_validation ],
1844
+ [ InterceptableSpec::CbHasOneParent, :before_save ],
1845
+
1846
+ [ InterceptableSpec::CbHasOneParent, :around_save_open ],
1847
+ [ InterceptableSpec::CbHasOneParent, :before_create ],
1848
+ [ InterceptableSpec::CbHasOneParent, :around_create_open ],
1849
+
1850
+ [ InterceptableSpec::CbHasOneParent, :insert_into_database ],
1851
+
1852
+ [ InterceptableSpec::CbHasOneChild, :before_validation ],
1853
+ [ InterceptableSpec::CbHasOneChild, :after_validation ],
1854
+ [ InterceptableSpec::CbHasOneChild, :before_save ],
1855
+ [ InterceptableSpec::CbHasOneChild, :around_save_open ],
1856
+ [ InterceptableSpec::CbHasOneChild, :before_create ],
1857
+ [ InterceptableSpec::CbHasOneChild, :around_create_open ],
1858
+
1859
+ [ InterceptableSpec::CbHasOneChild, :around_create_close ],
1860
+ [ InterceptableSpec::CbHasOneChild, :after_create ],
1861
+ [ InterceptableSpec::CbHasOneChild, :around_save_close ],
1862
+ [ InterceptableSpec::CbHasOneChild, :after_save ],
1863
+
1864
+ [ InterceptableSpec::CbHasOneParent, :around_create_close ],
1865
+ [ InterceptableSpec::CbHasOneParent, :after_create ],
1866
+ [ InterceptableSpec::CbHasOneParent, :around_save_close ],
1867
+ [ InterceptableSpec::CbHasOneParent, :after_save ]
1996
1868
  ]
1997
1869
  end
1998
1870
 
@@ -2002,7 +1874,7 @@ describe Mongoid::Interceptable do
2002
1874
  end
2003
1875
  end
2004
1876
 
2005
- context "embeds_one" do
1877
+ context 'embeds_one' do
2006
1878
  let(:registry) { InterceptableSpec::CallbackRegistry.new }
2007
1879
 
2008
1880
  let(:parent) do
@@ -2011,40 +1883,40 @@ describe Mongoid::Interceptable do
2011
1883
  end
2012
1884
  end
2013
1885
 
2014
- context "create" do
2015
- context "with around callbacks" do
1886
+ context 'create' do
1887
+ context 'with around callbacks' do
2016
1888
  config_override :around_callbacks_for_embeds, true
2017
1889
 
2018
1890
  let(:expected) do
2019
1891
  [
2020
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2021
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2022
- [InterceptableSpec::CbEmbedsOneParent, :before_validation],
2023
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2024
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2025
- [InterceptableSpec::CbEmbedsOneParent, :after_validation],
2026
-
2027
- [InterceptableSpec::CbEmbedsOneParent, :before_save],
2028
- [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
2029
- [InterceptableSpec::CbEmbedsOneParent, :before_create],
2030
- [InterceptableSpec::CbEmbedsOneParent, :around_create_open],
2031
-
2032
- [InterceptableSpec::CbEmbedsOneChild, :before_save],
2033
- [InterceptableSpec::CbEmbedsOneChild, :around_save_open],
2034
- [InterceptableSpec::CbEmbedsOneChild, :before_create],
2035
- [InterceptableSpec::CbEmbedsOneChild, :around_create_open],
2036
-
2037
- [InterceptableSpec::CbEmbedsOneParent, :insert_into_database],
2038
-
2039
- [InterceptableSpec::CbEmbedsOneChild, :around_create_close],
2040
- [InterceptableSpec::CbEmbedsOneChild, :after_create],
2041
- [InterceptableSpec::CbEmbedsOneChild, :around_save_close],
2042
- [InterceptableSpec::CbEmbedsOneChild, :after_save],
2043
-
2044
- [InterceptableSpec::CbEmbedsOneParent, :around_create_close],
2045
- [InterceptableSpec::CbEmbedsOneParent, :after_create],
2046
- [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
2047
- [InterceptableSpec::CbEmbedsOneParent, :after_save]
1892
+ [ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
1893
+ [ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
1894
+ [ InterceptableSpec::CbEmbedsOneParent, :before_validation ],
1895
+ [ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
1896
+ [ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
1897
+ [ InterceptableSpec::CbEmbedsOneParent, :after_validation ],
1898
+
1899
+ [ InterceptableSpec::CbEmbedsOneParent, :before_save ],
1900
+ [ InterceptableSpec::CbEmbedsOneParent, :around_save_open ],
1901
+ [ InterceptableSpec::CbEmbedsOneParent, :before_create ],
1902
+ [ InterceptableSpec::CbEmbedsOneParent, :around_create_open ],
1903
+
1904
+ [ InterceptableSpec::CbEmbedsOneChild, :before_save ],
1905
+ [ InterceptableSpec::CbEmbedsOneChild, :around_save_open ],
1906
+ [ InterceptableSpec::CbEmbedsOneChild, :before_create ],
1907
+ [ InterceptableSpec::CbEmbedsOneChild, :around_create_open ],
1908
+
1909
+ [ InterceptableSpec::CbEmbedsOneParent, :insert_into_database ],
1910
+
1911
+ [ InterceptableSpec::CbEmbedsOneChild, :around_create_close ],
1912
+ [ InterceptableSpec::CbEmbedsOneChild, :after_create ],
1913
+ [ InterceptableSpec::CbEmbedsOneChild, :around_save_close ],
1914
+ [ InterceptableSpec::CbEmbedsOneChild, :after_save ],
1915
+
1916
+ [ InterceptableSpec::CbEmbedsOneParent, :around_create_close ],
1917
+ [ InterceptableSpec::CbEmbedsOneParent, :after_create ],
1918
+ [ InterceptableSpec::CbEmbedsOneParent, :around_save_close ],
1919
+ [ InterceptableSpec::CbEmbedsOneParent, :after_save ]
2048
1920
  ]
2049
1921
  end
2050
1922
 
@@ -2054,35 +1926,35 @@ describe Mongoid::Interceptable do
2054
1926
  end
2055
1927
  end
2056
1928
 
2057
- context "without around callbacks" do
1929
+ context 'without around callbacks' do
2058
1930
  config_override :around_callbacks_for_embeds, false
2059
1931
 
2060
1932
  let(:expected) do
2061
1933
  [
2062
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2063
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2064
- [InterceptableSpec::CbEmbedsOneParent, :before_validation],
2065
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2066
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2067
- [InterceptableSpec::CbEmbedsOneParent, :after_validation],
2068
-
2069
- [InterceptableSpec::CbEmbedsOneParent, :before_save],
2070
- [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
2071
- [InterceptableSpec::CbEmbedsOneParent, :before_create],
2072
- [InterceptableSpec::CbEmbedsOneParent, :around_create_open],
2073
-
2074
- [InterceptableSpec::CbEmbedsOneChild, :before_save],
2075
- [InterceptableSpec::CbEmbedsOneChild, :before_create],
2076
-
2077
- [InterceptableSpec::CbEmbedsOneParent, :insert_into_database],
2078
-
2079
- [InterceptableSpec::CbEmbedsOneChild, :after_create],
2080
- [InterceptableSpec::CbEmbedsOneChild, :after_save],
2081
-
2082
- [InterceptableSpec::CbEmbedsOneParent, :around_create_close],
2083
- [InterceptableSpec::CbEmbedsOneParent, :after_create],
2084
- [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
2085
- [InterceptableSpec::CbEmbedsOneParent, :after_save]
1934
+ [ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
1935
+ [ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
1936
+ [ InterceptableSpec::CbEmbedsOneParent, :before_validation ],
1937
+ [ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
1938
+ [ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
1939
+ [ InterceptableSpec::CbEmbedsOneParent, :after_validation ],
1940
+
1941
+ [ InterceptableSpec::CbEmbedsOneParent, :before_save ],
1942
+ [ InterceptableSpec::CbEmbedsOneParent, :around_save_open ],
1943
+ [ InterceptableSpec::CbEmbedsOneParent, :before_create ],
1944
+ [ InterceptableSpec::CbEmbedsOneParent, :around_create_open ],
1945
+
1946
+ [ InterceptableSpec::CbEmbedsOneChild, :before_save ],
1947
+ [ InterceptableSpec::CbEmbedsOneChild, :before_create ],
1948
+
1949
+ [ InterceptableSpec::CbEmbedsOneParent, :insert_into_database ],
1950
+
1951
+ [ InterceptableSpec::CbEmbedsOneChild, :after_create ],
1952
+ [ InterceptableSpec::CbEmbedsOneChild, :after_save ],
1953
+
1954
+ [ InterceptableSpec::CbEmbedsOneParent, :around_create_close ],
1955
+ [ InterceptableSpec::CbEmbedsOneParent, :after_create ],
1956
+ [ InterceptableSpec::CbEmbedsOneParent, :around_save_close ],
1957
+ [ InterceptableSpec::CbEmbedsOneParent, :after_save ]
2086
1958
  ]
2087
1959
  end
2088
1960
 
@@ -2093,38 +1965,38 @@ describe Mongoid::Interceptable do
2093
1965
  end
2094
1966
  end
2095
1967
 
2096
- context "update" do
2097
- context "with around callbacks" do
1968
+ context 'update' do
1969
+ context 'with around callbacks' do
2098
1970
  config_override :around_callbacks_for_embeds, true
2099
1971
 
2100
1972
  let(:expected) do
2101
1973
  [
2102
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2103
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2104
- [InterceptableSpec::CbEmbedsOneParent, :before_validation],
2105
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2106
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2107
- [InterceptableSpec::CbEmbedsOneParent, :after_validation],
2108
-
2109
- [InterceptableSpec::CbEmbedsOneParent, :before_save],
2110
- [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
2111
- [InterceptableSpec::CbEmbedsOneParent, :before_update],
2112
- [InterceptableSpec::CbEmbedsOneParent, :around_update_open],
2113
-
2114
- [InterceptableSpec::CbEmbedsOneChild, :before_save],
2115
- [InterceptableSpec::CbEmbedsOneChild, :around_save_open],
2116
- [InterceptableSpec::CbEmbedsOneChild, :before_update],
2117
- [InterceptableSpec::CbEmbedsOneChild, :around_update_open],
2118
-
2119
- [InterceptableSpec::CbEmbedsOneChild, :around_update_close],
2120
- [InterceptableSpec::CbEmbedsOneChild, :after_update],
2121
- [InterceptableSpec::CbEmbedsOneChild, :around_save_close],
2122
- [InterceptableSpec::CbEmbedsOneChild, :after_save],
2123
-
2124
- [InterceptableSpec::CbEmbedsOneParent, :around_update_close],
2125
- [InterceptableSpec::CbEmbedsOneParent, :after_update],
2126
- [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
2127
- [InterceptableSpec::CbEmbedsOneParent, :after_save]
1974
+ [ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
1975
+ [ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
1976
+ [ InterceptableSpec::CbEmbedsOneParent, :before_validation ],
1977
+ [ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
1978
+ [ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
1979
+ [ InterceptableSpec::CbEmbedsOneParent, :after_validation ],
1980
+
1981
+ [ InterceptableSpec::CbEmbedsOneParent, :before_save ],
1982
+ [ InterceptableSpec::CbEmbedsOneParent, :around_save_open ],
1983
+ [ InterceptableSpec::CbEmbedsOneParent, :before_update ],
1984
+ [ InterceptableSpec::CbEmbedsOneParent, :around_update_open ],
1985
+
1986
+ [ InterceptableSpec::CbEmbedsOneChild, :before_save ],
1987
+ [ InterceptableSpec::CbEmbedsOneChild, :around_save_open ],
1988
+ [ InterceptableSpec::CbEmbedsOneChild, :before_update ],
1989
+ [ InterceptableSpec::CbEmbedsOneChild, :around_update_open ],
1990
+
1991
+ [ InterceptableSpec::CbEmbedsOneChild, :around_update_close ],
1992
+ [ InterceptableSpec::CbEmbedsOneChild, :after_update ],
1993
+ [ InterceptableSpec::CbEmbedsOneChild, :around_save_close ],
1994
+ [ InterceptableSpec::CbEmbedsOneChild, :after_save ],
1995
+
1996
+ [ InterceptableSpec::CbEmbedsOneParent, :around_update_close ],
1997
+ [ InterceptableSpec::CbEmbedsOneParent, :after_update ],
1998
+ [ InterceptableSpec::CbEmbedsOneParent, :around_save_close ],
1999
+ [ InterceptableSpec::CbEmbedsOneParent, :after_save ]
2128
2000
  ]
2129
2001
  end
2130
2002
 
@@ -2135,7 +2007,7 @@ describe Mongoid::Interceptable do
2135
2007
 
2136
2008
  parent.callback_registry = registry
2137
2009
  parent.child.callback_registry = registry
2138
- parent.name = "name"
2010
+ parent.name = 'name'
2139
2011
  parent.child.age = 10
2140
2012
 
2141
2013
  parent.save!
@@ -2143,33 +2015,33 @@ describe Mongoid::Interceptable do
2143
2015
  end
2144
2016
  end
2145
2017
 
2146
- context "without around callbacks" do
2018
+ context 'without around callbacks' do
2147
2019
  config_override :around_callbacks_for_embeds, false
2148
2020
 
2149
2021
  let(:expected) do
2150
2022
  [
2151
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2152
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2153
- [InterceptableSpec::CbEmbedsOneParent, :before_validation],
2154
- [InterceptableSpec::CbEmbedsOneChild, :before_validation],
2155
- [InterceptableSpec::CbEmbedsOneChild, :after_validation],
2156
- [InterceptableSpec::CbEmbedsOneParent, :after_validation],
2157
-
2158
- [InterceptableSpec::CbEmbedsOneParent, :before_save],
2159
- [InterceptableSpec::CbEmbedsOneParent, :around_save_open],
2160
- [InterceptableSpec::CbEmbedsOneParent, :before_update],
2161
- [InterceptableSpec::CbEmbedsOneParent, :around_update_open],
2162
-
2163
- [InterceptableSpec::CbEmbedsOneChild, :before_save],
2164
- [InterceptableSpec::CbEmbedsOneChild, :before_update],
2165
-
2166
- [InterceptableSpec::CbEmbedsOneChild, :after_update],
2167
- [InterceptableSpec::CbEmbedsOneChild, :after_save],
2168
-
2169
- [InterceptableSpec::CbEmbedsOneParent, :around_update_close],
2170
- [InterceptableSpec::CbEmbedsOneParent, :after_update],
2171
- [InterceptableSpec::CbEmbedsOneParent, :around_save_close],
2172
- [InterceptableSpec::CbEmbedsOneParent, :after_save]
2023
+ [ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
2024
+ [ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
2025
+ [ InterceptableSpec::CbEmbedsOneParent, :before_validation ],
2026
+ [ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
2027
+ [ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
2028
+ [ InterceptableSpec::CbEmbedsOneParent, :after_validation ],
2029
+
2030
+ [ InterceptableSpec::CbEmbedsOneParent, :before_save ],
2031
+ [ InterceptableSpec::CbEmbedsOneParent, :around_save_open ],
2032
+ [ InterceptableSpec::CbEmbedsOneParent, :before_update ],
2033
+ [ InterceptableSpec::CbEmbedsOneParent, :around_update_open ],
2034
+
2035
+ [ InterceptableSpec::CbEmbedsOneChild, :before_save ],
2036
+ [ InterceptableSpec::CbEmbedsOneChild, :before_update ],
2037
+
2038
+ [ InterceptableSpec::CbEmbedsOneChild, :after_update ],
2039
+ [ InterceptableSpec::CbEmbedsOneChild, :after_save ],
2040
+
2041
+ [ InterceptableSpec::CbEmbedsOneParent, :around_update_close ],
2042
+ [ InterceptableSpec::CbEmbedsOneParent, :after_update ],
2043
+ [ InterceptableSpec::CbEmbedsOneParent, :around_save_close ],
2044
+ [ InterceptableSpec::CbEmbedsOneParent, :after_save ]
2173
2045
  ]
2174
2046
  end
2175
2047
 
@@ -2180,7 +2052,7 @@ describe Mongoid::Interceptable do
2180
2052
 
2181
2053
  parent.callback_registry = registry
2182
2054
  parent.child.callback_registry = registry
2183
- parent.name = "name"
2055
+ parent.name = 'name'
2184
2056
  parent.child.age = 10
2185
2057
 
2186
2058
  parent.save!
@@ -2190,7 +2062,7 @@ describe Mongoid::Interceptable do
2190
2062
  end
2191
2063
  end
2192
2064
 
2193
- context "has_many" do
2065
+ context 'has_many' do
2194
2066
  let(:registry) { InterceptableSpec::CallbackRegistry.new }
2195
2067
 
2196
2068
  let(:parent) do
@@ -2204,46 +2076,46 @@ describe Mongoid::Interceptable do
2204
2076
 
2205
2077
  let(:expected) do
2206
2078
  [
2207
- [InterceptableSpec::CbHasManyParent, :before_validation],
2208
- [InterceptableSpec::CbHasManyChild, :before_validation],
2209
- [InterceptableSpec::CbHasManyChild, :after_validation],
2210
- [InterceptableSpec::CbHasManyChild, :before_validation],
2211
- [InterceptableSpec::CbHasManyChild, :after_validation],
2212
- [InterceptableSpec::CbHasManyParent, :after_validation],
2213
-
2214
- [InterceptableSpec::CbHasManyParent, :before_save],
2215
- [InterceptableSpec::CbHasManyParent, :around_save_open],
2216
- [InterceptableSpec::CbHasManyParent, :before_create],
2217
- [InterceptableSpec::CbHasManyParent, :around_create_open],
2218
-
2219
- [InterceptableSpec::CbHasManyParent, :insert_into_database],
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::CbHasManyChild, :before_validation],
2233
- [InterceptableSpec::CbHasManyChild, :after_validation],
2234
- [InterceptableSpec::CbHasManyChild, :before_save],
2235
- [InterceptableSpec::CbHasManyChild, :around_save_open],
2236
- [InterceptableSpec::CbHasManyChild, :before_create],
2237
- [InterceptableSpec::CbHasManyChild, :around_create_open],
2238
- [InterceptableSpec::CbHasManyChild, :around_create_close],
2239
- [InterceptableSpec::CbHasManyChild, :after_create],
2240
- [InterceptableSpec::CbHasManyChild, :around_save_close],
2241
- [InterceptableSpec::CbHasManyChild, :after_save],
2242
-
2243
- [InterceptableSpec::CbHasManyParent, :around_create_close],
2244
- [InterceptableSpec::CbHasManyParent, :after_create],
2245
- [InterceptableSpec::CbHasManyParent, :around_save_close],
2246
- [InterceptableSpec::CbHasManyParent, :after_save]
2079
+ [ InterceptableSpec::CbHasManyParent, :before_validation ],
2080
+ [ InterceptableSpec::CbHasManyChild, :before_validation ],
2081
+ [ InterceptableSpec::CbHasManyChild, :after_validation ],
2082
+ [ InterceptableSpec::CbHasManyChild, :before_validation ],
2083
+ [ InterceptableSpec::CbHasManyChild, :after_validation ],
2084
+ [ InterceptableSpec::CbHasManyParent, :after_validation ],
2085
+
2086
+ [ InterceptableSpec::CbHasManyParent, :before_save ],
2087
+ [ InterceptableSpec::CbHasManyParent, :around_save_open ],
2088
+ [ InterceptableSpec::CbHasManyParent, :before_create ],
2089
+ [ InterceptableSpec::CbHasManyParent, :around_create_open ],
2090
+
2091
+ [ InterceptableSpec::CbHasManyParent, :insert_into_database ],
2092
+
2093
+ [ InterceptableSpec::CbHasManyChild, :before_validation ],
2094
+ [ InterceptableSpec::CbHasManyChild, :after_validation ],
2095
+ [ InterceptableSpec::CbHasManyChild, :before_save ],
2096
+ [ InterceptableSpec::CbHasManyChild, :around_save_open ],
2097
+ [ InterceptableSpec::CbHasManyChild, :before_create ],
2098
+ [ InterceptableSpec::CbHasManyChild, :around_create_open ],
2099
+ [ InterceptableSpec::CbHasManyChild, :around_create_close ],
2100
+ [ InterceptableSpec::CbHasManyChild, :after_create ],
2101
+ [ InterceptableSpec::CbHasManyChild, :around_save_close ],
2102
+ [ InterceptableSpec::CbHasManyChild, :after_save ],
2103
+
2104
+ [ InterceptableSpec::CbHasManyChild, :before_validation ],
2105
+ [ InterceptableSpec::CbHasManyChild, :after_validation ],
2106
+ [ InterceptableSpec::CbHasManyChild, :before_save ],
2107
+ [ InterceptableSpec::CbHasManyChild, :around_save_open ],
2108
+ [ InterceptableSpec::CbHasManyChild, :before_create ],
2109
+ [ InterceptableSpec::CbHasManyChild, :around_create_open ],
2110
+ [ InterceptableSpec::CbHasManyChild, :around_create_close ],
2111
+ [ InterceptableSpec::CbHasManyChild, :after_create ],
2112
+ [ InterceptableSpec::CbHasManyChild, :around_save_close ],
2113
+ [ InterceptableSpec::CbHasManyChild, :after_save ],
2114
+
2115
+ [ InterceptableSpec::CbHasManyParent, :around_create_close ],
2116
+ [ InterceptableSpec::CbHasManyParent, :after_create ],
2117
+ [ InterceptableSpec::CbHasManyParent, :around_save_close ],
2118
+ [ InterceptableSpec::CbHasManyParent, :after_save ]
2247
2119
  ]
2248
2120
  end
2249
2121
 
@@ -2253,68 +2125,68 @@ describe Mongoid::Interceptable do
2253
2125
  end
2254
2126
  end
2255
2127
 
2256
- context "embeds_many" do
2128
+ context 'embeds_many' do
2257
2129
  let(:registry) { InterceptableSpec::CallbackRegistry.new }
2258
2130
 
2259
2131
  let(:parent) do
2260
2132
  InterceptableSpec::CbEmbedsManyParent.new(registry).tap do |parent|
2261
2133
  parent.children = [
2262
2134
  InterceptableSpec::CbEmbedsManyChild.new(registry),
2263
- InterceptableSpec::CbEmbedsManyChild.new(registry),
2135
+ InterceptableSpec::CbEmbedsManyChild.new(registry)
2264
2136
  ]
2265
2137
  end
2266
2138
  end
2267
2139
 
2268
- context "with around callbacks" do
2140
+ context 'with around callbacks' do
2269
2141
  config_override :around_callbacks_for_embeds, true
2270
2142
 
2271
2143
  let(:expected) do
2272
2144
  [
2273
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2274
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2275
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2276
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2277
- [InterceptableSpec::CbEmbedsManyParent, :before_validation],
2278
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2279
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2280
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2281
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2282
- [InterceptableSpec::CbEmbedsManyParent, :after_validation],
2283
-
2284
- [InterceptableSpec::CbEmbedsManyParent, :before_save],
2285
- [InterceptableSpec::CbEmbedsManyParent, :around_save_open],
2286
- [InterceptableSpec::CbEmbedsManyParent, :before_create],
2287
- [InterceptableSpec::CbEmbedsManyParent, :around_create_open],
2288
-
2289
- [InterceptableSpec::CbEmbedsManyChild, :before_save],
2290
- [InterceptableSpec::CbEmbedsManyChild, :around_save_open],
2291
- [InterceptableSpec::CbEmbedsManyChild, :before_save],
2292
-
2293
- [InterceptableSpec::CbEmbedsManyChild, :around_save_open],
2294
- [InterceptableSpec::CbEmbedsManyChild, :before_create],
2295
- [InterceptableSpec::CbEmbedsManyChild, :around_create_open],
2296
-
2297
- [InterceptableSpec::CbEmbedsManyChild, :before_create],
2298
- [InterceptableSpec::CbEmbedsManyChild, :around_create_open],
2299
-
2300
- [InterceptableSpec::CbEmbedsManyParent, :insert_into_database],
2301
-
2302
- [InterceptableSpec::CbEmbedsManyChild, :around_create_close],
2303
- [InterceptableSpec::CbEmbedsManyChild, :after_create],
2304
-
2305
- [InterceptableSpec::CbEmbedsManyChild, :around_create_close],
2306
- [InterceptableSpec::CbEmbedsManyChild, :after_create],
2307
-
2308
- [InterceptableSpec::CbEmbedsManyChild, :around_save_close],
2309
- [InterceptableSpec::CbEmbedsManyChild, :after_save],
2310
-
2311
- [InterceptableSpec::CbEmbedsManyChild, :around_save_close],
2312
- [InterceptableSpec::CbEmbedsManyChild, :after_save],
2313
-
2314
- [InterceptableSpec::CbEmbedsManyParent, :around_create_close],
2315
- [InterceptableSpec::CbEmbedsManyParent, :after_create],
2316
- [InterceptableSpec::CbEmbedsManyParent, :around_save_close],
2317
- [InterceptableSpec::CbEmbedsManyParent, :after_save]
2145
+ [ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
2146
+ [ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
2147
+ [ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
2148
+ [ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
2149
+ [ InterceptableSpec::CbEmbedsManyParent, :before_validation ],
2150
+ [ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
2151
+ [ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
2152
+ [ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
2153
+ [ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
2154
+ [ InterceptableSpec::CbEmbedsManyParent, :after_validation ],
2155
+
2156
+ [ InterceptableSpec::CbEmbedsManyParent, :before_save ],
2157
+ [ InterceptableSpec::CbEmbedsManyParent, :around_save_open ],
2158
+ [ InterceptableSpec::CbEmbedsManyParent, :before_create ],
2159
+ [ InterceptableSpec::CbEmbedsManyParent, :around_create_open ],
2160
+
2161
+ [ InterceptableSpec::CbEmbedsManyChild, :before_save ],
2162
+ [ InterceptableSpec::CbEmbedsManyChild, :around_save_open ],
2163
+ [ InterceptableSpec::CbEmbedsManyChild, :before_save ],
2164
+
2165
+ [ InterceptableSpec::CbEmbedsManyChild, :around_save_open ],
2166
+ [ InterceptableSpec::CbEmbedsManyChild, :before_create ],
2167
+ [ InterceptableSpec::CbEmbedsManyChild, :around_create_open ],
2168
+
2169
+ [ InterceptableSpec::CbEmbedsManyChild, :before_create ],
2170
+ [ InterceptableSpec::CbEmbedsManyChild, :around_create_open ],
2171
+
2172
+ [ InterceptableSpec::CbEmbedsManyParent, :insert_into_database ],
2173
+
2174
+ [ InterceptableSpec::CbEmbedsManyChild, :around_create_close ],
2175
+ [ InterceptableSpec::CbEmbedsManyChild, :after_create ],
2176
+
2177
+ [ InterceptableSpec::CbEmbedsManyChild, :around_create_close ],
2178
+ [ InterceptableSpec::CbEmbedsManyChild, :after_create ],
2179
+
2180
+ [ InterceptableSpec::CbEmbedsManyChild, :around_save_close ],
2181
+ [ InterceptableSpec::CbEmbedsManyChild, :after_save ],
2182
+
2183
+ [ InterceptableSpec::CbEmbedsManyChild, :around_save_close ],
2184
+ [ InterceptableSpec::CbEmbedsManyChild, :after_save ],
2185
+
2186
+ [ InterceptableSpec::CbEmbedsManyParent, :around_create_close ],
2187
+ [ InterceptableSpec::CbEmbedsManyParent, :after_create ],
2188
+ [ InterceptableSpec::CbEmbedsManyParent, :around_save_close ],
2189
+ [ InterceptableSpec::CbEmbedsManyParent, :after_save ]
2318
2190
  ]
2319
2191
  end
2320
2192
 
@@ -2324,48 +2196,48 @@ describe Mongoid::Interceptable do
2324
2196
  end
2325
2197
  end
2326
2198
 
2327
- context "without around callbacks" do
2199
+ context 'without around callbacks' do
2328
2200
  config_override :around_callbacks_for_embeds, false
2329
2201
 
2330
2202
  let(:expected) do
2331
2203
  [
2332
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2333
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2334
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2335
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2336
- [InterceptableSpec::CbEmbedsManyParent, :before_validation],
2337
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2338
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2339
- [InterceptableSpec::CbEmbedsManyChild, :before_validation],
2340
- [InterceptableSpec::CbEmbedsManyChild, :after_validation],
2341
- [InterceptableSpec::CbEmbedsManyParent, :after_validation],
2204
+ [ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
2205
+ [ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
2206
+ [ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
2207
+ [ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
2208
+ [ InterceptableSpec::CbEmbedsManyParent, :before_validation ],
2209
+ [ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
2210
+ [ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
2211
+ [ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
2212
+ [ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
2213
+ [ InterceptableSpec::CbEmbedsManyParent, :after_validation ],
2342
2214
 
2343
- [InterceptableSpec::CbEmbedsManyParent, :before_save],
2344
- [InterceptableSpec::CbEmbedsManyParent, :around_save_open],
2345
- [InterceptableSpec::CbEmbedsManyParent, :before_create],
2346
- [InterceptableSpec::CbEmbedsManyParent, :around_create_open],
2215
+ [ InterceptableSpec::CbEmbedsManyParent, :before_save ],
2216
+ [ InterceptableSpec::CbEmbedsManyParent, :around_save_open ],
2217
+ [ InterceptableSpec::CbEmbedsManyParent, :before_create ],
2218
+ [ InterceptableSpec::CbEmbedsManyParent, :around_create_open ],
2347
2219
 
2348
- [InterceptableSpec::CbEmbedsManyChild, :before_save],
2349
- [InterceptableSpec::CbEmbedsManyChild, :before_save],
2220
+ [ InterceptableSpec::CbEmbedsManyChild, :before_save ],
2221
+ [ InterceptableSpec::CbEmbedsManyChild, :before_save ],
2350
2222
 
2351
- [InterceptableSpec::CbEmbedsManyChild, :before_create],
2223
+ [ InterceptableSpec::CbEmbedsManyChild, :before_create ],
2352
2224
 
2353
- [InterceptableSpec::CbEmbedsManyChild, :before_create],
2225
+ [ InterceptableSpec::CbEmbedsManyChild, :before_create ],
2354
2226
 
2355
- [InterceptableSpec::CbEmbedsManyParent, :insert_into_database],
2227
+ [ InterceptableSpec::CbEmbedsManyParent, :insert_into_database ],
2356
2228
 
2357
- [InterceptableSpec::CbEmbedsManyChild, :after_create],
2229
+ [ InterceptableSpec::CbEmbedsManyChild, :after_create ],
2358
2230
 
2359
- [InterceptableSpec::CbEmbedsManyChild, :after_create],
2231
+ [ InterceptableSpec::CbEmbedsManyChild, :after_create ],
2360
2232
 
2361
- [InterceptableSpec::CbEmbedsManyChild, :after_save],
2233
+ [ InterceptableSpec::CbEmbedsManyChild, :after_save ],
2362
2234
 
2363
- [InterceptableSpec::CbEmbedsManyChild, :after_save],
2235
+ [ InterceptableSpec::CbEmbedsManyChild, :after_save ],
2364
2236
 
2365
- [InterceptableSpec::CbEmbedsManyParent, :around_create_close],
2366
- [InterceptableSpec::CbEmbedsManyParent, :after_create],
2367
- [InterceptableSpec::CbEmbedsManyParent, :around_save_close],
2368
- [InterceptableSpec::CbEmbedsManyParent, :after_save]
2237
+ [ InterceptableSpec::CbEmbedsManyParent, :around_create_close ],
2238
+ [ InterceptableSpec::CbEmbedsManyParent, :after_create ],
2239
+ [ InterceptableSpec::CbEmbedsManyParent, :around_save_close ],
2240
+ [ InterceptableSpec::CbEmbedsManyParent, :after_save ]
2369
2241
  ]
2370
2242
  end
2371
2243
 
@@ -2377,33 +2249,35 @@ describe Mongoid::Interceptable do
2377
2249
  end
2378
2250
  end
2379
2251
 
2380
- context "when accessing parent document from callbacks" do
2252
+ context 'when accessing parent document from callbacks' do
2381
2253
  shared_examples 'accesses the correct parent' do
2382
- it "accesses the correct parent in after_find" do
2254
+ it 'accesses the correct parent in after_find' do
2383
2255
  expect(from_db.after_find_player).to eq(player._id)
2384
2256
  end
2385
2257
 
2386
- it "accesses the correct parent in after_initialize" do
2258
+ it 'accesses the correct parent in after_initialize' do
2387
2259
  expect(from_db.after_initialize_player).to eq(player._id)
2388
2260
  end
2389
2261
 
2390
- it "accesses the correct parent in default" do
2262
+ it 'accesses the correct parent in default' do
2391
2263
  expect(from_db.after_default_player).to eq(player._id)
2392
2264
  end
2393
2265
 
2394
- it "accesses the correct parent in unpersisted after_initialize" do
2266
+ it 'accesses the correct parent in unpersisted after_initialize' do
2395
2267
  expect(unpersisted.after_initialize_player).to eq(player._id)
2396
2268
  end
2397
2269
  end
2398
2270
 
2399
- context "when using create methods" do
2400
-
2401
- context "when the child is an embeds_many association" do
2271
+ context 'when using create methods' do
2272
+ context 'when the child is an embeds_many association' do
2402
2273
  let!(:player) do
2403
2274
  Player.create!.tap do |player|
2404
2275
  player.implants.create!
2405
2276
  end
2406
2277
  end
2278
+ let(:from_db) do
2279
+ Player.find(player.id).implants.first
2280
+ end
2407
2281
 
2408
2282
  let(:unpersisted) { player.implants.first }
2409
2283
 
@@ -2417,19 +2291,18 @@ describe Mongoid::Interceptable do
2417
2291
  Player.find(player.id).implants.first.unset(:after_default_player)
2418
2292
  end
2419
2293
 
2420
- let(:from_db) do
2421
- Player.find(player.id).implants.first
2422
- end
2423
-
2424
2294
  include_examples 'accesses the correct parent'
2425
2295
  end
2426
2296
 
2427
- context "when the child is an embeds_one association" do
2297
+ context 'when the child is an embeds_one association' do
2428
2298
  let!(:player) do
2429
2299
  Player.create!.tap do |player|
2430
2300
  player.create_augmentation
2431
2301
  end
2432
2302
  end
2303
+ let(:from_db) do
2304
+ Player.find(player.id).augmentation
2305
+ end
2433
2306
 
2434
2307
  let(:unpersisted) { player.augmentation }
2435
2308
 
@@ -2437,19 +2310,18 @@ describe Mongoid::Interceptable do
2437
2310
  Player.find(player.id).augmentation.unset(:after_default_player)
2438
2311
  end
2439
2312
 
2440
- let(:from_db) do
2441
- Player.find(player.id).augmentation
2442
- end
2443
-
2444
2313
  include_examples 'accesses the correct parent'
2445
2314
  end
2446
2315
 
2447
- context "when the child is a has_many association" do
2316
+ context 'when the child is a has_many association' do
2448
2317
  let!(:player) do
2449
2318
  Player.create!.tap do |player|
2450
2319
  player.weapons.create!
2451
2320
  end
2452
2321
  end
2322
+ let(:from_db) do
2323
+ Player.find(player.id).weapons.first
2324
+ end
2453
2325
 
2454
2326
  let(:unpersisted) { player.weapons.first }
2455
2327
 
@@ -2457,20 +2329,19 @@ describe Mongoid::Interceptable do
2457
2329
  Player.find(player.id).weapons.first.unset(:after_default_player)
2458
2330
  end
2459
2331
 
2460
- let(:from_db) do
2461
- Player.find(player.id).weapons.first
2462
- end
2463
-
2464
2332
  include_examples 'accesses the correct parent'
2465
2333
  end
2466
2334
 
2467
- context "when the child is a has_one association" do
2335
+ context 'when the child is a has_one association' do
2468
2336
  let!(:player) do
2469
2337
  Player.create!.tap do |player|
2470
2338
  player.create_powerup
2471
2339
  player.save!
2472
2340
  end
2473
2341
  end
2342
+ let(:from_db) do
2343
+ Player.find(player.id).powerup
2344
+ end
2474
2345
 
2475
2346
  let(:unpersisted) { player.powerup }
2476
2347
 
@@ -2478,19 +2349,18 @@ describe Mongoid::Interceptable do
2478
2349
  Player.find(player.id).powerup.unset(:after_default_player)
2479
2350
  end
2480
2351
 
2481
- let(:from_db) do
2482
- Player.find(player.id).powerup
2483
- end
2484
-
2485
2352
  include_examples 'accesses the correct parent'
2486
2353
  end
2487
2354
 
2488
- context "when the child is a has_and_belongs_to_many association" do
2355
+ context 'when the child is a has_and_belongs_to_many association' do
2489
2356
  let!(:player) do
2490
2357
  Player.create!.tap do |player|
2491
2358
  player.shields.create!
2492
2359
  end
2493
2360
  end
2361
+ let(:from_db) do
2362
+ Player.find(player.id).shields.first
2363
+ end
2494
2364
 
2495
2365
  let(:unpersisted) { player.shields.first }
2496
2366
 
@@ -2498,23 +2368,21 @@ describe Mongoid::Interceptable do
2498
2368
  Player.find(player.id).shields.unset(:after_default_player)
2499
2369
  end
2500
2370
 
2501
- let(:from_db) do
2502
- Player.find(player.id).shields.first
2503
- end
2504
-
2505
2371
  include_examples 'accesses the correct parent'
2506
2372
  end
2507
2373
  end
2508
2374
 
2509
- context "when using build methods" do
2510
-
2511
- context "when the child is an embeds_many association" do
2375
+ context 'when using build methods' do
2376
+ context 'when the child is an embeds_many association' do
2512
2377
  let!(:player) do
2513
2378
  Player.create!.tap do |player|
2514
2379
  player.implants.build
2515
2380
  player.implants.first.save!
2516
2381
  end
2517
2382
  end
2383
+ let(:from_db) do
2384
+ Player.find(player.id).implants.first
2385
+ end
2518
2386
 
2519
2387
  let(:unpersisted) { player.implants.first }
2520
2388
 
@@ -2522,20 +2390,19 @@ describe Mongoid::Interceptable do
2522
2390
  Player.find(player.id).implants.first.unset(:after_default_player)
2523
2391
  end
2524
2392
 
2525
- let(:from_db) do
2526
- Player.find(player.id).implants.first
2527
- end
2528
-
2529
2393
  include_examples 'accesses the correct parent'
2530
2394
  end
2531
2395
 
2532
- context "when the child is an embeds_one association" do
2396
+ context 'when the child is an embeds_one association' do
2533
2397
  let!(:player) do
2534
2398
  Player.create!.tap do |player|
2535
2399
  player.build_augmentation
2536
2400
  player.save!
2537
2401
  end
2538
2402
  end
2403
+ let(:from_db) do
2404
+ Player.find(player.id).augmentation
2405
+ end
2539
2406
 
2540
2407
  let(:unpersisted) { player.augmentation }
2541
2408
 
@@ -2543,20 +2410,19 @@ describe Mongoid::Interceptable do
2543
2410
  Player.find(player.id).augmentation.unset(:after_default_player)
2544
2411
  end
2545
2412
 
2546
- let(:from_db) do
2547
- Player.find(player.id).augmentation
2548
- end
2549
-
2550
2413
  include_examples 'accesses the correct parent'
2551
2414
  end
2552
2415
 
2553
- context "when the child is a has_many association" do
2416
+ context 'when the child is a has_many association' do
2554
2417
  let!(:player) do
2555
2418
  Player.create!.tap do |player|
2556
2419
  player.weapons.build
2557
2420
  player.weapons.first.save!
2558
2421
  end
2559
2422
  end
2423
+ let(:from_db) do
2424
+ Player.find(player.id).weapons.first
2425
+ end
2560
2426
 
2561
2427
  let(:unpersisted) { player.weapons.first }
2562
2428
 
@@ -2564,20 +2430,19 @@ describe Mongoid::Interceptable do
2564
2430
  Player.find(player.id).weapons.first.unset(:after_default_player)
2565
2431
  end
2566
2432
 
2567
- let(:from_db) do
2568
- Player.find(player.id).weapons.first
2569
- end
2570
-
2571
2433
  include_examples 'accesses the correct parent'
2572
2434
  end
2573
2435
 
2574
- context "when the child is a has_one association" do
2436
+ context 'when the child is a has_one association' do
2575
2437
  let!(:player) do
2576
2438
  Player.create!.tap do |player|
2577
2439
  player.build_powerup
2578
2440
  player.powerup.save!
2579
2441
  end
2580
2442
  end
2443
+ let(:from_db) do
2444
+ Player.find(player.id).powerup
2445
+ end
2581
2446
 
2582
2447
  let(:unpersisted) { player.powerup }
2583
2448
 
@@ -2585,20 +2450,19 @@ describe Mongoid::Interceptable do
2585
2450
  Player.find(player.id).powerup.unset(:after_default_player)
2586
2451
  end
2587
2452
 
2588
- let(:from_db) do
2589
- Player.find(player.id).powerup
2590
- end
2591
-
2592
2453
  include_examples 'accesses the correct parent'
2593
2454
  end
2594
2455
 
2595
- context "when the child is a has_and_belongs_to_many association" do
2456
+ context 'when the child is a has_and_belongs_to_many association' do
2596
2457
  let!(:player) do
2597
2458
  Player.create!.tap do |player|
2598
2459
  player.shields.build
2599
2460
  player.shields.first.save!
2600
2461
  end
2601
2462
  end
2463
+ let(:from_db) do
2464
+ Player.find(player.id).shields.first
2465
+ end
2602
2466
 
2603
2467
  let(:unpersisted) { player.shields.first }
2604
2468
 
@@ -2606,26 +2470,22 @@ describe Mongoid::Interceptable do
2606
2470
  Player.find(player.id).shields.unset(:after_default_player)
2607
2471
  end
2608
2472
 
2609
- let(:from_db) do
2610
- Player.find(player.id).shields.first
2611
- end
2612
-
2613
2473
  include_examples 'accesses the correct parent'
2614
2474
  end
2615
2475
  end
2616
2476
  end
2617
2477
 
2618
- context "when accessing associations in defaults" do
2619
- context "when not using autobuilding" do
2620
- let(:band) { InterceptableBand.create(name: "Molejo") }
2621
- let(:song) { band.songs.create(name: "Cilada") }
2478
+ context 'when accessing associations in defaults' do
2479
+ context 'when not using autobuilding' do
2480
+ let(:band) { InterceptableBand.create(name: 'Molejo') }
2481
+ let(:song) { band.songs.create(name: 'Cilada') }
2622
2482
 
2623
- it "assigns the default correctly" do
2624
- expect(song.band_name).to eq("Molejo")
2483
+ it 'assigns the default correctly' do
2484
+ expect(song.band_name).to eq('Molejo')
2625
2485
  end
2626
2486
  end
2627
2487
 
2628
- context "when using autobuilding" do
2488
+ context 'when using autobuilding' do
2629
2489
  before do
2630
2490
  InterceptablePlane.create!.tap do |plane|
2631
2491
  plane.wings.create!
@@ -2636,8 +2496,8 @@ describe Mongoid::Interceptable do
2636
2496
  let(:wing) { InterceptableWing.first }
2637
2497
  let(:engine) { wing.engine }
2638
2498
 
2639
- it "sets the defaults correctly" do
2640
- expect(wing._id).to eq("hello-wing")
2499
+ it 'sets the defaults correctly' do
2500
+ expect(wing._id).to eq('hello-wing')
2641
2501
  expect(wing.p_id).to eq(plane._id.to_s)
2642
2502
  expect(wing.e_id).to eq(engine._id.to_s)
2643
2503
  expect(engine._id).to eq("hello-engine-#{wing.id}")
@@ -2650,22 +2510,22 @@ describe Mongoid::Interceptable do
2650
2510
  # MissingAttributeError to be raised when accessing another association. This
2651
2511
  # was fixed by using `.pluck` over `.only`. Look at MONGOID-5306 for a more
2652
2512
  # detailed explanation.
2653
- context "when accessing _ids in validate and access an association in after_initialize" do
2513
+ context 'when accessing _ids in validate and access an association in after_initialize' do
2654
2514
  it "doesn't raise AttributeNotLoaded" do
2655
2515
  company = InterceptableCompany.create!
2656
- shop = InterceptableShop.create!(company: company)
2516
+ InterceptableShop.create!(company: company)
2657
2517
  user = InterceptableUser.new
2658
2518
  user.company = company
2659
2519
  expect do
2660
2520
  user.save!
2661
- end.to_not raise_error(Mongoid::Errors::AttributeNotLoaded)
2521
+ end.not_to raise_error(Mongoid::Errors::AttributeNotLoaded)
2662
2522
  end
2663
2523
  end
2664
2524
 
2665
- context "when around callbacks for embedded are disabled" do
2525
+ context 'when around callbacks for embedded are disabled' do
2666
2526
  config_override :around_callbacks_for_embeds, false
2667
2527
 
2668
- context "when around callback is defined" do
2528
+ context 'when around callback is defined' do
2669
2529
  let(:registry) { InterceptableSpec::CallbackRegistry.new }
2670
2530
 
2671
2531
  let(:parent) do
@@ -2679,23 +2539,25 @@ describe Mongoid::Interceptable do
2679
2539
  expect(Mongoid.logger).to receive(:warn).with(/To enable around callbacks for embedded documents/).twice.and_call_original
2680
2540
  end
2681
2541
 
2682
- it "logs a warning" do
2542
+ it 'logs a warning' do
2683
2543
  parent.save!
2684
2544
  end
2685
2545
  end
2686
2546
  end
2687
2547
 
2688
- context "when around callbacks for embedded children are enabled" do
2548
+ context 'when around callbacks for embedded children are enabled' do
2689
2549
  config_override :around_callbacks_for_embeds, true
2690
2550
 
2691
- context "when around callback is defined without a yield" do
2551
+ context 'when around callback is defined without a yield' do
2692
2552
  class Mother
2693
2553
  include Mongoid::Document
2554
+
2694
2555
  embeds_many :daughters, cascade_callbacks: true
2695
2556
  end
2696
2557
 
2697
2558
  class Daughter
2698
2559
  include Mongoid::Document
2560
+
2699
2561
  embedded_in :mother
2700
2562
  around_save :log_callback
2701
2563
 
@@ -2708,7 +2570,7 @@ describe Mongoid::Interceptable do
2708
2570
 
2709
2571
  let(:mom) { Mother.create(daughters: [ Daughter.new, Daughter.new ]) }
2710
2572
 
2711
- it "raises an InvalidAroundCallback error" do
2573
+ it 'raises an InvalidAroundCallback error' do
2712
2574
  expect do
2713
2575
  mom.save
2714
2576
  end.to raise_error(Mongoid::Errors::InvalidAroundCallback)