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,87 +1,74 @@
1
1
  # frozen_string_literal: true
2
- # rubocop:todo all
3
2
 
4
- require "spec_helper"
5
- require_relative './attributes/nested_spec_models'
3
+ require 'spec_helper'
4
+ require_relative 'attributes/nested_spec_models'
6
5
 
7
6
  describe Mongoid::Attributes do
8
-
9
7
  describe "\#{attribute}" do
10
-
11
- context "when setting the value in the getter" do
12
-
8
+ context 'when setting the value in the getter' do
13
9
  let(:account) do
14
10
  Account.new
15
11
  end
16
12
 
17
- it "does not cause an infinite loop" do
18
- expect(account.overridden).to eq("not recommended")
13
+ it 'does not cause an infinite loop' do
14
+ expect(account.overridden).to eq('not recommended')
19
15
  end
20
16
  end
21
17
 
22
- context "when the attribute was excluded in a criteria" do
23
-
18
+ context 'when the attribute was excluded in a criteria' do
24
19
  let!(:person) do
25
- Person.create!(title: "sir")
20
+ Person.create!(title: 'sir')
26
21
  end
27
22
 
28
- context "when the attribute is localized" do
29
-
23
+ context 'when the attribute is localized' do
30
24
  before do
31
- person.update_attribute(:desc, "test")
25
+ person.update_attribute(:desc, 'test')
32
26
  end
33
27
 
34
- context "when the context includes" do
35
-
36
- context "when the attribute exists" do
37
-
28
+ context 'when the context includes' do
29
+ context 'when the attribute exists' do
38
30
  let(:from_db) do
39
31
  Person.only(:desc).first
40
32
  end
41
33
 
42
- it "does not raise an error" do
43
- expect(from_db.desc).to eq("test")
34
+ it 'does not raise an error' do
35
+ expect(from_db.desc).to eq('test')
44
36
  end
45
37
 
46
- context "accessing via []" do
47
-
48
- it "does not raise an error" do
49
- expect(from_db["desc"]).to eq("test")
38
+ context 'accessing via []' do
39
+ it 'does not raise an error' do
40
+ expect(from_db['desc']).to eq('test')
50
41
  end
51
42
  end
52
43
 
53
- context "when calling only on a sub-document" do
54
-
55
- let(:title) {"Executive"}
56
- let(:city) {"NYC"}
44
+ context 'when calling only on a sub-document' do
45
+ let(:title) { 'Executive' }
46
+ let(:city) { 'NYC' }
57
47
  let!(:agent) do
58
- agent = Agent.new(:title => title)
59
- agent.build_address(:city => city)
60
- agent.save!()
48
+ agent = Agent.new(title: title)
49
+ agent.build_address(city: city)
50
+ agent.save!
61
51
  agent
62
52
  end
63
53
  let(:from_db) do
64
- Agent.only(:title, "address.city").first
54
+ Agent.only(:title, 'address.city').first
65
55
  end
66
56
 
67
- context "when the field is in the only" do
68
-
69
- it "does not raise an error" do
57
+ context 'when the field is in the only' do
58
+ it 'does not raise an error' do
70
59
  expect(from_db.address.city).to eq(city)
71
60
  end
72
61
  end
73
62
 
74
- context "accessing via []" do
75
-
76
- it "does not raise an error" do
77
- expect(from_db["address.city"]).to eq(city)
63
+ context 'accessing via []' do
64
+ it 'does not raise an error' do
65
+ expect(from_db['address.city']).to eq(city)
78
66
  end
79
67
  end
80
68
  end
81
69
  end
82
70
 
83
71
  context 'when the attribute is a hash field' do
84
-
85
72
  before do
86
73
  person.update_attribute(:map, map)
87
74
  end
@@ -94,19 +81,18 @@ describe Mongoid::Attributes do
94
81
  Person.only('map.dates.y.2016').first
95
82
  end
96
83
 
97
- it "does not raise an error" do
84
+ it 'does not raise an error' do
98
85
  expect(from_db.map).to eq(map)
99
86
  end
100
87
 
101
88
  context 'when only one of the hash fields is projected' do
102
-
103
89
  let(:map) do
104
90
  { 'dates' => { 'y' => { '2016' => 'Berlin', '2017' => 'Munich' } } }
105
91
  end
106
92
 
107
93
  let(:expected) do
108
94
  { 'dates' => { 'y' => {
109
- '2016' => 'Berlin',
95
+ '2016' => 'Berlin'
110
96
  } } }
111
97
  end
112
98
 
@@ -116,19 +102,18 @@ describe Mongoid::Attributes do
116
102
  end
117
103
 
118
104
  context 'when several of the hash fields is projected' do
119
-
120
105
  let(:map) do
121
106
  { 'dates' => { 'y' => {
122
107
  '2016' => 'Berlin',
123
108
  '2017' => 'Munich',
124
- '2018' => 'Krakow',
109
+ '2018' => 'Krakow'
125
110
  } } }
126
111
  end
127
112
 
128
113
  let(:expected) do
129
114
  { 'dates' => { 'y' => {
130
115
  '2016' => 'Berlin',
131
- '2018' => 'Krakow',
116
+ '2018' => 'Krakow'
132
117
  } } }
133
118
  end
134
119
 
@@ -143,62 +128,58 @@ describe Mongoid::Attributes do
143
128
  end
144
129
  end
145
130
 
146
- context "when the context excludes" do
147
-
148
- context "when the attribute exists" do
149
-
131
+ context 'when the context excludes' do
132
+ context 'when the attribute exists' do
150
133
  let(:from_db) do
151
134
  Person.without(:pets).first
152
135
  end
153
136
 
154
- it "does not raise an error" do
155
- expect(from_db.desc).to eq("test")
137
+ it 'does not raise an error' do
138
+ expect(from_db.desc).to eq('test')
156
139
  end
157
140
  end
158
141
  end
159
142
  end
160
143
 
161
- context "when excluding with only" do
162
-
144
+ context 'when excluding with only' do
163
145
  let(:from_db) do
164
146
  Person.only(:_id).first
165
147
  end
166
148
 
167
- it "raises an error" do
168
- expect {
149
+ it 'raises an error' do
150
+ expect do
169
151
  from_db.title
170
- }.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'title' on Person which was not loaded/)
152
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
153
+ /Attempted to access attribute 'title' on Person which was not loaded/)
171
154
  end
172
155
 
173
- context "accessing via []" do
174
-
175
- it "raises an error" do
176
- expect {
177
- from_db["title"]
178
- }.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'title' on Person which was not loaded/)
156
+ context 'accessing via []' do
157
+ it 'raises an error' do
158
+ expect do
159
+ from_db['title']
160
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
161
+ /Attempted to access attribute 'title' on Person which was not loaded/)
179
162
  end
180
163
  end
181
164
  end
182
165
 
183
- context "when excluding with without" do
184
-
166
+ context 'when excluding with without' do
185
167
  let(:from_db) do
186
168
  Person.without(:title).first
187
169
  end
188
170
 
189
- it "raises an error" do
190
- expect {
171
+ it 'raises an error' do
172
+ expect do
191
173
  from_db.title
192
- }.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'title' on Person which was not loaded/)
174
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
175
+ /Attempted to access attribute 'title' on Person which was not loaded/)
193
176
  end
194
177
  end
195
178
  end
196
179
  end
197
180
 
198
- describe "#[]" do
199
-
181
+ describe '#[]' do
200
182
  context 'when the document has a custom attribute type' do
201
-
202
183
  let(:bar) do
203
184
  Bar.create!(lat_lng: LatLng.new(52.30, 13.25))
204
185
  end
@@ -208,139 +189,125 @@ describe Mongoid::Attributes do
208
189
  end
209
190
  end
210
191
 
211
- context "when the document is a new record" do
212
-
192
+ context 'when the document is a new record' do
213
193
  let(:person) do
214
194
  Person.new
215
195
  end
216
196
 
217
- context "when accessing a localized field" do
218
-
197
+ context 'when accessing a localized field' do
219
198
  before do
220
- person.desc = "testing"
199
+ person.desc = 'testing'
221
200
  end
222
201
 
223
- context "when passing just the name" do
224
-
225
- it "returns the full value" do
226
- expect(person[:desc]).to eq("testing")
202
+ context 'when passing just the name' do
203
+ it 'returns the full value' do
204
+ expect(person[:desc]).to eq('testing')
227
205
  end
228
206
  end
229
207
 
230
- context "when passing the name with locale" do
231
-
232
- it "returns the value for the locale" do
233
- expect(person["desc.en"]).to eq("testing")
208
+ context 'when passing the name with locale' do
209
+ it 'returns the value for the locale' do
210
+ expect(person['desc.en']).to eq('testing')
234
211
  end
235
212
  end
236
213
  end
237
214
 
238
- context "when attribute does not exist" do
239
-
240
- it "returns the default value" do
215
+ context 'when attribute does not exist' do
216
+ it 'returns the default value' do
241
217
  expect(person[:age]).to eq(100)
242
218
  end
243
219
  end
244
220
 
245
- context "when attribute is not accessible" do
246
-
221
+ context 'when attribute is not accessible' do
247
222
  before do
248
223
  person.owner_id = 5
249
224
  end
250
225
 
251
- it "returns the value" do
226
+ it 'returns the value' do
252
227
  expect(person[:owner_id]).to eq(5)
253
228
  end
254
229
  end
255
230
  end
256
231
 
257
- context "when the document is an existing record" do
258
-
232
+ context 'when the document is an existing record' do
259
233
  let!(:person) do
260
- Person.create!(title: "sir")
234
+ Person.create!(title: 'sir')
261
235
  end
262
236
 
263
- context "when the attribute was excluded in a criteria" do
264
-
265
- context "when excluding with only" do
266
-
237
+ context 'when the attribute was excluded in a criteria' do
238
+ context 'when excluding with only' do
267
239
  let(:from_db) do
268
240
  Person.only(:_id).first
269
241
  end
270
242
 
271
- it "raises an error" do
272
- expect {
243
+ it 'raises an error' do
244
+ expect do
273
245
  from_db[:title]
274
- }.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'title' on Person which was not loaded/)
246
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
247
+ /Attempted to access attribute 'title' on Person which was not loaded/)
275
248
  end
276
249
  end
277
250
 
278
- context "when excluding with without" do
279
-
251
+ context 'when excluding with without' do
280
252
  let(:from_db) do
281
253
  Person.without(:title).first
282
254
  end
283
255
 
284
- it "raises an error" do
285
- expect {
256
+ it 'raises an error' do
257
+ expect do
286
258
  from_db[:title]
287
- }.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'title' on Person which was not loaded/)
259
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
260
+ /Attempted to access attribute 'title' on Person which was not loaded/)
288
261
  end
289
262
  end
290
263
  end
291
264
 
292
- context "when given nil" do
293
-
294
- it "returns nil" do
295
- expect(person[nil]).to be nil
265
+ context 'when given nil' do
266
+ it 'returns nil' do
267
+ expect(person[nil]).to be_nil
296
268
  end
297
-
298
269
  end
299
270
 
300
- context "when given an empty string" do
301
-
302
- it "returns nil" do
303
- expect(person[""]).to be nil
271
+ context 'when given an empty string' do
272
+ it 'returns nil' do
273
+ expect(person['']).to be_nil
304
274
  end
305
-
306
275
  end
307
276
 
308
- context "when the field was not explicitly defined" do
309
-
310
- context "when excluding with only and the field was not excluded" do
311
-
277
+ context 'when the field was not explicitly defined' do
278
+ context 'when excluding with only and the field was not excluded' do
312
279
  let(:from_db) do
313
280
  Person.only(:_id).first
314
281
  end
315
282
 
316
- it "raises an error" do
317
- expect {
283
+ it 'raises an error' do
284
+ expect do
318
285
  from_db[:undefined_field]
319
- }.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'undefined_field' on Person which was not loaded/)
286
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
287
+ /Attempted to access attribute 'undefined_field' on Person which was not loaded/)
320
288
  end
321
289
  end
322
290
 
323
- context "when excluding with without and the field was excluded" do
324
-
291
+ context 'when excluding with without and the field was excluded' do
325
292
  let(:from_db) do
326
293
  Person.without(:title).first
327
294
  end
328
295
 
329
- it "raises an error" do
330
- expect {
296
+ it 'raises an error' do
297
+ expect do
331
298
  from_db[:title]
332
- }.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'title' on Person which was not loaded/)
299
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
300
+ /Attempted to access attribute 'title' on Person which was not loaded/)
333
301
  end
334
302
  end
335
303
 
336
- context "when excluding with without and the field was not excluded" do
337
-
304
+ context 'when excluding with without and the field was not excluded' do
338
305
  let(:from_db) do
339
306
  Person.without(:title).first
340
307
  end
341
308
 
342
- it "returns nil" do
343
- from_db[:undefined_field].should be nil
309
+ it 'returns nil' do
310
+ from_db[:undefined_field].should be_nil
344
311
  end
345
312
  end
346
313
  end
@@ -356,7 +323,6 @@ describe Mongoid::Attributes do
356
323
  end
357
324
 
358
325
  context 'when retrieving a field of the association using the dot notation' do
359
-
360
326
  it 'retrieves the field' do
361
327
  expect(from_db['name.first_name']).to eq 'Jose'
362
328
  end
@@ -384,39 +350,38 @@ describe Mongoid::Attributes do
384
350
  it 'raises AttributeNotLoaded' do
385
351
  expect do
386
352
  from_db['name.first_name']
387
- end.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'name.first_name' on Person which was not loaded/)
353
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
354
+ /Attempted to access attribute 'name.first_name' on Person which was not loaded/)
388
355
  end
389
356
  end
390
357
  end
391
358
  end
392
359
 
393
- context "when the attribute does not exist" do
394
-
360
+ context 'when the attribute does not exist' do
395
361
  before do
396
362
  person.collection
397
- .find({ _id: person.id })
398
- .update_one({ "$unset" => { age: 1 }})
363
+ .find({ _id: person.id })
364
+ .update_one({ '$unset' => { age: 1 } })
399
365
  end
