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,23 +1,20 @@
1
1
  # frozen_string_literal: true
2
- # rubocop:todo all
3
2
 
4
- require "spec_helper"
5
- require_relative './touchable_spec_models'
3
+ require 'spec_helper'
4
+ require_relative 'touchable_spec_models'
6
5
 
7
6
  describe Mongoid::Touchable do
8
-
9
- describe "#touch" do
10
-
11
- context "when the document has no associations" do
7
+ describe '#touch' do
8
+ context 'when the document has no associations' do
12
9
  let(:updatable) do
13
10
  Updatable.create!
14
11
  end
15
12
 
16
- it "responds to #touch" do
13
+ it 'responds to #touch' do
17
14
  expect(updatable).to respond_to(:touch)
18
15
  end
19
16
 
20
- it "updates the timestamp when called" do
17
+ it 'updates the timestamp when called' do
21
18
  expect(updatable.updated_at).to be_nil
22
19
 
23
20
  updatable.touch
@@ -35,7 +32,6 @@ describe Mongoid::Touchable do
35
32
  end
36
33
 
37
34
  context 'when the document has a parent association' do
38
-
39
35
  let(:building) do
40
36
  parent_cls.create!
41
37
  end
@@ -59,7 +55,7 @@ describe Mongoid::Touchable do
59
55
  end
60
56
 
61
57
  shared_examples 'updates the child' do
62
- it "updates the updated_at timestamp" do
58
+ it 'updates the updated_at timestamp' do
63
59
  entrance
64
60
  update_time
65
61
  entrance.touch
@@ -67,7 +63,7 @@ describe Mongoid::Touchable do
67
63
  expect(entrance.updated_at).to eq(update_time)
68
64
  end
69
65
 
70
- it "persists the changes" do
66
+ it 'persists the changes' do
71
67
  entrance
72
68
  update_time
73
69
  entrance.touch
@@ -77,7 +73,6 @@ describe Mongoid::Touchable do
77
73
  end
78
74
 
79
75
  shared_examples 'updates the parent when :touch is true' do
80
-
81
76
  it 'updates updated_at on parent' do
82
77
  floor
83
78
  update_time
@@ -117,7 +112,7 @@ describe Mongoid::Touchable do
117
112
  it_behaves_like 'does not update the parent when :touch is false'
118
113
  end
119
114
 
120
- context "when the document is embedded" do
115
+ context 'when the document is embedded' do
121
116
  let(:parent_cls) { TouchableSpec::Embedded::Building }
122
117
 
123
118
  include_examples 'updates the child'
@@ -161,7 +156,7 @@ describe Mongoid::Touchable do
161
156
  end
162
157
  end
163
158
 
164
- context "when the document is referenced" do
159
+ context 'when the document is referenced' do
165
160
  let(:parent_cls) { TouchableSpec::Referenced::Building }
166
161
 
167
162
  include_examples 'updates the child'
@@ -170,164 +165,152 @@ describe Mongoid::Touchable do
170
165
  end
171
166
  end
172
167
 
173
- context "when no relations have touch options" do
174
-
175
- context "when no updated at is defined" do
176
-
168
+ context 'when no relations have touch options' do
169
+ context 'when no updated at is defined' do
177
170
  let(:person) do
178
171
  Person.create!
179
172
  end
180
173
 
181
- context "when no attribute is provided" do
182
-
174
+ context 'when no attribute is provided' do
183
175
  let!(:touched) do
184
176
  person.touch
185
177
  end
186
178
 
187
- it "returns true" do
179
+ it 'returns true' do
188
180
  expect(touched).to be true
189
181
  end
190
182
 
191
- it "does not set the updated at field" do
183
+ it 'does not set the updated at field' do
192
184
  expect(person[:updated_at]).to be_nil
193
185
  end
194
186
  end
195
187
 
196
- context "when an attribute is provided" do
197
-
188
+ context 'when an attribute is provided' do
198
189
  let!(:touched) do
199
190
  person.touch(:lunch_time)
200
191
  end
201
192
 
202
- it "sets the attribute to the current time" do
193
+ it 'sets the attribute to the current time' do
203
194
  expect(person.lunch_time).to be_within(5).of(Time.now)
204
195
  end
205
196
 
206
- it "persists the change" do
197
+ it 'persists the change' do
207
198
  expect(person.reload.lunch_time).to be_within(5).of(Time.now)
208
199
  end
209
200
 
210
- it "returns true" do
201
+ it 'returns true' do
211
202
  expect(touched).to be true
212
203
  end
213
204
  end
214
205
 
215
- context "when an attribute alias is provided" do
216
-
206
+ context 'when an attribute alias is provided' do
217
207
  let!(:touched) do
218
208
  person.touch(:aliased_timestamp)
219
209
  end
220
210
 
221
- it "sets the attribute to the current time" do
211
+ it 'sets the attribute to the current time' do
222
212
  expect(person.aliased_timestamp).to be_within(5).of(Time.now)
223
213
  end
224
214
 
225
- it "persists the change" do
215
+ it 'persists the change' do
226
216
  expect(person.reload.aliased_timestamp).to be_within(5).of(Time.now)
227
217
  end
228
218
 
229
- it "returns true" do
219
+ it 'returns true' do
230
220
  expect(touched).to be true
231
221
  end
232
222
  end
233
223
  end
234
224
 
235
- context "when an updated at is defined" do
236
-
225
+ context 'when an updated at is defined' do
237
226
  let!(:agent) do
238
227
  Agent.create!(updated_at: 2.days.ago)
239
228
  end
240
229
 
241
- context "when no attribute is provided" do
242
-
230
+ context 'when no attribute is provided' do
243
231
  let!(:touched) do
244
232
  agent.touch
245
233
  end
246
234
 
247
- it "sets the updated at to the current time" do
235
+ it 'sets the updated at to the current time' do
248
236
  expect(agent.updated_at).to be_within(5).of(Time.now)
249
237
  end
250
238
 
251
- it "persists the change" do
239
+ it 'persists the change' do
252
240
  expect(agent.reload.updated_at).to be_within(5).of(Time.now)
253
241
  end
254
242
 
255
- it "returns true" do
243
+ it 'returns true' do
256
244
  expect(touched).to be true
257
245
  end
258
246
 
259
- it "clears changes" do
247
+ it 'clears changes' do
260
248
  expect(agent.changes).to be_empty
261
249
  end
262
250
  end
263
251
 
