mongoid 9.0.11 → 9.1.0

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