400
366
 
401
- context "when found" do
402
-
367
+ context 'when found' do
403
368
  let(:found) do
404
369
  Person.find(person.id)
405
370
  end
406
371
 
407
- it "returns the default value" do
372
+ it 'returns the default value' do
408
373
  expect(found[:age]).to eq(100)
409
374
  end
410
375
  end
411
376
 
412
- context "when reloaded" do
377
+ context 'when reloaded' do
413
378
  config_override :raise_not_found_error, false
414
379
 
415
380
  before do
416
381
  person.reload
417
382
  end
418
383
 
419
- it "returns the default value" do
384
+ it 'returns the default value' do
420
385
  expect(person[:age]).to eq(100)
421
386
  end
422
387
  end
@@ -424,10 +389,12 @@ describe Mongoid::Attributes do
424
389
  end
425
390
  end
426
391
 
427
- describe "#[]=" do
392
+ describe '#[]=' do
393
+ let(:person) do
394
+ Person.new
395
+ end
428
396
 
429
397
  context 'when the document has a custom attribute type' do
430
-
431
398
  let(:bar) do
432
399
  Bar.new.tap do |b|
433
400
  b[:lat_lng] = LatLng.new(52.30, 13.25)
@@ -440,36 +407,30 @@ describe Mongoid::Attributes do
440
407
  end
441
408
  end
442
409
 
443
- let(:person) do
444
- Person.new
445
- end
446
-
447
- context "when setting the attribute to nil" do
448
-
410
+ context 'when setting the attribute to nil' do
449
411
  let!(:age) do
450
412
  person[:age] = nil
451
413
  end
452
414
 
453
- it "does not use the default value" do
415
+ it 'does not use the default value' do
454
416
  expect(person.age).to be_nil
455
417
  end
456
418
 
457
- it "returns the set value" do
419
+ it 'returns the set value' do
458
420
  expect(age).to be_nil
459
421
  end
460
422
  end
461
423
 
462
- context "when field has a default value" do
463
-
424
+ context 'when field has a default value' do
464
425
  let!(:terms) do
465
426
  person[:terms] = true
466
427
  end
467
428
 
468
- it "allows overwriting of the default value" do
429
+ it 'allows overwriting of the default value' do
469
430
  expect(person.terms).to be true
470
431
  end
471
432
 
472
- it "returns the set value" do
433
+ it 'returns the set value' do
473
434
  expect(terms).to eq(true)
474
435
  end
475
436
  end
@@ -482,102 +443,96 @@ describe Mongoid::Attributes do
482
443
  end
483
444
 
484
445
  it 'writes the value into attributes' do
485
- bar.attributes.should == {'_id' => bar.id, 'missing_field' => 42}
446
+ bar.attributes.should eq({ '_id' => bar.id, 'missing_field' => 42 })
486
447
  end
487
448
 
488
449
  it 'makes the attribute accessible via []' do
489
- bar['missing_field'].should == 42
450
+ bar['missing_field'].should eq 42
490
451
  end
491
452
 
492
453
  context 'when writing fields on a document with projection' do
493
-
494
454
  let!(:person) do
495
- Person.create!(title: "sir")
455
+ Person.create!(title: 'sir')
496
456
  end
497
457
 
498
- context "when excluding with only and the field was not excluded" do
499
-
458
+ context 'when excluding with only and the field was not excluded' do
500
459
  let(:from_db) do
501
460
  Person.only(:_id).first
502
461
  end
503
462
 
504
- it "raises an error" do
505
- expect {
463
+ it 'raises an error' do
464
+ expect do
506
465
  from_db[:undefined_field] = 'x'
507
- }.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'undefined_field' on Person which was not loaded/)
466
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
467
+ /Attempted to access attribute 'undefined_field' on Person which was not loaded/)
508
468
  end
509
469
  end
510
470
 
511
- context "when excluding with without and the field was excluded" do
512
-
471
+ context 'when excluding with without and the field was excluded' do
513
472
  let(:from_db) do
514
473
  Person.without(:title).first
515
474
  end
516
475
 
517
- it "raises an error" do
518
- expect {
476
+ it 'raises an error' do
477
+ expect do
519
478
  from_db[:title] = 'x'
520
- }.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'title' on Person which was not loaded/)
479
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
480
+ /Attempted to access attribute 'title' on Person which was not loaded/)
521
481
  end
522
482
  end
523
483
 
524
- context "when excluding with without and the field was not excluded" do
525
-
484
+ context 'when excluding with without and the field was not excluded' do
526
485
  let(:from_db) do
527
486
  Person.without(:title).first
528
487
  end
529
488
 
530
- it "writes the value" do
489
+ it 'writes the value' do
531
490
  from_db[:undefined_field] = 'x'
532
- from_db[:undefined_field].should == 'x'
491
+ from_db[:undefined_field].should eq 'x'
533
492
  end
534
493
  end
535
494
  end
536
495
  end
537
496
  end
538
497
 
539
- describe "#_id" do
540
-
498
+ describe '#_id' do
541
499
  let(:person) do
542
500
  Person.new
543
501
  end
544
502
 
545
- it "delegates to #id" do
503
+ it 'delegates to #id' do
546
504
  expect(person._id).to eq(person.id)
547
505
  end
548
506
 
549
- context "when #id alias is overridden" do
550
-
507
+ context 'when #id alias is overridden' do
551
508
  let(:object) do
552
509
  IdKey.new(key: 'foo')
553
510
  end
554
511
 
555
- it "delegates to another method" do
512
+ it 'delegates to another method' do
556
513
  expect(object.id).to eq(object.key)
557
514
  end
558
515
  end
559
516
  end
560
517
 
561
- describe "#_id=" do
562
-
518
+ describe '#_id=' do
563
519
  after(:all) do
564
520
  Person.field(
565
521
  :_id,
566
522
  type: BSON::ObjectId,
567
523
  pre_processed: true,
568
- default: ->{ BSON::ObjectId.new },
524
+ default: -> { BSON::ObjectId.new },
569
525
  overwrite: true
570
526
  )
571
527
  end
572
528
 
573
- context "when using object ids" do
574
-
529
+ context 'when using object ids' do
575
530
  before(:all) do
576
531
  Person.field(
577
532
  :_id,
578
533
  type: BSON::ObjectId,
579
534
  pre_processed: true,
580
- default: ->{ BSON::ObjectId.new },
535
+ default: -> { BSON::ObjectId.new },
581
536
  overwrite: true
582
537
  )
583
538
  end
@@ -590,61 +545,55 @@ describe Mongoid::Attributes do
590
545
  BSON::ObjectId.new
591
546
  end
592
547
 
593
- context "when providing an object id" do
594
-
548
+ context 'when providing an object id' do
595
549
  before do
596
550
  person._id = bson_id
597
551
  end
598
552
 
599
- it "sets the id as the object id" do
553
+ it 'sets the id as the object id' do
600
554
  expect(person.id).to eq(bson_id)
601
555
  end
602
556
  end
603
557
 
604
- context "when providing a string" do
605
-
558
+ context 'when providing a string' do
606
559
  before do
607
560
  person._id = bson_id.to_s
608
561
  end
609
562
 
610
- it "sets the id as the object id" do
563
+ it 'sets the id as the object id' do
611
564
  expect(person.id).to eq(bson_id)
612
565
  end
613
566
  end
614
567
 
615
- context "when providing an integer" do
616
-
568
+ context 'when providing an integer' do
617
569
  before do
618
570
  person._id = 2
619
571
  end
620
572
 
621
- it "sets the id as the supplied value to_s" do
573
+ it 'sets the id as the supplied value to_s' do
622
574
  expect(person.id).to eq(2)
623
575
  end
624
576
  end
625
577
 
626
- context "when #id= alias is overridden" do
627
-
578
+ context 'when #id= alias is overridden' do
628
579
  let(:object) do
629
580
  IdKey.new(key: 'foo')
630
581
  end
631
582
 
632
- it "delegates to another method" do
583
+ it 'delegates to another method' do
633
584
  object.id = 'bar'
634
585
  expect(object.id).to eq('bar')
635
586
  end
636
587
  end
637
-
638
588
  end
639
589
 
640
- context "when using string ids" do
641
-
590
+ context 'when using string ids' do
642
591
  before(:all) do
643
592
  Person.field(
644
593
  :_id,
645
594
  type: String,
646
595
  pre_processed: true,
647
- default: ->{ BSON::ObjectId.new.to_s },
596
+ default: -> { BSON::ObjectId.new.to_s },
648
597
  overwrite: true
649
598
  )
650
599
  end
@@ -657,42 +606,38 @@ describe Mongoid::Attributes do
657
606
  BSON::ObjectId.new
658
607
  end
659
608
 
660
- context "when providing an object id" do
661
-
609
+ context 'when providing an object id' do
662
610
  before do
663
611
  person._id = bson_id
664
612
  end
665
613
 
666
- it "sets the id as the string of the object id" do
614
+ it 'sets the id as the string of the object id' do
667
615
  expect(person.id).to eq(bson_id.to_s)
668
616
  end
669
617
  end
670
618
 
671
- context "when providing a string" do
672
-
619
+ context 'when providing a string' do
673
620
  before do
674
621
  person._id = bson_id.to_s
675
622
  end
676
623
 
677
- it "sets the id as the string" do
624
+ it 'sets the id as the string' do
678
625
  expect(person.id).to eq(bson_id.to_s)
679
626
  end
680
627
  end
681
628
 
682
- context "when providing an integer" do
683
-
629
+ context 'when providing an integer' do
684
630
  before do
685
631
  person._id = 2
686
632
  end
687
633
 
688
- it "sets the id as the supplied value to_s" do
689
- expect(person.id).to eq("2")
634
+ it 'sets the id as the supplied value to_s' do
635
+ expect(person.id).to eq('2')
690
636
  end
691
637
  end
692
638
  end
693
639
 
694
- context "when using integer ids" do
695
-
640
+ context 'when using integer ids' do
696
641
  before(:all) do
697
642
  Person.field(:_id, type: Integer, overwrite: true)
698
643
  end
@@ -701,62 +646,57 @@ describe Mongoid::Attributes do
701
646
  Person.new
702
647
  end
703
648
 
704
- context "when providing a string" do
705
-
649
+ context 'when providing a string' do
706
650
  before do
707
651
  person._id = 1.to_s
708
652
  end
709
653
 
710
- it "sets the id as the integer" do
654
+ it 'sets the id as the integer' do
711
655
  expect(person.id).to eq(1)
712
656
  end
713
657
  end
714
658
 
715
- context "when providing an integer" do
716
-
659
+ context 'when providing an integer' do
717
660
  before do
718
661
  person._id = 2
719
662
  end
720
663
 
721
- it "sets the id as the supplied value" do
664
+ it 'sets the id as the supplied value' do
722
665
  expect(person.id).to eq(2)
723
666
  end
724
667
  end
725
668
  end
726
669
  end
727
670
 
728
- describe "#method_missing" do
729
-
671
+ describe '#method_missing' do
730
672
  let(:attributes) do
731
- { testing: "Testing" }
673
+ { testing: 'Testing' }
732
674
  end
733
675
 
734
676
  let(:person) do
735
677
  Person.new(attributes)
736
678
  end
737
679
 
738
- context "when an attribute exists" do
739
-
740
- it "allows the getter" do
741
- expect(person.testing).to eq("Testing")
680
+ context 'when an attribute exists' do
681
+ it 'allows the getter' do
682
+ expect(person.testing).to eq('Testing')
742
683
  end
743
684
 
744
- it "allows the setter" do
745
- person.testing = "Test"
746
- expect(person.testing).to eq("Test")
685
+ it 'allows the setter' do
686
+ person.testing = 'Test'
687
+ expect(person.testing).to eq('Test')
747
688
  end
748
689
 
749
- it "allows the getter before_type_cast" do
750
- expect(person.testing_before_type_cast).to eq("Testing")
690
+ it 'allows the getter before_type_cast' do
691
+ expect(person.testing_before_type_cast).to eq('Testing')
751
692
  end
752
693
 
753
- it "returns true for respond_to?" do
694
+ it 'returns true for respond_to?' do
754
695
  expect(person.respond_to?(:testing)).to be true
755
696
  end
756
697
  end
757
698
 
758
- context "when the provided value needs mongoization" do
759
-
699
+ context 'when the provided value needs mongoization' do
760
700
  let(:new_years) do
761
701
  DateTime.new(2013, 1, 1, 0, 0, 0)
762
702
  end
@@ -765,77 +705,70 @@ describe Mongoid::Attributes do
765
705
  person[:new_years] = new_years
766
706
  end
767
707
 
768
- it "mongoizes the dynamic field" do
708
+ it 'mongoizes the dynamic field' do
769
709
  expect(person.new_years).to be_a(Time)
770
710
  end
771
711
 
772
- it "keeps the same value" do
712
+ it 'keeps the same value' do
773
713
  expect(person.new_years).to eq(new_years)
774
714
  end
775
715
  end
776
716
  end
777
717
 
778
- describe "#process" do
779
-
780
- context "when attributes dont have fields defined" do
781
-
718
+ describe '#process' do
719
+ context 'when attributes dont have fields defined' do
782
720
  let(:attributes) do
783
721
  {
784
- nofieldstring: "Testing",
722
+ nofieldstring: 'Testing',
785
723
  nofieldint: 5,
786
724
  employer: Employer.new
787
725
  }
788
726
  end
789
727
 
790
- context "when allowing dynamic fields" do
791
-
728
+ context 'when allowing dynamic fields' do
792
729
  let!(:person) do
793
730
  Person.new(attributes)
794
731
  end
795
732
 
796
- context "when attribute is a string" do
797
-
798
- it "adds the string to the attributes" do
799
- expect(person.attributes["nofieldstring"]).to eq("Testing")
733
+ context 'when attribute is a string' do
734
+ it 'adds the string to the attributes' do
735
+ expect(person.attributes['nofieldstring']).to eq('Testing')
800
736
  end
801
737
  end