264
- context "when an attribute is provided" do
265
-
252
+ context 'when an attribute is provided' do
266
253
  let!(:touched) do
267
254
  agent.touch(:dob)
268
255
  end
269
256
 
270
- it "sets the updated at to the current time" do
257
+ it 'sets the updated at to the current time' do
271
258
  expect(agent.updated_at).to be_within(5).of(Time.now)
272
259
  end
273
260
 
274
- it "sets the attribute to the current time" do
261
+ it 'sets the attribute to the current time' do
275
262
  expect(agent.dob).to be_within(5).of(Time.now)
276
263
  end
277
264
 
278
- it "sets both attributes to the exact same time" do
265
+ it 'sets both attributes to the exact same time' do
279
266
  expect(agent.updated_at).to eq(agent.dob)
280
267
  end
281
268
 
282
- it "persists the updated at change" do
269
+ it 'persists the updated at change' do
283
270
  expect(agent.reload.updated_at).to be_within(5).of(Time.now)
284
271
  end
285
272
 
286
- it "persists the attribute change" do
273
+ it 'persists the attribute change' do
287
274
  expect(agent.reload.dob).to be_within(5).of(Time.now)
288
275
  end
289
276
 
290
- it "returns true" do
277
+ it 'returns true' do
291
278
  expect(touched).to be true
292
279
  end
293
280
 
294
- it "clears changes" do
281
+ it 'clears changes' do
295
282
  expect(agent.changes).to be_empty
296
283
  end
297
284
  end
298
285
  end
299
286
 
300
- context "when record is new" do
301
-
287
+ context 'when record is new' do
302
288
  let!(:agent) do
303
289
  Agent.new(updated_at: 2.days.ago)
304
290
  end
305
291
 
306
- context "when no attribute is provided" do
307
-
292
+ context 'when no attribute is provided' do
308
293
  let(:touched) do
309
294
  agent.touch
310
295
  end
311
296
 
312
- it "returns false" do
297
+ it 'returns false' do
313
298
  expect(touched).to be false
314
299
  end
315
300
  end
316
301
 
317
- context "when an attribute is provided" do
318
-
302
+ context 'when an attribute is provided' do
319
303
  let(:touched) do
320
304
  agent.touch(:dob)
321
305
  end
322
306
 
323
- it "returns false" do
307
+ it 'returns false' do
324
308
  expect(touched).to be false
325
309
  end
326
310
  end
327
311
  end
328
312
 
329
- context "when record is destroyed" do
330
-
313
+ context 'when record is destroyed' do
331
314
  let!(:agent) do
332
315
  Agent.create!(updated_at: 2.days.ago).tap do |agent|
333
316
  agent.destroy
@@ -338,26 +321,24 @@ describe Mongoid::Touchable do
338
321
  FrozenError
339
322
  end
340
323
 
341
- context "when no attribute is provided" do
342
-
324
+ context 'when no attribute is provided' do
343
325
  let(:touched) do
344
326
  agent.touch
345
327
  end
346
328
 
347
- it "raises FrozenError" do
329
+ it 'raises FrozenError' do
348
330
  expect do
349
331
  touched
350
332
  end.to raise_error(frozen_error_cls)
351
333
  end
352
334
  end
353
335
 
354
- context "when an attribute is provided" do
355
-
336
+ context 'when an attribute is provided' do
356
337
  let(:touched) do
357
338
  agent.touch(:dob)
358
339
  end
359
340
 
360
- it "raises FrozenError" do
341
+ it 'raises FrozenError' do
361
342
  expect do
362
343
  touched
363
344
  end.to raise_error(frozen_error_cls)
@@ -365,8 +346,7 @@ describe Mongoid::Touchable do
365
346
  end
366
347
  end
367
348
 
368
- context "when creating the child" do
369
-
349
+ context 'when creating the child' do
370
350
  let(:time) do
371
351
  Time.utc(2012, 4, 3, 12)
372
352
  end
@@ -381,18 +361,16 @@ describe Mongoid::Touchable do
381
361
  jar.cookies.create!(updated_at: time)
382
362
  end
383
363
 
384
- it "does not touch the parent" do
364
+ it 'does not touch the parent' do
385
365
  expect(jar.updated_at).to eq(time)
386
366
  end
387
367
  end
388
368
  end
389
369
 
390
- context "when relations have touch options" do
391
-
392
- context "when the relation is a parent of an embedded doc" do
393
-
370
+ context 'when relations have touch options' do
371
+ context 'when the relation is a parent of an embedded doc' do
394
372
  let(:page) do
395
- WikiPage.create!(title: "test")
373
+ WikiPage.create!(title: 'test')
396
374
  end
397
375
 
398
376
  let!(:edit) do
@@ -404,13 +382,12 @@ describe Mongoid::Touchable do
404
382
  edit.touch
405
383
  end
406
384
 
407
- it "touches the parent document" do
385
+ it 'touches the parent document' do
408
386
  expect(page.updated_at).to be_within(5).of(Time.now)
409
387
  end
410
388
  end
411
389
 
412
- context "when the parent of embedded doc has cascade callbacks" do
413
-
390
+ context 'when the parent of embedded doc has cascade callbacks' do
414
391
  let!(:book) do
415
392
  Book.new
416
393
  end
@@ -422,13 +399,12 @@ describe Mongoid::Touchable do
422
399
  book.pages.first.touch
423
400
  end
424
401
 
425
- it "touches the parent document" do
402
+ it 'touches the parent document' do
426
403
  expect(book.updated_at).to be_within(5).of(Time.now)
427
404
  end
428
405
  end
429
406
 
430
- context "when multiple embedded docs with cascade callbacks" do
431
-
407
+ context 'when multiple embedded docs with cascade callbacks' do
432
408
  let!(:book) do
433
409
  Book.new
434
410
  end
@@ -437,36 +413,33 @@ describe Mongoid::Touchable do
437
413
  2.times { book.pages.new }
438
414
  book.save!
439
415
  book.unset(:updated_at)
440
- book.pages.first.content = "foo"
441
- book.pages.second.content = "bar"
416
+ book.pages.first.content = 'foo'
417
+ book.pages.second.content = 'bar'
442
418
  book.pages.first.touch
443
419
  end
444
420
 
445
- it "touches the parent document" do
421
+ it 'touches the parent document' do
446
422
  expect(book.updated_at).to be_within(5).of(Time.now)
447
423
  end
448
424
  end
