mongoid 7.0.13 → 9.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1421) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -41
  3. data/LICENSE +1 -1
  4. data/README.md +29 -25
  5. data/Rakefile +150 -40
  6. data/lib/config/locales/en.yml +364 -108
  7. data/lib/mongoid/association/accessors.rb +205 -107
  8. data/lib/mongoid/association/bindable.rb +102 -56
  9. data/lib/mongoid/association/builders.rb +24 -26
  10. data/lib/mongoid/association/constrainable.rb +8 -11
  11. data/lib/mongoid/association/depending.rb +65 -59
  12. data/lib/mongoid/association/eager.rb +203 -0
  13. data/lib/mongoid/association/eager_load/discriminated_inclusion.rb +88 -0
  14. data/lib/mongoid/association/eager_load/embedded_distributor.rb +151 -0
  15. data/lib/mongoid/association/eager_load/inclusion.rb +173 -0
  16. data/lib/mongoid/association/eager_load/inclusion_tree.rb +96 -0
  17. data/lib/mongoid/association/eager_load/lookup_pipeline.rb +121 -0
  18. data/lib/mongoid/association/eager_load/polymorphic_preloader.rb +61 -0
  19. data/lib/mongoid/association/eager_load/polymorphic_targets.rb +151 -0
  20. data/lib/mongoid/association/eager_loadable.rb +135 -15
  21. data/lib/mongoid/association/embedded/batchable.rb +87 -75
  22. data/lib/mongoid/association/embedded/cyclic.rb +16 -25
  23. data/lib/mongoid/association/embedded/eager.rb +18 -0
  24. data/lib/mongoid/association/embedded/embedded_in/binding.rb +30 -14
  25. data/lib/mongoid/association/embedded/embedded_in/buildable.rb +10 -7
  26. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +39 -32
  27. data/lib/mongoid/association/embedded/embedded_in.rb +37 -46
  28. data/lib/mongoid/association/embedded/embeds_many/binding.rb +7 -11
  29. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +11 -7
  30. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +309 -243
  31. data/lib/mongoid/association/embedded/embeds_many.rb +32 -56
  32. data/lib/mongoid/association/embedded/embeds_one/binding.rb +6 -11
  33. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +25 -11
  34. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +145 -53
  35. data/lib/mongoid/association/embedded/embeds_one.rb +30 -50
  36. data/lib/mongoid/association/embedded.rb +3 -0
  37. data/lib/mongoid/association/macros.rb +97 -56
  38. data/lib/mongoid/association/many.rb +99 -36
  39. data/lib/mongoid/association/marshalable.rb +5 -7
  40. data/lib/mongoid/association/nested/many.rb +86 -47
  41. data/lib/mongoid/association/nested/nested_buildable.rb +58 -21
  42. data/lib/mongoid/association/nested/one.rb +81 -36
  43. data/lib/mongoid/association/nested.rb +4 -5
  44. data/lib/mongoid/association/one.rb +5 -14
  45. data/lib/mongoid/association/options.rb +48 -53
  46. data/lib/mongoid/association/proxy.rb +65 -54
  47. data/lib/mongoid/association/referenced/auto_save.rb +59 -20
  48. data/lib/mongoid/association/referenced/belongs_to/binding.rb +21 -22
  49. data/lib/mongoid/association/referenced/belongs_to/buildable.rb +32 -11
  50. data/lib/mongoid/association/referenced/belongs_to/eager.rb +47 -6
  51. data/lib/mongoid/association/referenced/belongs_to/proxy.rb +35 -42
  52. data/lib/mongoid/association/referenced/belongs_to.rb +77 -77
  53. data/lib/mongoid/association/referenced/counter_cache.rb +24 -35
  54. data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +26 -15
  55. data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +12 -7
  56. data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +3 -4
  57. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +202 -133
  58. data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +81 -83
  59. data/lib/mongoid/association/referenced/has_many/binding.rb +3 -7
  60. data/lib/mongoid/association/referenced/has_many/buildable.rb +15 -8
  61. data/lib/mongoid/association/referenced/has_many/eager.rb +3 -4
  62. data/lib/mongoid/association/referenced/has_many/enumerable.rb +601 -456
  63. data/lib/mongoid/association/referenced/has_many/proxy.rb +344 -216
  64. data/lib/mongoid/association/referenced/has_many.rb +58 -74
  65. data/lib/mongoid/association/referenced/has_many_through/eager.rb +99 -0
  66. data/lib/mongoid/association/referenced/has_many_through/proxy.rb +68 -0
  67. data/lib/mongoid/association/referenced/has_many_through.rb +201 -0
  68. data/lib/mongoid/association/referenced/has_one/binding.rb +4 -10
  69. data/lib/mongoid/association/referenced/has_one/buildable.rb +29 -17
  70. data/lib/mongoid/association/referenced/has_one/eager.rb +4 -6
  71. data/lib/mongoid/association/referenced/has_one/proxy.rb +51 -47
  72. data/lib/mongoid/association/referenced/has_one.rb +45 -55
  73. data/lib/mongoid/association/referenced/has_one_through/eager.rb +65 -0
  74. data/lib/mongoid/association/referenced/has_one_through/proxy.rb +30 -0
  75. data/lib/mongoid/association/referenced/has_one_through.rb +167 -0
  76. data/lib/mongoid/association/referenced/syncable.rb +44 -62
  77. data/lib/mongoid/association/referenced/with_polymorphic_criteria.rb +41 -0
  78. data/lib/mongoid/association/referenced.rb +4 -0
  79. data/lib/mongoid/association/reflections.rb +11 -12
  80. data/lib/mongoid/association/relatable.rb +173 -146
  81. data/lib/mongoid/association.rb +35 -40
  82. data/lib/mongoid/atomic/modifiers.rb +91 -74
  83. data/lib/mongoid/atomic/paths/embedded/many.rb +25 -11
  84. data/lib/mongoid/atomic/paths/embedded/one.rb +6 -10
  85. data/lib/mongoid/atomic/paths/embedded.rb +5 -8
  86. data/lib/mongoid/atomic/paths/root.rb +5 -10
  87. data/lib/mongoid/atomic/paths.rb +4 -3
  88. data/lib/mongoid/atomic.rb +41 -89
  89. data/lib/mongoid/atomic_update_preparer.rb +89 -0
  90. data/lib/mongoid/attributes/dynamic.rb +12 -27
  91. data/lib/mongoid/attributes/embedded.rb +34 -0
  92. data/lib/mongoid/attributes/nested.rb +22 -25
  93. data/lib/mongoid/attributes/processing.rb +51 -34
  94. data/lib/mongoid/attributes/projector.rb +107 -0
  95. data/lib/mongoid/attributes/readonly.rb +15 -17
  96. data/lib/mongoid/attributes.rb +119 -126
  97. data/lib/mongoid/cacheable.rb +30 -14
  98. data/lib/mongoid/changeable.rb +196 -99
  99. data/lib/mongoid/clients/factory.rb +73 -17
  100. data/lib/mongoid/clients/options.rb +140 -19
  101. data/lib/mongoid/clients/sessions.rb +239 -87
  102. data/lib/mongoid/clients/storage_options.rb +42 -17
  103. data/lib/mongoid/clients/validators/storage.rb +6 -25
  104. data/lib/mongoid/clients/validators.rb +3 -2
  105. data/lib/mongoid/clients.rb +44 -22
  106. data/lib/mongoid/collection_configurable.rb +63 -0
  107. data/lib/mongoid/composable.rb +40 -39
  108. data/lib/mongoid/config/defaults.rb +46 -0
  109. data/lib/mongoid/config/encryption.rb +228 -0
  110. data/lib/mongoid/config/environment.rb +26 -13
  111. data/lib/mongoid/config/introspection.rb +150 -0
  112. data/lib/mongoid/config/options.rb +37 -26
  113. data/lib/mongoid/config/validators/async_query_executor.rb +31 -0
  114. data/lib/mongoid/config/validators/client.rb +20 -37
  115. data/lib/mongoid/config/validators/option.rb +5 -7
  116. data/lib/mongoid/config/validators.rb +5 -3
  117. data/lib/mongoid/config.rb +418 -60
  118. data/lib/mongoid/contextual/aggregable/memory.rb +45 -28
  119. data/lib/mongoid/contextual/aggregable/mongo.rb +49 -47
  120. data/lib/mongoid/contextual/aggregable/none.rb +64 -0
  121. data/lib/mongoid/contextual/aggregable.rb +16 -0
  122. data/lib/mongoid/contextual/atomic.rb +126 -45
  123. data/lib/mongoid/contextual/command.rb +3 -6
  124. data/lib/mongoid/contextual/map_reduce.rb +23 -49
  125. data/lib/mongoid/contextual/memory.rb +448 -121
  126. data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
  127. data/lib/mongoid/contextual/mongo.rb +707 -351
  128. data/lib/mongoid/contextual/none.rb +249 -33
  129. data/lib/mongoid/contextual/queryable.rb +6 -6
  130. data/lib/mongoid/contextual.rb +40 -15
  131. data/lib/mongoid/copyable.rb +45 -21
  132. data/lib/mongoid/criteria/findable.rb +65 -27
  133. data/lib/mongoid/criteria/includable.rb +97 -45
  134. data/lib/mongoid/criteria/inspectable.rb +6 -6
  135. data/lib/mongoid/criteria/marshalable.rb +15 -10
  136. data/lib/mongoid/criteria/modifiable.rb +8 -28
  137. data/lib/mongoid/criteria/options.rb +2 -5
  138. data/lib/mongoid/criteria/permission.rb +40 -37
  139. data/lib/mongoid/criteria/queryable/aggregable.rb +13 -24
  140. data/lib/mongoid/criteria/queryable/expandable.rb +64 -0
  141. data/lib/mongoid/criteria/queryable/extensions/array.rb +14 -50
  142. data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +29 -13
  143. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +6 -9
  144. data/lib/mongoid/criteria/queryable/extensions/date.rb +13 -16
  145. data/lib/mongoid/criteria/queryable/extensions/date_time.rb +14 -18
  146. data/lib/mongoid/criteria/queryable/extensions/hash.rb +5 -44
  147. data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +23 -24
  148. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +31 -29
  149. data/lib/mongoid/criteria/queryable/extensions/object.rb +15 -37
  150. data/lib/mongoid/criteria/queryable/extensions/range.rb +52 -22
  151. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +22 -25
  152. data/lib/mongoid/criteria/queryable/extensions/set.rb +8 -10
  153. data/lib/mongoid/criteria/queryable/extensions/string.rb +24 -41
  154. data/lib/mongoid/criteria/queryable/extensions/symbol.rb +10 -28
  155. data/lib/mongoid/criteria/queryable/extensions/time.rb +11 -14
  156. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +12 -20
  157. data/lib/mongoid/criteria/queryable/extensions.rb +19 -24
  158. data/lib/mongoid/criteria/queryable/key.rb +49 -30
  159. data/lib/mongoid/criteria/queryable/macroable.rb +3 -6
  160. data/lib/mongoid/criteria/queryable/mergeable.rb +203 -46
  161. data/lib/mongoid/criteria/queryable/optional.rb +32 -81
  162. data/lib/mongoid/criteria/queryable/options.rb +24 -29
  163. data/lib/mongoid/criteria/queryable/pipeline.rb +11 -23
  164. data/lib/mongoid/criteria/queryable/selectable.rb +558 -242
  165. data/lib/mongoid/criteria/queryable/selector.rb +134 -43
  166. data/lib/mongoid/criteria/queryable/smash.rb +41 -21
  167. data/lib/mongoid/criteria/queryable/storable.rb +219 -0
  168. data/lib/mongoid/criteria/queryable.rb +41 -27
  169. data/lib/mongoid/criteria/scopable.rb +37 -30
  170. data/lib/mongoid/criteria/translator.rb +43 -0
  171. data/lib/mongoid/criteria.rb +257 -152
  172. data/lib/mongoid/deprecable.rb +78 -0
  173. data/lib/mongoid/deprecation.rb +25 -0
  174. data/lib/mongoid/document.rb +277 -171
  175. data/lib/mongoid/encryptable.rb +98 -0
  176. data/lib/mongoid/equality.rb +29 -31
  177. data/lib/mongoid/errors/ambiguous_relationship.rb +6 -9
  178. data/lib/mongoid/errors/attribute_not_loaded.rb +31 -0
  179. data/lib/mongoid/errors/callback.rb +3 -6
  180. data/lib/mongoid/errors/config_redactor.rb +43 -0
  181. data/lib/mongoid/errors/create_collection_failure.rb +31 -0
  182. data/lib/mongoid/errors/criteria_argument_required.rb +16 -0
  183. data/lib/mongoid/errors/delete_restriction.rb +11 -16
  184. data/lib/mongoid/errors/document_not_destroyed.rb +5 -10
  185. data/lib/mongoid/errors/document_not_found.rb +37 -27
  186. data/lib/mongoid/errors/drop_collection_failure.rb +25 -0
  187. data/lib/mongoid/errors/empty_config_file.rb +23 -0
  188. data/lib/mongoid/errors/immutable_attribute.rb +24 -0
  189. data/lib/mongoid/errors/in_memory_collation_not_supported.rb +3 -6
  190. data/lib/mongoid/errors/in_memory_regexp_timeout.rb +26 -0
  191. data/lib/mongoid/errors/invalid_around_callback.rb +16 -0
  192. data/lib/mongoid/errors/invalid_async_query_executor.rb +23 -0
  193. data/lib/mongoid/errors/invalid_auto_encryption_configuration.rb +30 -0
  194. data/lib/mongoid/errors/invalid_collection.rb +3 -3
  195. data/lib/mongoid/errors/invalid_config_file.rb +23 -0
  196. data/lib/mongoid/errors/invalid_config_option.rb +5 -8
  197. data/lib/mongoid/errors/invalid_dependent_strategy.rb +9 -13
  198. data/lib/mongoid/errors/invalid_discriminator_key_target.rb +23 -0
  199. data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +21 -0
  200. data/lib/mongoid/errors/invalid_elem_match_operator.rb +29 -0
  201. data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +24 -0
  202. data/lib/mongoid/errors/invalid_estimated_count_scoping.rb +24 -0
  203. data/lib/mongoid/errors/invalid_expression_operator.rb +24 -0
  204. data/lib/mongoid/errors/invalid_field.rb +10 -11
  205. data/lib/mongoid/errors/invalid_field_operator.rb +29 -0
  206. data/lib/mongoid/errors/invalid_field_option.rb +4 -7
  207. data/lib/mongoid/errors/invalid_field_type.rb +24 -0
  208. data/lib/mongoid/errors/invalid_find.rb +3 -6
  209. data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +20 -0
  210. data/lib/mongoid/errors/invalid_includes.rb +5 -8
  211. data/lib/mongoid/errors/invalid_index.rb +3 -6
  212. data/lib/mongoid/errors/invalid_options.rb +5 -8
  213. data/lib/mongoid/errors/invalid_path.rb +3 -6
  214. data/lib/mongoid/errors/invalid_persistence_option.rb +6 -11
  215. data/lib/mongoid/errors/invalid_query.rb +36 -0
  216. data/lib/mongoid/errors/invalid_relation.rb +15 -22
  217. data/lib/mongoid/errors/invalid_relation_option.rb +8 -11
  218. data/lib/mongoid/errors/invalid_scope.rb +3 -6
  219. data/lib/mongoid/errors/invalid_session_nesting.rb +14 -0
  220. data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +8 -9
  221. data/lib/mongoid/errors/invalid_storage_options.rb +4 -7
  222. data/lib/mongoid/errors/invalid_time.rb +3 -6
  223. data/lib/mongoid/errors/invalid_transaction_nesting.rb +14 -0
  224. data/lib/mongoid/errors/inverse_not_found.rb +4 -7
  225. data/lib/mongoid/errors/mixed_client_configuration.rb +4 -7
  226. data/lib/mongoid/errors/mixed_relations.rb +3 -5
  227. data/lib/mongoid/errors/mongoid_error.rb +13 -23
  228. data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +4 -7
  229. data/lib/mongoid/errors/no_client_config.rb +5 -8
  230. data/lib/mongoid/errors/no_client_database.rb +5 -8
  231. data/lib/mongoid/errors/no_client_hosts.rb +5 -8
  232. data/lib/mongoid/errors/no_clients_config.rb +3 -6
  233. data/lib/mongoid/errors/no_default_client.rb +4 -7
  234. data/lib/mongoid/errors/no_encryption_schema.rb +28 -0
  235. data/lib/mongoid/errors/no_environment.rb +3 -6
  236. data/lib/mongoid/errors/no_map_reduce_output.rb +3 -6
  237. data/lib/mongoid/errors/no_metadata.rb +3 -6
  238. data/lib/mongoid/errors/no_parent.rb +3 -6
  239. data/lib/mongoid/errors/readonly_association.rb +29 -0
  240. data/lib/mongoid/errors/readonly_attribute.rb +4 -7
  241. data/lib/mongoid/errors/readonly_document.rb +4 -9
  242. data/lib/mongoid/errors/rollback.rb +13 -0
  243. data/lib/mongoid/errors/scope_overwrite.rb +4 -4
  244. data/lib/mongoid/errors/sessions_not_supported.rb +14 -0
  245. data/lib/mongoid/errors/too_many_nested_attribute_records.rb +4 -3
  246. data/lib/mongoid/errors/transaction_error.rb +22 -0
  247. data/lib/mongoid/errors/transactions_not_supported.rb +14 -0
  248. data/lib/mongoid/errors/unknown_attribute.rb +4 -7
  249. data/lib/mongoid/errors/unknown_model.rb +3 -6
  250. data/lib/mongoid/errors/unrecognized_model_alias.rb +53 -0
  251. data/lib/mongoid/errors/unrecognized_resolver.rb +27 -0
  252. data/lib/mongoid/errors/unregistered_class.rb +47 -0
  253. data/lib/mongoid/errors/unsaved_document.rb +4 -4
  254. data/lib/mongoid/errors/unsupported_isolation_level.rb +22 -0
  255. data/lib/mongoid/errors/unsupported_javascript.rb +3 -6
  256. data/lib/mongoid/errors/validations.rb +5 -5
  257. data/lib/mongoid/errors.rb +82 -51
  258. data/lib/mongoid/evolvable.rb +4 -7
  259. data/lib/mongoid/extensions/array.rb +32 -55
  260. data/lib/mongoid/extensions/big_decimal.rb +45 -24
  261. data/lib/mongoid/extensions/binary.rb +42 -0
  262. data/lib/mongoid/extensions/boolean.rb +12 -8
  263. data/lib/mongoid/extensions/bson_document.rb +28 -0
  264. data/lib/mongoid/extensions/date.rb +38 -30
  265. data/lib/mongoid/extensions/date_time.rb +8 -22
  266. data/lib/mongoid/extensions/decimal128.rb +4 -8
  267. data/lib/mongoid/extensions/false_class.rb +11 -13
  268. data/lib/mongoid/extensions/float.rb +15 -19
  269. data/lib/mongoid/extensions/hash.rb +31 -116
  270. data/lib/mongoid/extensions/integer.rb +17 -21
  271. data/lib/mongoid/extensions/module.rb +6 -7
  272. data/lib/mongoid/extensions/nil_class.rb +6 -7
  273. data/lib/mongoid/extensions/object.rb +42 -84
  274. data/lib/mongoid/extensions/object_id.rb +5 -11
  275. data/lib/mongoid/extensions/range.rb +49 -25
  276. data/lib/mongoid/extensions/raw_value.rb +31 -0
  277. data/lib/mongoid/extensions/regexp.rb +16 -10
  278. data/lib/mongoid/extensions/set.rb +27 -15
  279. data/lib/mongoid/extensions/string.rb +40 -67
  280. data/lib/mongoid/extensions/symbol.rb +11 -26
  281. data/lib/mongoid/extensions/time.rb +49 -47
  282. data/lib/mongoid/extensions/time_with_zone.rb +30 -12
  283. data/lib/mongoid/extensions/true_class.rb +11 -13
  284. data/lib/mongoid/extensions/vector.rb +64 -0
  285. data/lib/mongoid/extensions.rb +28 -41
  286. data/lib/mongoid/factory.rb +205 -28
  287. data/lib/mongoid/field_readable.rb +69 -0
  288. data/lib/mongoid/fields/encrypted.rb +47 -0
  289. data/lib/mongoid/fields/foreign_key.rb +48 -35
  290. data/lib/mongoid/fields/localized.rb +33 -21
  291. data/lib/mongoid/fields/standard.rb +31 -48
  292. data/lib/mongoid/fields/validators/macro.rb +48 -45
  293. data/lib/mongoid/fields/validators.rb +3 -2
  294. data/lib/mongoid/fields.rb +499 -117
  295. data/lib/mongoid/findable.rb +174 -64
  296. data/lib/mongoid/identifiable.rb +28 -0
  297. data/lib/mongoid/indexable/specification.rb +76 -39
  298. data/lib/mongoid/indexable/validators/options.rb +36 -43
  299. data/lib/mongoid/indexable.rb +57 -58
  300. data/lib/mongoid/inspectable.rb +37 -15
  301. data/lib/mongoid/interceptable.rb +235 -66
  302. data/lib/mongoid/loadable.rb +146 -0
  303. data/lib/mongoid/loggable.rb +12 -18
  304. data/lib/mongoid/matchable.rb +7 -154
  305. data/lib/mongoid/matcher/all.rb +34 -0
  306. data/lib/mongoid/matcher/and.rb +32 -0
  307. data/lib/mongoid/matcher/bits.rb +65 -0
  308. data/lib/mongoid/matcher/bits_all_clear.rb +39 -0
  309. data/lib/mongoid/matcher/bits_all_set.rb +39 -0
  310. data/lib/mongoid/matcher/bits_any_clear.rb +39 -0
  311. data/lib/mongoid/matcher/bits_any_set.rb +39 -0
  312. data/lib/mongoid/matcher/elem_match.rb +49 -0
  313. data/lib/mongoid/matcher/elem_match_expression.rb +29 -0
  314. data/lib/mongoid/matcher/eq.rb +23 -0
  315. data/lib/mongoid/matcher/eq_impl.rb +79 -0
  316. data/lib/mongoid/matcher/eq_impl_with_regexp.rb +33 -0
  317. data/lib/mongoid/matcher/exists.rb +27 -0
  318. data/lib/mongoid/matcher/expression.rb +43 -0
  319. data/lib/mongoid/matcher/expression_operator.rb +31 -0
  320. data/lib/mongoid/matcher/field_expression.rb +74 -0
  321. data/lib/mongoid/matcher/field_operator.rb +76 -0
  322. data/lib/mongoid/matcher/gt.rb +29 -0
  323. data/lib/mongoid/matcher/gte.rb +29 -0
  324. data/lib/mongoid/matcher/in.rb +37 -0
  325. data/lib/mongoid/matcher/lt.rb +29 -0
  326. data/lib/mongoid/matcher/lte.rb +29 -0
  327. data/lib/mongoid/matcher/mod.rb +29 -0
  328. data/lib/mongoid/matcher/ne.rb +28 -0
  329. data/lib/mongoid/matcher/nin.rb +23 -0
  330. data/lib/mongoid/matcher/nor.rb +34 -0
  331. data/lib/mongoid/matcher/not.rb +42 -0
  332. data/lib/mongoid/matcher/or.rb +32 -0
  333. data/lib/mongoid/matcher/regex.rb +61 -0
  334. data/lib/mongoid/matcher/regexp_budget.rb +372 -0
  335. data/lib/mongoid/matcher/size.rb +39 -0
  336. data/lib/mongoid/matcher/type.rb +119 -0
  337. data/lib/mongoid/matcher.rb +141 -0
  338. data/lib/mongoid/model_resolver.rb +155 -0
  339. data/lib/mongoid/persistable/creatable.rb +50 -36
  340. data/lib/mongoid/persistable/deletable.rb +18 -30
  341. data/lib/mongoid/persistable/destroyable.rb +38 -14
  342. data/lib/mongoid/persistable/incrementable.rb +8 -10
  343. data/lib/mongoid/persistable/logical.rb +7 -10
  344. data/lib/mongoid/persistable/maxable.rb +35 -0
  345. data/lib/mongoid/persistable/minable.rb +35 -0
  346. data/lib/mongoid/persistable/multipliable.rb +34 -0
  347. data/lib/mongoid/persistable/poppable.rb +5 -9
  348. data/lib/mongoid/persistable/pullable.rb +6 -12
  349. data/lib/mongoid/persistable/pushable.rb +8 -14
  350. data/lib/mongoid/persistable/renamable.rb +11 -10
  351. data/lib/mongoid/persistable/savable.rb +16 -11
  352. data/lib/mongoid/persistable/settable.rb +7 -18
  353. data/lib/mongoid/persistable/unsettable.rb +11 -12
  354. data/lib/mongoid/persistable/updatable.rb +113 -35
  355. data/lib/mongoid/persistable/upsertable.rb +37 -12
  356. data/lib/mongoid/persistable.rb +169 -60
  357. data/lib/mongoid/persistence_context.rb +189 -75
  358. data/lib/mongoid/pluckable.rb +130 -0
  359. data/lib/mongoid/positional.rb +7 -15
  360. data/lib/mongoid/railtie.rb +36 -32
  361. data/lib/mongoid/railties/bson_object_id_serializer.rb +46 -0
  362. data/lib/mongoid/railties/console_sandbox.rb +40 -0
  363. data/lib/mongoid/railties/controller_runtime.rb +34 -20
  364. data/lib/mongoid/railties/database.rake +53 -29
  365. data/lib/mongoid/reloadable.rb +56 -45
  366. data/lib/mongoid/scopable.rb +50 -79
  367. data/lib/mongoid/search_indexable.rb +538 -0
  368. data/lib/mongoid/selectable.rb +8 -19
  369. data/lib/mongoid/serializable.rb +46 -40
  370. data/lib/mongoid/shardable.rb +102 -23
  371. data/lib/mongoid/stateful.rb +67 -26
  372. data/lib/mongoid/stringified_symbol.rb +61 -0
  373. data/lib/mongoid/tasks/database.rake +46 -15
  374. data/lib/mongoid/tasks/database.rb +204 -31
  375. data/lib/mongoid/tasks/encryption.rake +59 -0
  376. data/lib/mongoid/tasks/encryption.rb +103 -0
  377. data/lib/mongoid/threaded/lifecycle.rb +13 -34
  378. data/lib/mongoid/threaded.rb +353 -108
  379. data/lib/mongoid/timestamps/created/short.rb +4 -3
  380. data/lib/mongoid/timestamps/created.rb +15 -7
  381. data/lib/mongoid/timestamps/short.rb +2 -1
  382. data/lib/mongoid/timestamps/timeless.rb +127 -29
  383. data/lib/mongoid/timestamps/updated/short.rb +4 -3
  384. data/lib/mongoid/timestamps/updated.rb +6 -9
  385. data/lib/mongoid/timestamps.rb +7 -7
  386. data/lib/mongoid/touchable.rb +176 -40
  387. data/lib/mongoid/traversable.rb +309 -106
  388. data/lib/mongoid/utils.rb +52 -0
  389. data/lib/mongoid/validatable/associated.rb +115 -22
  390. data/lib/mongoid/validatable/format.rb +2 -2
  391. data/lib/mongoid/validatable/length.rb +2 -2
  392. data/lib/mongoid/validatable/localizable.rb +3 -6
  393. data/lib/mongoid/validatable/macros.rb +25 -14
  394. data/lib/mongoid/validatable/numericality.rb +40 -0
  395. data/lib/mongoid/validatable/presence.rb +15 -21
  396. data/lib/mongoid/validatable/queryable.rb +9 -4
  397. data/lib/mongoid/validatable/uniqueness.rb +40 -53
  398. data/lib/mongoid/validatable.rb +41 -52
  399. data/lib/mongoid/version.rb +6 -2
  400. data/lib/mongoid/warnings.rb +40 -0
  401. data/lib/mongoid.rb +105 -44
  402. data/lib/rails/generators/mongoid/config/config_generator.rb +18 -5
  403. data/lib/rails/generators/mongoid/config/templates/mongoid.rb +24 -0
  404. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +51 -56
  405. data/lib/rails/generators/mongoid/model/model_generator.rb +10 -8
  406. data/lib/rails/generators/mongoid_generator.rb +17 -7
  407. data/lib/rails/mongoid.rb +4 -32
  408. data/spec/README.md +19 -4
  409. data/spec/config/mongoid.yml +17 -1
  410. data/spec/config/mongoid_with_schema_map_uuid.yml +27 -0
  411. data/spec/integration/active_job_spec.rb +35 -0
  412. data/spec/integration/app_spec.rb +327 -144
  413. data/spec/integration/associations/belongs_to_spec.rb +165 -0
  414. data/spec/integration/associations/embedded_dirty_spec.rb +57 -0
  415. data/spec/integration/associations/embedded_spec.rb +241 -67
  416. data/spec/integration/associations/embeds_many_spec.rb +347 -0
  417. data/spec/integration/associations/embeds_one_spec.rb +62 -0
  418. data/spec/integration/associations/foreign_key_spec.rb +107 -0
  419. data/spec/integration/associations/foreign_key_spec_models.rb +64 -0
  420. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +161 -0
  421. data/spec/integration/associations/has_many_spec.rb +184 -0
  422. data/spec/integration/associations/has_one_spec.rb +322 -0
  423. data/spec/integration/associations/nested_attributes_assignment_spec.rb +113 -0
  424. data/spec/integration/associations/reverse_population_spec.rb +34 -0
  425. data/spec/integration/associations/reverse_population_spec_models.rb +36 -0
  426. data/spec/integration/associations/scope_option_spec.rb +100 -0
  427. data/spec/integration/atomic/modifiers_spec.rb +137 -0
  428. data/spec/integration/bson_regexp_raw_spec.rb +19 -0
  429. data/spec/integration/caching_spec.rb +68 -0
  430. data/spec/integration/callbacks_models.rb +149 -3
  431. data/spec/integration/callbacks_spec.rb +422 -34
  432. data/spec/integration/contextual/empty_spec.rb +141 -0
  433. data/spec/integration/criteria/alias_query_spec.rb +91 -0
  434. data/spec/integration/criteria/date_field_spec.rb +1 -2
  435. data/spec/integration/criteria/default_scope_spec.rb +78 -0
  436. data/spec/integration/criteria/logical_spec.rb +105 -0
  437. data/spec/integration/criteria/range_spec.rb +349 -0
  438. data/spec/integration/criteria/raw_value_spec.rb +538 -0
  439. data/spec/integration/criteria/time_with_zone_spec.rb +135 -15
  440. data/spec/integration/discriminator_key_spec.rb +392 -0
  441. data/spec/integration/discriminator_value_spec.rb +204 -0
  442. data/spec/integration/document_spec.rb +32 -3
  443. data/spec/integration/dots_and_dollars_spec.rb +273 -0
  444. data/spec/integration/encryption_spec.rb +248 -0
  445. data/spec/integration/i18n_fallbacks_spec.rb +47 -0
  446. data/spec/integration/isolation_state_spec.rb +241 -0
  447. data/spec/integration/matcher_examples_spec.rb +743 -0
  448. data/spec/integration/matcher_operator_data/all.yml +140 -0
  449. data/spec/integration/matcher_operator_data/and.yml +93 -0
  450. data/spec/integration/matcher_operator_data/bits_all_clear.yml +144 -0
  451. data/spec/integration/matcher_operator_data/bits_all_set.yml +144 -0
  452. data/spec/integration/matcher_operator_data/bits_any_clear.yml +144 -0
  453. data/spec/integration/matcher_operator_data/bits_any_set.yml +144 -0
  454. data/spec/integration/matcher_operator_data/comment.yml +22 -0
  455. data/spec/integration/matcher_operator_data/elem_match.yml +409 -0
  456. data/spec/integration/matcher_operator_data/elem_match_expr.yml +213 -0
  457. data/spec/integration/matcher_operator_data/eq.yml +191 -0
  458. data/spec/integration/matcher_operator_data/exists.yml +213 -0
  459. data/spec/integration/matcher_operator_data/generic_op.yml +17 -0
  460. data/spec/integration/matcher_operator_data/gt.yml +132 -0
  461. data/spec/integration/matcher_operator_data/gt_types.yml +63 -0
  462. data/spec/integration/matcher_operator_data/gte.yml +132 -0
  463. data/spec/integration/matcher_operator_data/gte_types.yml +15 -0
  464. data/spec/integration/matcher_operator_data/implicit.yml +331 -0
  465. data/spec/integration/matcher_operator_data/implicit_traversal.yml +112 -0
  466. data/spec/integration/matcher_operator_data/in.yml +210 -0
  467. data/spec/integration/matcher_operator_data/invalid_op.yml +59 -0
  468. data/spec/integration/matcher_operator_data/invalid_syntax.yml +39 -0
  469. data/spec/integration/matcher_operator_data/lt.yml +132 -0
  470. data/spec/integration/matcher_operator_data/lt_types.yml +15 -0
  471. data/spec/integration/matcher_operator_data/lte.yml +132 -0
  472. data/spec/integration/matcher_operator_data/lte_types.yml +15 -0
  473. data/spec/integration/matcher_operator_data/mod.yml +55 -0
  474. data/spec/integration/matcher_operator_data/multiple.yml +29 -0
  475. data/spec/integration/matcher_operator_data/ne.yml +150 -0
  476. data/spec/integration/matcher_operator_data/ne_types.yml +15 -0
  477. data/spec/integration/matcher_operator_data/nin.yml +114 -0
  478. data/spec/integration/matcher_operator_data/nor.yml +126 -0
  479. data/spec/integration/matcher_operator_data/not.yml +196 -0
  480. data/spec/integration/matcher_operator_data/or.yml +137 -0
  481. data/spec/integration/matcher_operator_data/regex.yml +195 -0
  482. data/spec/integration/matcher_operator_data/regex_options.yml +72 -0
  483. data/spec/integration/matcher_operator_data/size.yml +171 -0
  484. data/spec/integration/matcher_operator_data/type.yml +64 -0
  485. data/spec/integration/matcher_operator_data/type_array.yml +15 -0
  486. data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
  487. data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
  488. data/spec/integration/matcher_operator_data/type_code.yml +26 -0
  489. data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
  490. data/spec/integration/matcher_operator_data/type_date.yml +39 -0
  491. data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
  492. data/spec/integration/matcher_operator_data/type_decimal.yml +37 -0
  493. data/spec/integration/matcher_operator_data/type_double.yml +15 -0
  494. data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
  495. data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
  496. data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
  497. data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
  498. data/spec/integration/matcher_operator_data/type_null.yml +23 -0
  499. data/spec/integration/matcher_operator_data/type_object.yml +23 -0
  500. data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
  501. data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
  502. data/spec/integration/matcher_operator_data/type_string.yml +15 -0
  503. data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
  504. data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
  505. data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
  506. data/spec/integration/matcher_operator_spec.rb +113 -0
  507. data/spec/integration/matcher_regexp_timeout_spec.rb +215 -0
  508. data/spec/integration/matcher_spec.rb +237 -0
  509. data/spec/integration/persistence/collection_options_spec.rb +34 -0
  510. data/spec/integration/persistence/range_field_spec.rb +373 -0
  511. data/spec/integration/query_operator_guard_spec.rb +89 -0
  512. data/spec/integration/server_query_spec.rb +148 -0
  513. data/spec/integration/shardable_spec.rb +148 -0
  514. data/spec/integration/stringified_symbol_field_spec.rb +189 -0
  515. data/spec/lite_spec_helper.rb +56 -19
  516. data/spec/mongoid/association/accessors_spec.rb +375 -273
  517. data/spec/mongoid/association/auto_save_spec.rb +215 -106
  518. data/spec/mongoid/association/builders_spec.rb +124 -74
  519. data/spec/mongoid/association/constrainable_spec.rb +11 -21
  520. data/spec/mongoid/association/counter_cache_spec.rb +101 -131
  521. data/spec/mongoid/association/depending_spec.rb +454 -402
  522. data/spec/mongoid/association/eager_loadable_spec.rb +47 -0
  523. data/spec/mongoid/association/eager_spec.rb +471 -60
  524. data/spec/mongoid/association/embedded/cyclic_spec.rb +40 -49
  525. data/spec/mongoid/association/embedded/dirty_spec.rb +19 -21
  526. data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +39 -53
  527. data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +58 -8
  528. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +208 -158
  529. data/spec/mongoid/association/embedded/embedded_in_spec.rb +46 -134
  530. data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +11 -13
  531. data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +137 -35
  532. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +1716 -1327
  533. data/spec/mongoid/association/embedded/embeds_many_models.rb +191 -2
  534. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +68 -0
  535. data/spec/mongoid/association/embedded/embeds_many_spec.rb +77 -119
  536. data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +17 -22
  537. data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +44 -24
  538. data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +234 -287
  539. data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +2 -0
  540. data/spec/mongoid/association/embedded/embeds_one_models.rb +27 -1
  541. data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +28 -0
  542. data/spec/mongoid/association/embedded/embeds_one_spec.rb +50 -134
  543. data/spec/mongoid/association/fallback_spec.rb +425 -0
  544. data/spec/mongoid/association/macros_spec.rb +250 -308
  545. data/spec/mongoid/association/nested/many_spec.rb +53 -72
  546. data/spec/mongoid/association/nested/one_spec.rb +68 -85
  547. data/spec/mongoid/association/options_spec.rb +189 -309
  548. data/spec/mongoid/association/polymorphic_spec.rb +36 -51
  549. data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +58 -75
  550. data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +131 -40
  551. data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +280 -52
  552. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +345 -370
  553. data/spec/mongoid/association/referenced/belongs_to_models.rb +13 -0
  554. data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +57 -0
  555. data/spec/mongoid/association/referenced/belongs_to_spec.rb +171 -329
  556. data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +45 -56
  557. data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +66 -29
  558. data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +75 -36
  559. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +28 -8
  560. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +1151 -1283
  561. data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +69 -2
  562. data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +39 -0
  563. data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +176 -166
  564. data/spec/mongoid/association/referenced/has_many/binding_spec.rb +32 -43
  565. data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +161 -24
  566. data/spec/mongoid/association/referenced/has_many/eager_spec.rb +169 -67
  567. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +1021 -689
  568. data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -1
  569. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +1743 -1955
  570. data/spec/mongoid/association/referenced/has_many_models.rb +85 -1
  571. data/spec/mongoid/association/referenced/has_many_query_spec.rb +37 -0
  572. data/spec/mongoid/association/referenced/has_many_spec.rb +83 -178
  573. data/spec/mongoid/association/referenced/has_many_through/eager_spec.rb +58 -0
  574. data/spec/mongoid/association/referenced/has_many_through/proxy_spec.rb +62 -0
  575. data/spec/mongoid/association/referenced/has_many_through_spec.rb +399 -0
  576. data/spec/mongoid/association/referenced/has_one/binding_spec.rb +28 -37
  577. data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +74 -28
  578. data/spec/mongoid/association/referenced/has_one/eager_spec.rb +60 -42
  579. data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +380 -333
  580. data/spec/mongoid/association/referenced/has_one_models.rb +73 -0
  581. data/spec/mongoid/association/referenced/has_one_query_spec.rb +37 -0
  582. data/spec/mongoid/association/referenced/has_one_spec.rb +61 -185
  583. data/spec/mongoid/association/referenced/has_one_through/eager_spec.rb +58 -0
  584. data/spec/mongoid/association/referenced/has_one_through/proxy_spec.rb +49 -0
  585. data/spec/mongoid/association/referenced/has_one_through_spec.rb +211 -0
  586. data/spec/mongoid/association/reflections_spec.rb +16 -23
  587. data/spec/mongoid/association/syncable_spec.rb +132 -138
  588. data/spec/mongoid/association_spec.rb +59 -65
  589. data/spec/mongoid/atomic/modifiers_spec.rb +217 -180
  590. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +41 -51
  591. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +37 -48
  592. data/spec/mongoid/atomic/paths/root_spec.rb +11 -14
  593. data/spec/mongoid/atomic/paths_spec.rb +133 -128
  594. data/spec/mongoid/atomic_spec.rb +187 -154
  595. data/spec/mongoid/atomic_update_preparer_spec.rb +83 -0
  596. data/spec/mongoid/attributes/dynamic_spec.rb +5 -6
  597. data/spec/mongoid/attributes/embedded_spec.rb +118 -0
  598. data/spec/mongoid/attributes/nested_spec.rb +1604 -1737
  599. data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
  600. data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
  601. data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
  602. data/spec/mongoid/attributes/projector_spec.rb +37 -0
  603. data/spec/mongoid/attributes/readonly_spec.rb +106 -108
  604. data/spec/mongoid/attributes_spec.rb +1217 -715
  605. data/spec/mongoid/cacheable_spec.rb +78 -45
  606. data/spec/mongoid/changeable_spec.rb +914 -638
  607. data/spec/mongoid/clients/factory_spec.rb +314 -137
  608. data/spec/mongoid/clients/options_spec.rb +205 -76
  609. data/spec/mongoid/clients/sessions_spec.rb +73 -116
  610. data/spec/mongoid/clients/transactions_spec.rb +1128 -186
  611. data/spec/mongoid/clients/transactions_spec_models.rb +251 -0
  612. data/spec/mongoid/clients_spec.rb +433 -312
  613. data/spec/mongoid/collection_configurable_spec.rb +156 -0
  614. data/spec/mongoid/composable_spec.rb +4 -8
  615. data/spec/mongoid/config/defaults_spec.rb +125 -0
  616. data/spec/mongoid/config/encryption_spec.rb +377 -0
  617. data/spec/mongoid/config/environment_spec.rb +129 -49
  618. data/spec/mongoid/config/introspection_spec.rb +119 -0
  619. data/spec/mongoid/config/options_spec.rb +36 -23
  620. data/spec/mongoid/config_spec.rb +497 -148
  621. data/spec/mongoid/contextual/aggregable/memory_spec.rb +507 -161
  622. data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
  623. data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +60 -0
  624. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +242 -158
  625. data/spec/mongoid/contextual/aggregable/none_spec.rb +47 -0
  626. data/spec/mongoid/contextual/atomic_spec.rb +510 -229
  627. data/spec/mongoid/contextual/map_reduce_spec.rb +114 -153
  628. data/spec/mongoid/contextual/memory_spec.rb +1947 -563
  629. data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +193 -0
  630. data/spec/mongoid/contextual/mongo_spec.rb +3317 -1268
  631. data/spec/mongoid/contextual/none_spec.rb +98 -89
  632. data/spec/mongoid/contextual/short_circuit_spec.rb +139 -0
  633. data/spec/mongoid/copyable_spec.rb +769 -191
  634. data/spec/mongoid/copyable_spec_models.rb +30 -0
  635. data/spec/mongoid/criteria/findable_spec.rb +565 -506
  636. data/spec/mongoid/criteria/includable_spec.rb +2417 -0
  637. data/spec/mongoid/criteria/includable_spec_models.rb +64 -0
  638. data/spec/mongoid/criteria/inspectable_spec.rb +13 -13
  639. data/spec/mongoid/criteria/marshalable_spec.rb +29 -12
  640. data/spec/mongoid/criteria/modifiable_spec.rb +388 -530
  641. data/spec/mongoid/criteria/options_spec.rb +4 -6
  642. data/spec/mongoid/criteria/queryable/aggregable_spec.rb +114 -140
  643. data/spec/mongoid/criteria/queryable/expandable_spec.rb +59 -0
  644. data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +132 -198
  645. data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +199 -25
  646. data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +86 -116
  647. data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +69 -67
  648. data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +121 -113
  649. data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +96 -32
  650. data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +105 -152
  651. data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +97 -33
  652. data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +27 -37
  653. data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +79 -15
  654. data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +34 -53
  655. data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +259 -191
  656. data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +18 -34
  657. data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +16 -33
  658. data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +14 -18
  659. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +91 -189
  660. data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +34 -100
  661. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +99 -103
  662. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +78 -85
  663. data/spec/mongoid/criteria/queryable/key_spec.rb +34 -35
  664. data/spec/mongoid/criteria/queryable/mergeable_spec.rb +150 -21
  665. data/spec/mongoid/criteria/queryable/optional_spec.rb +375 -954
  666. data/spec/mongoid/criteria/queryable/options_spec.rb +175 -123
  667. data/spec/mongoid/criteria/queryable/pipeline_spec.rb +67 -86
  668. data/spec/mongoid/criteria/queryable/queryable_spec.rb +43 -52
  669. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +2101 -414
  670. data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +35 -0
  671. data/spec/mongoid/criteria/queryable/selectable_spec.rb +1283 -3140
  672. data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +754 -0
  673. data/spec/mongoid/criteria/queryable/selector_spec.rb +404 -317
  674. data/spec/mongoid/criteria/queryable/smash_spec.rb +8 -10
  675. data/spec/mongoid/criteria/queryable/storable_spec.rb +249 -0
  676. data/spec/mongoid/criteria/queryable_mql_spec.rb +92 -0
  677. data/spec/mongoid/criteria/scopable_spec.rb +212 -118
  678. data/spec/mongoid/criteria/translator_spec.rb +132 -0
  679. data/spec/mongoid/criteria_projection_spec.rb +389 -0
  680. data/spec/mongoid/criteria_spec.rb +1942 -2301
  681. data/spec/mongoid/document_fields_spec.rb +187 -14
  682. data/spec/mongoid/document_persistence_context_spec.rb +80 -6
  683. data/spec/mongoid/document_query_spec.rb +87 -0
  684. data/spec/mongoid/document_spec.rb +394 -538
  685. data/spec/mongoid/encryptable_spec.rb +61 -0
  686. data/spec/mongoid/equality_spec.rb +77 -103
  687. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +10 -10
  688. data/spec/mongoid/errors/attribute_not_loaded_spec.rb +29 -0
  689. data/spec/mongoid/errors/callback_spec.rb +10 -10
  690. data/spec/mongoid/errors/config_redactor_spec.rb +112 -0
  691. data/spec/mongoid/errors/delete_restriction_spec.rb +9 -9
  692. data/spec/mongoid/errors/document_not_destroyed_spec.rb +9 -9
  693. data/spec/mongoid/errors/document_not_found_spec.rb +108 -32
  694. data/spec/mongoid/errors/invalid_collection_spec.rb +11 -12
  695. data/spec/mongoid/errors/invalid_config_file_spec.rb +29 -0
  696. data/spec/mongoid/errors/invalid_config_option_spec.rb +10 -10
  697. data/spec/mongoid/errors/invalid_field_option_spec.rb +9 -9
  698. data/spec/mongoid/errors/invalid_field_spec.rb +13 -11
  699. data/spec/mongoid/errors/invalid_field_type_spec.rb +53 -0
  700. data/spec/mongoid/errors/invalid_find_spec.rb +10 -10
  701. data/spec/mongoid/errors/invalid_includes_spec.rb +11 -12
  702. data/spec/mongoid/errors/invalid_index_spec.rb +10 -10
  703. data/spec/mongoid/errors/invalid_options_spec.rb +10 -10
  704. data/spec/mongoid/errors/invalid_path_spec.rb +9 -9
  705. data/spec/mongoid/errors/invalid_relation_spec.rb +17 -15
  706. data/spec/mongoid/errors/invalid_scope_spec.rb +10 -10
  707. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +5 -5
  708. data/spec/mongoid/errors/invalid_storage_options_spec.rb +10 -10
  709. data/spec/mongoid/errors/invalid_time_spec.rb +10 -10
  710. data/spec/mongoid/errors/inverse_not_found_spec.rb +11 -11
  711. data/spec/mongoid/errors/mixed_client_configuration_spec.rb +42 -11
  712. data/spec/mongoid/errors/mixed_relations_spec.rb +10 -10
  713. data/spec/mongoid/errors/mongoid_error_spec.rb +23 -23
  714. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +10 -10
  715. data/spec/mongoid/errors/no_client_config_spec.rb +11 -11
  716. data/spec/mongoid/errors/no_client_database_spec.rb +40 -11
  717. data/spec/mongoid/errors/no_client_hosts_spec.rb +37 -11
  718. data/spec/mongoid/errors/no_clients_config_spec.rb +9 -9
  719. data/spec/mongoid/errors/no_environment_spec.rb +10 -10
  720. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +10 -10
  721. data/spec/mongoid/errors/no_metadata_spec.rb +9 -9
  722. data/spec/mongoid/errors/no_parent_spec.rb +10 -10
  723. data/spec/mongoid/errors/readonly_association_spec.rb +34 -0
  724. data/spec/mongoid/errors/readonly_attribute_spec.rb +9 -9
  725. data/spec/mongoid/errors/readonly_document_spec.rb +9 -9
  726. data/spec/mongoid/errors/scope_overwrite_spec.rb +11 -11
  727. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +11 -11
  728. data/spec/mongoid/errors/unknown_attribute_spec.rb +9 -9
  729. data/spec/mongoid/errors/unsaved_document_spec.rb +10 -10
  730. data/spec/mongoid/errors/unsupported_javascript_spec.rb +11 -11
  731. data/spec/mongoid/errors/validations_spec.rb +13 -13
  732. data/spec/mongoid/extensions/array_spec.rb +92 -377
  733. data/spec/mongoid/extensions/big_decimal_spec.rb +640 -217
  734. data/spec/mongoid/extensions/binary_spec.rb +50 -23
  735. data/spec/mongoid/extensions/boolean_spec.rb +73 -107
  736. data/spec/mongoid/extensions/date_class_mongoize_spec.rb +329 -0
  737. data/spec/mongoid/extensions/date_spec.rb +62 -173
  738. data/spec/mongoid/extensions/date_time_spec.rb +42 -95
  739. data/spec/mongoid/extensions/decimal128_spec.rb +14 -17
  740. data/spec/mongoid/extensions/false_class_spec.rb +13 -24
  741. data/spec/mongoid/extensions/float_spec.rb +66 -100
  742. data/spec/mongoid/extensions/hash_spec.rb +79 -165
  743. data/spec/mongoid/extensions/integer_spec.rb +63 -91
  744. data/spec/mongoid/extensions/module_spec.rb +15 -17
  745. data/spec/mongoid/extensions/nil_class_spec.rb +4 -4
  746. data/spec/mongoid/extensions/object_id_spec.rb +161 -246
  747. data/spec/mongoid/extensions/object_spec.rb +36 -238
  748. data/spec/mongoid/extensions/range_spec.rb +259 -69
  749. data/spec/mongoid/extensions/raw_value_spec.rb +65 -0
  750. data/spec/mongoid/extensions/regexp_spec.rb +56 -41
  751. data/spec/mongoid/extensions/set_spec.rb +110 -14
  752. data/spec/mongoid/extensions/string_spec.rb +139 -237
  753. data/spec/mongoid/extensions/stringified_symbol_spec.rb +71 -0
  754. data/spec/mongoid/extensions/symbol_spec.rb +19 -62
  755. data/spec/mongoid/extensions/time_spec.rb +394 -192
  756. data/spec/mongoid/extensions/time_with_zone_spec.rb +111 -176
  757. data/spec/mongoid/extensions/true_class_spec.rb +13 -24
  758. data/spec/mongoid/extensions/vector_spec.rb +175 -0
  759. data/spec/mongoid/factory_spec.rb +378 -80
  760. data/spec/mongoid/fields/foreign_key_spec.rb +387 -267
  761. data/spec/mongoid/fields/localized_spec.rb +197 -196
  762. data/spec/mongoid/fields/standard_spec.rb +45 -58
  763. data/spec/mongoid/fields_spec.rb +1448 -525
  764. data/spec/mongoid/findable_spec.rb +659 -230
  765. data/spec/mongoid/indexable/specification_spec.rb +145 -40
  766. data/spec/mongoid/indexable_spec.rb +551 -188
  767. data/spec/mongoid/inspectable_spec.rb +126 -18
  768. data/spec/mongoid/interceptable_spec.rb +1431 -573
  769. data/spec/mongoid/interceptable_spec_models.rb +244 -0
  770. data/spec/mongoid/loadable_spec.rb +86 -0
  771. data/spec/mongoid/loading_spec.rb +114 -0
  772. data/spec/mongoid/loggable_spec.rb +5 -5
  773. data/spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml +104 -0
  774. data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +239 -0
  775. data/spec/mongoid/matcher/extract_attribute_spec.rb +33 -0
  776. data/spec/mongoid/matcher/regexp_budget_spec.rb +570 -0
  777. data/spec/mongoid/model_resolver_spec.rb +167 -0
  778. data/spec/mongoid/mongoizable_spec.rb +277 -0
  779. data/spec/mongoid/monkey_patches_spec.rb +215 -0
  780. data/spec/mongoid/persistable/creatable_spec.rb +256 -209
  781. data/spec/mongoid/persistable/deletable_spec.rb +369 -80
  782. data/spec/mongoid/persistable/destroyable_spec.rb +439 -80
  783. data/spec/mongoid/persistable/incrementable_spec.rb +112 -77
  784. data/spec/mongoid/persistable/logical_spec.rb +92 -51
  785. data/spec/mongoid/persistable/maxable_spec.rb +148 -0
  786. data/spec/mongoid/persistable/minable_spec.rb +148 -0
  787. data/spec/mongoid/persistable/multipliable_spec.rb +212 -0
  788. data/spec/mongoid/persistable/poppable_spec.rb +87 -47
  789. data/spec/mongoid/persistable/pullable_spec.rb +161 -82
  790. data/spec/mongoid/persistable/pushable_spec.rb +188 -110
  791. data/spec/mongoid/persistable/renamable_spec.rb +91 -51
  792. data/spec/mongoid/persistable/savable_spec.rb +373 -155
  793. data/spec/mongoid/persistable/settable_spec.rb +164 -134
  794. data/spec/mongoid/persistable/unsettable_spec.rb +94 -58
  795. data/spec/mongoid/persistable/updatable_spec.rb +235 -267
  796. data/spec/mongoid/persistable/upsertable_spec.rb +150 -38
  797. data/spec/mongoid/persistable_spec.rb +198 -128
  798. data/spec/mongoid/persistence_context_spec.rb +133 -137
  799. data/spec/mongoid/positional_spec.rb +69 -78
  800. data/spec/mongoid/railties/bson_object_id_serializer_spec.rb +27 -0
  801. data/spec/mongoid/railties/console_sandbox_spec.rb +43 -0
  802. data/spec/mongoid/relations/proxy_spec.rb +8 -6
  803. data/spec/mongoid/reloadable_spec.rb +552 -123
  804. data/spec/mongoid/scopable_spec.rb +522 -455
  805. data/spec/mongoid/search_indexable_spec.rb +838 -0
  806. data/spec/mongoid/selectable_spec.rb +41 -53
  807. data/spec/mongoid/serializable_spec.rb +394 -319
  808. data/spec/mongoid/shardable_models.rb +76 -0
  809. data/spec/mongoid/shardable_spec.rb +245 -41
  810. data/spec/mongoid/stateful_spec.rb +170 -45
  811. data/spec/mongoid/tasks/database_rake_spec.rb +284 -133
  812. data/spec/mongoid/tasks/database_spec.rb +245 -51
  813. data/spec/mongoid/tasks/encryption_spec.rb +189 -0
  814. data/spec/mongoid/threaded_spec.rb +118 -85
  815. data/spec/mongoid/timestamps/created/short_spec.rb +15 -16
  816. data/spec/mongoid/timestamps/created_spec.rb +36 -14
  817. data/spec/mongoid/timestamps/timeless_spec.rb +230 -47
  818. data/spec/mongoid/timestamps/updated/short_spec.rb +26 -30
  819. data/spec/mongoid/timestamps/updated_spec.rb +23 -27
  820. data/spec/mongoid/timestamps_spec.rb +408 -34
  821. data/spec/mongoid/timestamps_spec_models.rb +67 -0
  822. data/spec/mongoid/touchable_spec.rb +1235 -136
  823. data/spec/mongoid/touchable_spec_models.rb +178 -0
  824. data/spec/mongoid/traversable_spec.rb +1188 -79
  825. data/spec/mongoid/validatable/associated_spec.rb +86 -89
  826. data/spec/mongoid/validatable/format_spec.rb +26 -33
  827. data/spec/mongoid/validatable/length_spec.rb +64 -85
  828. data/spec/mongoid/validatable/numericality_spec.rb +124 -14
  829. data/spec/mongoid/validatable/presence_spec.rb +168 -215
  830. data/spec/mongoid/validatable/uniqueness_spec.rb +702 -826
  831. data/spec/mongoid/validatable_spec.rb +76 -105
  832. data/spec/mongoid/warnings_spec.rb +32 -0
  833. data/spec/mongoid_spec.rb +67 -30
  834. data/spec/rails/controller_extension/controller_runtime_spec.rb +59 -60
  835. data/spec/rails/mongoid_spec.rb +38 -139
  836. data/spec/shared/CANDIDATE.md +28 -0
  837. data/spec/shared/bin/s3-copy +45 -0
  838. data/spec/shared/bin/s3-upload +69 -0
  839. data/spec/shared/lib/mrss/cluster_config.rb +16 -41
  840. data/spec/shared/lib/mrss/constraints.rb +44 -59
  841. data/spec/shared/lib/mrss/docker_runner.rb +42 -20
  842. data/spec/shared/lib/mrss/eg_config_utils.rb +20 -0
  843. data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
  844. data/spec/shared/lib/mrss/lite_constraints.rb +48 -1
  845. data/spec/shared/lib/mrss/release/candidate.rb +287 -0
  846. data/spec/shared/lib/mrss/release/product_data.rb +144 -0
  847. data/spec/shared/lib/mrss/server_version_registry.rb +18 -24
  848. data/spec/shared/lib/mrss/session_registry.rb +69 -0
  849. data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
  850. data/spec/shared/lib/mrss/spec_organizer.rb +48 -2
  851. data/spec/shared/lib/mrss/utils.rb +28 -6
  852. data/spec/shared/lib/tasks/candidate.rake +64 -0
  853. data/spec/shared/share/Dockerfile.erb +114 -96
  854. data/spec/shared/share/haproxy-1.conf +16 -0
  855. data/spec/shared/share/haproxy-2.conf +17 -0
  856. data/spec/shared/shlib/config.sh +27 -0
  857. data/spec/shared/shlib/distro.sh +12 -1
  858. data/spec/shared/shlib/server.sh +148 -65
  859. data/spec/shared/shlib/set_env.sh +56 -80
  860. data/spec/spec_helper.rb +104 -72
  861. data/spec/support/authorization.rb +2 -0
  862. data/spec/support/client_registry.rb +9 -0
  863. data/spec/support/constraints.rb +37 -22
  864. data/spec/support/crypt/models.rb +206 -0
  865. data/spec/support/crypt.rb +77 -0
  866. data/spec/support/expectations.rb +38 -17
  867. data/spec/support/feature_sandbox.rb +69 -0
  868. data/spec/support/helpers.rb +11 -0
  869. data/spec/support/immutable_ids.rb +118 -0
  870. data/spec/support/macros.rb +106 -1
  871. data/spec/support/models/account.rb +38 -0
  872. data/spec/support/models/acolyte.rb +20 -0
  873. data/spec/support/models/actor.rb +21 -0
  874. data/spec/support/models/actress.rb +4 -0
  875. data/spec/support/models/address.rb +88 -0
  876. data/spec/support/models/address_component.rb +8 -0
  877. data/spec/support/models/address_number.rb +9 -0
  878. data/spec/support/models/agency.rb +8 -0
  879. data/spec/support/models/agent.rb +19 -0
  880. data/spec/support/models/album.rb +20 -0
  881. data/spec/support/models/alert.rb +10 -0
  882. data/spec/support/models/animal.rb +28 -0
  883. data/spec/support/models/answer.rb +9 -0
  884. data/spec/support/models/appointment.rb +10 -0
  885. data/spec/support/models/armrest.rb +9 -0
  886. data/spec/support/models/article.rb +14 -0
  887. data/spec/support/models/artist.rb +95 -0
  888. data/spec/support/models/artwork.rb +7 -0
  889. data/spec/support/models/audible_sound.rb +3 -0
  890. data/spec/support/models/audio.rb +8 -0
  891. data/spec/support/models/augmentation.rb +25 -0
  892. data/spec/support/models/author.rb +9 -0
  893. data/spec/support/models/baby.rb +7 -0
  894. data/spec/support/models/band.rb +46 -0
  895. data/spec/support/models/bar.rb +13 -0
  896. data/spec/support/models/basic.rb +8 -0
  897. data/spec/support/models/bed.rb +3 -0
  898. data/spec/support/models/big_palette.rb +4 -0
  899. data/spec/support/models/birthday.rb +14 -0
  900. data/spec/support/models/bolt.rb +7 -0
  901. data/spec/support/models/bomb.rb +7 -0
  902. data/spec/support/models/book.rb +20 -0
  903. data/spec/support/models/breed.rb +7 -0
  904. data/spec/support/models/browser.rb +8 -0
  905. data/spec/support/models/building.rb +10 -0
  906. data/spec/support/models/building_address.rb +10 -0
  907. data/spec/support/models/bus.rb +10 -0
  908. data/spec/support/models/business.rb +8 -0
  909. data/spec/support/models/callback_test.rb +12 -0
  910. data/spec/support/models/canvas.rb +27 -0
  911. data/spec/support/models/car.rb +3 -0
  912. data/spec/support/models/cat.rb +9 -0
  913. data/spec/support/models/catalog.rb +24 -0
  914. data/spec/support/models/category.rb +11 -0
  915. data/spec/support/models/child.rb +7 -0
  916. data/spec/support/models/child_doc.rb +24 -0
  917. data/spec/support/models/church.rb +9 -0
  918. data/spec/support/models/circle.rb +5 -0
  919. data/spec/support/models/circuit.rb +7 -0
  920. data/spec/support/models/circus.rb +12 -0
  921. data/spec/support/models/code.rb +17 -0
  922. data/spec/support/models/coding/pull_request.rb +11 -0
  923. data/spec/support/models/coding.rb +3 -0
  924. data/spec/support/models/comment.rb +18 -0
  925. data/spec/support/models/company.rb +9 -0
  926. data/spec/support/models/consumption_period.rb +9 -0
  927. data/spec/support/models/contextable_item.rb +8 -0
  928. data/spec/support/models/contractor.rb +8 -0
  929. data/spec/support/models/cookie.rb +8 -0
  930. data/spec/support/models/country_code.rb +12 -0
  931. data/spec/support/models/courier_job.rb +7 -0
  932. data/spec/support/models/cover.rb +10 -0
  933. data/spec/support/models/crate.rb +12 -0
  934. data/spec/support/models/customer.rb +10 -0
  935. data/spec/support/models/customer_address.rb +11 -0
  936. data/spec/support/models/deed.rb +8 -0
  937. data/spec/support/models/definition.rb +12 -0
  938. data/spec/support/models/delegating_patient.rb +15 -0
  939. data/spec/support/models/description.rb +13 -0
  940. data/spec/support/models/dictionary.rb +19 -0
  941. data/spec/support/models/division.rb +13 -0
  942. data/spec/support/models/doctor.rb +14 -0
  943. data/spec/support/models/dog.rb +10 -0
  944. data/spec/support/models/dokument.rb +9 -0
  945. data/spec/support/models/draft.rb +11 -0
  946. data/spec/support/models/dragon.rb +7 -0
  947. data/spec/support/models/driver.rb +10 -0
  948. data/spec/support/models/drug.rb +9 -0
  949. data/spec/support/models/dungeon.rb +7 -0
  950. data/spec/support/models/edit.rb +8 -0
  951. data/spec/support/models/email.rb +9 -0
  952. data/spec/support/models/employer.rb +7 -0
  953. data/spec/support/models/entry.rb +9 -0
  954. data/spec/support/models/eraser.rb +3 -0
  955. data/spec/support/models/even.rb +10 -0
  956. data/spec/support/models/event.rb +24 -0
  957. data/spec/support/models/exhibition.rb +7 -0
  958. data/spec/support/models/exhibitor.rb +9 -0
  959. data/spec/support/models/explosion.rb +7 -0
  960. data/spec/support/models/eye.rb +11 -0
  961. data/spec/support/models/eye_bowl.rb +11 -0
  962. data/spec/support/models/face.rb +10 -0
  963. data/spec/support/models/fanatic.rb +9 -0
  964. data/spec/support/models/favorite.rb +15 -0
  965. data/spec/support/models/filesystem.rb +8 -0
  966. data/spec/support/models/fire_hydrant.rb +9 -0
  967. data/spec/support/models/firefox.rb +6 -0
  968. data/spec/support/models/fish.rb +9 -0
  969. data/spec/support/models/folder.rb +8 -0
  970. data/spec/support/models/folder_item.rb +10 -0
  971. data/spec/support/models/fruits.rb +41 -0
  972. data/spec/support/models/game.rb +21 -0
  973. data/spec/support/models/ghost.rb +9 -0
  974. data/spec/support/models/guitar.rb +4 -0
  975. data/spec/support/models/hole.rb +12 -0
  976. data/spec/support/models/home.rb +7 -0
  977. data/spec/support/models/house.rb +9 -0
  978. data/spec/support/models/html_writer.rb +5 -0
  979. data/spec/support/models/id_key.rb +9 -0
  980. data/spec/support/models/idnodef.rb +7 -0
  981. data/spec/support/models/image.rb +24 -0
  982. data/spec/support/models/implant.rb +27 -0
  983. data/spec/support/models/instrument.rb +8 -0
  984. data/spec/support/models/item.rb +11 -0
  985. data/spec/support/models/jar.rb +9 -0
  986. data/spec/support/models/kaleidoscope.rb +9 -0
  987. data/spec/support/models/kangaroo.rb +7 -0
  988. data/spec/support/models/label.rb +53 -0
  989. data/spec/support/models/language.rb +8 -0
  990. data/spec/support/models/lat_lng.rb +23 -0
  991. data/spec/support/models/league.rb +14 -0
  992. data/spec/support/models/learner.rb +4 -0
  993. data/spec/support/models/line_item.rb +9 -0
  994. data/spec/support/models/location.rb +11 -0
  995. data/spec/support/models/login.rb +10 -0
  996. data/spec/support/models/manufacturer.rb +9 -0
  997. data/spec/support/models/meat.rb +7 -0
  998. data/spec/support/models/membership.rb +8 -0
  999. data/spec/support/models/message.rb +13 -0
  1000. data/spec/support/models/minim.rb +6 -0
  1001. data/spec/support/models/mixed_drink.rb +7 -0
  1002. data/spec/support/models/modifier_models.rb +25 -0
  1003. data/spec/support/models/mop.rb +24 -0
  1004. data/spec/support/models/movie.rb +16 -0
  1005. data/spec/support/models/my_hash.rb +4 -0
  1006. data/spec/support/models/name.rb +36 -0
  1007. data/spec/support/models/name_only.rb +8 -0
  1008. data/spec/support/models/node.rb +8 -0
  1009. data/spec/support/models/note.rb +20 -0
  1010. data/spec/support/models/nut.rb +7 -0
  1011. data/spec/support/models/odd.rb +10 -0
  1012. data/spec/support/models/order.rb +13 -0
  1013. data/spec/support/models/ordered_post.rb +14 -0
  1014. data/spec/support/models/ordered_preference.rb +9 -0
  1015. data/spec/support/models/oscar.rb +17 -0
  1016. data/spec/support/models/other_owner_object.rb +4 -0
  1017. data/spec/support/models/override.rb +11 -0
  1018. data/spec/support/models/ownable.rb +9 -0
  1019. data/spec/support/models/owner.rb +11 -0
  1020. data/spec/support/models/pack.rb +5 -0
  1021. data/spec/support/models/page.rb +19 -0
  1022. data/spec/support/models/page_question.rb +7 -0
  1023. data/spec/support/models/palette.rb +10 -0
  1024. data/spec/support/models/parent.rb +8 -0
  1025. data/spec/support/models/parent_doc.rb +9 -0
  1026. data/spec/support/models/passport.rb +23 -0
  1027. data/spec/support/models/patient.rb +12 -0
  1028. data/spec/support/models/pdf_writer.rb +5 -0
  1029. data/spec/support/models/pencil.rb +3 -0
  1030. data/spec/support/models/person.rb +237 -0
  1031. data/spec/support/models/pet.rb +26 -0
  1032. data/spec/support/models/pet_owner.rb +9 -0
  1033. data/spec/support/models/phone.rb +13 -0
  1034. data/spec/support/models/piano.rb +4 -0
  1035. data/spec/support/models/pizza.rb +10 -0
  1036. data/spec/support/models/player.rb +40 -0
  1037. data/spec/support/models/post.rb +53 -0
  1038. data/spec/support/models/post_genre.rb +9 -0
  1039. data/spec/support/models/powerup.rb +25 -0
  1040. data/spec/support/models/preference.rb +12 -0
  1041. data/spec/support/models/princess.rb +13 -0
  1042. data/spec/support/models/product.rb +23 -0
  1043. data/spec/support/models/profile.rb +19 -0
  1044. data/spec/support/models/pronunciation.rb +8 -0
  1045. data/spec/support/models/pub.rb +9 -0
  1046. data/spec/support/models/publication/encyclopedia.rb +11 -0
  1047. data/spec/support/models/publication/review.rb +13 -0
  1048. data/spec/support/models/publication.rb +4 -0
  1049. data/spec/support/models/purchase.rb +7 -0
  1050. data/spec/support/models/purchased_item.rb +11 -0
  1051. data/spec/support/models/purse.rb +9 -0
  1052. data/spec/support/models/question.rb +11 -0
  1053. data/spec/support/models/quiz.rb +10 -0
  1054. data/spec/support/models/rating.rb +11 -0
  1055. data/spec/support/models/record.rb +54 -0
  1056. data/spec/support/models/registry.rb +8 -0
  1057. data/spec/support/models/role.rb +10 -0
  1058. data/spec/support/models/root_category.rb +7 -0
  1059. data/spec/support/models/sandbox/app/models/app_models_message.rb +3 -0
  1060. data/spec/support/models/sandbox/lib/models/lib_models_message.rb +3 -0
  1061. data/spec/support/models/sandbox/sandbox_message.rb +3 -0
  1062. data/spec/support/models/sandbox/sandbox_user.rb +3 -0
  1063. data/spec/support/models/sandbox/subdir/sandbox_comment.rb +3 -0
  1064. data/spec/support/models/sandwich.rb +12 -0
  1065. data/spec/support/models/scheduler.rb +9 -0
  1066. data/spec/support/models/school.rb +14 -0
  1067. data/spec/support/models/scribe.rb +8 -0
  1068. data/spec/support/models/sealer.rb +7 -0
  1069. data/spec/support/models/seat.rb +24 -0
  1070. data/spec/support/models/seo.rb +12 -0
  1071. data/spec/support/models/series.rb +8 -0
  1072. data/spec/support/models/server.rb +16 -0
  1073. data/spec/support/models/service.rb +25 -0
  1074. data/spec/support/models/shape.rb +15 -0
  1075. data/spec/support/models/shelf.rb +8 -0
  1076. data/spec/support/models/shield.rb +19 -0
  1077. data/spec/support/models/shipment_address.rb +5 -0
  1078. data/spec/support/models/shipping_container.rb +8 -0
  1079. data/spec/support/models/shipping_pack.rb +5 -0
  1080. data/spec/support/models/shirt.rb +11 -0
  1081. data/spec/support/models/shop.rb +9 -0
  1082. data/spec/support/models/short_agent.rb +6 -0
  1083. data/spec/support/models/short_quiz.rb +8 -0
  1084. data/spec/support/models/simple.rb +8 -0
  1085. data/spec/support/models/slave.rb +9 -0
  1086. data/spec/support/models/song.rb +10 -0
  1087. data/spec/support/models/sound.rb +8 -0
  1088. data/spec/support/models/spacer.rb +7 -0
  1089. data/spec/support/models/square.rb +6 -0
  1090. data/spec/support/models/staff.rb +9 -0
  1091. data/spec/support/models/store_as_dup_test1.rb +8 -0
  1092. data/spec/support/models/store_as_dup_test2.rb +8 -0
  1093. data/spec/support/models/store_as_dup_test3.rb +8 -0
  1094. data/spec/support/models/store_as_dup_test4.rb +8 -0
  1095. data/spec/support/models/strategy.rb +5 -0
  1096. data/spec/support/models/student.rb +14 -0
  1097. data/spec/support/models/sub_item.rb +5 -0
  1098. data/spec/support/models/subscription.rb +8 -0
  1099. data/spec/support/models/survey.rb +8 -0
  1100. data/spec/support/models/symptom.rb +9 -0
  1101. data/spec/support/models/system_role.rb +7 -0
  1102. data/spec/support/models/tag.rb +11 -0
  1103. data/spec/support/models/target.rb +8 -0
  1104. data/spec/support/models/template.rb +8 -0
  1105. data/spec/support/models/thing.rb +12 -0
  1106. data/spec/support/models/threadlocker.rb +7 -0
  1107. data/spec/support/models/title.rb +5 -0
  1108. data/spec/support/models/tool.rb +11 -0
  1109. data/spec/support/models/topping.rb +8 -0
  1110. data/spec/support/models/toy.rb +9 -0
  1111. data/spec/support/models/track.rb +41 -0
  1112. data/spec/support/models/translation.rb +8 -0
  1113. data/spec/support/models/tree.rb +11 -0
  1114. data/spec/support/models/truck.rb +7 -0
  1115. data/spec/support/models/user.rb +23 -0
  1116. data/spec/support/models/user_account.rb +13 -0
  1117. data/spec/support/models/validation_callback.rb +13 -0
  1118. data/spec/support/models/vehicle.rb +18 -0
  1119. data/spec/support/models/version.rb +8 -0
  1120. data/spec/support/models/vertex.rb +8 -0
  1121. data/spec/support/models/vet_visit.rb +8 -0
  1122. data/spec/support/models/video.rb +16 -0
  1123. data/spec/support/models/video_game.rb +3 -0
  1124. data/spec/support/models/washer.rb +7 -0
  1125. data/spec/support/models/weapon.rb +25 -0
  1126. data/spec/support/models/wiki_page.rb +17 -0
  1127. data/spec/support/models/word.rb +18 -0
  1128. data/spec/support/models/word_origin.rb +13 -0
  1129. data/spec/support/models/writer.rb +14 -0
  1130. data/spec/support/rails_mock.rb +27 -0
  1131. data/spec/support/schema_maps/schema_map_aws.json +17 -0
  1132. data/spec/support/schema_maps/schema_map_aws_key_alt_names.json +12 -0
  1133. data/spec/support/schema_maps/schema_map_azure.json +17 -0
  1134. data/spec/support/schema_maps/schema_map_azure_key_alt_names.json +12 -0
  1135. data/spec/support/schema_maps/schema_map_gcp.json +17 -0
  1136. data/spec/support/schema_maps/schema_map_gcp_key_alt_names.json +12 -0
  1137. data/spec/support/schema_maps/schema_map_kmip.json +17 -0
  1138. data/spec/support/schema_maps/schema_map_kmip_key_alt_names.json +12 -0
  1139. data/spec/support/schema_maps/schema_map_local.json +18 -0
  1140. data/spec/support/schema_maps/schema_map_local_key_alt_names.json +12 -0
  1141. data/spec/support/shared/time.rb +34 -0
  1142. data/spec/support/sinatra_mock.rb +9 -0
  1143. data/spec/support/spec_config.rb +45 -14
  1144. metadata +1341 -780
  1145. checksums.yaml.gz.sig +0 -0
  1146. data/lib/mongoid/association/referenced/eager.rb +0 -162
  1147. data/lib/mongoid/association/referenced/has_one/nested_builder.rb +0 -126
  1148. data/lib/mongoid/contextual/geo_near.rb +0 -267
  1149. data/lib/mongoid/criteria/queryable/forwardable.rb +0 -65
  1150. data/lib/mongoid/errors/eager_load.rb +0 -22
  1151. data/lib/mongoid/errors/invalid_session_use.rb +0 -24
  1152. data/lib/mongoid/errors/invalid_storage_parent.rb +0 -26
  1153. data/lib/mongoid/errors/invalid_value.rb +0 -16
  1154. data/lib/mongoid/matchable/all.rb +0 -28
  1155. data/lib/mongoid/matchable/and.rb +0 -30
  1156. data/lib/mongoid/matchable/default.rb +0 -119
  1157. data/lib/mongoid/matchable/elem_match.rb +0 -34
  1158. data/lib/mongoid/matchable/eq.rb +0 -22
  1159. data/lib/mongoid/matchable/exists.rb +0 -23
  1160. data/lib/mongoid/matchable/gt.rb +0 -23
  1161. data/lib/mongoid/matchable/gte.rb +0 -23
  1162. data/lib/mongoid/matchable/in.rb +0 -24
  1163. data/lib/mongoid/matchable/lt.rb +0 -23
  1164. data/lib/mongoid/matchable/lte.rb +0 -23
  1165. data/lib/mongoid/matchable/ne.rb +0 -21
  1166. data/lib/mongoid/matchable/nin.rb +0 -22
  1167. data/lib/mongoid/matchable/nor.rb +0 -37
  1168. data/lib/mongoid/matchable/or.rb +0 -33
  1169. data/lib/mongoid/matchable/regexp.rb +0 -27
  1170. data/lib/mongoid/matchable/size.rb +0 -21
  1171. data/lib/mongoid/query_cache.rb +0 -331
  1172. data/lib/support/ruby_version.rb +0 -26
  1173. data/spec/app/models/account.rb +0 -36
  1174. data/spec/app/models/acolyte.rb +0 -17
  1175. data/spec/app/models/actor.rb +0 -18
  1176. data/spec/app/models/actress.rb +0 -2
  1177. data/spec/app/models/address.rb +0 -79
  1178. data/spec/app/models/address_component.rb +0 -5
  1179. data/spec/app/models/address_number.rb +0 -6
  1180. data/spec/app/models/agency.rb +0 -5
  1181. data/spec/app/models/agent.rb +0 -16
  1182. data/spec/app/models/album.rb +0 -18
  1183. data/spec/app/models/alert.rb +0 -7
  1184. data/spec/app/models/animal.rb +0 -26
  1185. data/spec/app/models/answer.rb +0 -6
  1186. data/spec/app/models/appointment.rb +0 -7
  1187. data/spec/app/models/article.rb +0 -12
  1188. data/spec/app/models/artist.rb +0 -87
  1189. data/spec/app/models/artwork.rb +0 -4
  1190. data/spec/app/models/audio.rb +0 -5
  1191. data/spec/app/models/augmentation.rb +0 -11
  1192. data/spec/app/models/author.rb +0 -6
  1193. data/spec/app/models/baby.rb +0 -4
  1194. data/spec/app/models/band.rb +0 -31
  1195. data/spec/app/models/bar.rb +0 -10
  1196. data/spec/app/models/basic.rb +0 -6
  1197. data/spec/app/models/bed.rb +0 -1
  1198. data/spec/app/models/big_palette.rb +0 -2
  1199. data/spec/app/models/birthday.rb +0 -13
  1200. data/spec/app/models/bomb.rb +0 -4
  1201. data/spec/app/models/book.rb +0 -16
  1202. data/spec/app/models/breed.rb +0 -4
  1203. data/spec/app/models/browser.rb +0 -6
  1204. data/spec/app/models/building.rb +0 -6
  1205. data/spec/app/models/building_address.rb +0 -7
  1206. data/spec/app/models/bus.rb +0 -7
  1207. data/spec/app/models/business.rb +0 -5
  1208. data/spec/app/models/callback_test.rb +0 -9
  1209. data/spec/app/models/canvas.rb +0 -25
  1210. data/spec/app/models/car.rb +0 -1
  1211. data/spec/app/models/cat.rb +0 -8
  1212. data/spec/app/models/category.rb +0 -8
  1213. data/spec/app/models/child.rb +0 -4
  1214. data/spec/app/models/child_doc.rb +0 -22
  1215. data/spec/app/models/church.rb +0 -6
  1216. data/spec/app/models/circle.rb +0 -3
  1217. data/spec/app/models/circuit.rb +0 -4
  1218. data/spec/app/models/circus.rb +0 -7
  1219. data/spec/app/models/code.rb +0 -11
  1220. data/spec/app/models/comment.rb +0 -16
  1221. data/spec/app/models/company.rb +0 -5
  1222. data/spec/app/models/consumption_period.rb +0 -7
  1223. data/spec/app/models/contextable_item.rb +0 -5
  1224. data/spec/app/models/contractor.rb +0 -5
  1225. data/spec/app/models/cookie.rb +0 -6
  1226. data/spec/app/models/country_code.rb +0 -8
  1227. data/spec/app/models/courier_job.rb +0 -4
  1228. data/spec/app/models/customer.rb +0 -11
  1229. data/spec/app/models/customer_address.rb +0 -12
  1230. data/spec/app/models/definition.rb +0 -9
  1231. data/spec/app/models/delegating_patient.rb +0 -16
  1232. data/spec/app/models/description.rb +0 -11
  1233. data/spec/app/models/dictionary.rb +0 -10
  1234. data/spec/app/models/division.rb +0 -10
  1235. data/spec/app/models/doctor.rb +0 -12
  1236. data/spec/app/models/dog.rb +0 -7
  1237. data/spec/app/models/dokument.rb +0 -6
  1238. data/spec/app/models/draft.rb +0 -9
  1239. data/spec/app/models/dragon.rb +0 -4
  1240. data/spec/app/models/driver.rb +0 -7
  1241. data/spec/app/models/drug.rb +0 -6
  1242. data/spec/app/models/dungeon.rb +0 -4
  1243. data/spec/app/models/edit.rb +0 -5
  1244. data/spec/app/models/email.rb +0 -6
  1245. data/spec/app/models/employer.rb +0 -5
  1246. data/spec/app/models/entry.rb +0 -6
  1247. data/spec/app/models/eraser.rb +0 -1
  1248. data/spec/app/models/even.rb +0 -7
  1249. data/spec/app/models/event.rb +0 -22
  1250. data/spec/app/models/exhibition.rb +0 -4
  1251. data/spec/app/models/exhibitor.rb +0 -6
  1252. data/spec/app/models/explosion.rb +0 -4
  1253. data/spec/app/models/eye.rb +0 -9
  1254. data/spec/app/models/eye_bowl.rb +0 -9
  1255. data/spec/app/models/face.rb +0 -8
  1256. data/spec/app/models/favorite.rb +0 -6
  1257. data/spec/app/models/filesystem.rb +0 -5
  1258. data/spec/app/models/fire_hydrant.rb +0 -6
  1259. data/spec/app/models/firefox.rb +0 -4
  1260. data/spec/app/models/fish.rb +0 -7
  1261. data/spec/app/models/folder.rb +0 -7
  1262. data/spec/app/models/folder_item.rb +0 -9
  1263. data/spec/app/models/fruits.rb +0 -34
  1264. data/spec/app/models/game.rb +0 -19
  1265. data/spec/app/models/ghost.rb +0 -7
  1266. data/spec/app/models/home.rb +0 -4
  1267. data/spec/app/models/house.rb +0 -6
  1268. data/spec/app/models/html_writer.rb +0 -3
  1269. data/spec/app/models/id_key.rb +0 -6
  1270. data/spec/app/models/image.rb +0 -22
  1271. data/spec/app/models/implant.rb +0 -16
  1272. data/spec/app/models/item.rb +0 -8
  1273. data/spec/app/models/jar.rb +0 -7
  1274. data/spec/app/models/kaleidoscope.rb +0 -6
  1275. data/spec/app/models/kangaroo.rb +0 -4
  1276. data/spec/app/models/label.rb +0 -47
  1277. data/spec/app/models/language.rb +0 -5
  1278. data/spec/app/models/lat_lng.rb +0 -15
  1279. data/spec/app/models/league.rb +0 -11
  1280. data/spec/app/models/learner.rb +0 -2
  1281. data/spec/app/models/line_item.rb +0 -6
  1282. data/spec/app/models/location.rb +0 -8
  1283. data/spec/app/models/login.rb +0 -8
  1284. data/spec/app/models/manufacturer.rb +0 -7
  1285. data/spec/app/models/meat.rb +0 -4
  1286. data/spec/app/models/membership.rb +0 -4
  1287. data/spec/app/models/message.rb +0 -11
  1288. data/spec/app/models/minim.rb +0 -7
  1289. data/spec/app/models/mixed_drink.rb +0 -4
  1290. data/spec/app/models/movie.rb +0 -13
  1291. data/spec/app/models/my_hash.rb +0 -2
  1292. data/spec/app/models/name.rb +0 -24
  1293. data/spec/app/models/node.rb +0 -5
  1294. data/spec/app/models/note.rb +0 -17
  1295. data/spec/app/models/odd.rb +0 -7
  1296. data/spec/app/models/ordered_post.rb +0 -11
  1297. data/spec/app/models/ordered_preference.rb +0 -6
  1298. data/spec/app/models/oscar.rb +0 -14
  1299. data/spec/app/models/other_owner_object.rb +0 -2
  1300. data/spec/app/models/override.rb +0 -16
  1301. data/spec/app/models/ownable.rb +0 -6
  1302. data/spec/app/models/owner.rb +0 -6
  1303. data/spec/app/models/pack.rb +0 -3
  1304. data/spec/app/models/page.rb +0 -16
  1305. data/spec/app/models/page_question.rb +0 -4
  1306. data/spec/app/models/palette.rb +0 -7
  1307. data/spec/app/models/parent.rb +0 -5
  1308. data/spec/app/models/parent_doc.rb +0 -6
  1309. data/spec/app/models/passport.rb +0 -5
  1310. data/spec/app/models/patient.rb +0 -9
  1311. data/spec/app/models/pdf_writer.rb +0 -3
  1312. data/spec/app/models/pencil.rb +0 -1
  1313. data/spec/app/models/person.rb +0 -210
  1314. data/spec/app/models/pet.rb +0 -23
  1315. data/spec/app/models/pet_owner.rb +0 -6
  1316. data/spec/app/models/phone.rb +0 -9
  1317. data/spec/app/models/pizza.rb +0 -7
  1318. data/spec/app/models/player.rb +0 -35
  1319. data/spec/app/models/post.rb +0 -50
  1320. data/spec/app/models/post_genre.rb +0 -6
  1321. data/spec/app/models/powerup.rb +0 -11
  1322. data/spec/app/models/preference.rb +0 -9
  1323. data/spec/app/models/princess.rb +0 -10
  1324. data/spec/app/models/product.rb +0 -17
  1325. data/spec/app/models/profile.rb +0 -5
  1326. data/spec/app/models/pronunciation.rb +0 -5
  1327. data/spec/app/models/pub.rb +0 -6
  1328. data/spec/app/models/purchase.rb +0 -4
  1329. data/spec/app/models/question.rb +0 -8
  1330. data/spec/app/models/quiz.rb +0 -7
  1331. data/spec/app/models/rating.rb +0 -8
  1332. data/spec/app/models/record.rb +0 -52
  1333. data/spec/app/models/registry.rb +0 -4
  1334. data/spec/app/models/role.rb +0 -7
  1335. data/spec/app/models/root_category.rb +0 -4
  1336. data/spec/app/models/sandwich.rb +0 -9
  1337. data/spec/app/models/scheduler.rb +0 -7
  1338. data/spec/app/models/seo.rb +0 -7
  1339. data/spec/app/models/series.rb +0 -4
  1340. data/spec/app/models/server.rb +0 -13
  1341. data/spec/app/models/service.rb +0 -22
  1342. data/spec/app/models/shape.rb +0 -12
  1343. data/spec/app/models/shelf.rb +0 -5
  1344. data/spec/app/models/shipment_address.rb +0 -3
  1345. data/spec/app/models/shipping_container.rb +0 -5
  1346. data/spec/app/models/shipping_pack.rb +0 -3
  1347. data/spec/app/models/shop.rb +0 -6
  1348. data/spec/app/models/short_agent.rb +0 -4
  1349. data/spec/app/models/short_quiz.rb +0 -5
  1350. data/spec/app/models/simple.rb +0 -5
  1351. data/spec/app/models/slave.rb +0 -6
  1352. data/spec/app/models/song.rb +0 -8
  1353. data/spec/app/models/sound.rb +0 -5
  1354. data/spec/app/models/square.rb +0 -4
  1355. data/spec/app/models/staff.rb +0 -7
  1356. data/spec/app/models/store_as_dup_test1.rb +0 -5
  1357. data/spec/app/models/store_as_dup_test2.rb +0 -5
  1358. data/spec/app/models/store_as_dup_test3.rb +0 -7
  1359. data/spec/app/models/store_as_dup_test4.rb +0 -7
  1360. data/spec/app/models/strategy.rb +0 -3
  1361. data/spec/app/models/sub_item.rb +0 -3
  1362. data/spec/app/models/subscription.rb +0 -5
  1363. data/spec/app/models/survey.rb +0 -5
  1364. data/spec/app/models/symptom.rb +0 -6
  1365. data/spec/app/models/tag.rb +0 -8
  1366. data/spec/app/models/target.rb +0 -5
  1367. data/spec/app/models/template.rb +0 -5
  1368. data/spec/app/models/thing.rb +0 -9
  1369. data/spec/app/models/title.rb +0 -3
  1370. data/spec/app/models/tool.rb +0 -8
  1371. data/spec/app/models/topping.rb +0 -5
  1372. data/spec/app/models/track.rb +0 -38
  1373. data/spec/app/models/translation.rb +0 -5
  1374. data/spec/app/models/tree.rb +0 -9
  1375. data/spec/app/models/truck.rb +0 -3
  1376. data/spec/app/models/user.rb +0 -21
  1377. data/spec/app/models/user_account.rb +0 -10
  1378. data/spec/app/models/validation_callback.rb +0 -10
  1379. data/spec/app/models/vehicle.rb +0 -11
  1380. data/spec/app/models/version.rb +0 -5
  1381. data/spec/app/models/vertex.rb +0 -6
  1382. data/spec/app/models/vet_visit.rb +0 -5
  1383. data/spec/app/models/video.rb +0 -13
  1384. data/spec/app/models/video_game.rb +0 -1
  1385. data/spec/app/models/weapon.rb +0 -11
  1386. data/spec/app/models/wiki_page.rb +0 -14
  1387. data/spec/app/models/word.rb +0 -15
  1388. data/spec/app/models/word_origin.rb +0 -11
  1389. data/spec/app/models/writer.rb +0 -11
  1390. data/spec/integration/matchable_spec.rb +0 -680
  1391. data/spec/mongoid/contextual/geo_near_spec.rb +0 -469
  1392. data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -58
  1393. data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -58
  1394. data/spec/mongoid/criteria/queryable/forwardable_spec.rb +0 -87
  1395. data/spec/mongoid/errors/eager_load_spec.rb +0 -29
  1396. data/spec/mongoid/extensions_spec.rb +0 -29
  1397. data/spec/mongoid/matchable/all_spec.rb +0 -31
  1398. data/spec/mongoid/matchable/and_spec.rb +0 -187
  1399. data/spec/mongoid/matchable/default_spec.rb +0 -137
  1400. data/spec/mongoid/matchable/elem_match_spec.rb +0 -106
  1401. data/spec/mongoid/matchable/eq_spec.rb +0 -48
  1402. data/spec/mongoid/matchable/exists_spec.rb +0 -57
  1403. data/spec/mongoid/matchable/gt_spec.rb +0 -86
  1404. data/spec/mongoid/matchable/gte_spec.rb +0 -84
  1405. data/spec/mongoid/matchable/in_spec.rb +0 -49
  1406. data/spec/mongoid/matchable/lt_spec.rb +0 -85
  1407. data/spec/mongoid/matchable/lte_spec.rb +0 -85
  1408. data/spec/mongoid/matchable/ne_spec.rb +0 -46
  1409. data/spec/mongoid/matchable/nin_spec.rb +0 -48
  1410. data/spec/mongoid/matchable/nor_spec.rb +0 -209
  1411. data/spec/mongoid/matchable/or_spec.rb +0 -131
  1412. data/spec/mongoid/matchable/regexp_spec.rb +0 -59
  1413. data/spec/mongoid/matchable/size_spec.rb +0 -25
  1414. data/spec/mongoid/matchable_spec.rb +0 -853
  1415. data/spec/mongoid/query_cache_spec.rb +0 -618
  1416. data/spec/support/cluster_config.rb +0 -158
  1417. data/spec/support/session_registry.rb +0 -50
  1418. data.tar.gz.sig +0 -0
  1419. metadata.gz.sig +0 -1
  1420. /data/spec/{app → support}/models/array_field.rb +0 -0
  1421. /data/spec/{app → support}/models/updatable.rb +0 -0