802
738
 
803
- context "when attribute is not a string" do
804
-
805
- it "adds a cast value to the attributes" do
806
- expect(person.attributes["nofieldint"]).to eq(5)
739
+ context 'when attribute is not a string' do
740
+ it 'adds a cast value to the attributes' do
741
+ expect(person.attributes['nofieldint']).to eq(5)
807
742
  end
808
743
  end
809
744
  end
810
745
 
811
- context "when not allowing dynamic fields" do
812
-
813
- it "raises an unknown attribute error on instantiation" do
814
- expect {
815
- Account.new({ anothernew: "Test" })
816
- }.to raise_error(Mongoid::Errors::UnknownAttribute)
746
+ context 'when not allowing dynamic fields' do
747
+ it 'raises an unknown attribute error on instantiation' do
748
+ expect do
749
+ Account.new({ anothernew: 'Test' })
750
+ end.to raise_error(Mongoid::Errors::UnknownAttribute)
817
751
  end
818
752
  end
819
753
  end
820
754
 
821
- context "when supplied hash has string values" do
822
-
755
+ context 'when supplied hash has string values' do
823
756
  let(:bson_id) do
824
757
  BSON::ObjectId.new
825
758
  end
826
759
 
827
760
  let!(:attributes) do
828
761
  {
829
- title: "value",
830
- age: "30",
831
- terms: "true",
832
- score: "",
762
+ title: 'value',
763
+ age: '30',
764
+ terms: 'true',
765
+ score: '',
833
766
  name: {
834
- _id: "2", first_name: "Test", last_name: "User"
767
+ _id: '2', first_name: 'Test', last_name: 'User'
835
768
  },
836
769
  addresses: [
837
- { _id: "3", street: "First Street" },
838
- { _id: "4", street: "Second Street" }
770
+ { _id: '3', street: 'First Street' },
771
+ { _id: '4', street: 'Second Street' }
839
772
  ]
840
773
  }
841
774
  end
@@ -844,25 +777,23 @@ describe Mongoid::Attributes do
844
777
  Person.new(attributes)
845
778
  end
846
779
 
847
- it "casts integers" do
780
+ it 'casts integers' do
848
781
  expect(person[:age]).to eq(30)
849
782
  end
850
783
 
851
- it "casts booleans" do
784
+ it 'casts booleans' do
852
785
  expect(person[:terms]).to be true
853
786
  end
854
787
 
855
- it "sets empty strings to nil" do
788
+ it 'sets empty strings to nil' do
856
789
  expect(person[:score]).to be_nil
857
790
  end
858
791
  end
859
792
 
860
- context "when associations provided in the attributes" do
861
-
862
- context "when association is a has_one" do
863
-
793
+ context 'when associations provided in the attributes' do
794
+ context 'when association is a has_one' do
864
795
  let(:name) do
865
- Name.new(first_name: "Testy")
796
+ Name.new(first_name: 'Testy')
866
797
  end
867
798
 
868
799
  let(:attributes) do
@@ -873,13 +804,12 @@ describe Mongoid::Attributes do
873
804
  Person.new(attributes)
874
805
  end
875
806
 
876
- it "sets the associations" do
807
+ it 'sets the associations' do
877
808
  expect(person.name).to eq(name)
878
809
  end
879
810
  end
880
811
 
881
- context "when association is a references_one" do
882
-
812
+ context 'when association is a references_one' do
883
813
  let(:game) do
884
814
  Game.new(score: 100)
885
815
  end
@@ -892,52 +822,49 @@ describe Mongoid::Attributes do
892
822
  Person.new(attributes)
893
823
  end
894
824
 
895
- it "sets the parent association" do
825
+ it 'sets the parent association' do
896
826
  expect(person.game).to eq(game)
897
827
  end
898
828
 
899
- it "sets the inverse association" do
829
+ it 'sets the inverse association' do
900
830
  expect(game.person).to eq(person)
901
831
  end
902
832
  end
903
833
 
904
- context "when association is a embedded_in" do
905
-
834
+ context 'when association is a embedded_in' do
906
835
  let(:person) do
907
836
  Person.new
908
837
  end
909
838
 
910
839
  let(:name) do
911
- Name.new(first_name: "Tyler", person: person)
840
+ Name.new(first_name: 'Tyler', person: person)
912
841
  end
913
842
 
914
- it "sets the association" do
843
+ it 'sets the association' do
915
844
  expect(name.person).to eq(person)
916
845
  end
917
846
  end
918
847
  end
919
848
 
920
- context "when non-associations provided in the attributes" do
921
-
849
+ context 'when non-associations provided in the attributes' do
922
850
  let(:employer) do
923
851
  Employer.new
924
852
  end
925
853
 
926
854
  let(:attributes) do
927
- { employer_id: employer.id, title: "Sir" }
855
+ { employer_id: employer.id, title: 'Sir' }
928
856
  end
929
857
 
930
858
  let(:person) do
931
859
  Person.new(attributes)
932
860
  end
933
861
 
934
- it "calls the setter for the association" do
935
- expect(person.employer_id).to eq("1")
862
+ it 'calls the setter for the association' do
863
+ expect(person.employer_id).to eq('1')
936
864
  end
937
865
  end
938
866
 
939
- context "when an empty array is provided in the attributes" do
940
-
867
+ context 'when an empty array is provided in the attributes' do
941
868
  let(:attributes) do
942
869
  { aliases: [] }
943
870
  end
@@ -946,13 +873,12 @@ describe Mongoid::Attributes do
946
873
  Person.new(attributes)
947
874
  end
948
875
 
949
- it "sets the empty array" do
876
+ it 'sets the empty array' do
950
877
  expect(person.aliases).to be_empty
951
878
  end
952
879
  end
953
880
 
954
- context "when an empty hash is provided in the attributes" do
955
-
881
+ context 'when an empty hash is provided in the attributes' do
956
882
  let(:attributes) do
957
883
  { map: {} }
958
884
  end
@@ -961,48 +887,44 @@ describe Mongoid::Attributes do
961
887
  Person.new(attributes)
962
888
  end
963
889
 
964
- it "sets the empty hash" do
890
+ it 'sets the empty hash' do
965
891
  expect(person.map).to eq({})
966
892
  end
967
893
  end
968
894
 
969
- context "when providing tainted parameters" do
970
-
895
+ context 'when providing tainted parameters' do
971
896
  let(:params) do
972
- ActionController::Parameters.new(title: "sir")
897
+ ActionController::Parameters.new(title: 'sir')
973
898
  end
974
899
 
975
- it "raises an error" do
976
- expect {
900
+ it 'raises an error' do
901
+ expect do
977
902
  Person.new(params)
978
- }.to raise_error(ActiveModel::ForbiddenAttributesError)
903
+ end.to raise_error(ActiveModel::ForbiddenAttributesError)
979
904
  end
980
905
  end
981
906
  end
982
907
 
983
- context "updating when attributes already exist" do
984
-
908
+ context 'updating when attributes already exist' do
985
909
  let(:person) do
986
- Person.new(title: "Sir")
910
+ Person.new(title: 'Sir')
987
911
  end
988
912
 
989
913
  let(:attributes) do
990
- { dob: "2000-01-01" }
914
+ { dob: '2000-01-01' }
991
915
  end
992
916
 
993
917
  before do
994
918
  person.process_attributes(attributes)
995
919
  end
996
920
 
997
- it "only overwrites supplied attributes" do
998
- expect(person.title).to eq("Sir")
921
+ it 'only overwrites supplied attributes' do
922
+ expect(person.title).to eq('Sir')
999
923
  end
1000
924
  end
1001
925
 
1002
- describe "#read_attribute" do
1003
-
926
+ describe '#read_attribute' do
1004
927
  context 'when the document has a custom attribute type' do
1005
-
1006
928
  let(:bar) do
1007
929
  Bar.create!(lat_lng: LatLng.new(52.30, 13.25))
1008
930
  end
@@ -1012,204 +934,185 @@ describe Mongoid::Attributes do
1012
934
  end
1013
935
  end
1014
936
 
1015
- context "when the document is a new record" do
1016
-
937
+ context 'when the document is a new record' do
1017
938
  let(:person) do
1018
939
  Person.new
1019
940
  end
1020
941
 
1021
- context "when attribute does not exist" do
1022
-
1023
- it "returns the default value" do
942
+ context 'when attribute does not exist' do
943
+ it 'returns the default value' do
1024
944
  expect(person.age).to eq(100)
1025
945
  expect(person.pets).to be false
1026
946
  end
1027
-
1028
947
  end
1029
948
 
1030
- context "when attribute is not accessible" do
1031
-
949
+ context 'when attribute is not accessible' do
1032
950
  before do
1033
951
  person.owner_id = 5
1034
952
  end
1035
953
 
1036
- it "returns the value" do
954
+ it 'returns the value' do
1037
955
  expect(person.read_attribute(:owner_id)).to eq(5)
1038
956
  end
1039
957
  end
1040
958
  end
1041
959
 
1042
- context "when the document is an existing record" do
1043
-
960
+ context 'when the document is an existing record' do
1044
961
  let(:person) do
1045
962
  Person.create!
1046
963
  end
1047
964
 
1048
- context "when the attribute does not exist" do
965
+ context 'when the attribute does not exist' do
1049
966
  config_override :raise_not_found_error, false
1050
967
 
1051
968
  before do
1052
969
  person.collection
1053
- .find({ _id: person.id })
1054
- .update_one({ "$unset" => { age: 1 }})
970
+ .find({ _id: person.id })
971
+ .update_one({ '$unset' => { age: 1 } })
1055
972
  person.reload
1056
973
  end
1057
974
 
1058
- it "returns the default value" do
975
+ it 'returns the default value' do
1059
976
  expect(person.age).to eq(100)
1060
977
  end
1061
978
  end
1062
979
  end
1063
980
 
1064
- context "when attribute has an aliased name" do
1065
-
981
+ context 'when attribute has an aliased name' do
1066
982
  let(:person) do
1067
983
  Person.new
1068
984
  end
1069
985
 
1070
- before(:each) do
1071
- person.write_attribute(:t, "aliased field to test")
986
+ before do
987
+ person.write_attribute(:t, 'aliased field to test')
1072
988
  end
1073
989
 
1074
- it "returns the value of the aliased field" do
1075
- expect(person.read_attribute(:test)).to eq("aliased field to test")
990
+ it 'returns the value of the aliased field' do
991
+ expect(person.read_attribute(:test)).to eq('aliased field to test')
1076
992
  end
1077
993
  end
1078
994
  end
1079
995
 
1080
- describe "#read_attribute_before_type_cast" do
1081
-
996
+ describe '#read_attribute_before_type_cast' do
1082
997
  let(:person) do
1083
998
  Person.create!
1084
999
  end
1085
1000
 
1086
- context "when the attribute has not yet been assigned" do
1087
-
1088
- it "returns the default value" do
1001
+ context 'when the attribute has not yet been assigned' do
1002
+ it 'returns the default value' do
1089
1003
  expect(person.age_before_type_cast).to eq(100)
1090
1004
  end
1091
1005
  end
1092
1006
 
1093
- context "after the attribute has been assigned" do
1094
-
1095
- it "returns the default value" do
1096
- person.age = "42"
1097
- expect(person.age_before_type_cast).to eq("42")
1007
+ context 'after the attribute has been assigned' do
1008
+ it 'returns the default value' do
1009
+ person.age = '42'
1010
+ expect(person.age_before_type_cast).to eq('42')
1098
1011
  end
1099
1012
  end
1100
1013
 
1101
1014
  context 'when reading fields on a document with projection' do
1102
-
1103
1015
  let!(:person) do
1104
- Person.create!(title: "sir")
1016
+ Person.create!(title: 'sir')
1105
1017
  end
1106
1018
 
1107
- context "when excluding with only and the field was not excluded" do
1108
-
1019
+ context 'when excluding with only and the field was not excluded' do
1109
1020
  let(:from_db) do
1110
1021
  Person.only(:_id).first
1111
1022
  end
1112
1023
 
1113
- it "raises an error" do
1114
- expect {
1024
+ it 'raises an error' do
1025
+ expect do
1115
1026
  from_db.read_attribute(:undefined_field)
1116
- }.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'undefined_field' on Person which was not loaded/)
1027
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
1028
+ /Attempted to access attribute 'undefined_field' on Person which was not loaded/)
1117
1029
  end
1118
1030
  end
1119
1031
 
1120
- context "when excluding with without and the field was excluded" do
1121
-
1032
+ context 'when excluding with without and the field was excluded' do
1122
1033
  let(:from_db) do
1123
1034
  Person.without(:title).first
1124
1035
  end
1125
1036
 
1126
- it "raises an error" do
1127
- expect {
1037
+ it 'raises an error' do
1038
+ expect do
1128
1039
  from_db.read_attribute(:title)
1129
- }.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'title' on Person which was not loaded/)
1040
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
1041
+ /Attempted to access attribute 'title' on Person which was not loaded/)
1130
1042
  end
1131
1043
  end
1132
1044
 
1133
- context "when excluding with without and the field was not excluded" do
1134
-
1045
+ context 'when excluding with without and the field was not excluded' do
1135
1046
  let(:from_db) do
1136
1047
  Person.without(:title).first
1137
1048
  end
1138
1049
 
1139
- it "returns nil" do
1140
- from_db.read_attribute(:undefined_field).should be nil
1050
+ it 'returns nil' do
1051
+ from_db.read_attribute(:undefined_field).should be_nil
1141
1052
  end
1142
1053
  end
1143
1054
  end
1144
1055
  end
1145
1056
 
1146
- describe "#attribute_present?" do
1147
-
1148
- context "when document is a new record" do
1149
-
1057
+ describe '#attribute_present?' do
1058
+ context 'when document is a new record' do
1150
1059
  let(:person) do
1151
1060
  Person.new
1152
1061
  end
1153
1062
 
1154
- context "when attribute does not exist" do
1155
-
1156
- it "returns false" do
1063
+ context 'when attribute does not exist' do
1064
+ it 'returns false' do
1157
1065
  expect(person.attribute_present?(:owner_id)).to be false