449
425
 
450
- context "when the relation is nil" do
451
-
426
+ context 'when the relation is nil' do
452
427
  let!(:agent) do
453
428
  Agent.create!
454
429
  end
455
430
 
456
- context "when the relation autobuilds" do
457
-
431
+ context 'when the relation autobuilds' do
458
432
  let!(:touched) do
459
433
  agent.touch
460
434
  end
461
435
 
462
- it "does nothing to the relation" do
436
+ it 'does nothing to the relation' do
463
437
  expect(agent.instance_variable_get(:@agency)).to be_nil
464
438
  end
465
439
  end
466
440
  end
467
441
 
468
- context "when the relation is not nil" do
469
-
442
+ context 'when the relation is not nil' do
470
443
  let!(:agent) do
471
444
  Agent.create!
472
445
  end
@@ -481,17 +454,16 @@ describe Mongoid::Touchable do
481
454
  agent.touch
482
455
  end
483
456
 
484
- it "sets the parent updated at to the current time" do
457
+ it 'sets the parent updated at to the current time' do
485
458
  expect(agency.updated_at).to be_within(5).of(Time.now)
486
459
  end
487
460
 
488
- it "persists the change" do
461
+ it 'persists the change' do
489
462
  expect(agency.reload.updated_at).to be_within(5).of(Time.now)
490
463
  end
491
464
  end
492
465
 
493
- context "when creating the child" do
494
-
466
+ context 'when creating the child' do
495
467
  let!(:agency) do
496
468
  Agency.create!
497
469
  end
@@ -505,12 +477,11 @@ describe Mongoid::Touchable do
505
477
  end
506
478
 
507
479
  it "updates the parent's updated at" do
508
- expect(agency.updated_at).to_not eq(updated)
480
+ expect(agency.updated_at).not_to eq(updated)
509
481
  end
510
482
  end
511
483
 
512
- context "when modifying the child" do
513
-
484
+ context 'when modifying the child' do
514
485
  let!(:agency) do
515
486
  Agency.create!
516
487
  end
@@ -520,14 +491,13 @@ describe Mongoid::Touchable do
520
491
  end
521
492
 
522
493
  it "updates the parent's updated at" do
523
- expect {
494
+ expect do
524
495
  agent.update_attributes!(number: '2')
525
- }.to change { agency.updated_at }
496
+ end.to(change { agency.updated_at })
526
497
  end
527
498
  end
528
499
 
529
- context "when destroying the child" do
530
-
500
+ context 'when destroying the child' do
531
501
  let!(:agency) do
532
502
  Agency.create!
533
503
  end
@@ -545,46 +515,43 @@ describe Mongoid::Touchable do
545
515
  end
546
516
 
547
517
  it "updates the parent's updated at" do
548
- expect(agency.updated_at).to_not eq(updated)
518
+ expect(agency.updated_at).not_to eq(updated)
549
519
  end
550
520
  end
551
521
  end
552
522
 
553
- context "when other document attributes have been changed" do
554
-
523
+ context 'when other document attributes have been changed' do
555
524
  let(:band) do
556
- Band.create!(name: "Placebo")
525
+ Band.create!(name: 'Placebo')
557
526
  end
558
527
 
559
- context "when an attribute is provided" do
528
+ context 'when an attribute is provided' do
560
529
  before do
561
530
  band.name = 'Nocebo'
562
531
  band.touch(:last_release)
563
532
  end
564
533
 
565
- it "does not persist other attribute changes" do
534
+ it 'does not persist other attribute changes' do
566
535
  expect(band.name).to eq('Nocebo')
567
536
  expect(band.reload.name).not_to eq('Nocebo')
568
537
  end
569
538
  end
570
539
 
571
- context "when an attribute is not provided" do
540
+ context 'when an attribute is not provided' do
572
541
  before do
573
542
  band.name = 'Nocebo'
574
543
  band.touch
575
544
  end
576
545
 
577
- it "does not persist other attribute changes" do
546
+ it 'does not persist other attribute changes' do
578
547
  expect(band.name).to eq('Nocebo')
579
548
  expect(band.reload.name).not_to eq('Nocebo')
580
549
  end
581
550
  end
582
551
  end
583
552
 
584
- context "when the touch option is true" do
585
-
553
+ context 'when the touch option is true' do
586
554
  shared_examples "updates the parent's updated_at" do
587
-
588
555
  let!(:start_time) { Timecop.freeze(Time.at(Time.now.to_i)) }
589
556
 
590
557
  let(:update_time) do
@@ -610,8 +577,8 @@ describe Mongoid::Touchable do
610
577
  floor.send(meth)
611
578
  end
612
579
 
613
- it "the parent is not nil" do
614
- expect(floor.building).to_not be nil
580
+ it 'the parent is not nil' do
581
+ expect(floor.building).not_to be_nil
615
582
  end
616
583
 
617
584
  it "updates the parent's timestamp" do
@@ -621,7 +588,6 @@ describe Mongoid::Touchable do
621
588
  end
622
589
 
623
590
  shared_examples "updates the child's updated_at" do
624
-
625
591
  let!(:start_time) { Timecop.freeze(Time.at(Time.now.to_i)) }
626
592
 
627
593
  let(:update_time) do
@@ -647,17 +613,17 @@ describe Mongoid::Touchable do
647
613
  floor.send(meth)
648
614
  end
649
615
 
650
- it "the parent is not nil" do
651
- expect(floor.building).to_not be nil
616
+ it 'the parent is not nil' do
617
+ expect(floor.building).not_to be_nil
652
618
  end
653
619
 
654
620
  it "updates the child's timestamp" do
655
- floor.updated_at.should == update_time
656
- floor.reload.updated_at.should == update_time
621
+ floor.updated_at.should eq update_time
622
+ floor.reload.updated_at.should eq update_time
657
623
  end
658
624
  end
659
625
 
660
- [ :save!, :destroy, :touch].each do |meth|
626
+ %i[save! destroy touch].each do |meth|
661
627
  context "with #{meth} on referenced associations" do
662
628
  let(:parent_cls) { TouchableSpec::Referenced::Building }
663
629
  let(:meth) { meth }
@@ -676,9 +642,8 @@ describe Mongoid::Touchable do
676
642
  end
677
643
  end
678
644
 
679
- context "when the touch option is false" do
680
-
681
- shared_examples "does not update the parent" do
645
+ context 'when the touch option is false' do
646
+ shared_examples 'does not update the parent' do
682
647
  let!(:start_time) { Timecop.freeze(Time.at(Time.now.to_i)) }