@@ -1,102 +1,94 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe Mongoid::Changeable do
4
-
5
- describe "#attribute_change" do
6
-
7
- context "when the attribute has changed from the persisted value" do
8
-
9
- context "when using the setter" do
3
+ require 'spec_helper'
10
4
 
5
+ describe Mongoid::Changeable do
6
+ describe '#attribute_change' do
7
+ context 'when the attribute has changed from the persisted value' do
8
+ context 'when using the setter' do
11
9
  let(:person) do
12
- Person.new(title: "Grand Poobah").tap(&:move_changes)
10
+ Person.new(title: 'Grand Poobah').tap(&:move_changes)
13
11
  end
14
12
 
15
13
  before do
16
- person.title = "Captain Obvious"
14
+ person.title = 'Captain Obvious'
17
15
  end
18
16
 
19
- it "returns an array of the old value and new value" do
20
- expect(person.send(:attribute_change, "title")).to eq(
21
- [ "Grand Poobah", "Captain Obvious" ]
17
+ it 'returns an array of the old value and new value' do
18
+ expect(person.send(:attribute_change, 'title')).to eq(
19
+ [ 'Grand Poobah', 'Captain Obvious' ]
22
20
  )
23
21
  end
24
22
 
25
- it "allows access via (attribute)_change" do
23
+ it 'allows access via (attribute)_change' do
26
24
  expect(person.title_change).to eq(
27
- [ "Grand Poobah", "Captain Obvious" ]
25
+ [ 'Grand Poobah', 'Captain Obvious' ]
28
26
  )
29
27
  end
30
28
 
31
- context "when the field is aliased" do
32
-
29
+ context 'when the field is aliased' do
33
30
  let(:person) do
34
- Person.new(test: "Aliased 1").tap(&:move_changes)
31
+ Person.new(test: 'Aliased 1').tap(&:move_changes)
35
32
  end
36
33
 
37
34
  before do
38
- person.test = "Aliased 2"
35
+ person.test = 'Aliased 2'
39
36
  end
40
37
 
41
- it "returns an array of the old value and new value" do
42
- expect(person.send(:attribute_change, "test")).to eq(
43
- [ "Aliased 1", "Aliased 2" ]
38
+ it 'returns an array of the old value and new value' do
39
+ expect(person.send(:attribute_change, 'test')).to eq(
40
+ [ 'Aliased 1', 'Aliased 2' ]
44
41
  )
45
42
  end
46
43
 
47
- it "allows access via (attribute)_change" do
44
+ it 'allows access via (attribute)_change' do
48
45
  expect(person.test_change).to eq(
49
- [ "Aliased 1", "Aliased 2" ]
46
+ [ 'Aliased 1', 'Aliased 2' ]
50
47
  )
51
48
  end
52
49
  end
53
50
  end
54
51
 
55
- context "when using [] methods" do
56
-
52
+ context 'when using [] methods' do
57
53
  let(:person) do
58
- Person.new(title: "Grand Poobah").tap(&:move_changes)
54
+ Person.new(title: 'Grand Poobah').tap(&:move_changes)
59
55
  end
60
56
 
61
57
  before do
62
- person[:title] = "Captain Obvious"
58
+ person[:title] = 'Captain Obvious'
63
59
  end
64
60
 
65
- it "returns an array of the old value and new value" do
66
- expect(person.send(:attribute_change, "title")).to eq(
67
- [ "Grand Poobah", "Captain Obvious" ]
61
+ it 'returns an array of the old value and new value' do
62
+ expect(person.send(:attribute_change, 'title')).to eq(
63
+ [ 'Grand Poobah', 'Captain Obvious' ]
68
64
  )
69
65
  end
70
66
 
71
- it "allows access via (attribute)_change" do
67
+ it 'allows access via (attribute)_change' do
72
68
  expect(person.title_change).to eq(
73
- [ "Grand Poobah", "Captain Obvious" ]
69
+ [ 'Grand Poobah', 'Captain Obvious' ]
74
70
  )
75
71
  end
76
72
  end
77
73
  end
78
74
 
79
- context "when the attribute has changed from the default value" do
80
-
81
- context "when using the setter" do
82
-
75
+ context 'when the attribute has changed from the default value' do
76
+ context 'when using the setter' do
83
77
  let(:person) do
84
78
  Person.new(pets: true)
85
79
  end
86
80
 
87
- it "returns an array of nil and new value" do
88
- expect(person.send(:attribute_change, "pets")).to eq([ nil, true ])
81
+ it 'returns an array of nil and new value' do
82
+ expect(person.send(:attribute_change, 'pets')).to eq([ nil, true ])
89
83
  end
90
84
 
91
- it "allows access via (attribute)_change" do
85
+ it 'allows access via (attribute)_change' do
92
86
  expect(person.pets_change).to eq([ nil, true ])
93
87
  end
94
88
  end
95
89
 
96
- context "when using [] methods" do
97
-
98
- context "when the field is defined" do
99
-
90
+ context 'when using [] methods' do
91
+ context 'when the field is defined' do
100
92
  let(:person) do
101
93
  Person.new
102
94
  end
@@ -105,136 +97,128 @@ describe Mongoid::Changeable do
105
97
  person[:pets] = true
106
98
  end
107
99
 
108
- it "returns an array of nil and new value" do
109
- expect(person.send(:attribute_change, "pets")).to eq([ nil, true ])
100
+ it 'returns an array of nil and new value' do
101
+ expect(person.send(:attribute_change, 'pets')).to eq([ nil, true ])
110
102
  end
111
103
 
112
- it "allows access via (attribute)_change" do
104
+ it 'allows access via (attribute)_change' do
113
105
  expect(person.pets_change).to eq([ nil, true ])
114
106
  end
115
107
  end
116
108
 
117
- context "when the field is not defined" do
118
-
109
+ context 'when the field is not defined' do
119
110
  let(:person) do
120
111
  Person.new
121
112
  end
122
113
 
123
114
  before do
124
- person[:t] = "test"
115
+ person[:t] = 'test'
125
116
  end
126
117
 
127
- it "returns an array of nil and new value" do
128
- expect(person.send(:attribute_change, "t")).to eq([ nil, "test" ])
118
+ it 'returns an array of nil and new value' do
119
+ expect(person.send(:attribute_change, 't')).to eq([ nil, 'test' ])
129
120
  end
130
121
  end
131
122
  end
132
123
  end
133
124
 
134
- context "when the attribute changes multiple times" do
135
-
125
+ context 'when the attribute changes multiple times' do
136
126
  let(:person) do
137
- Person.new(title: "Grand Poobah").tap(&:move_changes)
127
+ Person.new(title: 'Grand Poobah').tap(&:move_changes)
138
128
  end
139
129
 
140
130
  before do
141
- person.title = "Captain Obvious"
142
- person.title = "Dark Helmet"
131
+ person.title = 'Captain Obvious'
132
+ person.title = 'Dark Helmet'
143
133
  end
144
134
 
145
- it "returns an array of the original value and new value" do
146
- expect(person.send(:attribute_change, "title")).to eq(
147
- [ "Grand Poobah", "Dark Helmet" ]
135
+ it 'returns an array of the original value and new value' do
136
+ expect(person.send(:attribute_change, 'title')).to eq(
137
+ [ 'Grand Poobah', 'Dark Helmet' ]
148
138
  )
149
139
  end
150
140
 
151
- it "allows access via (attribute)_change" do
141
+ it 'allows access via (attribute)_change' do
152
142
  expect(person.title_change).to eq(
153
- [ "Grand Poobah", "Dark Helmet" ]
143
+ [ 'Grand Poobah', 'Dark Helmet' ]
154
144
  )
155
145
  end
156
146
  end
157
147
 
158
- context "when the attribute is modified in place" do
159
-
160
- context "when the attribute is an array" do
161
-
148
+ context 'when the attribute is modified in place' do
149
+ context 'when the attribute is an array' do
162
150
  let(:person) do
163
- Person.new(aliases: [ "Grand Poobah" ]).tap(&:move_changes)
151
+ Person.new(aliases: [ 'Grand Poobah' ]).tap(&:move_changes)
164
152
  end
165
153
 
166
154
  before do
167
- person.aliases[0] = "Dark Helmet"
155
+ person.aliases[0] = 'Dark Helmet'
168
156
  end
169
157
 
170
- it "returns an array of the original value and new value" do
171
- expect(person.send(:attribute_change, "aliases")).to eq(
172
- [[ "Grand Poobah" ], [ "Dark Helmet" ]]
158
+ it 'returns an array of the original value and new value' do
159
+ expect(person.send(:attribute_change, 'aliases')).to eq(
160
+ [ [ 'Grand Poobah' ], [ 'Dark Helmet' ] ]
173
161
  )
174
162
  end
175
163
 
176
- it "allows access via (attribute)_change" do
164
+ it 'allows access via (attribute)_change' do
177
165
  expect(person.aliases_change).to eq(
178
- [[ "Grand Poobah" ], [ "Dark Helmet" ]]
166
+ [ [ 'Grand Poobah' ], [ 'Dark Helmet' ] ]
179
167
  )
180
168
  end
181
169
 
182
- context "when the attribute changes multiple times" do
183
-
170
+ context 'when the attribute changes multiple times' do
184
171
  before do
185
- person.aliases << "Colonel Sanders"
172
+ person.aliases << 'Colonel Sanders'
186
173
  end
187
174
 
188
- it "returns an array of the original value and new value" do
189
- expect(person.send(:attribute_change, "aliases")).to eq(
190
- [[ "Grand Poobah" ], [ "Dark Helmet", "Colonel Sanders" ]]
175
+ it 'returns an array of the original value and new value' do
176
+ expect(person.send(:attribute_change, 'aliases')).to eq(
177
+ [ [ 'Grand Poobah' ], [ 'Dark Helmet', 'Colonel Sanders' ] ]
191
178
  )
192
179
  end
193
180
  end
194
181
  end
195
182
 
196
- context "when the attribute is a hash" do
197
-
183
+ context 'when the attribute is a hash' do
198
184
  let(:person) do
199
- Person.new(map: { location: "Home" }).tap(&:move_changes)
185
+ Person.new(map: { location: 'Home' }).tap(&:move_changes)
200
186
  end
201
187
 
202
188
  before do
203
- person.map[:location] = "Work"
189
+ person.map[:location] = 'Work'
204
190
  end
205
191
 
206
- it "returns an array of the original value and new value" do
207
- expect(person.send(:attribute_change, "map")).to eq(
208
- [{ location: "Home" }, { location: "Work" }]
192
+ it 'returns an array of the original value and new value' do
193
+ expect(person.send(:attribute_change, 'map')).to eq(
194
+ [ { 'location' => 'Home' }, { 'location' => 'Work' } ]
209
195
  )
210
196
  end
211
197
 
212
- it "allows access via (attribute)_change" do
198
+ it 'allows access via (attribute)_change' do
213
199
  expect(person.map_change).to eq(
214
- [{ location: "Home" }, { location: "Work" }]
200
+ [ { 'location' => 'Home' }, { 'location' => 'Work' } ]
215
201
  )
216
202
  end
217
203
 
218
- context "when the attribute changes multiple times" do
219
-
204
+ context 'when the attribute changes multiple times' do
220
205
  before do
221
206
  person.map[:lat] = 20.0
222
207
  end
223
208
 
224
- it "returns an array of the original value and new value" do
225
- expect(person.send(:attribute_change, "map")).to eq(
226
- [{ location: "Home" }, { location: "Work", lat: 20.0 }]
209
+ it 'returns an array of the original value and new value' do
210
+ expect(person.send(:attribute_change, 'map')).to eq(
211
+ [ { 'location' => 'Home' }, { 'location' => 'Work', 'lat' => 20.0 } ]
227
212
  )
228
213
  end
229
214
  end
230
215
 
231
- context "when the values are arrays" do
232
-
216
+ context 'when the values are arrays' do
233
217
  let(:map) do
234
218
  {
235
- "stack1" => [ 1, 2, 3, 4 ],
236
- "stack2" => [ 1, 2, 3, 4 ],
237
- "stack3" => [ 1, 2, 3, 4 ]
219
+ 'stack1' => [ 1, 2, 3, 4 ],
220
+ 'stack2' => [ 1, 2, 3, 4 ],
221
+ 'stack3' => [ 1, 2, 3, 4 ]
238
222
  }
239
223
  end
240
224
 
@@ -243,25 +227,24 @@ describe Mongoid::Changeable do
243
227
  person.move_changes
244
228
  end
245
229
 
246
- context "when reordering the arrays inline" do
247
-
230
+ context 'when reordering the arrays inline' do
248
231
  before do
249
- person.map["stack1"].reverse!
232
+ person.map['stack1'].reverse!
250
233
  end
251
234
 
252
- it "flags the attribute as changed" do
253
- expect(person.send(:attribute_change, "map")).to eq(
235
+ it 'flags the attribute as changed' do
236
+ expect(person.send(:attribute_change, 'map')).to eq(
254
237
  [
255
238
  {
256
- "stack1" => [ 1, 2, 3, 4 ],
257
- "stack2" => [ 1, 2, 3, 4 ],
258
- "stack3" => [ 1, 2, 3, 4 ]
239
+ 'stack1' => [ 1, 2, 3, 4 ],
240
+ 'stack2' => [ 1, 2, 3, 4 ],
241
+ 'stack3' => [ 1, 2, 3, 4 ]
259
242
  },
260
243
  {
261
- "stack1" => [ 4, 3, 2, 1 ],
262
- "stack2" => [ 1, 2, 3, 4 ],
263
- "stack3" => [ 1, 2, 3, 4 ]
264
- },
244
+ 'stack1' => [ 4, 3, 2, 1 ],
245
+ 'stack2' => [ 1, 2, 3, 4 ],
246
+ 'stack3' => [ 1, 2, 3, 4 ]
247
+ }
265
248
  ]
266
249
  )
267
250
  end
@@ -270,117 +253,107 @@ describe Mongoid::Changeable do
270
253
  end
271
254
  end
272
255
 
273
- context "when the attribute has not changed from the persisted value" do
274
-
256
+ context 'when the attribute has not changed from the persisted value' do
275
257
  let(:person) do
276
258
  Person.new(title: nil)
277
259
  end
278
260
 
279
- it "returns nil" do
280
- expect(person.send(:attribute_change, "title")).to be_nil
261
+ it 'returns nil' do
262
+ expect(person.send(:attribute_change, 'title')).to be_nil
281
263
  end
282
264
  end
283
265
 
284
- context "when the attribute has not changed from the default value" do
285
-
286
- context "when the attribute differs from the persisted value" do
287
-
266
+ context 'when the attribute has not changed from the default value' do
267
+ context 'when the attribute differs from the persisted value' do
288
268
  let(:person) do
289
269
  Person.new
290
270
  end
291
271
 
292
- it "returns the change" do
293
- expect(person.send(:attribute_change, "pets")).to eq([ nil, false ])
272
+ it 'returns the change' do
273
+ expect(person.send(:attribute_change, 'pets')).to eq([ nil, false ])
294
274
  end
295
275
  end
296
276
 
297
- context "when the attribute does not differ from the persisted value" do
298
-
277
+ context 'when the attribute does not differ from the persisted value' do
299
278
  let(:person) do
300
- Person.instantiate("pets" => false)
279
+ Person.instantiate('pets' => false)
301
280
  end
302
281
 
303
- it "returns nil" do
304
- expect(person.send(:attribute_change, "pets")).to be_nil
282
+ it 'returns nil' do
283
+ expect(person.send(:attribute_change, 'pets')).to be_nil
305
284
  end
306
285
  end
307
286
  end
308
287
 
309
- context "when the attribute has been set with the same value" do
310
-
288
+ context 'when the attribute has been set with the same value' do
311
289
  let(:person) do
312
- Person.new(title: "Grand Poobah").tap(&:move_changes)
290
+ Person.new(title: 'Grand Poobah').tap(&:move_changes)
313
291
  end
314
292
 
315
293
  before do
316
- person.title = "Grand Poobah"
294
+ person.title = 'Grand Poobah'
317
295
  end
318
296
 
319
- it "returns an empty array" do
320
- expect(person.send(:attribute_change, "title")).to be_nil
297
+ it 'returns an empty array' do
298
+ expect(person.send(:attribute_change, 'title')).to be_nil
321
299
  end
322
300
  end
323
301
 
324
- context "when the attribute is removed" do
325
-
302
+ context 'when the attribute is removed' do
326
303
  let(:person) do
327
- Person.new(title: "Grand Poobah").tap(&:move_changes)
304
+ Person.new(title: 'Grand Poobah').tap(&:move_changes)
328
305
  end
329
306
 
330
307
  before do
331
308
  person.remove_attribute(:title)
332
309
  end
333
310
 
334
- it "returns an empty array" do
335
- expect(person.send(:attribute_change, "title")).to eq(
336
- [ "Grand Poobah", nil ]
311
+ it 'returns an empty array' do
312
+ expect(person.send(:attribute_change, 'title')).to eq(
313
+ [ 'Grand Poobah', nil ]
337
314
  )
338
315
  end
339
316
  end
340
317
  end
341
318
 
342
- describe "#attribute_changed?" do
343
-
344
- context "when the attribute has changed from the persisted value" do
345
-
319
+ describe '#attribute_changed?' do
320
+ context 'when the attribute has changed from the persisted value' do
346
321
  let(:person) do
347
- Person.new(title: "Grand Poobah")
322
+ Person.new(title: 'Grand Poobah')
348
323
  end
349
324
 
350
325
  before do
351
- person.title = "Captain Obvious"
326
+ person.title = 'Captain Obvious'
352
327
  end
353
328
 
354
- it "returns true" do
355
- expect(person.send(:attribute_changed?, "title")).to be true
329
+ it 'returns true' do
330
+ expect(person.send(:attribute_changed?, 'title')).to be true
356
331
  end
357
332
 
358
- it "allows access via (attribute)_changed?" do
333
+ it 'allows access via (attribute)_changed?' do
359
334
  expect(person.title_changed?).to be true
360
335
  end
361
336
 
362
- context "when the field is aliased" do
363
-
337
+ context 'when the field is aliased' do
364
338
  let(:person) do
365
- Person.new(test: "Aliased 1")
339
+ Person.new(test: 'Aliased 1')
366
340
  end
367
341
 
368
342
  before do
369
- person.test = "Aliased 2"
343
+ person.test = 'Aliased 2'
370
344
  end
371
345
 
372
- it "returns true" do
373
- expect(person.send(:attribute_changed?, "test")).to be true
346
+ it 'returns true' do
347
+ expect(person.send(:attribute_changed?, 'test')).to be true
374
348
  end
375
349
 
376
- it "allows access via (attribute)_changed?" do
350
+ it 'allows access via (attribute)_changed?' do
377
351
  expect(person.test_changed?).to be true
378
352
  end
379
353
  end
380
354
  end
381
355
 
382
- context "when the attribute has changed from the default value" do
383
-
356
+ context 'when the attribute has changed from the default value' do
384
357
  let(:person) do
385
358
  Person.new
386
359
  end
@@ -389,186 +362,401 @@ describe Mongoid::Changeable do
389
362
  person.pets = true
390
363
  end
391
364
 
392
- it "returns true" do
393
- expect(person.send(:attribute_changed?, "pets")).to be true
365
+ it 'returns true' do
366
+ expect(person.send(:attribute_changed?, 'pets')).to be true
394
367
  end
395
368
 
396
- it "allows access via (attribute)_changed?" do
369
+ it 'allows access via (attribute)_changed?' do
397
370
  expect(person.pets_changed?).to be true
398
371
  end
399
372
  end
400
373
 
401
- context "when the attribute has not changed the persisted value" do
402
-
374
+ context 'when the attribute has not changed the persisted value' do
403
375
  let!(:person) do
404
- Person.new(title: "Grand Poobah").tap(&:move_changes)
376
+ Person.new(title: 'Grand Poobah').tap(&:move_changes)
405
377
  end
406
378
 
407
- it "returns false" do
408
- expect(person.send(:attribute_changed?, "title")).to be false
379
+ it 'returns false' do
380
+ expect(person.send(:attribute_changed?, 'title')).to be false
409
381
  end
410
382
  end
411
383
 
412
- context "when the attribute has not changed from the default value" do
413
-
414
- context "when the attribute is not enumerable" do
415
-
416
- context "when the attribute differs from the persisted value" do
417
-
384
+ context 'when the attribute has not changed from the default value' do
385
+ context 'when the attribute is not enumerable' do
386
+ context 'when the attribute differs from the persisted value' do
418
387
  let!(:person) do
419
388
  Person.new
420
389
  end
421
390
 
422
- it "returns true" do
423
- expect(person.send(:attribute_changed?, "pets")).to be true
391
+ it 'returns true' do
392
+ expect(person.send(:attribute_changed?, 'pets')).to be true
424
393
  end
425
394
  end
426
395
 
427
- context "when the attribute does not differ from the persisted value" do
428
-
396
+ context 'when the attribute does not differ from the persisted value' do
429
397
  let!(:person) do
430
- Person.instantiate("pets" => false)
398
+ Person.instantiate('pets' => false)
431
399
  end
432
400
 
433
- it "returns false" do
434
- expect(person.send(:attribute_changed?, "pets")).to be false
401
+ it 'returns false' do
402
+ expect(person.send(:attribute_changed?, 'pets')).to be false
435
403
  end
436
404
  end
437
405
  end
438
406
 
439
- context "when the attribute is an array" do
440
-
407
+ context 'when the attribute is an array' do
441
408
  let!(:person) do
442
- Person.new(aliases: [ "Bond" ])
409
+ Person.new(aliases: [ 'Bond' ])
443
410
  end
444
411
 
445
- context "when the array is only accessed" do
446
-
412
+ context 'when the array is only accessed' do
447
413
  before do
448
414
  person.move_changes
449
415
  person.aliases
450
416
  end
451
417
 
452
- it "returns false" do
453
- expect(person).to_not be_aliases_changed
418
+ it 'returns false' do
419
+ expect(person).not_to be_aliases_changed
454
420
  end
455
421
  end
456
422
  end
457
423
 
458
- context "when the attribute is a hash" do
459
-
424
+ context 'when the attribute is a hash' do
460
425
  let!(:person) do
461
- Person.new(map: { key: "value" })
426
+ Person.new(map: { key: 'value' })
462
427
  end
463
428
 
464
- context "when the hash is only accessed" do
465
-
429
+ context 'when the hash is only accessed' do
466
430
  before do
467
431
  person.move_changes
468
432
  person.map
469
433
  end
470
434
 
471
- it "returns false" do
472
- expect(person).to_not be_map_changed
435
+ it 'returns false' do
436
+ expect(person).not_to be_map_changed
473
437
  end
474
438
  end
475
439
  end
476
440
  end
477
- end
478
441
 
479
- describe "#attribute_changed_from_default?" do
442
+ context 'when including key word args' do
443
+ let(:person) { Person.new }
444
+
445
+ context 'when only including from' do
446
+ context 'when the object has not changed' do
447
+ it 'returns false' do
448
+ expect(person.send(:attribute_changed?, :score, from: nil)).to be false
449
+ end
450
+
451
+ it 'returns false using (attribute)_changed?' do
452
+ expect(person.score_changed?(from: nil)).to be false
453
+ end
454
+ end
455
+
456
+ context 'when the object has changed from the wrong item' do
457
+ before do
458
+ person.score = 2
459
+ end
460
+
461
+ it 'returns false' do
462
+ expect(person.send(:attribute_changed?, :score, from: 1)).to be false
463
+ end
464
+
465
+ it 'returns false using (attribute)_changed?' do
466
+ expect(person.score_changed?(from: 1)).to be false
467
+ end
468
+ end
469
+
470
+ context 'when the object has changed from the correct item' do
471
+ before do
472
+ person.score = 2
473
+ end
474
+
475
+ it 'returns true' do
476
+ expect(person.send(:attribute_changed?, :score, from: nil)).to be true
477
+ end
478
+
479
+ it 'returns true using (attribute)_changed?' do
480
+ expect(person.score_changed?(from: nil)).to be true
481
+ end
482
+ end
483
+ end
484
+
485
+ context 'when only including to' do
486
+ context 'when the object has not changed' do
487
+ it 'returns false' do
488
+ expect(person.send(:attribute_changed?, :score, to: nil)).to be false
489
+ end
490
+
491
+ it 'returns false using (attribute)_changed?' do
492
+ expect(person.score_changed?(to: nil)).to be false
493
+ end
494
+ end
495
+
496
+ context 'when the object has changed to the wrong item' do
497
+ before do
498
+ person.score = 2
499
+ end
500
+
501
+ it 'returns false' do
502
+ expect(person.send(:attribute_changed?, :score, to: 1)).to be false
503
+ end
504
+
505
+ it 'returns false using (attribute)_changed?' do
506
+ expect(person.score_changed?(to: 1)).to be false
507
+ end
508
+ end
509
+
510
+ context 'when the object has changed to the correct item' do
511
+ before do
512
+ person.score = 2
513
+ end
514
+
515
+ it 'returns true' do
516
+ expect(person.send(:attribute_changed?, :score, to: 2)).to be true
517
+ end
518
+
519
+ it 'returns true using (attribute)_changed?' do
520
+ expect(person.score_changed?(to: 2)).to be true
521
+ end
522
+ end
523
+ end
524
+
525
+ context 'when including from and to' do
526
+ context 'when the object has not changed' do
527
+ it 'returns false' do
528
+ expect(person.send(:attribute_changed?, :score, from: nil, to: nil)).to be false
529
+ end
530
+
531
+ it 'returns false using (attribute)_changed?' do
532
+ expect(person.score_changed?(from: nil, to: nil)).to be false
533
+ end
534
+ end
535
+
536
+ context 'when only the from is correct' do
537
+ before do
538
+ person.score = 2
539
+ end
540
+
541
+ it 'returns false' do
542
+ expect(person.send(:attribute_changed?, :score, from: nil, to: 3)).to be false
543
+ end
544
+
545
+ it 'returns false using (attribute)_changed?' do
546
+ expect(person.score_changed?(from: nil, to: 3)).to be false
547
+ end
548
+ end
549
+
550
+ context 'when only the to is correct' do
551
+ before do
552
+ person.score = 2
553
+ end
554
+
555
+ it 'returns false' do
556
+ expect(person.send(:attribute_changed?, :score, from: 1, to: 2)).to be false
557
+ end
558
+
559
+ it 'returns false using (attribute)_changed?' do
560
+ expect(person.score_changed?(from: 1, to: 2)).to be false
561
+ end
562
+ end
563
+
564
+ context 'when the from and to are correct' do
565
+ before do
566
+ person.score = 2
567
+ end
568
+
569
+ it 'returns true' do
570
+ expect(person.send(:attribute_changed?, :score, from: nil, to: 2)).to be true
571
+ end
572
+
573
+ it 'returns true using (attribute)_changed?' do
574
+ expect(person.score_changed?(from: nil, to: 2)).to be true
575
+ end
576
+ end
480
577
 
481
- context "when the attribute differs from the default value" do
578
+ context 'when value is mongoized' do
579
+ before do
580
+ person.score = '2'
581
+ end
482
582
 
583
+ it 'returns true with mongoized value' do
584
+ expect(person.send(:attribute_changed?, :score, from: nil, to: 2)).to be true
585
+ end
586
+
587
+ it 'returns true with mongoized value using (attribute)_changed?' do
588
+ expect(person.score_changed?(from: nil, to: 2)).to be true
589
+ end
590
+ end
591
+
592
+ context 'when value is mongoized' do
593
+ before do
594
+ person.score = '2'
595
+ end
596
+
597
+ it 'returns false with unmongoized value' do
598
+ expect(person.send(:attribute_changed?, :score, from: nil, to: '2')).to be false
599
+ end
600
+
601
+ it 'returns false with unmongoized value using (attribute)_changed?' do
602
+ expect(person.score_changed?(from: nil, to: '2')).to be false
603
+ end
604
+ end
605
+ end
606
+ end
607
+ end
608
+
609
+ describe '#attribute_changed_from_default?' do
610
+ context 'when the attribute differs from the default value' do
483
611
  let(:person) do
484
612
  Person.new(age: 33)
485
613
  end
486
614
 
487
- it "returns true" do
615
+ it 'returns true' do
488
616
  expect(person).to be_age_changed_from_default
489
617
  end
490
618
  end
491
619
 
492
- context "when the attribute is the same as the default" do
493
-
620
+ context 'when the attribute is the same as the default' do
494
621
  let(:person) do
495
622
  Person.new
496
623
  end
497
624
 
498
- it "returns false" do
499
- expect(person).to_not be_age_changed_from_default
625
+ it 'returns false' do
626
+ expect(person).not_to be_age_changed_from_default
500
627
  end
501
628
  end
502
629
  end
503
630
 
504
- describe "#attribute_was" do
505
-
506
- context "when the attribute has changed from the persisted value" do
507
-
631
+ describe '#attribute_was' do
632
+ context 'when the attribute has changed from the persisted value' do
508
633
  let(:person) do
509
- Person.new(title: "Grand Poobah").tap(&:move_changes)
634
+ Person.new(title: 'Grand Poobah').tap(&:move_changes)
510
635
  end
511
636
 
512
637
  before do
513
- person.title = "Captain Obvious"
638
+ person.title = 'Captain Obvious'
514
639
  end
515
640
 
516
- it "returns the old value" do
517
- expect(person.send(:attribute_was, "title")).to eq("Grand Poobah")
641
+ it 'returns the old value' do
642
+ expect(person.send(:attribute_was, 'title')).to eq('Grand Poobah')
518
643
  end
519
644
 
520
- it "allows access via (attribute)_was" do
521
- expect(person.title_was).to eq("Grand Poobah")
645
+ it 'allows access via (attribute)_was' do
646
+ expect(person.title_was).to eq('Grand Poobah')
522
647
  end
523
648
 
524
- context "when the field is aliased" do
525
-
649
+ context 'when the field is aliased' do
526
650
  let(:person) do
527
- Person.new(test: "Aliased 1").tap(&:move_changes)
651
+ Person.new(test: 'Aliased 1').tap(&:move_changes)
528
652
  end
529
653
 
530
654
  before do
531
- person.test = "Aliased 2"
655
+ person.test = 'Aliased 2'
532
656
  end
533
657
 
534
- it "returns the old value" do
535
- expect(person.send(:attribute_was, "test")).to eq("Aliased 1")
658
+ it 'returns the old value' do
659
+ expect(person.send(:attribute_was, 'test')).to eq('Aliased 1')
536
660
  end
537
661
 
538
- it "allows access via (attribute)_was" do
539
- expect(person.test_was).to eq("Aliased 1")
662
+ it 'allows access via (attribute)_was' do
663
+ expect(person.test_was).to eq('Aliased 1')
540
664
  end
541
665
  end
542
666
  end
543
667
 
544
- context "when the attribute has not changed from the persisted value" do
545
-
668
+ context 'when the attribute has not changed from the persisted value' do
546
669
  let!(:person) do
547
- Person.new(title: "Grand Poobah").tap(&:move_changes)
670
+ Person.new(title: 'Grand Poobah').tap(&:move_changes)
548
671
  end
549
672
 
550
- it "returns the original value" do
551
- expect(person.send(:attribute_was, "title")).to eq("Grand Poobah")
673
+ it 'returns the original value' do
674
+ expect(person.send(:attribute_was, 'title')).to eq('Grand Poobah')
675
+ end
676
+ end
677
+
678
+ context 'when the attribute is a Hash field stored as a BSON::Document' do
679
+ let(:person) do
680
+ Person.new(map: BSON::Document.new('foo' => true)).tap(&:move_changes)
681
+ end
682
+
683
+ before do
684
+ person.map['bar'] = true
685
+ end
686
+
687
+ it 'returns a BSON::Document, consistent with the field getter' do
688
+ expect(person.map_was).to be_a(BSON::Document)
689
+ end
690
+
691
+ it 'returns the correct previous value' do
692
+ expect(person.map_was).to eq('foo' => true)
552
693
  end
553
694
  end
554
695
  end
555
696
 
556
- describe "#attribute_will_change!" do
697
+ describe '#attribute_previously_was' do
698
+ let(:previous_title) do
699
+ 'Grand Poobah'
700
+ end
701
+
702
+ let(:age) do
703
+ 10
704
+ end
705
+
706
+ let(:person) do
707
+ Person.create!(title: previous_title, age: age)
708
+ end
709
+
710
+ let(:updated_title) do
711
+ 'Captain Obvious'
712
+ end
713
+
714
+ before do
715
+ person.title = updated_title
716
+ person.save!
717
+ end
718
+
719
+ context 'when attribute changed' do
720
+ it 'returns the old value' do
721
+ expect(person.send(:attribute_previously_was, 'title')).to eq(previous_title)
722
+ end
723
+
724
+ it 'allows access via (attribute)_was' do
725
+ expect(person.title_previously_was).to eq(previous_title)
726
+ end
727
+ end
728
+
729
+ context 'when attribute did not change' do
730
+ it 'returns the same value' do
731
+ expect(person.send(:attribute_previously_was, 'age')).to eq(age)
732
+ end
733
+
734
+ it 'allows access via (attribute)_was' do
735
+ expect(person.age_previously_was).to eq(age)
736
+ end
737
+ end
738
+
739
+ it 'clears after reload' do
740
+ person.reload
741
+ expect(person.title_previously_was).to be_nil
742
+ expect(person.age_previously_was).to be_nil
743
+ end
744
+ end
557
745
 
746
+ describe '#attribute_will_change!' do
558
747
  let(:aliases) do
559
- [ "007" ]
748
+ [ '007' ]
560
749
  end
561
750
 
562
751
  let(:person) do
563
- Person.new(aliases: aliases, test: "Aliased 1")
752
+ Person.new(aliases: aliases, test: 'Aliased 1')
564
753
  end
565
754
 
566
755
  before do
567
756
  person.changed_attributes.clear
568
757
  end
569
758
 
570
- context "when the value has not changed" do
571
-
759
+ context 'when the value has not changed' do
572
760
  before do
573
761
  person.aliases_will_change!
574
762
  end
@@ -577,35 +765,32 @@ describe Mongoid::Changeable do
577
765
  person.changes
578
766
  end
579
767
 
580
- it "does not return the value in the changes" do
768
+ it 'does not return the value in the changes' do
581
769
  expect(changes).to be_empty
582
770
  end
583
771
 
584
- it "is not flagged as changed" do
585
- expect(person).to_not be_changed
772
+ it 'is not flagged as changed' do
773
+ expect(person).not_to be_changed
586
774
  end
587
775
  end
588
776
 
589
- context "when the value has changed" do
590
-
777
+ context 'when the value has changed' do
591
778
  before do
592
779
  person.aliases_will_change!
593
- person.aliases << "008"
780
+ person.aliases << '008'
594
781
  end
595
782
 
596
783
  let(:changes) do
597
784
  person.changes
598
785
  end
599
786
 
600
- it "returns the value in the changes" do
601
- expect(changes).to eq({ "aliases" => [[ "007" ], [ "007", "008" ]] })
787
+ it 'returns the value in the changes' do
788
+ expect(changes).to eq({ 'aliases' => [ [ '007' ], %w[007 008] ] })
602
789
  end
603
790
  end
604
791
 
605
- context "when the value is duplicable" do
606
-
607
- context "when the attribute has not been cloned" do
608
-
792
+ context 'when the value is duplicable' do
793
+ context 'when the attribute has not been cloned' do
609
794
  before do
610
795
  person.aliases_will_change!
611
796
  end
@@ -614,20 +799,19 @@ describe Mongoid::Changeable do
614
799
  person.changed_attributes
615
800
  end
616
801
 
617
- it "clones the value" do
618
- expect(changed["aliases"]).to_not equal(aliases)
802
+ it 'clones the value' do
803
+ expect(changed['aliases']).not_to equal(aliases)
619
804
  end
620
805
 
621
- it "puts the old value in the changes" do
622
- expect(changed["aliases"]).to eq(aliases)
806
+ it 'puts the old value in the changes' do
807
+ expect(changed['aliases']).to eq(aliases)
623
808
  end
624
809
  end
625
810
 
626
- context "when the attribute has been flagged" do
627
-
811
+ context 'when the attribute has been flagged' do
628
812
  before do
629
- person.changed_attributes["aliases"] = aliases
630
- expect(aliases).to receive(:clone).never
813
+ person.changed_attributes['aliases'] = aliases
814
+ expect(aliases).not_to receive(:clone)
631
815
  person.aliases_will_change!
632
816
  end
633
817
 
@@ -635,589 +819,602 @@ describe Mongoid::Changeable do
635
819
  person.changed_attributes
636
820
  end
637
821
 
638
- it "does not clone the value" do
639
- expect(changed["aliases"]).to equal(aliases)
822
+ it 'does not clone the value' do
823
+ expect(changed['aliases']).to equal(aliases)
640
824
  end
641
825
 
642
- it "retains the first value in the changes" do
643
- expect(changed["aliases"]).to eq(aliases)
826
+ it 'retains the first value in the changes' do
827
+ expect(changed['aliases']).to eq(aliases)
644
828
  end
645
829
  end
646
830
  end
647
831
  end
648
832
 
649
- describe "#changed" do
650
-
651
- context "when the document has changed" do
652
-
833
+ describe '#changed' do
834
+ context 'when the document has changed' do
653
835
  let(:person) do
654
- Person.instantiate(title: "Grand Poobah")
836
+ Person.instantiate(title: 'Grand Poobah')
655
837
  end
656
838
 
657
839
  before do
658
- person.title = "Captain Obvious"
840
+ person.title = 'Captain Obvious'
659
841
  end
660
842
 
661
- it "returns an array of changed field names" do
662
- expect(person.changed).to include("title")
843
+ it 'returns an array of changed field names' do
844
+ expect(person.changed).to include('title')
663
845
  end
664
-
665
846
  end
666
847
 
667
- context "When the document has changed but changed back to the original" do
668
-
848
+ context 'When the document has changed but changed back to the original' do
669
849
  let(:person) do
670
- Person.instantiate(title: "Grand Poobah")
850
+ Person.instantiate(title: 'Grand Poobah')
671
851
  end
672
852
 
673
853
  before do
674
- person.title = "Captain Obvious"
854
+ person.title = 'Captain Obvious'
675
855
  person.title = nil
676
856
  end
677
857
 
678
- it "returns an array of changed field names" do
679
- expect(person.changed).not_to include("title")
858
+ it 'returns an array of changed field names' do
859
+ expect(person.changed).not_to include('title')
680
860
  end
681
-
682
861
  end
683
862
 
684
- context "when the document has not changed" do
685
-
863
+ context 'when the document has not changed' do
686
864
  let(:person) do
687
865
  Person.instantiate({})
688
866
  end
689
867
 
690
- it "does not include non changed fields" do
691
- expect(person.changed).to_not include("title")
868
+ it 'does not include non changed fields' do
869
+ expect(person.changed).not_to include('title')
692
870
  end
693
871
  end
694
872
 
695
- context "when the document is embedded" do
696
-
873
+ context 'when the document is embedded' do
697
874
  let(:person) do
698
- Person.create
875
+ Person.create!
699
876
  end
700
877
 
701
878
  let!(:name) do
702
- person.create_name(first_name: "Layne", last_name: "Staley")
879
+ person.create_name(first_name: 'Layne', last_name: 'Staley')
703
880
  end
704
881
 
705
- context "when changing attributes via []" do
706
-
882
+ context 'when changing attributes via []' do
707
883
  before do
708
- person.name["a"] = "testing"
884
+ person.name['a'] = 'testing'
709
885
  end
710
886
 
711
- it "returns true" do
887
+ it 'returns true' do
712
888
  expect(person.name).to be_changed
713
889
  end
714
890
  end
715
891
  end
716
892
  end
717
893
 
718
- describe "#changed?" do
719
-
720
- context "when the document has changed" do
721
-
894
+ describe '#changed?' do
895
+ context 'when the document has changed' do
722
896
  let(:person) do
723
- Person.new(title: "Grand Poobah")
897
+ Person.new(title: 'Grand Poobah')
724
898
  end
725
899
 
726
900
  before do
727
- person.title = "Captain Obvious"
901
+ person.title = 'Captain Obvious'
728
902
  end
729
903
 
730
- it "returns true" do
904
+ it 'returns true' do
731
905
  expect(person).to be_changed
732
906
  end
733
907
  end
734
908
 
735
- context "when a hash field has been accessed" do
736
-
737
- context "when the field has not changed" do
738
-
909
+ context 'when a hash field has been accessed' do
910
+ context 'when the field has not changed' do
739
911
  let(:person) do
740
- Person.create(map: { name: "value" })
912
+ Person.create!(map: { name: 'value' })
741
913
  end
742
914
 
743
915
  before do
744
916
  person.map
745
917
  end
746
918
 
747
- it "returns false" do
748
- expect(person).to_not be_changed
919
+ it 'returns false' do
920
+ expect(person).not_to be_changed
749
921
  end
750
922
  end
751
923
 
752
- context "when the field is changed" do
753
-
924
+ context 'when the field is changed' do
754
925
  let(:person) do
755
- Person.create(map: { name: "value" })
926
+ Person.create!(map: { name: 'value' })
756
927
  end
757
928
 
758
929
  before do
759
- person.map = { name: "another" }
930
+ person.map = { name: 'another' }
760
931
  end
761
932
 
762
- it "returns true" do
933
+ it 'returns true' do
763
934
  expect(person).to be_changed
764
935
  end
765
936
  end
766
937
 
767
- context "when a dynamic field is changed in place" do
768
-
938
+ context 'when a dynamic field is changed in place' do
769
939
  let(:person) do
770
- Person.create(other_name: { full: {first: 'first', last: 'last'} })
940
+ Person.create!(other_name: { full: { first: 'first', last: 'last' } })
771
941
  end
772
942
 
773
943
  before do
774
944
  person.other_name[:full][:first] = 'Name'
775
945
  end
776
946
 
777
- it "returns true" do
778
- expect(person.changes).to_not be_empty
947
+ it 'returns true' do
948
+ expect(person.changes).not_to be_empty
779
949
  expect(person).to be_changed
780
950
  end
781
951
  end
782
952
  end
783
953
 
784
- context "when the document has not changed" do
785
-
954
+ context 'when the document has not changed' do
786
955
  let(:acolyte) do
787
- Acolyte.instantiate("_id" => BSON::ObjectId.new)
956
+ Acolyte.instantiate('_id' => BSON::ObjectId.new)
788
957
  end
789
958
 
790
- it "returns false" do
791
- expect(acolyte).to_not be_changed
959
+ it 'returns false' do
960
+ expect(acolyte).not_to be_changed
792
961
  end
793
962
  end
794
963
 
795
- context "when a child has changed" do
796
-
964
+ context 'when a child has changed' do
797
965
  let(:person) do
798
- Person.create
966
+ Person.create!
799
967
  end
800
968
 
801
969
  let!(:address) do
802
- person.addresses.create(street: "hobrecht")
970
+ person.addresses.create!(street: 'hobrecht')
803
971
  end
804
972
 
805
973
  before do
806
974
  address.number = 10
807
975
  end
808
976
 
809
- it "returns true" do
977
+ it 'returns true' do
810
978
  expect(person).to be_changed
811
979
  end
812
980
  end
813
981
 
814
- context "when changed? has been called before child elements size change" do
815
-
982
+ context 'when changed? has been called before child elements size change' do
816
983
  let(:person) do
817
- Person.create
984
+ Person.create!
818
985
  end
819
986
 
820
987
  let(:address) do
821
- person.addresses.create(street: "hobrecht")
988
+ person.addresses.create!(street: 'hobrecht')
822
989
  end
823
990
 
824
991
  let!(:location) do
825
- address.locations.create(name: "home")
992
+ address.locations.create!(name: 'home')
826
993
  end
827
994
 
828
995
  before do
829
996
  person.changed?
830
997
  end
831
998
 
832
- context "when adding via new" do
833
-
999
+ context 'when adding via new' do
834
1000
  before do
835
1001
  address.locations.new
836
1002
  end
837
1003
 
838
- it "returns true" do
1004
+ it 'returns true' do
839
1005
  expect(person).to be_changed
840
1006
  end
841
1007
  end
842
1008
 
843
- context "when adding via build" do
844
-
1009
+ context 'when adding via build' do
845
1010
  before do
846
1011
  address.locations.build
847
1012
  end
848
1013
 
849
- it "returns true" do
1014
+ it 'returns true' do
850
1015
  expect(person).to be_changed
851
1016
  end
852
1017
  end
853
1018
 
854
- context "when adding via create" do
855
-
1019
+ context 'when adding via create' do
856
1020
  before do
857
- address.locations.create
1021
+ address.locations.create!
858
1022
  end
859
1023
 
860
- it "returns false" do
861
- expect(person).to_not be_changed
1024
+ it 'returns false' do
1025
+ expect(person).not_to be_changed
862
1026
  end
863
1027
  end
864
1028
  end
865
1029
 
866
- context "when a deeply embedded child has changed" do
867
-
1030
+ context 'when a deeply embedded child has changed' do
868
1031
  let(:person) do
869
- Person.create
1032
+ Person.create!
870
1033
  end
871
1034
 
872
1035
  let(:address) do
873
- person.addresses.create(street: "hobrecht")
1036
+ person.addresses.create!(street: 'hobrecht')
874
1037
  end
875
1038
 
876
1039
  let!(:location) do
877
- address.locations.create(name: "home")
1040
+ address.locations.create!(name: 'home')
878
1041
  end
879
1042
 
880
1043
  before do
881
- location.name = "work"
1044
+ location.name = 'work'
882
1045
  end
883
1046
 
884
- it "returns true" do
1047
+ it 'returns true' do
885
1048
  expect(person).to be_changed
886
1049
  end
887
1050
  end
888
1051
 
889
- context "when a child is new" do
890
-
1052
+ context 'when a child is new' do
891
1053
  let(:person) do
892
- Person.create
1054
+ Person.create!
893
1055
  end
894
1056
 
895
1057
  let!(:address) do
896
- person.addresses.build(street: "hobrecht")
1058
+ person.addresses.build(street: 'hobrecht')
897
1059
  end
898
1060
 
899
- it "returns true" do
1061
+ it 'returns true' do
900
1062
  expect(person).to be_changed
901
1063
  end
902
1064
  end
903
1065
 
904
- context "when a deeply embedded child is new" do
905
-
1066
+ context 'when a deeply embedded child is new' do
906
1067
  let(:person) do
907
- Person.create
1068
+ Person.create!
908
1069
  end
909
1070
 
910
1071
  let(:address) do
911
- person.addresses.create(street: "hobrecht")
1072
+ person.addresses.create!(street: 'hobrecht')
912
1073
  end
913
1074
 
914
1075
  let!(:location) do
915
- address.locations.build(name: "home")
1076
+ address.locations.build(name: 'home')
916
1077
  end
917
1078
 
918
- it "returns true" do
1079
+ it 'returns true' do
919
1080
  expect(person).to be_changed
920
1081
  end
921
1082
  end
922
1083
  end
923
1084
 
924
- describe "#changes" do
925
-
926
- context "when the document has changed" do
927
-
1085
+ describe '#changes' do
1086
+ context 'when the document has changed' do
928
1087
  let(:person) do
929
- Person.instantiate(title: "Grand Poobah")
1088
+ Person.instantiate(title: 'Grand Poobah')
930
1089
  end
931
1090
 
932
1091
  before do
933
- person.title = "Captain Obvious"
1092
+ person.title = 'Captain Obvious'
934
1093
  end
935
1094
 
936
- it "returns a hash of changes" do
937
- expect(person.changes["title"]).to eq(
938
- [ nil, "Captain Obvious" ]
1095
+ it 'returns a hash of changes' do
1096
+ expect(person.changes['title']).to eq(
1097
+ [ nil, 'Captain Obvious' ]
939
1098
  )
940
1099
  end
941
1100
 
942
- it "returns a hash with indifferent access" do
1101
+ it 'returns a hash with indifferent access' do
943
1102
  expect(person.changes[:title]).to eq(
944
- [ nil, "Captain Obvious" ]
1103
+ [ nil, 'Captain Obvious' ]
945
1104
  )
946
1105
  end
947
1106
  end
948
1107
 
949
- context "when the document has not changed" do
1108
+ context 'when habtm association changes' do
1109
+ let(:person) do
1110
+ Person.create!(title: 'Grand Poobah')
1111
+ end
1112
+
1113
+ let(:user_account) do
1114
+ UserAccount.create!
1115
+ end
1116
+
1117
+ before do
1118
+ person.user_accounts << user_account
1119
+ end
950
1120
 
1121
+ it 'does not add to the changes or changed_attributes hash' do
1122
+ person.changes.should eq({})
1123
+ person.changed_attributes.should eq({})
1124
+ end
1125
+ end
1126
+
1127
+ context 'when habtm association _ids changes' do
1128
+ let(:person) do
1129
+ Person.create!(title: 'Grand Poobah')
1130
+ end
1131
+
1132
+ let(:user_account) do
1133
+ UserAccount.create!
1134
+ end
1135
+
1136
+ before do
1137
+ person.user_account_ids << user_account._id
1138
+ end
1139
+
1140
+ it 'adds to the changes or changed_attributes hash' do
1141
+ person.changes.should eq({ 'user_account_ids' => [ nil, [ user_account._id ] ] })
1142
+ person.changed_attributes.should eq({ 'user_account_ids' => nil })
1143
+ end
1144
+ end
1145
+
1146
+ context 'when assigning empty list to habtm association' do
1147
+ let(:person) do
1148
+ Person.create!(title: 'Grand Poobah', user_accounts: [ user_account ])
1149
+ end
1150
+
1151
+ let(:user_account) do
1152
+ UserAccount.create!
1153
+ end
1154
+
1155
+ before do
1156
+ person.user_accounts = []
1157
+ end
1158
+
1159
+ it 'does not add to the changes or changed_attributes hash' do
1160
+ person.changes.should eq({})
1161
+ person.changed_attributes.should eq({})
1162
+ end
1163
+ end
1164
+
1165
+ context 'when assigning empty list to habtm association _ids' do
1166
+ let(:person) do
1167
+ Person.create!(title: 'Grand Poobah', user_accounts: [ user_account ])
1168
+ end
1169
+
1170
+ let(:user_account) do
1171
+ UserAccount.create!
1172
+ end
1173
+
1174
+ before do
1175
+ person.user_account_ids = []
1176
+ end
1177
+
1178
+ it 'does not add to the changes or changed_attributes hash' do
1179
+ person.changes.should eq({ 'user_account_ids' => [ [ user_account._id ], [] ] })
1180
+ person.changed_attributes.should eq({ 'user_account_ids' => [ user_account._id ] })
1181
+ end
1182
+ end
1183
+
1184
+ context 'when the document has not changed' do
951
1185
  let(:acolyte) do
952
- Acolyte.instantiate("_id" => BSON::ObjectId.new)
1186
+ Acolyte.instantiate('_id' => BSON::ObjectId.new)
953
1187
  end
954
1188
 
955
- it "returns an empty hash" do
1189
+ it 'returns an empty hash' do
956
1190
  expect(acolyte.changes).to be_empty
957
1191
  end
958
1192
  end
959
1193
  end
960
1194
 
961
- describe "#setters" do
962
-
963
- context "when the document has changed" do
964
-
1195
+ describe '#setters' do
1196
+ context 'when the document has changed' do
965
1197
  let(:person) do
966
- Person.new(aliases: [ "007" ]).tap do |p|
1198
+ Person.new(aliases: [ '007' ]).tap do |p|
967
1199
  p.new_record = false
968
1200
  p.move_changes
969
1201
  end
970
1202
  end
971
1203
 
972
- context "when an array field has changed" do
973
-
974
- context "when the array has values removed" do
975
-
1204
+ context 'when an array field has changed' do
1205
+ context 'when the array has values removed' do
976
1206
  before do
977
- person.aliases.delete_one("007")
1207
+ person.aliases.delete_one('007')
978
1208
  end
979
1209
 
980
1210
  let!(:setters) do
981
1211
  person.setters
982
1212
  end
983
1213
 
984
- it "contains array changes in the setters" do
985
- expect(setters).to eq({ "aliases" => [] })
1214
+ it 'contains array changes in the setters' do
1215
+ expect(setters).to eq({ 'aliases' => [] })
986
1216
  end
987
1217
  end
988
1218
 
989
- context "when the array has values added" do
990
-
1219
+ context 'when the array has values added' do
991
1220
  before do
992
- person.aliases << "008"
1221
+ person.aliases << '008'
993
1222
  end
994
1223
 
995
1224
  let!(:setters) do
996
1225
  person.setters
997
1226
  end
998
1227
 
999
- it "contains array changes in the setters" do
1000
- expect(setters).to eq({ "aliases" => [ "007", "008" ] })
1228
+ it 'contains array changes in the setters' do
1229
+ expect(setters).to eq({ 'aliases' => %w[007 008] })
1001
1230
  end
1002
1231
  end
1003
1232
 
1004
- context "when the array has changed completely" do
1005
-
1233
+ context 'when the array has changed completely' do
1006
1234
  before do
1007
- person.aliases << "008"
1008
- person.aliases.delete_one("007")
1235
+ person.aliases << '008'
1236
+ person.aliases.delete_one('007')
1009
1237
  end
1010
1238
 
1011
1239
  let!(:setters) do
1012
1240
  person.setters
1013
1241
  end
1014
1242
 
1015
- it "does not contain array changes in the setters" do
1016
- expect(setters).to eq({ "aliases" => [ "008" ]})
1243
+ it 'does not contain array changes in the setters' do
1244
+ expect(setters).to eq({ 'aliases' => [ '008' ] })
1017
1245
  end
1018
1246
  end
1019
1247
  end
1020
1248
 
1021
- context "when the document is a root document" do
1022
-
1249
+ context 'when the document is a root document' do
1023
1250
  let(:person) do
1024
- Person.instantiate(title: "Grand Poobah")
1251
+ Person.instantiate(title: 'Grand Poobah')
1025
1252
  end
1026
1253
 
1027
1254
  before do
1028
- person.title = "Captain Obvious"
1255
+ person.title = 'Captain Obvious'
1029
1256
  end
1030
1257
 
1031
- it "returns a hash of field names and new values" do
1032
- expect(person.setters["title"]).to eq("Captain Obvious")
1258
+ it 'returns a hash of field names and new values' do
1259
+ expect(person.setters['title']).to eq('Captain Obvious')
1033
1260
  end
1034
1261
  end
1035
1262
 
1036
- context "when the document is embedded" do
1037
-
1038
- let(:person) do
1039
- Person.instantiate(title: "Grand Poobah")
1040
- end
1041
-
1042
- let(:address) do
1043
- Address.instantiate(street: "Oxford St")
1044
- end
1263
+ context 'when the document is embedded' do
1264
+ let(:person) { Person.create(title: 'Grand Poobah') }
1265
+ let(:address) { person.addresses.create(street: 'Oxford St') }
1045
1266
 
1046
- before do
1047
- person.addresses << address
1048
- person.instance_variable_set(:@new_record, false)
1049
- address.instance_variable_set(:@new_record, false)
1050
- address.street = "Bond St"
1051
- end
1267
+ before { address.street = 'Bond St' }
1052
1268
 
1053
- it "returns a hash of field names and new values" do
1269
+ it 'returns a hash of field names and new values' do
1054
1270
  expect(address.setters).to eq(
1055
- { "addresses.0.street" => "Bond St" }
1271
+ { 'addresses.0.street' => 'Bond St' }
1056
1272
  )
1057
1273
  end
1058
1274
 
1059
- context "when the document is embedded multiple levels" do
1275
+ context 'when the document is embedded multiple levels' do
1276
+ let(:location) { address.locations.create(name: 'Home') }
1060
1277
 
1061
- let(:location) do
1062
- Location.new(name: "Home")
1063
- end
1064
-
1065
- before do
1066
- location.instance_variable_set(:@new_record, false)
1067
- address.locations << location
1068
- location.name = "Work"
1069
- end
1278
+ before { location.name = 'Work' }
1070
1279
 
1071
- it "returns the proper hash with locations" do
1280
+ it 'returns the proper hash with locations' do
1072
1281
  expect(location.setters).to eq(
1073
- { "addresses.0.locations.0.name" => "Work" }
1282
+ { 'addresses.0.locations.0.name' => 'Work' }
1074
1283
  )
1075
1284
  end
1076
1285
  end
1077
1286
  end
1078
1287
  end
1079
1288
 
1080
- context "when the document has not changed" do
1081
-
1289
+ context 'when the document has not changed' do
1082
1290
  let(:acolyte) do
1083
- Acolyte.instantiate("_id" => BSON::ObjectId.new)
1291
+ Acolyte.instantiate('_id' => BSON::ObjectId.new)
1084
1292
  end
1085
1293
 
1086
- it "returns an empty hash" do
1294
+ it 'returns an empty hash' do
1087
1295
  expect(acolyte.setters).to be_empty
1088
1296
  end
1089
1297
  end
1090
1298
  end
1091
1299
 
1092
- describe "#previous_changes" do
1093
-
1300
+ describe '#previous_changes' do
1094
1301
  let(:person) do
1095
- Person.new(title: "Grand Poobah")
1302
+ Person.new(title: 'Grand Poobah')
1096
1303
  end
1097
1304
 
1098
1305
  before do
1099
- person.title = "Captain Obvious"
1306
+ person.title = 'Captain Obvious'
1100
1307
  end
1101
1308
 
1102
- context "when the document has been saved" do
1103
-
1309
+ context 'when the document has been saved' do
1104
1310
  before do
1105
1311
  person.save!
1106
1312
  end
1107
1313
 
1108
- it "returns the changes before the save" do
1109
- expect(person.previous_changes["title"]).to eq(
1110
- [ nil, "Captain Obvious" ]
1314
+ it 'returns the changes before the save' do
1315
+ expect(person.previous_changes['title']).to eq(
1316
+ [ nil, 'Captain Obvious' ]
1111
1317
  )
1112
1318
  end
1113
1319
  end
1114
1320
 
1115
- context "when the document has not been saved" do
1116
-
1117
- it "returns an empty hash" do
1321
+ context 'when the document has not been saved' do
1322
+ it 'returns an empty hash' do
1118
1323
  expect(person.previous_changes).to be_empty
1119
1324
  end
1120
1325
  end
1121
1326
  end
1122
1327
 
1123
- describe "#move_changes" do
1124
-
1328
+ describe '#move_changes' do
1125
1329
  let(:person) do
1126
- Person.new(title: "Sir")
1330
+ Person.new(title: 'Sir')
1127
1331
  end
1128
1332
 
1129
1333
  before do
1130
- person.atomic_pulls["addresses"] = Address.new
1334
+ person.atomic_pulls['addresses'] = Address.new
1131
1335
  person.atomic_unsets << Address.new
1132
- person.delayed_atomic_sets["addresses"] = Address.new
1336
+ person.delayed_atomic_sets['addresses'] = Address.new
1133
1337
  person.move_changes
1134
1338
  end
1135
1339
 
1136
- it "clears the atomic pulls" do
1340
+ it 'clears the atomic pulls' do
1137
1341
  expect(person.atomic_pulls).to be_empty
1138
1342
  end
1139
1343
 
1140
- it "clears the atomic unsets" do
1344
+ it 'clears the atomic unsets' do
1141
1345
  expect(person.atomic_unsets).to be_empty
1142
1346
  end
1143
1347
 
1144
- it "clears the delayed atomic sets" do
1348
+ it 'clears the delayed atomic sets' do
1145
1349
  expect(person.delayed_atomic_sets).to be_empty
1146
1350
  end
1147
1351
 
1148
- it "clears the changed attributes" do
1352
+ it 'clears the changed attributes' do
1149
1353
  expect(person.changed_attributes).to be_empty
1150
1354
  end
1151
1355
  end
1152
1356
 
1153
- describe "#reset_attribute!" do
1154
-
1155
- context "when the attribute has changed" do
1156
-
1357
+ describe '#reset_attribute!' do
1358
+ context 'when the attribute has changed' do
1157
1359
  let(:person) do
1158
- Person.instantiate(title: "Grand Poobah")
1360
+ Person.instantiate(title: 'Grand Poobah')
1159
1361
  end
1160
1362
 
1161
1363
  before do
1162
- person.title = "Captain Obvious"
1163
- person.send(:reset_attribute!, "title")
1364
+ person.title = 'Captain Obvious'
1365
+ person.send(:reset_attribute!, 'title')
1164
1366
  end
1165
1367
 
1166
- it "resets the value to the original" do
1368
+ it 'resets the value to the original' do
1167
1369
  expect(person.title).to be_nil
1168
1370
  end
1169
1371
 
1170
- it "allows access via reset_(attribute)!" do
1372
+ it 'allows access via reset_(attribute)!' do
1171
1373
  expect(person.title).to be_nil
1172
1374
  end
1173
1375
 
1174
- it "removes the field from the changes" do
1175
- expect(person.changed).to_not include("title")
1376
+ it 'removes the field from the changes' do
1377
+ expect(person.changed).not_to include('title')
1176
1378
  end
1177
1379
 
1178
- context "when the field is aliased" do
1179
-
1380
+ context 'when the field is aliased' do
1180
1381
  let(:person) do
1181
- Person.instantiate(test: "Aliased 1")
1382
+ Person.instantiate(test: 'Aliased 1')
1182
1383
  end
1183
1384
 
1184
1385
  before do
1185
- person.test = "Aliased 2"
1186
- person.send(:reset_attribute!, "test")
1386
+ person.test = 'Aliased 2'
1387
+ person.send(:reset_attribute!, 'test')
1187
1388
  end
1188
1389
 
1189
- it "resets the value to the original" do
1390
+ it 'resets the value to the original' do
1190
1391
  expect(person.test).to be_nil
1191
1392
  end
1192
1393
 
1193
- it "removes the field from the changes" do
1194
- expect(person.changed).to_not include("test")
1394
+ it 'removes the field from the changes' do
1395
+ expect(person.changed).not_to include('test')
1195
1396
  end
1196
1397
  end
1197
1398
  end
1198
1399
 
1199
- context "when the attribute has not changed" do
1200
-
1400
+ context 'when the attribute has not changed' do
1201
1401
  let(:person) do
1202
- Person.instantiate(title: "Grand Poobah")
1402
+ Person.instantiate(title: 'Grand Poobah')
1203
1403
  end
1204
1404
 
1205
1405
  before do
1206
- person.send(:reset_attribute!, "title")
1406
+ person.send(:reset_attribute!, 'title')
1207
1407
  end
1208
1408
 
1209
- it "does nothing" do
1409
+ it 'does nothing' do
1210
1410
  expect(person.title).to be_nil
1211
1411
  end
1212
1412
  end
1213
1413
  end
1214
1414
 
1215
- describe "#reset_attribute_to_default!" do
1216
-
1217
- context "when a default is defined" do
1218
-
1219
- context "when the document is new" do
1220
-
1415
+ describe '#reset_attribute_to_default!' do
1416
+ context 'when a default is defined' do
1417
+ context 'when the document is new' do
1221
1418
  let(:person) do
1222
1419
  Person.new(pets: true)
1223
1420
  end
@@ -1226,63 +1423,59 @@ describe Mongoid::Changeable do
1226
1423
  person.reset_pets_to_default!
1227
1424
  end
1228
1425
 
1229
- it "resets to the default value" do
1426
+ it 'resets to the default value' do
1230
1427
  expect(person.pets).to eq(false)
1231
1428
  end
1232
1429
  end
1233
1430
 
1234
- context "when the document is persisted" do
1235
-
1431
+ context 'when the document is persisted' do
1236
1432
  let(:person) do
1237
- Person.create(pets: true)
1433
+ Person.create!(pets: true)
1238
1434
  end
1239
1435
 
1240
1436
  before do
1241
1437
  person.reset_pets_to_default!
1242
1438
  end
1243
1439
 
1244
- it "resets to the default value" do
1440
+ it 'resets to the default value' do
1245
1441
  expect(person.pets).to eq(false)
1246
1442
  end
1247
1443
 
1248
- it "flags the document dirty" do
1444
+ it 'flags the document dirty' do
1249
1445
  expect(person).to be_pets_changed
1250
1446
  end
1251
1447
  end
1252
1448
  end
1253
1449
 
1254
- context "when a default is not defined" do
1255
-
1256
- context "when the document is new" do
1257
-
1450
+ context 'when a default is not defined' do
1451
+ context 'when the document is new' do
1258
1452
  let(:person) do
1259
- Person.new(title: "test")
1453
+ Person.new(title: 'test')
1260
1454
  end
1261
1455
 
1262
1456
  before do
1263
1457
  person.reset_title_to_default!
1264
1458
  end
1265
1459
 
1266
- it "resets to nil" do
1460
+ it 'resets to nil' do
1267
1461
  expect(person.title).to be_nil
1268
1462
  end
1269
1463
  end
1270
1464
 
1271
- context "when the document is persisted" do
1272
-
1465
+ context 'when the document is persisted' do
1273
1466
  let(:person) do
1274
- Person.create(title: "test")
1467
+ Person.create!(title: 'test')
1275
1468
  end
1276
1469
 
1277
1470
  before do
1278
1471
  person.reset_title_to_default!
1279
1472
  end
1280
1473
 
1281
- it "resets to nil" do
1474
+ it 'resets to nil' do
1282
1475
  expect(person.title).to be_nil
1283
1476
  end
1284
1477
 
1285
- it "flags the document dirty" do
1478
+ it 'flags the document dirty' do
1286
1479
  expect(person).to be_title_changed
1287
1480
  end
1288
1481
  end
@@ -1290,237 +1483,323 @@ describe Mongoid::Changeable do
1290
1483
  end
1291
1484
 
1292
1485
  describe '#previously_changed?' do
1293
-
1294
1486
  let(:person) do
1295
- Person.new(title: "Grand Poobah")
1487
+ Person.new(title: 'Grand Poobah')
1296
1488
  end
1297
1489
 
1298
1490
  before do
1299
- person.title = "Captain Obvious"
1491
+ person.title = 'Captain Obvious'
1300
1492
  end
1301
1493
 
1302
- context "when the document has been saved" do
1303
-
1494
+ context 'when the document has been saved' do
1304
1495
  before do
1305
1496
  person.save!
1306
1497
  end
1307
1498
 
1308
- it "returns true" do
1499
+ it 'returns true' do
1309
1500
  expect(person.title_previously_changed?).to be(true)
1310
1501
  end
1311
1502
  end
1312
1503
 
1313
- context "when the document has not been saved" do
1314
-
1315
- it "returns false" do
1504
+ context 'when the document has not been saved' do
1505
+ it 'returns false' do
1316
1506
  expect(person.title_previously_changed?).to be(false)
1317
1507
  end
1318
1508
  end
1319
1509
  end
1320
1510
 
1321
1511
  describe '#previous_change' do
1512
+ let(:person) do
1513
+ Person.new(title: 'Grand Poobah')
1514
+ end
1515
+
1516
+ before do
1517
+ person.title = 'Captain Obvious'
1518
+ end
1519
+
1520
+ context 'when the document has been saved' do
1521
+ before do
1522
+ person.save!
1523
+ end
1322
1524
 
1525
+ it 'returns the changes' do
1526
+ expect(person.title_previous_change).to eq([ nil, 'Captain Obvious' ])
1527
+ end
1528
+ end
1529
+
1530
+ context 'when the document has not been saved' do
1531
+ it 'returns no changes' do
1532
+ expect(person.title_previous_change).to eq(nil)
1533
+ end
1534
+ end
1535
+ end
1536
+
1537
+ describe '#attribute_before_last_save' do
1323
1538
  let(:person) do
1324
- Person.new(title: "Grand Poobah")
1539
+ Person.create!(title: 'Grand Poobah')
1325
1540
  end
1326
1541
 
1327
1542
  before do
1328
- person.title = "Captain Obvious"
1543
+ person.title = 'Captain Obvious'
1544
+ end
1545
+
1546
+ context 'when the document has been saved' do
1547
+ before do
1548
+ person.save!
1549
+ end
1550
+
1551
+ it 'returns the changes' do
1552
+ expect(person.attribute_before_last_save(:title)).to eq('Grand Poobah')
1553
+ expect(person.title_before_last_save).to eq('Grand Poobah')
1554
+ end
1555
+ end
1556
+
1557
+ context 'when the document has not been saved' do
1558
+ it 'returns no changes' do
1559
+ expect(person.attribute_before_last_save(:title)).to be_nil
1560
+ expect(person.title_before_last_save).to be_nil
1561
+ end
1329
1562
  end
1563
+ end
1330
1564
 
1331
- context "when the document has been saved" do
1565
+ describe '#saved_change_to_attribute' do
1566
+ let(:person) do
1567
+ Person.create!(title: 'Grand Poobah')
1568
+ end
1332
1569
 
1570
+ before do
1571
+ person.title = 'Captain Obvious'
1572
+ end
1573
+
1574
+ context 'when the document has been saved' do
1333
1575
  before do
1334
1576
  person.save!
1335
1577
  end
1336
1578
 
1337
- it "returns the changes" do
1338
- expect(person.title_previous_change).to eq([ nil, "Captain Obvious" ])
1579
+ it 'returns the changes' do
1580
+ expect(person.saved_change_to_attribute(:title)).to eq([ 'Grand Poobah', 'Captain Obvious' ])
1581
+ expect(person.saved_change_to_title).to eq([ 'Grand Poobah', 'Captain Obvious' ])
1339
1582
  end
1340
1583
  end
1341
1584
 
1342
- context "when the document has not been saved" do
1585
+ context 'when the document has not been saved' do
1586
+ it 'returns changes for the previous save' do
1587
+ expect(person.saved_change_to_attribute(:title)).to eq([ nil, 'Grand Poobah' ])
1588
+ expect(person.saved_change_to_title).to eq([ nil, 'Grand Poobah' ])
1589
+ end
1590
+ end
1591
+ end
1343
1592
 
1344
- it "returns no changes" do
1345
- expect(person.title_previous_change).to eq(nil)
1593
+ describe '#saved_change_to_attribute?' do
1594
+ context 'when the document has been saved' do
1595
+ let(:person) do
1596
+ Person.create!(title: 'Grand Poobah')
1597
+ end
1598
+
1599
+ before do
1600
+ person.title = 'Captain Obvious'
1601
+ person.save!
1602
+ end
1603
+
1604
+ it 'detects the changes' do
1605
+ expect(person.saved_change_to_attribute?(:title)).to be_truthy
1606
+ expect(person.saved_change_to_attribute?(:title, from: 'Grand Poobah')).to be_truthy
1607
+ expect(person.saved_change_to_attribute?(:title, to: 'Captain Obvious')).to be_truthy
1608
+ expect(person.saved_change_to_attribute?(:title, from: 'Grand Poobah', to: 'Captain Obvious')).to be_truthy
1609
+ expect(person.saved_change_to_title?(from: 'Grand Poobah', to: 'Captain Obvious')).to be_truthy
1610
+ expect(person.saved_change_to_attribute?(:age)).to be_falsey
1611
+ expect(person.saved_change_to_age?).to be_falsey
1612
+ end
1613
+ end
1614
+
1615
+ context 'when the document has not been saved' do
1616
+ let(:person) do
1617
+ Person.new(title: 'Grand Poobah')
1618
+ end
1619
+
1620
+ it 'returns changes for the previous save' do
1621
+ expect(person.saved_change_to_attribute?(:title)).to be_falsey
1622
+ expect(person.saved_change_to_title?).to be_falsey
1346
1623
  end
1347
1624
  end
1348
1625
  end
1349
1626
 
1350
- context "when fields have been defined pre-dirty inclusion" do
1627
+ describe '#will_save_change_to_attribute?' do
1628
+ let(:person) do
1629
+ Person.create!(title: 'Grand Poobah')
1630
+ end
1631
+
1632
+ before do
1633
+ person.title = 'Captain Obvious'
1634
+ end
1351
1635
 
1636
+ it 'correctly detects changes' do
1637
+ expect(person.will_save_change_to_attribute?(:title)).to eq(true)
1638
+ expect(person.will_save_change_to_title?).to eq(true)
1639
+ expect(person.will_save_change_to_attribute?(:score)).to eq(false)
1640
+ expect(person.will_save_change_to_score?).to eq(false)
1641
+ end
1642
+ end
1643
+
1644
+ context 'when fields have been defined pre-dirty inclusion' do
1352
1645
  let(:document) do
1353
1646
  Dokument.new
1354
1647
  end
1355
1648
 
1356
- it "defines a _change method" do
1649
+ it 'defines a _change method' do
1357
1650
  expect(document.updated_at_change).to be_nil
1358
1651
  end
1359
1652
 
1360
- it "defines a _changed? method" do
1653
+ it 'defines a _changed? method' do
1361
1654
  expect(document.updated_at_changed?).to be false
1362
1655
  end
1363
1656
 
1364
- it "defines a _changes method" do
1657
+ it 'defines a _changes method' do
1365
1658
  expect(document.updated_at_was).to be_nil
1366
1659
  end
1367
1660
  end
1368
1661
 
1369
- context "when only embedded documents change" do
1370
-
1662
+ context 'when only embedded documents change' do
1371
1663
  let!(:person) do
1372
- Person.create
1664
+ Person.create!
1373
1665
  end
1374
1666
 
1375
- context "when the child is an embeds one" do
1376
-
1377
- context "when the child is new" do
1378
-
1667
+ context 'when the child is an embeds one' do
1668
+ context 'when the child is new' do
1379
1669
  let!(:name) do
1380
- person.build_name(first_name: "Gordon", last_name: "Ramsay")
1670
+ person.build_name(first_name: 'Gordon', last_name: 'Ramsay')
1381
1671
  end
1382
1672
 
1383
- it "flags the parent as changed" do
1673
+ it 'flags the parent as changed' do
1384
1674
  expect(person).to be_changed
1385
1675
  end
1386
1676
  end
1387
1677
 
1388
- context "when the child is modified" do
1389
-
1678
+ context 'when the child is modified' do
1390
1679
  let!(:name) do
1391
- person.create_name(first_name: "Gordon", last_name: "Ramsay")
1680
+ person.create_name(first_name: 'Gordon', last_name: 'Ramsay')
1392
1681
  end
1393
1682
 
1394
1683
  before do
1395
- name.first_name = "G"
1684
+ name.first_name = 'G'
1396
1685
  end
1397
1686
 
1398
- it "flags the parent as changed" do
1687
+ it 'flags the parent as changed' do
1399
1688
  expect(person).to be_changed
1400
1689
  end
1401
1690
  end
1402
1691
 
1403
- context "when the child is not modified" do
1404
-
1692
+ context 'when the child is not modified' do
1405
1693
  let!(:name) do
1406
- person.create_name(first_name: "Gordon", last_name: "Ramsay")
1694
+ person.create_name(first_name: 'Gordon', last_name: 'Ramsay')
1407
1695
  end
1408
1696
 
1409
- it "does not flag the parent as changed" do
1410
- expect(person).to_not be_changed
1697
+ it 'does not flag the parent as changed' do
1698
+ expect(person).not_to be_changed
1411
1699
  end
1412
1700
  end
1413
1701
  end
1414
1702
 
1415
- context "when the child is an embeds many" do
1416
-
1417
- context "when a child is new" do
1418
-
1703
+ context 'when the child is an embeds many' do
1704
+ context 'when a child is new' do
1419
1705
  let!(:address) do
1420
- person.addresses.build(street: "jakobstr.")
1706
+ person.addresses.build(street: 'jakobstr.')
1421
1707
  end
1422
1708
 
1423
- it "flags the parent as changed" do
1709
+ it 'flags the parent as changed' do
1424
1710
  expect(person).to be_changed
1425
1711
  end
1426
1712
  end
1427
1713
 
1428
- context "when a child is modified" do
1429
-
1714
+ context 'when a child is modified' do
1430
1715
  let!(:address) do
1431
- person.addresses.create(street: "jakobstr.")
1716
+ person.addresses.create!(street: 'jakobstr.')
1432
1717
  end
1433
1718
 
1434
1719
  before do
1435
- address.city = "Berlin"
1720
+ address.city = 'Berlin'
1436
1721
  end
1437
1722
 
1438
- it "flags the parent as changed" do
1723
+ it 'flags the parent as changed' do
1439
1724
  expect(person).to be_changed
1440
1725
  end
1441
1726
  end
1442
1727
 
1443
- context "when no child is modified" do
1444
-
1728
+ context 'when no child is modified' do
1445
1729
  let!(:address) do
1446
- person.addresses.create(street: "skalitzerstr.")
1730
+ person.addresses.create!(street: 'skalitzerstr.')
1447
1731
  end
1448
1732
 
1449
- it "does not flag the parent as changed" do
1450
- expect(person).to_not be_changed
1733
+ it 'does not flag the parent as changed' do
1734
+ expect(person).not_to be_changed
1451
1735
  end
1452
1736
  end
1453
1737
  end
1454
1738
  end
1455
1739
 
1456
- context "when changing a hash of hashes" do
1457
-
1740
+ context 'when changing a hash of hashes' do
1458
1741
  let!(:person) do
1459
- Person.create(map: { "test" => {}})
1742
+ Person.create!(map: { 'test' => {} })
1460
1743
  end
1461
1744
 
1462
1745
  before do
1463
- person.map["test"]["value"] = 10
1746
+ person.map['test']['value'] = 10
1464
1747
  end
1465
1748
 
1466
- it "records the changes" do
1749
+ it 'records the changes' do
1467
1750
  expect(person.changes).to eq(
1468
- { "map" => [{ "test" => {}}, { "test" => { "value" => 10 }}]}
1751
+ { 'map' => [ { 'test' => {} }, { 'test' => { 'value' => 10 } } ] }
1469
1752
  )
1470
1753
  end
1471
1754
  end
1472
1755
 
1473
- context "when modifying a many to many key" do
1474
-
1756
+ context 'when modifying a many to many key' do
1475
1757
  let!(:person) do
1476
- Person.create
1758
+ Person.create!
1477
1759
  end
1478
1760
 
1479
1761
  let!(:preference) do
1480
- Preference.create(name: "dirty")
1762
+ Preference.create!(name: 'dirty')
1481
1763
  end
1482
1764
 
1483
1765
  before do
1484
- person.update_attributes(preference_ids: [ preference.id ])
1766
+ person.update_attributes!(preference_ids: [ preference.id ])
1485
1767
  end
1486
1768
 
1487
- it "records the foreign key dirty changes" do
1488
- expect(person.previous_changes["preference_ids"]).to eq(
1489
- [nil, [ preference.id ]]
1769
+ it 'records the foreign key dirty changes' do
1770
+ expect(person.previous_changes['preference_ids']).to eq(
1771
+ [ nil, [ preference.id ] ]
1490
1772
  )
1491
1773
  end
1492
1774
  end
1493
1775
 
1494
- context "when accessing an array field" do
1495
-
1776
+ context 'when accessing an array field' do
1496
1777
  let!(:person) do
1497
- Person.create
1778
+ Person.create!
1498
1779
  end
1499
1780
 
1500
1781
  let(:from_db) do
1501
1782
  Person.find(person.id)
1502
1783
  end
1503
1784
 
1504
- context "when the field is not changed" do
1505
-
1785
+ context 'when the field is not changed' do
1506
1786
  before do
1507
1787
  from_db.preference_ids
1508
1788
  end
1509
1789
 
1510
- it "flags the change" do
1511
- expect(from_db.changes["preference_ids"]).to eq([ nil, []])
1790
+ it 'flags the change' do
1791
+ expect(from_db.changes['preference_ids']).to eq([ nil, [] ])
1512
1792
  end
1513
1793
 
1514
- it "does not include the changes in the setters" do
1794
+ it 'does not include the changes in the setters' do
1515
1795
  expect(from_db.setters).to be_empty
1516
1796
  end
1517
1797
  end
1518
1798
  end
1519
1799
 
1520
- context "when reloading an unchanged document" do
1521
-
1800
+ context 'when reloading an unchanged document' do
1522
1801
  let!(:person) do
1523
- Person.create
1802
+ Person.create!
1524
1803
  end
1525
1804
 
1526
1805
  let(:from_db) do
@@ -1531,173 +1810,173 @@ describe Mongoid::Changeable do
1531
1810
  from_db.reload
1532
1811
  end
1533
1812
 
1534
- it "clears the changed attributes" do
1813
+ it 'clears the changed attributes' do
1535
1814
  expect(from_db.changed_attributes).to be_empty
1536
1815
  end
1537
1816
  end
1538
1817
 
1539
- context "when fields are getting changed" do
1540
-
1818
+ context 'when fields are getting changed' do
1541
1819
  let(:person) do
1542
- Person.create(
1543
- title: "MC",
1820
+ Person.create!(
1821
+ title: 'MC',
1544
1822
  some_dynamic_field: 'blah'
1545
1823
  )
1546
1824
  end
1547
1825
 
1548
1826
  before do
1549
- person.title = "DJ"
1550
- person.write_attribute(:ssn, "222-22-2222")
1827
+ person.title = 'DJ'
1828
+ person.write_attribute(:ssn, '222-22-2222')
1551
1829
  person.some_dynamic_field = 'bloop'
1552
1830
  end
1553
1831
 
1554
- it "marks the document as changed" do
1832
+ it 'marks the document as changed' do
1555
1833
  expect(person).to be_changed
1556
1834
  end
1557
1835
 
1558
- it "marks field changes" do
1836
+ it 'marks field changes' do
1559
1837
  expect(person.changes).to eq({
1560
- "title" => [ "MC", "DJ" ],
1561
- "ssn" => [ nil, "222-22-2222" ],
1562
- "some_dynamic_field" => [ "blah", "bloop" ]
1563
- })
1838
+ 'title' => %w[MC DJ],
1839
+ 'ssn' => [ nil, '222-22-2222' ],
1840
+ 'some_dynamic_field' => %w[blah bloop]
1841
+ })
1564
1842
  end
1565
1843
 
1566
- it "marks changed fields" do
1567
- expect(person.changed).to eq([ "title", "ssn", "some_dynamic_field" ])
1844
+ it 'marks changed fields' do
1845
+ expect(person.changed).to eq(%w[title ssn some_dynamic_field])
1568
1846
  end
1569
1847
 
1570
- it "marks the field as changed" do
1848
+ it 'marks the field as changed' do
1571
1849
  expect(person.title_changed?).to be true
1572
1850
  end
1573
1851
 
1574
- it "stores previous field values" do
1575
- expect(person.title_was).to eq("MC")
1852
+ it 'stores previous field values' do
1853
+ expect(person.title_was).to eq('MC')
1576
1854
  end
1577
1855
 
1578
- it "marks field changes" do
1579
- expect(person.title_change).to eq([ "MC", "DJ" ])
1856
+ it 'marks field changes' do
1857
+ expect(person.title_change).to eq(%w[MC DJ])
1580
1858
  end
1581
1859
 
1582
- it "allows reset of field changes" do
1860
+ it 'allows reset of field changes' do
1583
1861
  person.reset_title!
1584
- expect(person.title).to eq("MC")
1585
- expect(person.changed).to eq([ "ssn", "some_dynamic_field" ])
1862
+ expect(person.title).to eq('MC')
1863
+ expect(person.changed).to eq(%w[ssn some_dynamic_field])
1586
1864
  end
1587
1865
 
1588
- context "after a save" do
1589
-
1866
+ context 'after a save' do
1590
1867
  before do
1591
1868
  person.save!
1592
1869
  end
1593
1870
 
1594
- it "clears changes" do
1595
- expect(person).to_not be_changed
1871
+ it 'clears changes' do
1872
+ expect(person).not_to be_changed
1596
1873
  end
1597
1874
 
1598
- it "stores previous changes" do
1599
- expect(person.previous_changes["title"]).to eq([ "MC", "DJ" ])
1600
- expect(person.previous_changes["ssn"]).to eq([ nil, "222-22-2222" ])
1875
+ it 'stores previous changes' do
1876
+ expect(person.previous_changes['title']).to eq(%w[MC DJ])
1877
+ expect(person.previous_changes['ssn']).to eq([ nil, '222-22-2222' ])
1601
1878
  end
1602
1879
  end
1603
1880
 
1604
- context "when the previous value is nil" do
1605
-
1881
+ context 'when the previous value is nil' do
1606
1882
  before do
1607
1883
  person.score = 100
1608
1884
  person.reset_score!
1609
1885
  end
1610
1886
 
1611
- it "removes the attribute from the document" do
1887
+ it 'removes the attribute from the document' do
1612
1888
  expect(person.score).to be_nil
1613
1889
  end
1614
1890
  end
1615
1891
  end
1616
1892
 
1617
- context "when accessing dirty attributes in callbacks" do
1618
-
1619
- context "when the document is persisted" do
1620
-
1893
+ context 'when accessing dirty attributes in callbacks' do
1894
+ context 'when the document is persisted' do
1621
1895
  let!(:acolyte) do
1622
- Acolyte.create(name: "callback-test")
1896
+ Acolyte.create!(name: 'callback-test')
1623
1897
  end
1624
1898
 
1625
1899
  before do
1626
1900
  Acolyte.set_callback(:save, :after, if: :callback_test?) do |doc|
1627
- doc[:changed_in_callback] = doc.changes.dup
1901
+ doc[:changed_in_after_callback] = doc.changes.dup
1902
+ end
1903
+
1904
+ Acolyte.set_callback(:save, :before, if: :callback_test?) do |doc|
1905
+ doc[:changed_in_before_callback] = doc.changes.dup
1628
1906
  end
1629
1907
  end
1630
1908
 
1631
1909
  after do
1632
1910
  Acolyte._save_callbacks.select do |callback|
1633
- callback.kind == :after
1911
+ %i[before after].include?(callback.kind)
1634
1912
  end.each do |callback|
1635
1913
  Acolyte._save_callbacks.delete(callback)
1636
1914
  end
1637
1915
  end
1638
1916
 
1639
- it "retains the changes until after all callbacks" do
1640
- acolyte.update_attribute(:status, "testing")
1641
- expect(acolyte.changed_in_callback).to eq({ "status" => [ nil, "testing" ] })
1917
+ it 'does not retain the changes until after all callbacks' do
1918
+ acolyte.update_attribute(:status, 'testing')
1919
+ expect(acolyte.changed_in_before_callback).to eq({ 'status' => [ nil, 'testing' ] })
1920
+ expect(acolyte.changed_in_after_callback).to eq({})
1642
1921
  end
1643
1922
  end
1644
1923
 
1645
- context "when the document is new" do
1646
-
1924
+ context 'when the document is new' do
1647
1925
  let!(:acolyte) do
1648
- Acolyte.new(name: "callback-test")
1926
+ Acolyte.new(name: 'callback-test')
1649
1927
  end
1650
1928
 
1651
1929
  before do
1652
1930
  Acolyte.set_callback(:save, :after, if: :callback_test?) do |doc|
1653
- doc[:changed_in_callback] = doc.changes.dup
1931
+ doc[:changed_after_in_callback] = doc.changes.dup
1932
+ end
1933
+
1934
+ Acolyte.set_callback(:save, :before, if: :callback_test?) do |doc|
1935
+ doc[:changed_before_in_callback] = doc.changes.dup
1654
1936
  end
1655
1937
  end
1656
1938
 
1657
1939
  after do
1658
1940
  Acolyte._save_callbacks.select do |callback|
1659
- callback.kind == :after
1941
+ %i[before after].include?(callback.kind)
1660
1942
  end.each do |callback|
1661
1943
  Acolyte._save_callbacks.delete(callback)
1662
1944
  end
1663
1945
  end
1664
1946
 
1665
- it "retains the changes until after all callbacks" do
1666
- acolyte.save
1667
- expect(acolyte.changed_in_callback["name"]).to eq([ nil, "callback-test" ])
1947
+ it 'does not retain the changes until after all callbacks' do
1948
+ acolyte.save!
1949
+ expect(acolyte.changed_before_in_callback['name']).to eq([ nil, 'callback-test' ])
1950
+ expect(acolyte.changed_after_in_callback['name']).to be_nil
1668
1951
  end
1669
1952
  end
1670
1953
  end
1671
1954
 
1672
- context "when associations are getting changed" do
1673
-
1955
+ context 'when associations are getting changed' do
1674
1956
  let(:person) do
1675
- Person.create(addresses: [ Address.new ])
1957
+ Person.create!(addresses: [ Address.new ])
1676
1958
  end
1677
1959
 
1678
1960
  before do
1679
1961
  person.addresses = [ Address.new ]
1680
1962
  end
1681
1963
 
1682
- it "does not set the association to nil when hitting the database" do
1683
- expect(person.setters).to_not eq({ "addresses" => nil })
1964
+ it 'does not set the association to nil when hitting the database' do
1965
+ expect(person.setters).not_to eq({ 'addresses' => nil })
1684
1966
  end
1685
1967
  end
1686
1968
 
1687
1969
  context 'when nesting deeply embedded documents' do
1688
-
1689
1970
  context 'when persisting the root document' do
1690
-
1691
1971
  let!(:person) do
1692
- Person.create
1972
+ Person.create!
1693
1973
  end
1694
1974
 
1695
1975
  it 'is not marked as changed' do
1696
- expect(person).to_not be_changed
1976
+ expect(person).not_to be_changed
1697
1977
  end
1698
1978
 
1699
1979
  context 'when creating a new first level embedded document' do
1700
-
1701
1980
  let!(:address) do
1702
1981
  person.addresses.new(street: 'goltzstr.')
1703
1982
  end
@@ -1711,9 +1990,8 @@ describe Mongoid::Changeable do
1711
1990
  end
1712
1991
 
1713
1992
  context 'when building the lowest level document' do
1714
-
1715
1993
  before do
1716
- person.save
1994
+ person.save!
1717
1995
  end
1718
1996
 
1719
1997
  let!(:code) do
@@ -1733,9 +2011,8 @@ describe Mongoid::Changeable do
1733
2011
  end
1734
2012
 
1735
2013
  context 'when saving the hierarchy' do
1736
-
1737
2014
  before do
1738
- person.save
2015
+ person.save!
1739
2016
  end
1740
2017
 
1741
2018
  let(:reloaded) do
@@ -1751,13 +2028,12 @@ describe Mongoid::Changeable do
1751
2028
  end
1752
2029
 
1753
2030
  context 'when embedding further' do
1754
-
1755
2031
  let!(:deepest) do
1756
2032
  reloaded.addresses.first.code.build_deepest
1757
2033
  end
1758
2034
 
1759
2035
  before do
1760
- reloaded.save
2036
+ reloaded.save!
1761
2037
  end
1762
2038
 
1763
2039
  it 'saves the deepest embedded document' do