1158
1066
  end
1159
1067
  end
1160
1068
 
1161
- context "when attribute does exist" do
1069
+ context 'when attribute does exist' do
1162
1070
  before do
1163
1071
  person.owner_id = 5
1164
1072
  end
1165
1073
 
1166
- it "returns true" do
1074
+ it 'returns true' do
1167
1075
  expect(person.attribute_present?(:owner_id)).to be true
1168
1076
  end
1169
1077
  end
1170
1078
  end
1171
1079
 
1172
- context "when the document is an existing record" do
1173
-
1080
+ context 'when the document is an existing record' do
1174
1081
  let(:person) do
1175
1082
  Person.create!
1176
1083
  end
1177
1084
 
1178
- context "when the attribute does not exist" do
1085
+ context 'when the attribute does not exist' do
1179
1086
  config_override :raise_not_found_error, false
1180
1087
 
1181
1088
  before do
1182
1089
  person.collection
1183
- .find({ _id: person.id })
1184
- .update_one({ "$unset" => { age: 1 }})
1090
+ .find({ _id: person.id })
1091
+ .update_one({ '$unset' => { age: 1 } })
1185
1092
  person.reload
1186
1093
  end
1187
1094
 
1188
- it "returns true" do
1095
+ it 'returns true' do
1189
1096
  expect(person.attribute_present?(:age)).to be true
1190
1097
  end
1191
1098
  end
1192
1099
  end
1193
1100
 
1194
- context "when the value is boolean" do
1195
-
1101
+ context 'when the value is boolean' do
1196
1102
  let(:person) do
1197
1103
  Person.new
1198
1104
  end
1199
1105
 
1200
- context "when attribute does not exist" do
1201
-
1202
- context "when the value is true" do
1203
-
1204
- it "return true" do
1106
+ context 'when attribute does not exist' do
1107
+ context 'when the value is true' do
1108
+ it 'return true' do
1205
1109
  person.terms = false
1206
1110
  expect(person.attribute_present?(:terms)).to be true
1207
1111
  end
1208
1112
  end
1209
1113
 
1210
- context "when the value is false" do
1211
-
1212
- it "return true" do
1114
+ context 'when the value is false' do
1115
+ it 'return true' do
1213
1116
  person.terms = false
1214
1117
  expect(person.attribute_present?(:terms)).to be true
1215
1118
  end
@@ -1217,153 +1120,137 @@ describe Mongoid::Attributes do
1217
1120
  end
1218
1121
  end
1219
1122
 
1220
- context "when the value is blank string" do
1221
-
1123
+ context 'when the value is blank string' do
1222
1124
  let(:person) do
1223
1125
  Person.new(title: '')
1224
1126
  end
1225
1127
 
1226
- it "return false" do
1128
+ it 'return false' do
1227
1129
  expect(person.attribute_present?(:title)).to be false
1228
1130
  end
1229
1131
  end
1230
1132
 
1231
- context "when the attribute is not on only list" do
1232
-
1133
+ context 'when the attribute is not on only list' do
1233
1134
  before { Person.create! }
1135
+
1234
1136
  let(:person) do
1235
1137
  Person.only(:id).first
1236
1138
  end
1237
1139
 
1238
- it "return false" do
1140
+ it 'return false' do
1239
1141
  expect(person.attribute_present?(:foobar)).to be false
1240
1142
  end
1241
1143
  end
1242
1144
  end
1243
1145
 
1244
- describe "#has_attribute?" do
1245
-
1146
+ describe '#has_attribute?' do
1246
1147
  let(:person) do
1247
- Person.new(title: "sir")
1148
+ Person.new(title: 'sir')
1248
1149
  end
1249
1150
 
1250
- context "when the key is in the attributes" do
1251
-
1252
- context "when provided a symbol" do
1253
-
1254
- it "returns true" do
1151
+ context 'when the key is in the attributes' do
1152
+ context 'when provided a symbol' do
1153
+ it 'returns true' do
1255
1154
  expect(person.has_attribute?(:title)).to be true
1256
1155
  end
1257
1156
  end
1258
1157
 
1259
- context "when provided a string" do
1260
-
1261
- it "returns true" do
1262
- expect(person.has_attribute?("title")).to be true
1158
+ context 'when provided a string' do
1159
+ it 'returns true' do
1160
+ expect(person.has_attribute?('title')).to be true
1263
1161
  end
1264
1162
  end
1265
1163
  end
1266
1164
 
1267
- context "when the key is not in the attributes" do
1268
-
1269
- it "returns false" do
1165
+ context 'when the key is not in the attributes' do
1166
+ it 'returns false' do
1270
1167
  expect(person.has_attribute?(:employer_id)).to be false
1271
1168
  end
1272
1169
  end
1273
1170
  end
1274
1171
 
1275
1172
  describe '#has_attribute_before_type_cast?' do
1276
-
1277
1173
  let(:person) do
1278
1174
  Person.new
1279
1175
  end
1280
1176
 
1281
- context "before the attribute has been assigned" do
1282
-
1283
- it "returns true" do
1177
+ context 'before the attribute has been assigned' do
1178
+ it 'returns true' do
1284
1179
  expect(person.has_attribute_before_type_cast?(:age)).to be true
1285
1180
  end
1286
1181
  end
1287
1182
 
1288
- context "after the attribute has been assigned" do
1289
-
1290
- it "returns true" do
1183
+ context 'after the attribute has been assigned' do
1184
+ it 'returns true' do
1291
1185
  person.age = '42'
1292
1186
  expect(person.has_attribute_before_type_cast?(:age)).to be true
1293
1187
  end
1294
1188
  end
1295
1189
  end
1296
1190
 
1297
- describe "#remove_attribute" do
1298
-
1299
- context "when the attribute exists" do
1300
-
1191
+ describe '#remove_attribute' do
1192
+ context 'when the attribute exists' do
1301
1193
  let(:person) do
1302
- Person.create!(title: "Sir")
1194
+ Person.create!(title: 'Sir')
1303
1195
  end
1304
1196
 
1305
1197
  before do
1306
1198
  person.remove_attribute(:title)
1307
1199
  end
1308
1200
 
1309
- it "removes the attribute" do
1201
+ it 'removes the attribute' do
1310
1202
  expect(person.title).to be_nil
1311
1203
  end
1312
1204
 
1313
- it "removes the key from the attributes hash" do
1205
+ it 'removes the key from the attributes hash' do
1314
1206
  expect(person.has_attribute?(:title)).to be false
1315
1207
  end
1316
1208
 
1317
- context "when saving after the removal" do
1318
-
1209
+ context 'when saving after the removal' do
1319
1210
  before do
1320
1211
  person.save!
1321
1212
  end
1322
1213
 
1323
- it "persists the removal" do
1214
+ it 'persists the removal' do
1324
1215
  expect(person.reload.has_attribute?(:title)).to be false
1325
1216
  end
1326
1217
  end
1327
1218
  end
1328
1219
 
1329
- context "when the attribute exists in embedded document" do
1330
-
1331
- let(:pet) do
1332
- Animal.new(name: "Cat")
1333
- end
1334
-
1335
- let(:person) do
1336
- Person.new(pet: pet)
1337
- end
1338
-
1339
- before do
1340
- person.save!
1341
- person.pet.remove_attribute(:name)
1342
- end
1220
+ context 'when the attribute exists in embedded document' do
1221
+ let(:pet) do
1222
+ Animal.new(name: 'Cat')
1223
+ end
1343
1224
 
1344
- it "removes the attribute" do
1345
- expect(person.pet.name).to be_nil
1346
- end
1225
+ let(:person) do
1226
+ Person.new(pet: pet)
1227
+ end
1347
1228
 
1348
- it "removes the key from the attributes hash" do
1349
- expect(person.pet.has_attribute?(:name)).to be false
1350
- end
1229
+ before do
1230
+ person.save!
1231
+ person.pet.remove_attribute(:name)
1232
+ end
1351
1233
 
1352
- context "when saving after the removal" do
1234
+ it 'removes the attribute' do
1235
+ expect(person.pet.name).to be_nil
1236
+ end
1353
1237
 
1354
- before do
1355
- person.save!
1356
- end
1238
+ it 'removes the key from the attributes hash' do
1239
+ expect(person.pet.has_attribute?(:name)).to be false
1240
+ end
1357
1241
 
1358
- it "persists the removal" do
1359
- expect(person.reload.pet.has_attribute?(:name)).to be false
1360
- end
1361
- end
1242
+ context 'when saving after the removal' do
1243
+ before do
1244
+ person.save!
1245
+ end
1362
1246
 
1247
+ it 'persists the removal' do
1248
+ expect(person.reload.pet.has_attribute?(:name)).to be false
1249
+ end
1250
+ end
1363
1251
  end
1364
1252
 
1365
- context "when the attribute does not exist" do
1366
-
1253
+ context 'when the attribute does not exist' do
1367
1254
  let(:person) do
1368
1255
  Person.new
1369
1256
  end
@@ -1372,30 +1259,27 @@ describe Mongoid::Attributes do
1372
1259
  person.remove_attribute(:title)
1373
1260
  end
1374
1261
 
1375
- it "does not fail" do
1262
+ it 'does not fail' do
1376
1263
  expect(person.title).to be_nil
1377
1264
  end
1378
1265
  end
1379
1266
 
1380
- context "when the document is new" do
1381
-
1267
+ context 'when the document is new' do
1382
1268
  let(:person) do
1383
- Person.new(title: "sir")
1269
+ Person.new(title: 'sir')
1384
1270
  end
1385
1271
 
1386
1272
  before do
1387
1273
  person.remove_attribute(:title)
1388
1274
  end
1389
1275
 
1390
- it "does not add a delayed unset operation" do
1276
+ it 'does not add a delayed unset operation' do
1391
1277
  expect(person.delayed_atomic_unsets).to be_empty
1392
1278
  end
1393
1279
  end
1394
1280
 
1395
- context "when the attribute is aliased" do
1396
-
1281
+ context 'when the attribute is aliased' do
1397
1282
  context 'when the database name is used' do
1398
-
1399
1283
  let(:person) do
1400
1284
  Person.create!(at: Time.now)
1401
1285
  end
@@ -1404,28 +1288,26 @@ describe Mongoid::Attributes do
1404
1288
  person.remove_attribute(:at)
1405
1289
  end
1406
1290
 
1407
- it "removes the attribute" do
1291
+ it 'removes the attribute' do
1408
1292
  expect(person.at).to be_nil
1409
1293
  end
1410
1294
 
1411
- it "removes the key from the attributes hash" do
1295
+ it 'removes the key from the attributes hash' do
1412
1296
  expect(person.has_attribute?(:at)).to be false
1413
1297
  end
1414
1298
 
1415
- context "when saving after the removal" do
1416
-
1299
+ context 'when saving after the removal' do
1417
1300
  before do
1418
1301
  person.save!
1419
1302
  end
1420
1303
 
1421
- it "persists the removal" do
1304
+ it 'persists the removal' do
1422
1305
  expect(person.reload.has_attribute?(:at)).to be false
1423
1306
  end
1424
1307
  end
1425
1308
  end
1426
1309
 
1427
1310
  context 'when the alias is used' do
1428
-
1429
1311
  let(:person) do
1430
1312
  Person.create!(aliased_timestamp: Time.now)
1431
1313
  end
@@ -1434,21 +1316,20 @@ describe Mongoid::Attributes do
1434
1316
  person.remove_attribute(:aliased_timestamp)
1435
1317
  end
1436
1318
 
1437
- it "removes the attribute" do
1319
+ it 'removes the attribute' do
1438
1320
  expect(person.aliased_timestamp).to be_nil
1439
1321
  end
1440
1322
 
1441
- it "removes the key from the attributes hash" do
1323
+ it 'removes the key from the attributes hash' do
1442
1324
  expect(person.has_attribute?(:aliased_timestamp)).to be false
1443
1325
  end
1444
1326
 
1445
- context "when saving after the removal" do
1446
-
1327
+ context 'when saving after the removal' do
1447
1328
  before do
1448
1329
  person.save!
1449
1330
  end
1450
1331
 
1451
- it "persists the removal" do
1332
+ it 'persists the removal' do
1452
1333
  expect(person.reload.has_attribute?(:aliased_timestamp)).to be false
1453
1334
  end
1454
1335
  end
@@ -1456,116 +1337,100 @@ describe Mongoid::Attributes do
1456
1337
  end
1457
1338
  end
1458
1339
 
1459
- describe "#respond_to?" do
1460
-
1461
- context "when allowing dynamic fields" do
1462
-
1340
+ describe '#respond_to?' do
1341
+ context 'when allowing dynamic fields' do
1463
1342
  let(:person) do
1464
1343
  Person.new
1465
1344
  end
1466
1345
 
1467
- context "when asking for the getter" do
1468
-
1469
- context "when the attribute exists" do
1470
-
1346
+ context 'when asking for the getter' do
1347
+ context 'when the attribute exists' do
1471
1348
  before do
1472
- person[:attr] = "test"
1349
+ person[:attr] = 'test'
1473
1350
  end
1474
1351
 
1475
- it "returns true" do
1352
+ it 'returns true' do
1476
1353
  expect(person).to respond_to(:attr)
1477
1354
  end
1478
1355
  end
1479
1356
 
1480
- context "when the attribute does not exist" do
1481
-
1482
- it "returns false" do
1483
- expect(person).to_not respond_to(:attr)
1357
+ context 'when the attribute does not exist' do
1358
+ it 'returns false' do
1359
+ expect(person).not_to respond_to(:attr)
1484
1360
  end
1485
1361
  end
1486
1362
  end
1487
1363
 
1488
- context "when asking for the setter" do
1489
-
1490
- context "when the attribute exists" do
1491
-
1364
+ context 'when asking for the setter' do
1365
+ context 'when the attribute exists' do
1492
1366
  before do
1493
- person[:attr] = "test"
1367
+ person[:attr] = 'test'
1494
1368
  end
1495
1369
 