683
648
  let(:update_time) { Timecop.freeze(Time.at(Time.now.to_i) + 2) }
684
649
 
@@ -716,27 +681,25 @@ describe Mongoid::Touchable do
716
681
  end
717
682
  end
718
683
 
719
- [ :save!, :destroy, :touch].each do |meth|
684
+ %i[save! destroy touch].each do |meth|
720
685
  context "with #{meth} on belongs_to" do
721
686
  let(:meth) { meth }
722
687
  let(:parent_cls) { TouchableSpec::Referenced::Building }
723
688
 
724
- include_examples "does not update the parent"
689
+ include_examples 'does not update the parent'
725
690
  end
726
691
 
727
692
  context "with #{meth} on embedded_in" do
728
693
  let(:meth) { meth }
729
694
  let(:parent_cls) { TouchableSpec::Embedded::Building }
730
695
 
731
- include_examples "does not update the parent"
696
+ include_examples 'does not update the parent'
732
697
  end
733
698
  end
734
699
  end
735
700
 
736
- context "when a custom field is specified" do
737
-
701
+ context 'when a custom field is specified' do
738
702
  shared_examples "updates the child's updated_at" do
739
-
740
703
  let!(:start_time) { Timecop.freeze(Time.at(Time.now.to_i)) }
741
704
 
742
705
  let(:update_time) { Timecop.freeze(Time.at(Time.now.to_i) + 2) }
@@ -765,7 +728,6 @@ describe Mongoid::Touchable do
765
728
  end
766
729
 
767
730
  shared_examples "updates the parent's custom field and updated_at" do
768
-
769
731
  let!(:start_time) { Timecop.freeze(Time.at(Time.now.to_i)) }
770
732
 
771
733
  let(:update_time) { Timecop.freeze(Time.at(Time.now.to_i) + 2) }
@@ -796,12 +758,12 @@ describe Mongoid::Touchable do
796
758
  expect(label.updated_at).to eq(update_time)
797
759
  expect(label.reload.updated_at).to eq(update_time)
798
760
  end
799
-
800
761
  end
801
762
 
802
- [:save, :destroy, :touch].each do |meth|
763
+ %i[save destroy touch].each do |meth|
803
764
  context "with #{meth} on referenced associations" do
804
765
  let(:meth) { meth }
766
+
805
767
  include_examples "updates the child's updated_at" unless meth == :destroy
806
768
  include_examples "updates the parent's custom field and updated_at"
807
769
  end
@@ -809,7 +771,6 @@ describe Mongoid::Touchable do
809
771
  end
810
772
 
811
773
  context 'multi-level' do
812
-
813
774
  let!(:start_time) { Timecop.freeze(Time.at(Time.now.to_i)) }
814
775
 
815
776
  let(:update_time) { Timecop.freeze(Time.at(Time.now.to_i) + 2) }
@@ -836,35 +797,35 @@ describe Mongoid::Touchable do
836
797
  grandchild
837
798
  end
838
799
 
839
- shared_examples "updates the parent" do
800
+ shared_examples 'updates the parent' do
840
801
  it "updates the parent's timestamp" do
841
802
  expect(parent.updated_at).to eq(update_time)
842
803
  expect(parent.reload.updated_at).to eq(update_time)
843
804
  end
844
805
  end
845
806
 
846
- shared_examples "does not update the parent" do
807
+ shared_examples 'does not update the parent' do
847
808
  it "does not update the parent's timestamp" do
848
809
  expect(parent.updated_at).to eq(start_time)
849
810
  expect(parent.reload.updated_at).to eq(start_time)
850
811
  end
851
812
  end
852
813
 
853
- shared_examples "updates the child" do
814
+ shared_examples 'updates the child' do
854
815
  it "updates the child's timestamp" do
855
816
  expect(child.updated_at).to eq(update_time)
856
817
  expect(child.reload.updated_at).to eq(update_time)
857
818
  end
858
819
  end
859
820
 
860
- shared_examples "does not update the child" do
821
+ shared_examples 'does not update the child' do
861
822
  it "does not update the child's timestamp" do
862
823
  expect(child.updated_at).to eq(start_time)
863
824
  expect(child.reload.updated_at).to eq(start_time)
864
825
  end
865
826
  end
866
827
 
867
- shared_examples "updates the grandchild" do
828
+ shared_examples 'updates the grandchild' do
868
829
  it "updates the grandchild's timestamp" do
869
830
  if grandchild.destroyed?
870
831
  expect(grandchild.updated_at).to eq(start_time)
@@ -875,7 +836,7 @@ describe Mongoid::Touchable do
875
836
  end
876
837
  end
877
838
 
878
- shared_examples "does not update the grandchild" do
839
+ shared_examples 'does not update the grandchild' do
879
840
  it "does not update the grandchild's timestamp" do
880
841
  expect(grandchild.updated_at).to eq(start_time)
881
842
  expect(grandchild.reload.updated_at).to eq(start_time) unless grandchild.destroyed?
@@ -893,86 +854,79 @@ describe Mongoid::Touchable do
893
854
  end
894
855
 
895
856
  context 'parent > embedded child > embedded grandchild' do
896
-
897
857
  let(:parent_cls) { TouchableSpec::Embedded::Building }
898
858
 
899
859
  context 'child touch: true' do
900
-
901
860
  let(:child_cls) do
902
861
  TouchableSpec::Embedded::Floor
903
862
  end
904
863
 
905
864
  context 'grandchild touch: true' do
906
-
907
865
  let(:grandchild_cls) do
908
866
  TouchableSpec::Embedded::Sofa
909
867
  end
910
868
 
911
- [ :save!, :destroy, :touch ].each do |meth|
869
+ %i[save! destroy touch].each do |meth|
912
870
  context "when calling #{meth} method" do
913
871
  let(:meth) { meth }
914
872
 
915
- it_behaves_like "updates the parent"
916
- it_behaves_like "updates the child"
917
- it_behaves_like "updates the grandchild"
873
+ it_behaves_like 'updates the parent'
874
+ it_behaves_like 'updates the child'
875
+ it_behaves_like 'updates the grandchild'
918
876
  end
919
877
  end
920
878
  end
921
879
 
922
880
  context 'grandchild touch: false' do
923
-
924
881
  let(:grandchild_cls) do