1496
- it "returns true" do
1370
+ it 'returns true' do
1497
1371
  expect(person).to respond_to(:attr=)
1498
1372
  end
1499
1373
  end
1500
1374
 
1501
- context "when the attribute does not exist" do
1502
-
1503
- it "returns false" do
1504
- expect(person).to_not respond_to(:attr=)
1375
+ context 'when the attribute does not exist' do
1376
+ it 'returns false' do
1377
+ expect(person).not_to respond_to(:attr=)
1505
1378
  end
1506
1379
  end
1507
1380
  end
1508
1381
  end
1509
1382
 
1510
- context "when not allowing dynamic fields" do
1511
-
1383
+ context 'when not allowing dynamic fields' do
1512
1384
  let(:bar) do
1513
1385
  Bar.new
1514
1386
  end
1515
1387
 
1516
- context "when asking for the getter" do
1517
-
1518
- it "returns false" do
1519
- expect(bar).to_not respond_to(:attr)
1388
+ context 'when asking for the getter' do
1389
+ it 'returns false' do
1390
+ expect(bar).not_to respond_to(:attr)
1520
1391
  end
1521
1392
  end
1522
1393
 
1523
- context "when asking for the setter" do
1524
-
1525
- it "returns false" do
1526
- expect(bar).to_not respond_to(:attr=)
1394
+ context 'when asking for the setter' do
1395
+ it 'returns false' do
1396
+ expect(bar).not_to respond_to(:attr=)
1527
1397
  end
1528
1398
  end
1529
1399
  end
1530
1400
  end
1531
1401
 
1532
- describe "#write_attribute" do
1533
-
1534
- context "when attribute does not exist" do
1535
-
1402
+ describe '#write_attribute' do
1403
+ context 'when attribute does not exist' do
1536
1404
  let(:person) do
1537
1405
  Person.new
1538
1406
  end
1539
1407
 
1540
- it "returns the default value" do
1408
+ it 'returns the default value' do
1541
1409
  expect(person.age).to eq(100)
1542
1410
  end
1543
1411
  end
1544
1412
 
1545
- context "when setting an attribute that needs type casting" do
1546
-
1413
+ context 'when setting an attribute that needs type casting' do
1547
1414
  let(:person) do
1548
- Person.new(age: "42")
1415
+ Person.new(age: '42')
1549
1416
  end
1550
1417
 
1551
- it "should store the attribute before type cast" do
1552
- expect(person.age_before_type_cast).to eq("42")
1418
+ it 'stores the attribute before type cast' do
1419
+ expect(person.age_before_type_cast).to eq('42')
1553
1420
  end
1554
1421
  end
1555
1422
 
1556
- context "when setting the attribute to nil" do
1557
-
1423
+ context 'when setting the attribute to nil' do
1558
1424
  let(:person) do
1559
1425
  Person.new(age: nil)
1560
1426
  end
1561
1427
 
1562
- it "does not use the default value" do
1428
+ it 'does not use the default value' do
1563
1429
  expect(person.age).to be_nil
1564
1430
  end
1565
1431
  end
1566
1432
 
1567
- context "when field has a default value" do
1568
-
1433
+ context 'when field has a default value' do
1569
1434
  let(:person) do
1570
1435
  Person.new
1571
1436
  end
@@ -1574,121 +1439,118 @@ describe Mongoid::Attributes do
1574
1439
  person.terms = true
1575
1440
  end
1576
1441
 
1577
- it "allows overwriting of the default value" do
1442
+ it 'allows overwriting of the default value' do
1578
1443
  expect(person.terms).to be true
1579
1444
  end
1580
1445
  end
1581
1446
 
1582
- context "when attribute has an aliased name" do
1583
-
1447
+ context 'when attribute has an aliased name' do
1584
1448
  let(:person) do
1585
1449
  Person.new
1586
1450
  end
1587
1451
 
1588
- before(:each) do
1589
- person.write_attribute(:test, "aliased field to test")
1452
+ before do
1453
+ person.write_attribute(:test, 'aliased field to test')
1590
1454
  end
1591
1455
 
1592
- it "allows the field name to be updated" do
1593
- expect(person.t).to eq("aliased field to test")
1456
+ it 'allows the field name to be updated' do
1457
+ expect(person.t).to eq('aliased field to test')
1594
1458
  end
1595
1459
  end
1596
1460
 
1597
- context "when attribute is a Hash" do
1598
- let(:person) { Person.new map: { somekey: "somevalue" } }
1461
+ context 'when attribute is a Hash' do
1462
+ let(:person) { Person.new map: { somekey: 'somevalue' } }
1599
1463
 
1600
- it "writes nil when trying to set a value of invalid type - array" do
1464
+ it 'writes nil when trying to set a value of invalid type - array' do
1601
1465
  person.map = []
1602
1466
  expect(person.map).to be_nil
1603
1467
  end
1604
1468
 
1605
- it "writes nil when trying to set a value of invalid type - boolean" do
1469
+ it 'writes nil when trying to set a value of invalid type - boolean' do
1606
1470
  person.map = false
1607
1471
  expect(person.map).to be_nil
1608
1472
  end
1609
1473
 
1610
- it "can set a Hash value with stringified keys" do
1611
- expect(person.map).to eq( { "somekey" => "somevalue" } )
1474
+ it 'can set a Hash value with stringified keys' do
1475
+ expect(person.map).to eq({ 'somekey' => 'somevalue' })
1612
1476
  end
1613
1477
  end
1614
1478
 
1615
- context "when attribute is an Array" do
1479
+ context 'when attribute is an Array' do
1616
1480
  let(:person) { Person.new aliases: [ :alias_1 ] }
1617
1481
 
1618
- it "can set an Array Value" do
1482
+ it 'can set an Array Value' do
1619
1483
  expect(person.aliases).to eq([ :alias_1 ])
1620
1484
  end
1621
1485
 
1622
- it "writes nil when trying to set a value of invalid type - hash" do
1486
+ it 'writes nil when trying to set a value of invalid type - hash' do
1623
1487
  person.aliases = {}
1624
1488
  expect(person.aliases).to be_nil
1625
1489
  end
1626
1490
 
1627
- it "writes nil when trying to set a value of invalid type - boolean" do
1491
+ it 'writes nil when trying to set a value of invalid type - boolean' do
1628
1492
  person.aliases = false
1629
1493
  expect(person.aliases).to be_nil
1630
1494
  end
1631
1495
  end
1632
1496
 
1633
- context "when attribute is localized and #attributes is a BSON::Document" do
1497
+ context 'when attribute is localized and #attributes is a BSON::Document' do
1634
1498
  let(:dictionary) { Dictionary.new }
1635
1499
 
1636
1500
  before do
1637
1501
  allow(dictionary).to receive(:attributes).and_return(BSON::Document.new)
1638
1502
  end
1639
1503
 
1640
- it "sets the value for the current locale" do
1504
+ it 'sets the value for the current locale' do
1641
1505
  dictionary.write_attribute(:description, 'foo')
1642
1506
  expect(dictionary.description).to eq('foo')
1643
1507
  end
1644
1508
  end
1645
1509
 
1646
1510
  context 'when writing fields on a document with projection' do
1647
-
1648
1511
  let!(:person) do
1649
- Person.create!(title: "sir")
1512
+ Person.create!(title: 'sir')
1650
1513
  end
1651
1514
 
1652
- context "when excluding with only and the field was not excluded" do
1653
-
1515
+ context 'when excluding with only and the field was not excluded' do
1654
1516
  let(:from_db) do
1655
1517
  Person.only(:_id).first
1656
1518
  end
1657
1519
 
1658
- it "raises an error" do
1659
- expect {
1520
+ it 'raises an error' do
1521
+ expect do
1660
1522
  from_db.write_attribute(:undefined_field, 'x')
1661
- }.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'undefined_field' on Person which was not loaded/)
1523
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
1524
+ /Attempted to access attribute 'undefined_field' on Person which was not loaded/)
1662
1525
  end
1663
1526
  end
1664
1527
 
1665
- context "when excluding with without and the field was excluded" do
1666
-
1528
+ context 'when excluding with without and the field was excluded' do
1667
1529
  let(:from_db) do
1668
1530
  Person.without(:title).first
1669
1531
  end
1670
1532
 
1671
- it "raises an error" do
1672
- expect {
1533
+ it 'raises an error' do
1534
+ expect do
1673
1535
  from_db.write_attribute(:title, 'x')
1674
- }.to raise_error(Mongoid::Errors::AttributeNotLoaded, /Attempted to access attribute 'title' on Person which was not loaded/)
1536
+ end.to raise_error(Mongoid::Errors::AttributeNotLoaded,
1537
+ /Attempted to access attribute 'title' on Person which was not loaded/)
1675
1538
  end
1676
1539
  end
1677
1540
 
1678
- context "when excluding with without and the field was not excluded" do
1679
-
1541
+ context 'when excluding with without and the field was not excluded' do
1680
1542
  let(:from_db) do
1681
1543
  Person.without(:title).first
1682
1544
  end
1683
1545
 
1684
- it "writes the value" do
1546
+ it 'writes the value' do
1685
1547
  from_db.write_attribute(:undefined_field, 'x')
1686
- from_db.read_attribute(:undefined_field).should == 'x'
1548
+ from_db.read_attribute(:undefined_field).should eq 'x'
1687
1549
  end
1688
1550
  end
1689
1551
  end
1690
1552
 
1691
- context "when comparing the object_ids of the written value" do
1553
+ context 'when comparing the object_ids of the written value' do
1692
1554
  before do
1693
1555
  Person.create!
1694
1556
  end
@@ -1697,34 +1559,32 @@ describe Mongoid::Attributes do
1697
1559
  Person.first
1698
1560
  end
1699
1561
 
1700
- context "when the field is not resizable" do
1562
+ context 'when the field is not resizable' do
1701
1563
  let(:test) do
1702
- person.write_attribute(:test, "aliased field to test")
1564
+ person.write_attribute(:test, 'aliased field to test')
1703
1565
  end
1704
1566
 
1705
- it "has the same object_id as the attributes hash value" do
1567
+ it 'has the same object_id as the attributes hash value' do
1706
1568
  expect(test.object_id).to eq(person.test.object_id)
1707
1569
  end
1708
1570
  end
1709
1571
 
1710
- context "when the field is resizable" do
1711
-
1572
+ context 'when the field is resizable' do
1712
1573
  let(:arrays) do
1713
1574
  person.write_attribute(:arrays, [])
1714
1575
  end
1715
1576
 
1716
- it "has the same object_id as the attributes hash value" do
1577
+ it 'has the same object_id as the attributes hash value' do
1717
1578
  expect(arrays.object_id).to eq(person.arrays.object_id)
1718
1579
  end
1719
1580
  end
1720
1581
 
1721
- context "when the field is a HABTM foreign key array" do
1722
-
1582
+ context 'when the field is a HABTM foreign key array' do
1723
1583
  let(:preference_ids) do
1724
1584
  person.write_attribute(:preference_ids, [])
1725
1585
  end
1726
1586
 
1727
- it "has the same object_id as the attributes hash value" do
1587
+ it 'has the same object_id as the attributes hash value' do
1728
1588
  expect(preference_ids.object_id).to eq(person.preference_ids.object_id)
1729
1589
  end
1730
1590
  end
@@ -1734,54 +1594,49 @@ describe Mongoid::Attributes do
1734
1594
  config_override :map_big_decimal_to_decimal128, true
1735
1595
 
1736
1596
  context 'when writing an identical number' do
1737
- let(:band) { Band.create!(name: 'Nirvana', sales: 123456.78).reload }
1597
+ let(:band) { Band.create!(name: 'Nirvana', sales: 123_456.78).reload }
1738
1598
 
1739
1599
  it 'does not mark the document as changed' do
1740
- band.sales = 123456.78
1600
+ band.sales = 123_456.78
1741
1601
  expect(band.changed?).to be false
1742
1602
  end
1743
1603
  end
1744
1604
  end
1745
1605
  end
1746
1606
 
1747
- describe "#typed_value_for" do
1748
-
1607
+ describe '#typed_value_for' do
1749
1608
  let(:person) do
1750
1609
  Person.new
1751
1610
  end
1752
1611
 
1753
- context "when the key has been specified as a field" do
1754
-
1755
- it "retuns the typed value" do
1756
- person.send(:typed_value_for, "age", "51")
1612
+ context 'when the key has been specified as a field' do
1613
+ it 'returns the typed value' do
1614
+ person.send(:typed_value_for, 'age', '51')
1757
1615
  end
1758
1616
  end
1759
1617
 
1760
- context "when the key has not been specified as a field" do
1761
-
1618
+ context 'when the key has not been specified as a field' do
1762
1619
  before do
1763
1620
  allow(person).to receive(:fields).and_return({})
1764
1621
  end
1765
1622
 
1766
- it "returns the value" do
1767
- person.send(:typed_value_for, "age", expect("51")).to eq("51")
1623
+ it 'returns the value' do
1624
+ person.send(:typed_value_for, 'age', expect('51')).to eq('51')
1768
1625
  end
1769
1626
  end
1770
1627
  end
1771
1628
 
1772
- describe "#apply_default_attributes" do
1773
-
1629
+ describe '#apply_default_attributes' do
1774
1630
  let(:person) do
1775
1631
  Person.new
1776
1632
  end
1777
1633
 
1778
- it "typecasts proc values" do
1634
+ it 'typecasts proc values' do
1779
1635
  expect(person.age).to eq(100)
1780
1636
  end
1781
1637
  end
1782
1638
 
1783
- describe "#typed_attributes" do
1784
-
1639
+ describe '#typed_attributes' do
1785
1640
  let(:date_time) do
1786
1641
  DateTime.current
1787
1642
  end
@@ -1791,64 +1646,57 @@ describe Mongoid::Attributes do
1791
1646
  end
1792
1647
 
1793
1648
  it 'returns typecasted attributes' do
1794
- expect(user.typed_attributes).to include("last_login" => date_time)
1649
+ expect(user.typed_attributes).to include('last_login' => date_time)
1795
1650
  end
1796
1651
  end
1797
1652
 
1798
- [:attributes=, :write_attributes].each do |method|
1799
-
1653
+ %i[attributes= write_attributes].each do |method|
1800
1654
  describe "##{method}" do
1801
-
1802
- context "when nested" do
1803
-
1655
+ context 'when nested' do
1804
1656
  let(:person) do
1805
1657
  Person.new
1806
1658
  end
1807
1659
 
1808
1660
  before do
1809
- person.send(method, { videos: [{title: "Fight Club"}] })
1661
+ person.send(method, { videos: [ { title: 'Fight Club' } ] })
1810
1662
  end
1811
1663
 
1812
- it "sets nested documents" do
1813
- expect(person.videos.first.title).to eq("Fight Club")
1664
+ it 'sets nested documents' do
1665
+ expect(person.videos.first.title).to eq('Fight Club')
1814
1666
  end
1815
1667
  end
1816
1668
 
1817
- context "typecasting" do
1818
-
1669
+ context 'typecasting' do
1819
1670
  let(:person) do
1820
1671
  Person.new
1821
1672
  end
1822
1673
 
1823
1674
  let(:attributes) do
1824
- { age: "50" }
1675
+ { age: '50' }
1825
1676
  end
1826
1677
 
1827
- context "when passing a hash" do
1828
-
1678
+ context 'when passing a hash' do
1829
1679
  before do
1830
1680
  person.send(method, attributes)
1831
1681
  end
1832
1682
 
1833
- it "properly casts values" do
1683
+ it 'properly casts values' do
1834
1684
  expect(person.age).to eq(50)
1835
1685
  end
1836
1686
  end
1837
1687
 
1838
- context "when passing nil" do
1839
-
1688
+ context 'when passing nil' do
1840
1689
  before do
1841
1690
  person.send(method, nil)
1842
1691
  end
1843
1692
 
1844
- it "does not set anything" do
1693
+ it 'does not set anything' do
1845
1694
  expect(person.age).to eq(100)
1846
1695
  end
1847
1696
  end
1848
1697
  end
1849
1698
 
1850
- context "copying from instance" do
1851
-
1699
+ context 'copying from instance' do
1852
1700
  let(:person) do
1853
1701
  Person.new
1854
1702
  end
@@ -1865,25 +1713,23 @@ describe Mongoid::Attributes do
1865
1713
  person.send(method, instance.attributes)
1866
1714
  end
1867
1715
 
1868
- it "properly copies values" do
1716
+ it 'properly copies values' do
1869
1717
  expect(person.age).to eq(50)
1870
1718
  end
1871
1719
 
1872
- it "properly copies ranges" do
1720
+ it 'properly copies ranges' do
1873
1721
  expect(person.range).to eq(1..100)
1874
1722
  end
1875
1723
  end
1876
1724
 
1877
- context "on a parent document" do
1878
-
1879
- context "when the parent has a has many through a has one" do
1880
-
1725
+ context 'on a parent document' do
1726
+ context 'when the parent has a has many through a has one' do
1881
1727
  let(:owner) do
1882
- PetOwner.new(title: "Mr")
1728
+ PetOwner.new(title: 'Mr')
1883
1729
  end
1884
1730
 
1885
1731
  let(:pet) do
1886
- Pet.new(name: "Fido")
1732
+ Pet.new(name: 'Fido')
1887
1733
  end
1888
1734
 
1889
1735
  let(:vet_visit) do
@@ -1893,23 +1739,22 @@ describe Mongoid::Attributes do
1893
1739
  before do
1894
1740
  owner.pet = pet
1895
1741
  pet.vet_visits = [ vet_visit ]
1896
- owner.send(method, { pet: { name: "Bingo" } })
1742
+ owner.send(method, { pet: { name: 'Bingo' } })
1897
1743
  end
1898
1744
 
1899
- it "does not overwrite child attributes if not in the hash" do
1900
- expect(owner.pet.name).to eq("Bingo")
1745
+ it 'does not overwrite child attributes if not in the hash' do
1746
+ expect(owner.pet.name).to eq('Bingo')
1901
1747
  expect(owner.pet.vet_visits.size).to eq(1)
1902
1748
  end
1903
1749
  end
1904
1750
 
1905
- context "when parent destroy all child on setter" do
1906
-
1751
+ context 'when parent destroy all child on setter' do
1907
1752
  let(:owner) do
1908
- PetOwner.create!(title: "Mr")
1753
+ PetOwner.create!(title: 'Mr')
1909
1754
  end
1910
1755
 
1911
1756
  let(:pet) do
1912
- Pet.create!(name: "Kika", pet_owner: owner)
1757
+ Pet.create!(name: 'Kika', pet_owner: owner)
1913
1758
  end
1914
1759
 
1915
1760
  let!(:vet_visit) do
@@ -1921,17 +1766,16 @@ describe Mongoid::Attributes do
1921
1766
  pet.save!
1922
1767
  end
1923
1768
 
1924
- it "has 3 new entries" do
1769
+ it 'has 3 new entries' do
1925
1770
  expect(pet.vet_visits.count).to eq 3
1926
1771
  end
1927
1772
 
1928
- it "persists the changes" do
1773
+ it 'persists the changes' do
1929
1774
  expect(pet.reload.vet_visits.count).to eq 3
1930
1775
  end
1931
1776
  end
1932
1777
 
1933
- context "when the parent has an empty embeds_many" do
1934
-
1778
+ context 'when the parent has an empty embeds_many' do
1935
1779
  let(:person) do
1936
1780
  Person.new
1937
1781
  end
@@ -1940,54 +1784,51 @@ describe Mongoid::Attributes do
1940
1784
  { services: [] }
1941
1785
  end
1942
1786
 
1943
- it "does not raise an error" do
1787
+ it 'does not raise an error' do
1944
1788
  person.send(method, attributes)
1945
1789
  end
1946
1790
  end
1947
1791
  end
1948
1792
 
1949
- context "on a child document" do
1950
-
1951
- context "when child is part of a has one" do
1952
-
1793
+ context 'on a child document' do
1794
+ context 'when child is part of a has one' do
1953
1795
  let(:person) do
1954
- Person.new(title: "Sir", age: 30)
1796
+ Person.new(title: 'Sir', age: 30)
1955
1797
  end
1956
1798
 
1957
1799
  let(:name) do
1958
- Name.new(first_name: "Test", last_name: "User")
1800
+ Name.new(first_name: 'Test', last_name: 'User')
1959
1801
  end
1960
1802
 
1961
1803
  before do
1962
1804
  person.name = name
1963
- name.send(method, first_name: "Test2", last_name: "User2")
1805
+ name.send(method, first_name: 'Test2', last_name: 'User2')
1964
1806
  end
1965
1807
 
1966
- it "sets the child attributes on the parent" do
1808
+ it 'sets the child attributes on the parent' do
1967
1809
  expect(name.attributes).to eq(
1968
- { "_id" => "Test-User", "first_name" => "Test2", "last_name" => "User2" }
1810
+ { '_id' => 'Test-User', 'first_name' => 'Test2', 'last_name' => 'User2' }
1969
1811
  )
1970
1812
  end
1971
1813
  end
1972
1814
 
1973
- context "when child is part of a has many" do
1974
-
1815
+ context 'when child is part of a has many' do
1975
1816
  let(:person) do
1976
- Person.new(title: "Sir")
1817
+ Person.new(title: 'Sir')
1977
1818
  end
1978
1819
 
1979
1820
  let(:address) do
1980
- Address.new(street: "Test")
1821
+ Address.new(street: 'Test')
1981
1822
  end
1982
1823
 
1983
1824
  before do
1984
1825
  person.addresses << address
1985
- address.send(method, "street" => "Test2")
1826
+ address.send(method, 'street' => 'Test2')
1986
1827
  end
1987
1828
 
1988
- it "updates the child attributes on the parent" do
1829
+ it 'updates the child attributes on the parent' do
1989
1830
  expect(address.attributes).to eq(
1990
- { "_id" => "test", "street" => "Test2" }
1831
+ { '_id' => 'test', 'street' => 'Test2' }
1991
1832
  )
1992
1833
  end
1993
1834
  end
@@ -2050,134 +1891,125 @@ describe Mongoid::Attributes do
2050
1891
  end
2051
1892
  end
2052
1893
 
2053
- describe "#alias_attribute" do
2054
-
1894
+ describe '#alias_attribute' do
2055
1895
  let(:product) do
2056
1896
  Product.new
2057
1897
  end
2058
1898
 
2059
- context "when checking against the alias" do
2060
-
1899
+ context 'when checking against the alias' do
2061
1900
  before do
2062
1901
  product.cost = 500
2063
1902
  end
2064
1903
 
2065
- it "adds the alias for criteria" do
2066
- expect(Product.where(cost: 500).selector).to eq("price" => 500)
1904
+ it 'adds the alias for criteria' do
1905
+ expect(Product.where(cost: 500).selector).to eq('price' => 500)
2067
1906
  end
2068
1907
 
2069
- it "aliases the getter" do
1908
+ it 'aliases the getter' do
2070
1909
  expect(product.cost).to eq(500)
2071
1910
  end
2072
1911
 
2073
- it "aliases the existence check" do
1912
+ it 'aliases the existence check' do
2074
1913
  expect(product.cost?).to be true
2075
1914
  end
2076
1915
 
2077
- it "aliases *_changed?" do
1916
+ it 'aliases *_changed?' do
2078
1917
  expect(product.cost_changed?).to be true
2079
1918
  end
2080
1919
 
2081
- it "aliases *_change" do
1920
+ it 'aliases *_change' do
2082
1921
  expect(product.cost_change).to eq([ nil, 500 ])
2083
1922
  end
2084
1923
 
2085
- it "aliases *_will_change!" do
1924
+ it 'aliases *_will_change!' do
2086
1925
  expect(product).to respond_to(:cost_will_change!)
2087
1926
  end
2088
1927
 
2089
- it "aliases *_was" do
1928
+ it 'aliases *_was' do
2090
1929
  expect(product.cost_was).to be_nil
2091
1930
  end
2092
1931
 
2093
- it "aliases reset_*!" do
1932
+ it 'aliases reset_*!' do
2094
1933
  product.reset_cost!
2095
1934
  expect(product.cost).to be_nil
2096
1935
  end
2097
1936
 
2098
- it "aliases *_before_type_cast" do
2099
- product.cost = "42"
2100
- expect(product.cost_before_type_cast).to eq("42")
1937
+ it 'aliases *_before_type_cast' do
1938
+ product.cost = '42'
1939
+ expect(product.cost_before_type_cast).to eq('42')
2101
1940
  end
2102
1941
  end
2103
1942
 
2104
- context "when checking against the original" do
2105
-
1943
+ context 'when checking against the original' do
2106
1944
  before do
2107
1945
  product.price = 500
2108
1946
  end
2109
1947
 
2110
- it "aliases the getter" do
1948
+ it 'aliases the getter' do
2111
1949
  expect(product.price).to eq(500)
2112
1950
  end
2113
1951
 
2114
- it "aliases the existence check" do
1952
+ it 'aliases the existence check' do
2115
1953
  expect(product.price?).to be true
2116
1954
  end
2117
1955
 
2118
- it "aliases *_changed?" do
1956
+ it 'aliases *_changed?' do
2119
1957
  expect(product.price_changed?).to be true
2120
1958
  end
2121
1959
 
2122
- it "aliases *_change" do
1960
+ it 'aliases *_change' do
2123
1961
  expect(product.price_change).to eq([ nil, 500 ])
2124
1962
  end
2125
1963
 
2126
- it "aliases *_will_change!" do
1964
+ it 'aliases *_will_change!' do
2127
1965
  expect(product).to respond_to(:price_will_change!)
2128
1966
  end
2129
1967
 
2130
- it "aliases *_was" do
1968
+ it 'aliases *_was' do
2131
1969
  expect(product.price_was).to be_nil
2132
1970
  end
2133
1971
 
2134
- it "aliases reset_*!" do
1972
+ it 'aliases reset_*!' do
2135
1973
  product.reset_price!
2136
1974
  expect(product.price).to be_nil
2137
1975
  end
2138
1976
  end
2139
1977
  end
2140
1978
 
2141
- context "when persisting nil attributes" do
2142
-
1979
+ context 'when persisting nil attributes' do
2143
1980
  let!(:person) do
2144
1981
  Person.create!(score: nil)
2145
1982
  end
2146
1983
 
2147
- it "has an entry in the attributes" do
2148
- expect(person.reload.attributes).to have_key("score")
1984
+ it 'has an entry in the attributes' do
1985
+ expect(person.reload.attributes).to have_key('score')
2149
1986
  end
2150
1987
  end
2151
1988
 
2152
- context "with a default last_drink_taken_at" do
2153
-
1989
+ context 'with a default last_drink_taken_at' do
2154
1990
  let(:person) do
2155
1991
  Person.new
2156
1992
  end
2157
1993
 
2158
- it "saves the default" do
2159
- expect { person.save! }.to_not raise_error
2160
- expect(person.last_drink_taken_at).to eq(1.day.ago.in_time_zone("Alaska").to_date)
1994
+ it 'saves the default' do
1995
+ expect { person.save! }.not_to raise_error
1996
+ expect(person.last_drink_taken_at).to eq(1.day.ago.in_time_zone('Alaska').to_date)
2161
1997
  end
2162
1998
  end
2163
1999
 
2164
- context "when default values are defined" do
2165
-
2166
- context "when no value exists in the database" do
2167
-
2000
+ context 'when default values are defined' do
2001
+ context 'when no value exists in the database' do
2168
2002
  let(:person) do
2169
2003
  Person.create!
2170
2004
  end
2171
2005
 
2172
- it "applies the default value" do
2173
- expect(person.last_drink_taken_at).to eq(1.day.ago.in_time_zone("Alaska").to_date)
2006
+ it 'applies the default value' do
2007
+ expect(person.last_drink_taken_at).to eq(1.day.ago.in_time_zone('Alaska').to_date)
2174
2008
  end