925
882
  TouchableSpec::Embedded::Chair
926
883
  end
927
884
 
928
- [ :save!, :destroy, :touch ].each do |meth|
885
+ %i[save! destroy touch].each do |meth|
929
886
  context "when calling #{meth} method" do
930
887
  let(:meth) { meth }
931
888
 
932
- it_behaves_like "does not update the parent"
933
- it_behaves_like "does not update the child"
934
- it_behaves_like "updates the grandchild"
889
+ it_behaves_like 'does not update the parent'
890
+ it_behaves_like 'does not update the child'
891
+ it_behaves_like 'updates the grandchild'
935
892
  end
936
893
  end
937
894
  end
938
895
  end
939
896
 
940
897
  context 'child touch: false' do
941
-
942
898
  let(:child_cls) do
943
899
  TouchableSpec::Embedded::Entrance
944
900
  end
945
901
 
946
902
  context 'grandchild touch: true' do
947
-
948
903
  let(:grandchild_cls) do
949
904
  TouchableSpec::Embedded::Camera
950
905
  end
951
906
 
952
- [ :save!, :destroy, :touch ].each do |meth|
907
+ %i[save! destroy touch].each do |meth|
953
908
  context "when calling #{meth} method" do
954
909
  let(:meth) { meth }
955
910
 
956
- it_behaves_like "does not update the parent"
957
- it_behaves_like "updates the child"
958
- it_behaves_like "updates the grandchild"
911
+ it_behaves_like 'does not update the parent'
912
+ it_behaves_like 'updates the child'
913
+ it_behaves_like 'updates the grandchild'
959
914
  end
960
915
  end
961
916
  end
962
917
 
963
918
  context 'grandchild touch: false' do
964
-
965
919
  let(:grandchild_cls) do
966
920
  TouchableSpec::Embedded::Keypad
967
921
  end
968
922
 
969
- [ :save!, :destroy, :touch ].each do |meth|
923
+ %i[save! destroy touch].each do |meth|
970
924
  context "when calling #{meth} method" do
971
925
  let(:meth) { meth }
972
926
 
973
- it_behaves_like "does not update the parent"
974
- it_behaves_like "does not update the child"
975
- it_behaves_like "updates the grandchild"
927
+ it_behaves_like 'does not update the parent'
928
+ it_behaves_like 'does not update the child'
929
+ it_behaves_like 'updates the grandchild'
976
930
  end
977
931
  end
978
932
  end
@@ -980,86 +934,79 @@ describe Mongoid::Touchable do
980
934
  end
981
935
 
982
936
  context 'parent > referenced child > embedded grandchild' do
983
-
984
937
  let(:parent_cls) { TouchableSpec::Referenced::Building }
985
938
 
986
939
  context 'child touch: true' do
987
-
988
940
  let(:child_cls) do
989
941
  TouchableSpec::Referenced::Floor
990
942
  end
991
943
 
992
944
  context 'grandchild touch: true' do
993
-
994
945
  let(:grandchild_cls) do
995
946
  TouchableSpec::Referenced::Sofa
996
947
  end
997
948
 
998
- [ :save!, :destroy, :touch ].each do |meth|
949
+ %i[save! destroy touch].each do |meth|
999
950
  context "when calling #{meth} method" do
1000
951
  let(:meth) { meth }
1001
952
 
1002
- it_behaves_like "updates the parent"
1003
- it_behaves_like "updates the child"
1004
- it_behaves_like "updates the grandchild"
953
+ it_behaves_like 'updates the parent'
954
+ it_behaves_like 'updates the child'
955
+ it_behaves_like 'updates the grandchild'
1005
956
  end
1006
957
  end
1007
958
  end
1008
959
 
1009
960
  context 'grandchild touch: false' do
1010
-
1011
961
  let(:grandchild_cls) do
1012
962
  TouchableSpec::Referenced::Chair
1013
963
  end
1014
964
 
1015
- [ :save!, :destroy, :touch ].each do |meth|
965
+ %i[save! destroy touch].each do |meth|
1016
966
  context "when calling #{meth} method" do
1017
967
  let(:meth) { meth }
1018
968
 
1019
- it_behaves_like "does not update the parent"
1020
- it_behaves_like "does not update the child"
1021
- it_behaves_like "updates the grandchild"
969
+ it_behaves_like 'does not update the parent'
970
+ it_behaves_like 'does not update the child'
971
+ it_behaves_like 'updates the grandchild'
1022
972
  end
1023
973
  end
1024
974
  end
1025
975
  end
1026
976
 
1027
977
  context 'child touch: false' do
1028
-
1029
978
  let(:child_cls) do
1030
979
  TouchableSpec::Referenced::Entrance
1031
980
  end
1032
981
 
1033
982
  context 'grandchild touch: true' do
1034
-
1035
983
  let(:grandchild_cls) do
1036
984
  TouchableSpec::Referenced::Camera
1037
985
  end
1038
986
 
1039
- [ :save!, :destroy, :touch ].each do |meth|
987
+ %i[save! destroy touch].each do |meth|
1040
988
  context "when calling #{meth} method" do
1041
989
  let(:meth) { meth }
1042
990
 
1043
- it_behaves_like "does not update the parent"
1044
- it_behaves_like "updates the child"
1045
- it_behaves_like "updates the grandchild"
991
+ it_behaves_like 'does not update the parent'
992
+ it_behaves_like 'updates the child'
993
+ it_behaves_like 'updates the grandchild'
1046
994
  end
1047
995
  end
1048
996
  end
1049
997
 
1050
998
  context 'grandchild touch: false' do
1051
-
1052
999
  let(:grandchild_cls) do
1053
1000
  TouchableSpec::Referenced::Keypad
1054
1001
  end
1055
1002
 
1056
- [ :save!, :destroy, :touch ].each do |meth|
1003
+ %i[save! destroy touch].each do |meth|
1057
1004
  context "when calling #{meth} method" do
1058
1005
  let(:meth) { meth }
1059
1006
 
1060
- it_behaves_like "does not update the parent"
1061
- it_behaves_like "does not update the child"
1062
- it_behaves_like "updates the grandchild"
1007
+ it_behaves_like 'does not update the parent'
1008
+ it_behaves_like 'does not update the child'
1009
+ it_behaves_like 'updates the grandchild'
1063
1010
  end
1064
1011
  end
1065
1012
  end
@@ -1067,86 +1014,79 @@ describe Mongoid::Touchable do
1067
1014
  end