2175
2009
  end
2176
2010
 
2177
- context "when a value exists in the database" do
2178
-
2179
- context "when the value is not nil" do
2180
-
2011
+ context 'when a value exists in the database' do
2012
+ context 'when the value is not nil' do
2181
2013
  let!(:person) do
2182
2014
  Person.create!(age: 50)
2183
2015
  end
@@ -2186,13 +2018,12 @@ describe Mongoid::Attributes do
2186
2018
  Person.find(person.id)
2187
2019
  end
2188
2020
 
2189
- it "does not set the default" do
2021
+ it 'does not set the default' do
2190
2022
  expect(from_db.age).to eq(50)
2191
2023
  end
2192
2024
  end
2193
2025
 
2194
- context "when the value is explicitly nil" do
2195
-
2026
+ context 'when the value is explicitly nil' do
2196
2027
  let!(:person) do
2197
2028
  Person.create!(age: nil)
2198
2029
  end
@@ -2201,22 +2032,21 @@ describe Mongoid::Attributes do
2201
2032
  Person.find(person.id)
2202
2033
  end
2203
2034
 
2204
- it "does not set the default" do
2035
+ it 'does not set the default' do
2205
2036
  expect(from_db.age).to be_nil
2206
2037
  end
2207
2038
  end
2208
2039
 
2209
- context "when the default is a proc" do
2210
-
2040
+ context 'when the default is a proc' do
2211
2041
  let!(:account) do
2212
- Account.create!(name: "savings", balance: 100)
2042
+ Account.create!(name: 'savings', balance: 100)
2213
2043
  end
2214
2044
 
2215
2045
  let(:from_db) do
2216
2046
  Account.find(account.id)
2217
2047
  end
2218
2048
 
2219
- it "applies the defaults after all attributes are set" do
2049
+ it 'applies the defaults after all attributes are set' do
2220
2050
  expect(from_db).to be_balanced
2221
2051
  end
2222
2052
  end
@@ -2224,7 +2054,6 @@ describe Mongoid::Attributes do
2224
2054
  end
2225
2055
 
2226
2056
  context 'when calling the attribute check method' do
2227
-
2228
2057
  context 'when the attribute is blank' do
2229
2058
  let(:person) do
2230
2059
  Person.create!(title: '')
@@ -2241,14 +2070,12 @@ describe Mongoid::Attributes do
2241
2070
  end
2242
2071
 
2243
2072
  context 'after initialization when the field is nil' do
2244
-
2245
2073
  it 'returns false' do
2246
2074
  expect(person.desc?).to be(false)
2247
2075
  end
2248
2076
  end
2249
2077
 
2250
2078
  context 'when setting the field to nil' do
2251
-
2252
2079
  it 'applies the localization when checking the attribute' do
2253
2080
  person.desc = nil
2254
2081
  expect(person.desc?).to be(false)
@@ -2256,7 +2083,6 @@ describe Mongoid::Attributes do
2256
2083
  end
2257
2084
 
2258
2085
  context 'when the field is a boolean' do
2259
-
2260
2086
  before do
2261
2087
  person.desc = false
2262
2088
  end
@@ -2282,136 +2108,140 @@ describe Mongoid::Attributes do
2282
2108
  end
2283
2109
  end
2284
2110
 
2285
- context "when an attribute is removed then set" do
2286
- let(:cat) { Cat.create!(name: "Neil") }
2111
+ context 'when an attribute is removed then set' do
2112
+ let(:cat) { Cat.create!(name: 'Neil') }
2287
2113
 
2288
2114
  before do
2289
- cat.remove_attribute("name")
2290
- cat.name = "Nissim"
2115
+ cat.remove_attribute('name')
2116
+ cat.name = 'Nissim'
2291
2117
  cat.save!
2292
2118
  cat.reload
2293
2119
  end
2294
2120
 
2295
- it "correctly sets the attribute" do
2296
- expect(cat.name).to eq("Nissim")
2121
+ it 'correctly sets the attribute' do
2122
+ expect(cat.name).to eq('Nissim')
2297
2123
  end
2298
2124
  end
2299
2125
 
2300
- describe "attributes after setting an association without reloading" do
2301
-
2302
- context "on embeds_many" do
2303
-
2304
- context "when not setting anything" do
2126
+ describe 'attributes after setting an association without reloading' do
2127
+ context 'on embeds_many' do
2128
+ context 'when not setting anything' do
2305
2129
  let(:doc) { NestedBook.create! }
2306
2130
 
2307
2131
  it "doesn't add attributes" do
2308
- expect(doc.attributes).to_not have_key("pages")
2132
+ expect(doc.attributes).not_to have_key('pages')
2309
2133
  end
2310
2134
 
2311
- it "has the same attributes after reloading" do
2135
+ it 'has the same attributes after reloading' do
2312
2136
  expect(doc.attributes).to eq(doc.reload.attributes)
2313
2137
  end
2314
2138
  end
2315
2139
 
2316
- context "when using nested attributes" do
2140
+ context 'when using nested attributes' do
2317
2141
  let(:doc) { NestedBook.create! }
2318
2142
 
2319
2143
  before do
2320
2144
  doc.update_attributes({ pages_attributes: [ {} ] })
2321
2145
  end
2322
2146
 
2323
- it "updates the attributes" do
2324
- expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
2147
+ it 'updates the attributes' do
2148
+ expect(doc.attributes['pages']).to eq([ { '_id' => doc.pages.first.id } ])
2325
2149
  end
2326
2150
 
2327
- it "has the same attributes after reloading" do
2151
+ it 'has the same attributes after reloading' do
2328
2152
  expect(doc.attributes).to eq(doc.reload.attributes)
2329
2153
  end
2330
2154
  end
2331
2155
 
2332
- context "when doing assignments" do
2156
+ context 'when doing assignments' do
2333
2157
  let(:doc) { NestedBook.create! }
2158
+
2334
2159
  before do
2335
- doc.pages = [NestedPage.new]
2160
+ doc.pages = [ NestedPage.new ]
2336
2161
  end
2337
2162
 
2338
- it "updates the attributes" do
2339
- expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
2163
+ it 'updates the attributes' do
2164
+ expect(doc.attributes['pages']).to eq([ { '_id' => doc.pages.first.id } ])
2340
2165
  end
2341
2166
 
2342
- it "has the same attributes after reloading" do
2167
+ it 'has the same attributes after reloading' do
2343
2168
  expect(doc.attributes).to eq(doc.reload.attributes)
2344
2169
  end
2345
2170
  end
2346
2171
 
2347
- context "when replacing assignments" do
2172
+ context 'when replacing assignments' do
2348
2173
  let(:doc) { NestedBook.create! }
2174
+
2349
2175
  before do
2350
- doc.pages = [NestedPage.new(number: 1)]
2351
- doc.pages = [NestedPage.new(number: 2)]
2176
+ doc.pages = [ NestedPage.new(number: 1) ]
2177
+ doc.pages = [ NestedPage.new(number: 2) ]
2352
2178
  end
2353
2179
 
2354
- it "updates the attributes" do
2355
- expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id, "number" => 2 }])
2180
+ it 'updates the attributes' do
2181
+ expect(doc.attributes['pages']).to eq([ { '_id' => doc.pages.first.id, 'number' => 2 } ])
2356
2182
  end
2357
2183
 
2358
- it "has the same attributes after reloading" do
2184
+ it 'has the same attributes after reloading' do
2359
2185
  expect(doc.attributes).to eq(doc.reload.attributes)
2360
2186
  end
2361
2187
  end
2362
2188
 
2363
- context "when setting to nil" do
2189
+ context 'when setting to nil' do
2364
2190
  let(:doc) { NestedBook.create! }
2191
+
2365
2192
  before do
2366
- doc.pages = [NestedPage.new(number: 1)]
2193
+ doc.pages = [ NestedPage.new(number: 1) ]
2367
2194
  doc.pages = nil
2368
2195
  end
2369
2196
 
2370
- it "updates the attributes" do
2371
- expect(doc.attributes).to_not have_key("pages")
2197
+ it 'updates the attributes' do
2198
+ expect(doc.attributes).not_to have_key('pages')
2372
2199
  end
2373
2200
 
2374
- it "has the same attributes after reloading" do
2375
- expect({ "pages" => [] }.merge(doc.attributes)).to eq(doc.reload.attributes)
2201
+ it 'has the same attributes after reloading' do
2202
+ expect({ 'pages' => [] }.merge(doc.attributes)).to eq(doc.reload.attributes)
2376
2203
  end
2377
2204
  end
2378
2205
 
2379
- context "when setting to nil and back" do
2206
+ context 'when setting to nil and back' do
2380
2207
  let(:doc) { NestedBook.create! }
2381
2208
  let(:page) { NestedPage.new }
2209
+
2382
2210
  before do
2383
- doc.pages = [page]
2211
+ doc.pages = [ page ]
2384
2212
  doc.pages = nil
2385
- doc.pages = [page]
2213
+ doc.pages = [ page ]
2386
2214
  end
2387
2215
 
2388
- it "updates the attributes" do
2389
- expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
2216
+ it 'updates the attributes' do
2217
+ expect(doc.attributes['pages']).to eq([ { '_id' => doc.pages.first.id } ])
2390
2218
  end
2391
2219
 
2392
- it "has the same attributes after reloading" do
2220
+ it 'has the same attributes after reloading' do
2393
2221
  expect(doc.attributes).to eq(doc.reload.attributes)
2394
2222
  end
2395
2223
  end
2396
2224
 
2397
- context "when pushing" do
2225
+ context 'when pushing' do
2398
2226
  let(:doc) { NestedBook.create! }
2227
+
2399
2228
  before do
2400
2229
  doc.pages << NestedPage.new
2401
2230
  end
2402
2231
 
2403
- it "updates the attributes" do
2404
- expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
2232
+ it 'updates the attributes' do
2233
+ expect(doc.attributes['pages']).to eq([ { '_id' => doc.pages.first.id } ])
2405
2234
  end
2406
2235
 
2407
- it "has the same attributes after reloading" do
2236
+ it 'has the same attributes after reloading' do
2408
2237
  expect(doc.attributes).to eq(doc.reload.attributes)
2409
2238
  end
2410
2239
  end
2411
2240
 
2412
- [:shift, :pop].each do |meth|
2241
+ %i[shift pop].each do |meth|
2413
2242
  context "when performing #{meth}" do
2414
2243
  let(:doc) { NestedBook.create! }
2244
+
2415
2245
  before do
2416
2246
  doc.pages << NestedPage.new
2417
2247
  doc.pages << NestedPage.new
@@ -2420,52 +2250,55 @@ describe Mongoid::Attributes do
2420
2250
  doc.pages.send(meth, 2)
2421
2251
  end
2422
2252
 
2423
- it "updates the attributes" do
2424
- expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
2253
+ it 'updates the attributes' do
2254
+ expect(doc.attributes['pages']).to eq([ { '_id' => doc.pages.first.id } ])
2425
2255
  end
2426
2256
 
2427
- it "has the same attributes after reloading" do
2257
+ it 'has the same attributes after reloading' do
2428
2258
  expect(doc.attributes).to eq(doc.reload.attributes)
2429
2259
  end
2430
2260
  end
2431
2261
  end
2432
2262
 
2433
- context "when concatting" do
2263
+ context 'when concatting' do
2434
2264
  let(:doc) { NestedBook.create! }
2265
+
2435
2266
  before do
2436
2267
  doc.pages << NestedPage.new
2437
- doc.pages.concat([NestedPage.new, NestedPage.new])
2268
+ doc.pages.concat([ NestedPage.new, NestedPage.new ])
2438
2269
  end
2439
2270
 
2440
- it "updates the attributes" do
2441
- expect(doc.attributes["pages"].count).to eq 3
2271
+ it 'updates the attributes' do
2272
+ expect(doc.attributes['pages'].count).to eq 3
2442
2273
  end
2443
2274
 
2444
- it "has the same attributes after reloading" do
2275
+ it 'has the same attributes after reloading' do
2445
2276
  expect(doc.attributes).to eq(doc.reload.attributes)
2446
2277
  end
2447
2278
  end
2448
2279
 
2449
- [:build, :create].each do |meth|
2280
+ %i[build create].each do |meth|
2450
2281
  context "when preforming #{meth}" do
2451
2282
  let(:doc) { NestedBook.create! }
2283
+
2452
2284
  before do
2453
2285
  doc.pages.send(meth)
2454
2286
  end
2455
2287
 
2456
- it "updates the attributes" do
2457
- expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
2288
+ it 'updates the attributes' do
2289
+ expect(doc.attributes['pages']).to eq([ { '_id' => doc.pages.first.id } ])
2458
2290
  end
2459
2291
 
2460
- it "has the same attributes after reloading" do
2292
+ it 'has the same attributes after reloading' do
2461
2293
  doc.pages.first.save
2462
2294
  expect(doc.attributes).to eq(doc.reload.attributes)
2463
2295
  end
2464
2296
  end
2465
2297
  end
2466
2298
 
2467
- context "when clearing" do
2299
+ context 'when clearing' do
2468
2300
  let(:doc) { NestedBook.create! }
2301
+
2469
2302
  before do
2470
2303
  doc.pages << NestedPage.new
2471
2304
  doc.pages << NestedPage.new
@@ -2474,18 +2307,19 @@ describe Mongoid::Attributes do
2474
2307
  doc.pages.clear
2475
2308
  end
2476
2309
 
2477
- it "updates the attributes" do
2478
- expect(doc.attributes).to_not have_key("pages")
2310
+ it 'updates the attributes' do
2311
+ expect(doc.attributes).not_to have_key('pages')
2479
2312
  end
2480
2313
 
2481
- it "has the same attributes after reloading" do
2314
+ it 'has the same attributes after reloading' do
2482
2315
  expect(doc.attributes).to eq(doc.reload.attributes)
2483
2316
  end
2484
2317
  end
2485
2318
 
2486
- [:delete_all, :destroy_all, :remove_all].each do |meth|
2319
+ %i[delete_all destroy_all remove_all].each do |meth|
2487
2320
  context "when performing: #{meth}" do
2488
2321
  let(:doc) { NestedBook.create! }
2322
+
2489
2323
  before do
2490
2324
  doc.pages << NestedPage.new
2491
2325
  doc.pages << NestedPage.new
@@ -2494,19 +2328,20 @@ describe Mongoid::Attributes do
2494
2328
  doc.pages.send(meth)
2495
2329
  end
2496
2330
 
2497
- it "updates the attributes" do
2498
- expect(doc.attributes).to_not have_key("pages")
2331
+ it 'updates the attributes' do
2332
+ expect(doc.attributes).not_to have_key('pages')
2499
2333
  end
2500
2334
 
2501
- it "has the same attributes after reloading" do
2502
- expect({ "pages" => [] }.merge(doc.attributes)).to eq(doc.reload.attributes)
2335
+ it 'has the same attributes after reloading' do
2336
+ expect({ 'pages' => [] }.merge(doc.attributes)).to eq(doc.reload.attributes)
2503
2337
  end
2504
2338
  end
2505
2339
  end
2506
2340
 
2507
- context "when deleting" do
2341
+ context 'when deleting' do
2508
2342
  let(:doc) { NestedBook.create! }
2509
2343
  let(:page) { NestedPage.new }
2344
+
2510
2345
  before do
2511
2346
  doc.pages << page
2512
2347
  doc.pages << NestedPage.new
@@ -2515,18 +2350,19 @@ describe Mongoid::Attributes do
2515
2350
  doc.pages.delete(page)
2516
2351
  end
2517
2352
 
2518
- it "updates the attributes" do
2519
- expect(doc.attributes["pages"].count).to eq 2
2353
+ it 'updates the attributes' do
2354
+ expect(doc.attributes['pages'].count).to eq 2
2520
2355
  end
2521
2356
 
2522
- it "has the same attributes after reloading" do
2357
+ it 'has the same attributes after reloading' do
2523
2358
  expect(doc.attributes).to eq(doc.reload.attributes)
2524
2359
  end
2525
2360
  end
2526
2361
 
2527
- context "when doing _remove" do
2362
+ context 'when doing _remove' do
2528
2363
  let(:doc) { NestedBook.create! }
2529
2364
  let(:page) { NestedPage.new }
2365
+
2530
2366
  before do
2531
2367
  doc.pages << page
2532
2368
  doc.pages << NestedPage.new
@@ -2535,180 +2371,187 @@ describe Mongoid::Attributes do
2535
2371
  doc.pages._remove(page)
2536
2372
  end
2537
2373
 
2538
- it "updates the attributes" do
2539
- expect(doc.attributes["pages"].count).to eq 2
2374
+ it 'updates the attributes' do
2375
+ expect(doc.attributes['pages'].count).to eq 2
2540
2376
  end
2541
2377
  end
2542
2378
 
2543
- context "when assigning an array of hashes" do
2379
+ context 'when assigning an array of hashes' do
2544
2380
  let(:doc) { NestedBook.create! }
2381
+
2545
2382
  before do
2546
- doc.pages = [{}]
2383
+ doc.pages = [ {} ]
2547
2384
  end
2548
2385
 
2549
- it "updates the attributes" do
2550
- expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
2386
+ it 'updates the attributes' do
2387
+ expect(doc.attributes['pages']).to eq([ { '_id' => doc.pages.first.id } ])
2551
2388
  end
2552
2389
 
2553
- it "has the same attributes after reloading" do
2390
+ it 'has the same attributes after reloading' do
2554
2391
  expect(doc.attributes).to eq(doc.reload.attributes)
2555
2392
  end
2556
2393
  end
2557
2394
 
2558
- context "when assigning twice" do
2395
+ context 'when assigning twice' do
2559
2396
  let(:doc) { NestedBook.create! }
2397
+
2560
2398
  before do
2561
- doc.pages = [{ number: 1 }]
2562
- doc.pages = [{}]
2399
+ doc.pages = [ { number: 1 } ]
2400
+ doc.pages = [ {} ]
2563
2401
  end
2564
2402
 
2565
- it "updates the attributes" do
2566
- expect(doc.attributes["pages"]).to eq([{ "_id" => doc.pages.first.id }])
2403
+ it 'updates the attributes' do
2404
+ expect(doc.attributes['pages']).to eq([ { '_id' => doc.pages.first.id } ])
2567
2405
  end
2568
2406
 
2569
- it "has the same attributes after reloading" do
2407
+ it 'has the same attributes after reloading' do
2570
2408
  expect(doc.attributes).to eq(doc.reload.attributes)
2571
2409
  end
2572
2410
  end
2573
2411
  end
2574
2412
 
2575
- context "on embeds_one" do
2413
+ context 'on embeds_one' do
2414
+ let(:attrs) { { 'title' => 'Title' } }
2576
2415
 
2577
- let(:attrs) { { "title" => "Title" } }
2578
-
2579
- context "when using nested attributes" do
2416
+ context 'when using nested attributes' do
2580
2417
  let(:doc) { NestedBook.create! }
2581
2418
 
2582
2419
  before do
2583
2420
  doc.update_attributes({ cover_attributes: attrs })
2584
2421
  end
2585
2422
 
2586
- it "updates the attributes" do
2587
- expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
2423
+ it 'updates the attributes' do
2424
+ expect(doc.attributes['cover']).to eq(attrs.merge('_id' => doc.cover.id))
2588
2425
  end
2589
2426
 
2590
- it "has the same attributes after reloading" do
2427
+ it 'has the same attributes after reloading' do
2591
2428
  expect(doc.attributes).to eq(doc.reload.attributes)
2592
2429
  end
2593
2430
  end
2594
2431
 
2595
- context "when doing assignments" do
2432
+ context 'when doing assignments' do
2596
2433
  let(:doc) { NestedBook.create! }
2434
+
2597
2435
  before do
2598
2436
  doc.cover = NestedCover.new(attrs)
2599
2437
  end
2600
2438
 
2601
- it "updates the attributes" do
2602
- expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
2439
+ it 'updates the attributes' do
2440
+ expect(doc.attributes['cover']).to eq(attrs.merge('_id' => doc.cover.id))
2603
2441
  end
2604
2442
 
2605
- it "has the same attributes after reloading" do
2443
+ it 'has the same attributes after reloading' do
2606
2444
  expect(doc.attributes).to eq(doc.reload.attributes)
2607
2445
  end
2608
2446
  end
2609
2447
 
2610
- context "when replacing assignments" do
2448
+ context 'when replacing assignments' do
2611
2449
  let(:doc) { NestedBook.create! }
2450
+
2612
2451
  before do
2613
- doc.cover = NestedCover.new("title" => "Title1")
2452
+ doc.cover = NestedCover.new('title' => 'Title1')
2614
2453
  doc.cover = NestedCover.new(attrs)
2615
2454
  end
2616
2455
 
2617
- it "updates the attributes" do
2618
- expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
2456
+ it 'updates the attributes' do
2457
+ expect(doc.attributes['cover']).to eq(attrs.merge('_id' => doc.cover.id))
2619
2458
  end
2620
2459
 
2621
- it "has the same attributes after reloading" do
2460
+ it 'has the same attributes after reloading' do
2622
2461
  expect(doc.attributes).to eq(doc.reload.attributes)
2623
2462
  end
2624
2463
  end
2625
2464
 
2626
- context "when setting to nil" do
2465
+ context 'when setting to nil' do
2627
2466
  let(:doc) { NestedBook.create! }
2467
+
2628
2468
  before do
2629
2469
  doc.cover = NestedCover.new(attrs)
2630
2470
  doc.cover = nil
2631
2471
  end
2632
2472
 
2633
- it "updates the attributes" do
2634
- expect(doc.attributes.key?("cover")).to be false
2473
+ it 'updates the attributes' do
2474
+ expect(doc.attributes.key?('cover')).to be false
2635
2475
  end
2636
2476
 
2637
- it "has the same attributes after reloading" do
2477
+ it 'has the same attributes after reloading' do
2638
2478
  expect(doc.attributes).to eq(doc.reload.attributes)
2639
2479
  end
2640
2480
  end
2641
2481
 
2642
- context "when setting to nil and back" do
2482
+ context 'when setting to nil and back' do
2643
2483
  let(:doc) { NestedBook.create! }
2484
+
2644
2485
  before do
2645
2486
  doc.cover = NestedCover.new(attrs)
2646
2487
  doc.cover = nil
2647
2488
  doc.cover = NestedCover.new(attrs)
2648
2489
  end
2649
2490
 
2650
- it "updates the attributes" do
2651
- expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
2491
+ it 'updates the attributes' do
2492
+ expect(doc.attributes['cover']).to eq(attrs.merge('_id' => doc.cover.id))
2652
2493
  end
2653
2494
 
2654
-
2655
- it "has the same attributes after reloading" do
2495
+ it 'has the same attributes after reloading' do
2656
2496
  expect(doc.attributes).to eq(doc.reload.attributes)
2657
2497
  end
2658
2498
  end
2659
2499
 
2660
- [:build, :create].each do |meth|
2500
+ %i[build create].each do |meth|
2661
2501
  context "when preforming #{meth}" do
2662
2502
  let(:doc) { NestedBook.create! }
2503
+
2663
2504
  before do
2664
2505
  doc.send("#{meth}_cover", attrs)
2665
2506
  end
2666
2507
 
2667
- it "updates the attributes" do
2668
- expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
2508
+ it 'updates the attributes' do
2509
+ expect(doc.attributes['cover']).to eq(attrs.merge('_id' => doc.cover.id))
2669
2510
  end
2670
2511
 
2671
- it "has the same attributes after reloading" do
2512
+ it 'has the same attributes after reloading' do
2672
2513
  doc.cover.save
2673
2514
  expect(doc.attributes).to eq(doc.reload.attributes)
2674
2515
  end
2675
2516
  end
2676
2517
  end
2677
2518
 
2678
- context "when assigning a hash" do
2519
+ context 'when assigning a hash' do
2679
2520
  let(:doc) { NestedBook.create! }
2521
+
2680
2522
  before do
2681
2523
  doc.cover = attrs
2682
2524
  end
2683
2525
 
2684
- it "updates the attributes" do
2685
- expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
2526
+ it 'updates the attributes' do
2527
+ expect(doc.attributes['cover']).to eq(attrs.merge('_id' => doc.cover.id))
2686
2528
  end
2687
2529
 
2688
- it "has the same attributes after reloading" do
2530
+ it 'has the same attributes after reloading' do
2689
2531
  expect(doc.attributes).to eq(doc.reload.attributes)
2690
2532
  end
2691
2533
  end
2692
2534
 
2693
- context "when assigning twice" do
2535
+ context 'when assigning twice' do
2694
2536
  let(:doc) { NestedBook.create! }
2537
+
2695
2538
  before do
2696
- doc.cover = { "title" => "1984" }
2539
+ doc.cover = { 'title' => '1984' }
2697
2540
  doc.cover = attrs
2698
2541
  end
2699
2542
 
2700
- it "updates the attributes" do
2701
- expect(doc.attributes["cover"]).to eq(attrs.merge("_id" => doc.cover.id))
2543
+ it 'updates the attributes' do
2544
+ expect(doc.attributes['cover']).to eq(attrs.merge('_id' => doc.cover.id))
2702
2545
  end
2703
2546
 
2704
- it "has the same attributes after reloading" do
2547
+ it 'has the same attributes after reloading' do
2705
2548
  expect(doc.attributes).to eq(doc.reload.attributes)
2706
2549
  end
2707
2550
  end
2708
2551
  end
2709
2552
  end
2710
2553
 
2711
- context "when modifiying a hash referenced with the [] notation" do
2554
+ context 'when modifying a hash referenced with the [] notation' do
2712
2555
  let(:church) { Church.create!(location: { x: 1 }) }
2713
2556
 
2714
2557
  before do
@@ -2717,28 +2560,28 @@ describe Mongoid::Attributes do
2717
2560
  church.reload
2718
2561
  end
2719
2562
 
2720
- it "persists the updated hash" do
2721
- church.location.should == { "x" => 1, "y" => 2 }
2563
+ it 'persists the updated hash' do
2564
+ church.location.should eq({ 'x' => 1, 'y' => 2 })
2722
2565
  end
2723
2566
  end
2724
2567
 
2725
- context "when accessing an embedded document with the attribute accessor" do
2568
+ context 'when accessing an embedded document with the attribute accessor' do
2726
2569
  let(:band) { Band.create! }
2727
2570
 
2728
2571
  before do
2729
2572
  Band.where(id: band.id).update_all({
2730
- :$push => {records: { _id: BSON::ObjectId.new }}
2731
- })
2573
+ :$push => { records: { _id: BSON::ObjectId.new } }
2574
+ })
2732
2575
  end
2733
2576
 
2734
- it "does not throw a conflicting update error" do
2577
+ it 'does not throw a conflicting update error' do
2735
2578
  b1 = Band.find(band.id)
2736
2579
  b1[:records].is_a?(Array).should be true
2737
2580
  expect { b1.save! }.not_to raise_error
2738
2581
  end
2739
2582
  end
2740
2583
 
2741
- context "when modifying a set referenced with the [] notation" do
2584
+ context 'when modifying a set referenced with the [] notation' do
2742
2585
  let(:catalog) { Catalog.create!(set_field: [ 1 ].to_set) }
2743
2586
 
2744
2587
  before do
@@ -2747,9 +2590,9 @@ describe Mongoid::Attributes do
2747
2590
  catalog.reload
2748
2591
  end
2749
2592
 
2750
- it "persists the updated hash" do
2751
- pending "MONGOID-2951"
2752
- catalog.set_field.should == Set.new([ 1, 2 ])
2593
+ it 'persists the updated hash' do
2594
+ pending 'MONGOID-2951'
2595
+ catalog.set_field.should eq Set.new([ 1, 2 ])
2753
2596
  end
2754
2597
  end
2755
2598