1068
1015
 
1069
1016
  context 'parent > referenced child > referenced grandchild' do
1070
-
1071
1017
  let(:parent_cls) { TouchableSpec::Referenced::Building }
1072
1018
 
1073
1019
  context 'child touch: true' do
1074
-
1075
1020
  let(:child_cls) do
1076
1021
  TouchableSpec::Referenced::Floor
1077
1022
  end
1078
1023
 
1079
1024
  context 'grandchild touch: true' do
1080
-
1081
1025
  let(:grandchild_cls) do
1082
1026
  TouchableSpec::Referenced::Window
1083
1027
  end
1084
1028
 
1085
- [ :save!, :destroy, :touch ].each do |meth|
1029
+ %i[save! destroy touch].each do |meth|
1086
1030
  context "when calling #{meth} method" do
1087
1031
  let(:meth) { meth }
1088
1032
 
1089
- it_behaves_like "updates the parent"
1090
- it_behaves_like "updates the child"
1091
- it_behaves_like "updates the grandchild"
1033
+ it_behaves_like 'updates the parent'
1034
+ it_behaves_like 'updates the child'
1035
+ it_behaves_like 'updates the grandchild'
1092
1036
  end
1093
1037
  end
1094
1038
  end
1095
1039
 
1096
1040
  context 'grandchild touch: false' do
1097
-
1098
1041
  let(:grandchild_cls) do
1099
1042
  TouchableSpec::Referenced::Plant
1100
1043
  end
1101
1044
 
1102
- [ :save!, :destroy, :touch ].each do |meth|
1045
+ %i[save! destroy touch].each do |meth|
1103
1046
  context "when calling #{meth} method" do
1104
1047
  let(:meth) { meth }
1105
1048
 
1106
- it_behaves_like "does not update the parent"
1107
- it_behaves_like "does not update the child"
1108
- it_behaves_like "updates the grandchild"
1049
+ it_behaves_like 'does not update the parent'
1050
+ it_behaves_like 'does not update the child'
1051
+ it_behaves_like 'updates the grandchild'
1109
1052
  end
1110
1053
  end
1111
1054
  end
1112
1055
  end
1113
1056
 
1114
1057
  context 'child touch: false' do
1115
-
1116
1058
  let(:child_cls) do
1117
1059
  TouchableSpec::Referenced::Entrance
1118
1060
  end
1119
1061
 
1120
1062
  context 'grandchild touch: true' do
1121
-
1122
1063
  let(:grandchild_cls) do
1123
1064
  TouchableSpec::Referenced::Window
1124
1065
  end
1125
1066
 
1126
- [ :save!, :destroy, :touch ].each do |meth|
1067
+ %i[save! destroy touch].each do |meth|
1127
1068
  context "when calling #{meth} method" do
1128
1069
  let(:meth) { meth }
1129
1070
 
1130
- it_behaves_like "does not update the parent"
1131
- it_behaves_like "updates the child"
1132
- it_behaves_like "updates the grandchild"
1071
+ it_behaves_like 'does not update the parent'
1072
+ it_behaves_like 'updates the child'
1073
+ it_behaves_like 'updates the grandchild'
1133
1074
  end
1134
1075
  end
1135
1076
  end
1136
1077
 
1137
1078
  context 'grandchild touch: false' do
1138
-
1139
1079
  let(:grandchild_cls) do
1140
1080
  TouchableSpec::Referenced::Plant
1141
1081
  end
1142
1082
 
1143
- [ :save!, :destroy, :touch ].each do |meth|
1083
+ %i[save! destroy touch].each do |meth|
1144
1084
  context "when calling #{meth} method" do
1145
1085
  let(:meth) { meth }
1146
1086
 
1147
- it_behaves_like "does not update the parent"
1148
- it_behaves_like "does not update the child"
1149
- it_behaves_like "updates the grandchild"
1087
+ it_behaves_like 'does not update the parent'
1088
+ it_behaves_like 'does not update the child'
1089
+ it_behaves_like 'updates the grandchild'
1150
1090
  end
1151
1091
  end
1152
1092
  end
@@ -1155,8 +1095,7 @@ describe Mongoid::Touchable do
1155
1095
  end
1156
1096
  end
1157
1097
 
1158
- describe "when saving a document" do
1159
-
1098
+ describe 'when saving a document' do
1160
1099
  let!(:start_time) { Timecop.freeze(Time.at(Time.now.to_i)) }
1161
1100
 
1162
1101
  let(:update_time) do
@@ -1167,23 +1106,22 @@ describe Mongoid::Touchable do
1167
1106
  Timecop.return
1168
1107
  end
1169
1108
 
1170
- context "when only using the root document" do
1171
-
1172
- shared_examples "timeless is cleared" do
1173
- it "clears the timeless option" do
1109
+ context 'when only using the root document' do
1110
+ shared_examples 'timeless is cleared' do
1111
+ it 'clears the timeless option' do
1174
1112
  expect(doc.timeless?).to be false
1175
1113
  end
1176
1114
  end
1177
1115
 
1178
- shared_examples "touches the document" do
1179
- it "touches the document" do
1116
+ shared_examples 'touches the document' do
1117
+ it 'touches the document' do
1180
1118
  expect(doc.created_at).to eq(start_time)
1181
1119
  expect(doc.updated_at).to eq(start_time)
1182
1120
  end
1183
1121
  end
1184
1122
 
1185
- shared_examples "updates the document" do
1186
- it "updates the document" do
1123
+ shared_examples 'updates the document' do
1124
+ it 'updates the document' do
1187
1125
  expect(doc.created_at).to eq(start_time)
1188
1126
  expect(doc.updated_at).to eq(update_time)
1189
1127
  end
@@ -1191,110 +1129,102 @@ describe Mongoid::Touchable do
1191
1129
 
1192
1130
  let(:doc) { Dokument.new }
1193
1131
 
1194
- context "when saving a new document" do
1195
-
1196
- context "when not passing a touch option" do
1197
-
1132
+ context 'when saving a new document' do
1133
+ context 'when not passing a touch option' do
1198
1134
  before do
1199
1135
  doc.save!
1200
1136
  end
1201
1137
 
1202
- include_examples "touches the document"
1203
- include_examples "timeless is cleared"
1138
+ include_examples 'touches the document'
1139
+ include_examples 'timeless is cleared'
1204
1140
  end
1205
1141
 
1206
- context "when passing touch: true" do
1207
-
1142
+ context 'when passing touch: true' do
1208
1143
  before do
1209
1144
  doc.save!(touch: true)
1210
1145
  end
1211
1146
 
1212
- include_examples "touches the document"
1213
- include_examples "timeless is cleared"
1147
+ include_examples 'touches the document'
1148
+ include_examples 'timeless is cleared'
1214
1149
  end
1215
1150
 
1216
- context "when passing touch: false" do
1217
-
1151
+ context 'when passing touch: false' do
1218
1152
  before do
1219
1153
  doc.save!(touch: false)
1220
1154
  end
1221
1155
 
1222
- include_examples "touches the document"
1223
- include_examples "timeless is cleared"
1156
+ include_examples 'touches the document'
1157
+ include_examples 'timeless is cleared'
1224
1158
  end
1225
1159
  end
1226
1160
 
1227
- context "when updating a document" do
1161
+ context 'when updating a document' do
1228
1162
  before do
1229
1163
  doc.save!
1230
- doc.title = "title"
1164
+ doc.title = 'title'
1231
1165
  update_time
1232
1166
  end
1233
1167
 
1234
- context "when not passing a touch option" do
1235
-
1168
+ context 'when not passing a touch option' do
1236
1169
  before do
1237
1170
  doc.save!
1238
1171
  end
1239
1172
 
1240
- include_examples "updates the document"
1241
- include_examples "timeless is cleared"
1173
+ include_examples 'updates the document'
1174
+ include_examples 'timeless is cleared'
1242
1175
  end
1243
1176
 
1244
- context "when passing touch: true" do
1245
-
1177
+ context 'when passing touch: true' do
1246
1178
  before do
1247
1179
  doc.save!(touch: true)
1248
1180
  end
1249
1181
 
1250
- include_examples "updates the document"
1251
- include_examples "timeless is cleared"
1182
+ include_examples 'updates the document'
1183
+ include_examples 'timeless is cleared'
1252
1184
  end
1253
1185
 
1254
- context "when passing touch: false" do
1255
-
1186
+ context 'when passing touch: false' do
1256
1187
  before do
1257
1188
  doc.save!(touch: false)
1258
1189
  end
1259
1190
 
1260
- include_examples "touches the document"
1261
- include_examples "timeless is cleared"
1191
+ include_examples 'touches the document'
1192
+ include_examples 'timeless is cleared'
1262
1193
  end
1263
1194
  end
1264
1195
  end
1265
1196
 
1266
- context "when saving embedded associations with cascading callbacks" do
1267
-
1268
- shared_examples "timeless is cleared" do
1269
- it "clears the timeless option" do
1197
+ context 'when saving embedded associations with cascading callbacks' do
1198
+ shared_examples 'timeless is cleared' do
1199
+ it 'clears the timeless option' do
1270
1200
  expect(book.timeless?).to be false
1271
1201
  expect(book.covers.first.timeless?).to be false
1272
1202
  end
1273
1203
  end
1274
1204
 
1275
- shared_examples "touches the document" do
1276
- it "touches the document" do
1205
+ shared_examples 'touches the document' do
1206
+ it 'touches the document' do
1277
1207
  expect(book.created_at).to eq(start_time)
1278
1208
  expect(book.updated_at).to eq(start_time)
1279
1209
  end
1280
1210
  end
1281
1211
 
1282
- shared_examples "updates the document" do
1283
- it "updates the document" do
1212
+ shared_examples 'updates the document' do
1213
+ it 'updates the document' do
1284
1214
  expect(book.created_at).to eq(start_time)
1285
1215
  expect(book.updated_at).to eq(update_time)
1286
1216
  end
1287
1217
  end
1288
1218
 
1289
- shared_examples "touches the children" do
1290
- it "touches the children" do
1219
+ shared_examples 'touches the children' do
1220
+ it 'touches the children' do
1291
1221
  expect(book.covers.first.created_at).to eq(start_time)
1292
1222
  expect(book.covers.first.updated_at).to eq(start_time)
1293
1223
  end
1294
1224
  end
1295
1225
 
1296
- shared_examples "updates the children" do
1297
- it "updates the children" do
1226
+ shared_examples 'updates the children' do
1227
+ it 'updates the children' do
1298
1228
  expect(book.covers.first.created_at).to eq(start_time)
1299
1229
  expect(book.covers.first.updated_at).to eq(update_time)
1300
1230
  end
@@ -1308,81 +1238,74 @@ describe Mongoid::Touchable do
1308
1238
  Cover.new
1309
1239
  end
1310
1240
 
1311
- context "when saving a new document" do
1312
-
1313
- context "when not passing a touch option" do
1314
-
1241
+ context 'when saving a new document' do
1242
+ context 'when not passing a touch option' do
1315
1243
  before do
1316
1244
  book.save!
1317
1245
  end
1318
1246
 
1319
- include_examples "touches the document"
1320
- include_examples "touches the children"
1321
- include_examples "timeless is cleared"
1247
+ include_examples 'touches the document'
1248
+ include_examples 'touches the children'
1249
+ include_examples 'timeless is cleared'
1322
1250
  end
1323
1251
 
1324
- context "when passing touch: true" do
1325
-
1252
+ context 'when passing touch: true' do
1326
1253
  before do
1327
1254
  book.save!(touch: true)
1328
1255
  end
1329
1256
 
1330
- include_examples "touches the document"
1331
- include_examples "touches the children"
1332
- include_examples "timeless is cleared"
1257
+ include_examples 'touches the document'
1258
+ include_examples 'touches the children'
1259
+ include_examples 'timeless is cleared'
1333
1260
  end
1334
1261
 
1335
- context "when passing touch: false" do
1336
-
1262
+ context 'when passing touch: false' do
1337
1263
  before do
1338
1264
  book.save!(touch: false)
1339
1265
  end
1340
1266
 
1341
- include_examples "touches the document"
1342
- include_examples "touches the children"
1343
- include_examples "timeless is cleared"
1267
+ include_examples 'touches the document'
1268
+ include_examples 'touches the children'
1269
+ include_examples 'timeless is cleared'
1344
1270
  end
1345
1271
  end
1346
1272
 
1347
- context "when updating a document" do
1273
+ context 'when updating a document' do
1348
1274
  before do
1349
1275
  book.save!
1350
- book.title = "title"
1351
- book.covers.first.title = "title"
1276
+ book.title = 'title'
1277
+ book.covers.first.title = 'title'
1352
1278
  update_time
1353
1279
  end
1354
1280
 
1355
- context "when not passing a touch option" do
1356
-
1281
+ context 'when not passing a touch option' do
1357
1282
  before do
1358
1283
  book.save!
1359
1284
  end
1360
1285
 
1361
- include_examples "updates the document"
1362
- include_examples "updates the children"
1363
- include_examples "timeless is cleared"
1286
+ include_examples 'updates the document'
1287
+ include_examples 'updates the children'
1288
+ include_examples 'timeless is cleared'
1364
1289
  end
1365
1290
 
1366
- context "when passing touch: true" do
1367
-
1291
+ context 'when passing touch: true' do
1368
1292
  before do
1369
1293
  book.save!(touch: true)
1370
1294
  end
1371
1295
 
1372
- include_examples "updates the document"
1373
- include_examples "updates the children"
1374
- include_examples "timeless is cleared"
1296
+ include_examples 'updates the document'
1297
+ include_examples 'updates the children'
1298
+ include_examples 'timeless is cleared'
1375
1299
  end
1376
1300
 
1377
- context "when passing touch: false" do
1378
-
1301
+ context 'when passing touch: false' do
1379
1302
  before do
1380
1303
  book.save!(touch: false)
1381
1304
  end
1382
1305
 
1383
- include_examples "touches the document"
1384
- include_examples "touches the children"
1385
- include_examples "timeless is cleared"
1306
+ include_examples 'touches the document'
1307
+ include_examples 'touches the children'
1308
+ include_examples 'timeless is cleared'
1386
1309
  end
1387
1310
  end
1388
1311
  end
@@ -1460,7 +1383,7 @@ describe Mongoid::Touchable do
1460
1383
  expect(parent.after_touch_called).to eq(true)
1461
1384
  end
1462
1385
 
1463
- context 'when touch is calles on a child' do
1386
+ context 'when touch is called on a child' do
1464
1387
  before do
1465
1388
  child.touch
1466
1389
  end
@@ -1476,4 +1399,117 @@ describe Mongoid::Touchable do
1476
1399
  end
1477
1400
  end
1478
1401
  end
1402
+
1403
+ describe 'touch merged with embedded insert' do
1404
+ context 'when pushing an embedded document with touch: true' do
1405
+ let(:building) do
1406
+ TouchableSpec::Embedded::Building.create!(title: 'Tower')
1407
+ end
1408
+
1409
+ let(:floor) do
1410
+ building.floors.create!(level: 1)
1411
+ end
1412
+
1413
+ before do
1414
+ # Ensure building and floor are persisted and timestamps are set.
1415
+ building
1416
+ floor
1417
+ end
1418
+
1419
+ it 'issues a single update_one when pushing a child into a touchable parent' do
1420
+ sofa = TouchableSpec::Embedded::Sofa.new
1421
+
1422
+ expect_query(1) do
1423
+ floor.sofas.push(sofa)
1424
+ end
1425
+ end
1426
+
1427
+ it 'updates updated_at on the parent after push' do
1428
+ original_floor_updated_at = floor.updated_at
1429
+ original_building_updated_at = building.updated_at
1430
+
1431
+ Timecop.travel(Time.now + 10) do
1432
+ floor.sofas.push(TouchableSpec::Embedded::Sofa.new)
1433
+ end
1434
+
1435
+ building.reload
1436
+ expect(building.updated_at).to be > original_building_updated_at
1437
+ expect(building.floors.first.updated_at).to be > original_floor_updated_at
1438
+ end
1439
+
1440
+ it 'persists the embedded document' do
1441
+ sofa = TouchableSpec::Embedded::Sofa.new
1442
+ floor.sofas.push(sofa)
1443
+
1444
+ building.reload
1445
+ expect(building.floors.first.sofas.length).to eq(1)
1446
+ end
1447
+
1448
+ it 'runs touch callbacks on the parent chain' do
1449
+ sofa = TouchableSpec::Embedded::Sofa.new
1450
+ floor.sofas.push(sofa)
1451
+
1452
+ # Verify callbacks ran by checking the in-memory timestamps
1453
+ # were updated (touch sets updated_at in-memory via write_attribute).
1454
+ expect(floor.updated_at).to be_within(5).of(Time.now)
1455
+ expect(building.updated_at).to be_within(5).of(Time.now)
1456
+ end
1457
+ end
1458
+
1459
+ context 'when pushing an embedded document with touch: false' do
1460
+ let(:building) do
1461
+ TouchableSpec::Embedded::Building.create!(title: 'Tower')
1462
+ end
1463
+
1464
+ let(:floor) do
1465
+ building.floors.create!(level: 1)
1466
+ end
1467
+
1468
+ before do
1469
+ building
1470
+ floor
1471
+ end
1472
+
1473
+ it 'does not merge touch updates (touch: false on Chair)' do
1474
+ original_floor_updated_at = floor.updated_at
1475
+
1476
+ Timecop.travel(Time.now + 10) do
1477
+ floor.chairs.push(TouchableSpec::Embedded::Chair.new)
1478
+ end
1479
+
1480
+ # Floor should not be touched because Chair has touch: false.
1481
+ expect(floor.updated_at).to eq(original_floor_updated_at)
1482
+ end
1483
+ end
1484
+
1485
+ context 'when pushing into a non-touchable parent' do
1486
+ let(:building) do
1487
+ TouchableSpec::Embedded::Building.create!(title: 'Tower')
1488
+ end
1489
+
1490
+ let(:entrance) do
1491
+ building.entrances.create!(level: 0)
1492
+ end
1493
+
1494
+ before do
1495
+ building
1496
+ entrance
1497
+ end
1498
+
1499
+ it 'does not touch the building (Entrance has touch: false)' do
1500
+ # Reload to get the MongoDB-persisted timestamp (with truncated
1501
+ # sub-millisecond precision) so the comparison is stable.
1502
+ building.reload
1503
+ original_building_updated_at = building.updated_at
1504
+
1505
+ Timecop.travel(Time.now + 10) do
1506
+ entrance.cameras.push(TouchableSpec::Embedded::Camera.new)
1507
+ end
1508
+
1509
+ building.reload
1510
+ # Camera touches Entrance, but Entrance does NOT touch Building.
1511
+ expect(building.updated_at).to eq(original_building_updated_at)
1512
+ end
1513
+ end
1514
+ end
1479
1515
  end