mongoid 9.0.12 → 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 (1006) 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 -45
  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 +38 -46
  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 +23 -47
  32. data/lib/mongoid/association/nested/nested_buildable.rb +6 -23
  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 +11 -106
  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 -83
  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 -22
  83. data/lib/mongoid/composable.rb +30 -34
  84. data/lib/mongoid/config/defaults.rb +7 -4
  85. data/lib/mongoid/config/encryption.rb +19 -39
  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 +127 -84
  94. data/lib/mongoid/contextual/aggregable/memory.rb +4 -9
  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 +76 -80
  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 -43
  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 +130 -301
  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 -48
  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 -74
  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 +41 -52
  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 +1 -8
  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 -2
  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 +12 -11
  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 -16
  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 -76
  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 +337 -14
  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 +37 -53
  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 -69
  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 -185
  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 +18 -30
  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 +105 -130
  402. data/spec/integration/encryption_spec.rb +8 -160
  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_data/regex.yml +0 -21
  408. data/spec/integration/matcher_operator_spec.rb +16 -26
  409. data/spec/integration/matcher_spec.rb +31 -32
  410. data/spec/integration/persistence/collection_options_spec.rb +0 -2
  411. data/spec/integration/persistence/range_field_spec.rb +24 -2
  412. data/spec/integration/server_query_spec.rb +43 -37
  413. data/spec/integration/shardable_spec.rb +10 -11
  414. data/spec/integration/stringified_symbol_field_spec.rb +28 -43
  415. data/spec/lite_spec_helper.rb +11 -12
  416. data/spec/mongoid/association/accessors_spec.rb +197 -285
  417. data/spec/mongoid/association/auto_save_spec.rb +62 -93
  418. data/spec/mongoid/association/builders_spec.rb +121 -74
  419. data/spec/mongoid/association/constrainable_spec.rb +9 -22
  420. data/spec/mongoid/association/counter_cache_spec.rb +71 -104
  421. data/spec/mongoid/association/depending_spec.rb +166 -208
  422. data/spec/mongoid/association/eager_spec.rb +416 -80
  423. data/spec/mongoid/association/embedded/cyclic_spec.rb +36 -48
  424. data/spec/mongoid/association/embedded/dirty_spec.rb +15 -20
  425. data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +36 -54
  426. data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +8 -15
  427. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +135 -175
  428. data/spec/mongoid/association/embedded/embedded_in_spec.rb +25 -127
  429. data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +9 -14
  430. data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +38 -51
  431. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +1151 -1340
  432. data/spec/mongoid/association/embedded/embeds_many_models.rb +17 -17
  433. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +11 -11
  434. data/spec/mongoid/association/embedded/embeds_many_spec.rb +25 -138
  435. data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +15 -23
  436. data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +18 -26
  437. data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +204 -273
  438. data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +0 -1
  439. data/spec/mongoid/association/embedded/embeds_one_models.rb +0 -1
  440. data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +5 -6
  441. data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -143
  442. data/spec/mongoid/association/macros_spec.rb +213 -300
  443. data/spec/mongoid/association/nested/many_spec.rb +51 -73
  444. data/spec/mongoid/association/nested/one_spec.rb +56 -80
  445. data/spec/mongoid/association/options_spec.rb +187 -310
  446. data/spec/mongoid/association/polymorphic_spec.rb +35 -53
  447. data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +55 -76
  448. data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +36 -41
  449. data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +81 -101
  450. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +258 -345
  451. data/spec/mongoid/association/referenced/belongs_to_models.rb +4 -3
  452. data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +3 -4
  453. data/spec/mongoid/association/referenced/belongs_to_spec.rb +91 -294
  454. data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +42 -56
  455. data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +41 -32
  456. data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +36 -42
  457. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +8 -9
  458. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +771 -1023
  459. data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +9 -9
  460. data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +5 -6
  461. data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +59 -177
  462. data/spec/mongoid/association/referenced/has_many/binding_spec.rb +29 -43
  463. data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +53 -53
  464. data/spec/mongoid/association/referenced/has_many/eager_spec.rb +104 -67
  465. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +431 -675
  466. data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -2
  467. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +173 -156
  468. data/spec/mongoid/association/referenced/has_many_models.rb +1 -2
  469. data/spec/mongoid/association/referenced/has_many_query_spec.rb +3 -4
  470. data/spec/mongoid/association/referenced/has_many_spec.rb +44 -188
  471. data/spec/mongoid/association/referenced/has_one/binding_spec.rb +26 -38
  472. data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +28 -29
  473. data/spec/mongoid/association/referenced/has_one/eager_spec.rb +29 -42
  474. data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +270 -332
  475. data/spec/mongoid/association/referenced/has_one_models.rb +1 -2
  476. data/spec/mongoid/association/referenced/has_one_query_spec.rb +3 -4
  477. data/spec/mongoid/association/referenced/has_one_spec.rb +40 -188
  478. data/spec/mongoid/association/reflections_spec.rb +14 -24
  479. data/spec/mongoid/association/syncable_spec.rb +102 -125
  480. data/spec/mongoid/association_spec.rb +47 -70
  481. data/spec/mongoid/atomic/modifiers_spec.rb +184 -197
  482. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +39 -52
  483. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +35 -49
  484. data/spec/mongoid/atomic/paths/root_spec.rb +9 -15
  485. data/spec/mongoid/atomic/paths_spec.rb +81 -117
  486. data/spec/mongoid/atomic_spec.rb +156 -171
  487. data/spec/mongoid/attributes/dynamic_spec.rb +5 -6
  488. data/spec/mongoid/attributes/nested_spec.rb +1221 -1888
  489. data/spec/mongoid/attributes/nested_spec_models.rb +8 -9
  490. data/spec/mongoid/attributes/projector_spec.rb +2 -6
  491. data/spec/mongoid/attributes/readonly_spec.rb +73 -97
  492. data/spec/mongoid/attributes_spec.rb +669 -826
  493. data/spec/mongoid/cacheable_spec.rb +74 -44
  494. data/spec/mongoid/changeable_spec.rb +591 -733
  495. data/spec/mongoid/clients/factory_spec.rb +122 -154
  496. data/spec/mongoid/clients/options_spec.rb +40 -59
  497. data/spec/mongoid/clients/sessions_spec.rb +25 -44
  498. data/spec/mongoid/clients/transactions_spec.rb +33 -50
  499. data/spec/mongoid/clients/transactions_spec_models.rb +3 -4
  500. data/spec/mongoid/clients_spec.rb +265 -355
  501. data/spec/mongoid/collection_configurable_spec.rb +9 -12
  502. data/spec/mongoid/composable_spec.rb +2 -9
  503. data/spec/mongoid/config/defaults_spec.rb +24 -49
  504. data/spec/mongoid/config/encryption_spec.rb +53 -284
  505. data/spec/mongoid/config/environment_spec.rb +30 -40
  506. data/spec/mongoid/config/introspection_spec.rb +42 -37
  507. data/spec/mongoid/config/options_spec.rb +14 -21
  508. data/spec/mongoid/config_spec.rb +145 -195
  509. data/spec/mongoid/contextual/aggregable/memory_spec.rb +98 -226
  510. data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +4 -7
  511. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +149 -187
  512. data/spec/mongoid/contextual/aggregable/none_spec.rb +14 -16
  513. data/spec/mongoid/contextual/atomic_spec.rb +223 -271
  514. data/spec/mongoid/contextual/map_reduce_spec.rb +110 -138
  515. data/spec/mongoid/contextual/memory_spec.rb +706 -1031
  516. data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +12 -13
  517. data/spec/mongoid/contextual/mongo_spec.rb +1008 -1213
  518. data/spec/mongoid/contextual/none_spec.rb +54 -59
  519. data/spec/mongoid/contextual/short_circuit_spec.rb +139 -0
  520. data/spec/mongoid/copyable_spec.rb +254 -300
  521. data/spec/mongoid/copyable_spec_models.rb +0 -1
  522. data/spec/mongoid/criteria/findable_spec.rb +322 -387
  523. data/spec/mongoid/criteria/includable_spec.rb +421 -372
  524. data/spec/mongoid/criteria/includable_spec_models.rb +16 -7
  525. data/spec/mongoid/criteria/inspectable_spec.rb +11 -14
  526. data/spec/mongoid/criteria/marshalable_spec.rb +11 -14
  527. data/spec/mongoid/criteria/modifiable_spec.rb +366 -512
  528. data/spec/mongoid/criteria/options_spec.rb +2 -7
  529. data/spec/mongoid/criteria/queryable/aggregable_spec.rb +112 -141
  530. data/spec/mongoid/criteria/queryable/expandable_spec.rb +8 -11
  531. data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +127 -184
  532. data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +123 -60
  533. data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +84 -117
  534. data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +44 -65
  535. data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +86 -108
  536. data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +94 -33
  537. data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +103 -138
  538. data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +95 -34
  539. data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +25 -38
  540. data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +26 -28
  541. data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +32 -54
  542. data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +136 -130
  543. data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +16 -24
  544. data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +15 -24
  545. data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +12 -19
  546. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +46 -63
  547. data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +28 -42
  548. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +73 -96
  549. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +71 -92
  550. data/spec/mongoid/criteria/queryable/key_spec.rb +32 -36
  551. data/spec/mongoid/criteria/queryable/mergeable_spec.rb +44 -49
  552. data/spec/mongoid/criteria/queryable/optional_spec.rb +373 -486
  553. data/spec/mongoid/criteria/queryable/options_spec.rb +172 -123
  554. data/spec/mongoid/criteria/queryable/pipeline_spec.rb +65 -87
  555. data/spec/mongoid/criteria/queryable/queryable_spec.rb +41 -53
  556. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +576 -682
  557. data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +7 -11
  558. data/spec/mongoid/criteria/queryable/selectable_spec.rb +807 -998
  559. data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +154 -391
  560. data/spec/mongoid/criteria/queryable/selector_spec.rb +294 -390
  561. data/spec/mongoid/criteria/queryable/smash_spec.rb +6 -11
  562. data/spec/mongoid/criteria/queryable/storable_spec.rb +54 -81
  563. data/spec/mongoid/criteria/queryable_mql_spec.rb +92 -0
  564. data/spec/mongoid/criteria/scopable_spec.rb +102 -138
  565. data/spec/mongoid/criteria/translator_spec.rb +59 -60
  566. data/spec/mongoid/criteria_projection_spec.rb +81 -99
  567. data/spec/mongoid/criteria_spec.rb +935 -952
  568. data/spec/mongoid/document_fields_spec.rb +28 -30
  569. data/spec/mongoid/document_persistence_context_spec.rb +13 -15
  570. data/spec/mongoid/document_query_spec.rb +9 -12
  571. data/spec/mongoid/document_spec.rb +317 -409
  572. data/spec/mongoid/equality_spec.rb +69 -102
  573. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +8 -11
  574. data/spec/mongoid/errors/attribute_not_loaded_spec.rb +7 -10
  575. data/spec/mongoid/errors/callback_spec.rb +8 -11
  576. data/spec/mongoid/errors/delete_restriction_spec.rb +5 -8
  577. data/spec/mongoid/errors/document_not_destroyed_spec.rb +7 -10
  578. data/spec/mongoid/errors/document_not_found_spec.rb +51 -61
  579. data/spec/mongoid/errors/invalid_collection_spec.rb +9 -13
  580. data/spec/mongoid/errors/invalid_config_file_spec.rb +8 -11
  581. data/spec/mongoid/errors/invalid_config_option_spec.rb +8 -11
  582. data/spec/mongoid/errors/invalid_field_option_spec.rb +7 -10
  583. data/spec/mongoid/errors/invalid_field_spec.rb +10 -11
  584. data/spec/mongoid/errors/invalid_field_type_spec.rb +9 -12
  585. data/spec/mongoid/errors/invalid_find_spec.rb +8 -11
  586. data/spec/mongoid/errors/invalid_includes_spec.rb +9 -13
  587. data/spec/mongoid/errors/invalid_index_spec.rb +8 -11
  588. data/spec/mongoid/errors/invalid_options_spec.rb +8 -11
  589. data/spec/mongoid/errors/invalid_path_spec.rb +7 -10
  590. data/spec/mongoid/errors/invalid_relation_spec.rb +15 -16
  591. data/spec/mongoid/errors/invalid_scope_spec.rb +8 -11
  592. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -6
  593. data/spec/mongoid/errors/invalid_storage_options_spec.rb +8 -11
  594. data/spec/mongoid/errors/invalid_time_spec.rb +8 -11
  595. data/spec/mongoid/errors/inverse_not_found_spec.rb +9 -12
  596. data/spec/mongoid/errors/mixed_client_configuration_spec.rb +9 -12
  597. data/spec/mongoid/errors/mixed_relations_spec.rb +8 -11
  598. data/spec/mongoid/errors/mongoid_error_spec.rb +21 -24
  599. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +6 -9
  600. data/spec/mongoid/errors/no_client_config_spec.rb +7 -10
  601. data/spec/mongoid/errors/no_client_database_spec.rb +9 -12
  602. data/spec/mongoid/errors/no_client_hosts_spec.rb +9 -12
  603. data/spec/mongoid/errors/no_clients_config_spec.rb +7 -10
  604. data/spec/mongoid/errors/no_environment_spec.rb +8 -11
  605. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +8 -11
  606. data/spec/mongoid/errors/no_metadata_spec.rb +7 -10
  607. data/spec/mongoid/errors/no_parent_spec.rb +7 -10
  608. data/spec/mongoid/errors/readonly_attribute_spec.rb +7 -10
  609. data/spec/mongoid/errors/readonly_document_spec.rb +6 -9
  610. data/spec/mongoid/errors/scope_overwrite_spec.rb +9 -12
  611. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +9 -12
  612. data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -8
  613. data/spec/mongoid/errors/unsaved_document_spec.rb +8 -11
  614. data/spec/mongoid/errors/unsupported_javascript_spec.rb +9 -12
  615. data/spec/mongoid/errors/validations_spec.rb +11 -14
  616. data/spec/mongoid/extensions/array_spec.rb +70 -92
  617. data/spec/mongoid/extensions/big_decimal_spec.rb +233 -313
  618. data/spec/mongoid/extensions/binary_spec.rb +21 -32
  619. data/spec/mongoid/extensions/boolean_spec.rb +52 -75
  620. data/spec/mongoid/extensions/date_class_mongoize_spec.rb +43 -54
  621. data/spec/mongoid/extensions/date_spec.rb +26 -38
  622. data/spec/mongoid/extensions/date_time_spec.rb +22 -32
  623. data/spec/mongoid/extensions/decimal128_spec.rb +12 -18
  624. data/spec/mongoid/extensions/false_class_spec.rb +10 -17
  625. data/spec/mongoid/extensions/float_spec.rb +40 -61
  626. data/spec/mongoid/extensions/hash_spec.rb +46 -64
  627. data/spec/mongoid/extensions/integer_spec.rb +40 -61
  628. data/spec/mongoid/extensions/module_spec.rb +13 -18
  629. data/spec/mongoid/extensions/nil_class_spec.rb +2 -5
  630. data/spec/mongoid/extensions/object_id_spec.rb +159 -247
  631. data/spec/mongoid/extensions/object_spec.rb +31 -47
  632. data/spec/mongoid/extensions/range_spec.rb +112 -115
  633. data/spec/mongoid/extensions/raw_value_spec.rb +10 -12
  634. data/spec/mongoid/extensions/regexp_spec.rb +23 -36
  635. data/spec/mongoid/extensions/set_spec.rb +38 -49
  636. data/spec/mongoid/extensions/string_spec.rb +118 -167
  637. data/spec/mongoid/extensions/stringified_symbol_spec.rb +29 -43
  638. data/spec/mongoid/extensions/symbol_spec.rb +12 -20
  639. data/spec/mongoid/extensions/time_spec.rb +160 -202
  640. data/spec/mongoid/extensions/time_with_zone_spec.rb +79 -105
  641. data/spec/mongoid/extensions/true_class_spec.rb +10 -17
  642. data/spec/mongoid/factory_spec.rb +125 -148
  643. data/spec/mongoid/fields/foreign_key_spec.rb +124 -169
  644. data/spec/mongoid/fields/localized_spec.rb +140 -185
  645. data/spec/mongoid/fields/standard_spec.rb +43 -59
  646. data/spec/mongoid/fields_spec.rb +751 -620
  647. data/spec/mongoid/findable_spec.rb +260 -228
  648. data/spec/mongoid/indexable/specification_spec.rb +42 -58
  649. data/spec/mongoid/indexable_spec.rb +260 -264
  650. data/spec/mongoid/inspectable_spec.rb +45 -55
  651. data/spec/mongoid/interceptable_spec.rb +784 -922
  652. data/spec/mongoid/interceptable_spec_models.rb +35 -35
  653. data/spec/mongoid/loading_spec.rb +47 -43
  654. data/spec/mongoid/loggable_spec.rb +3 -6
  655. data/spec/mongoid/matcher/extract_attribute_spec.rb +2 -6
  656. data/spec/mongoid/mongoizable_spec.rb +81 -90
  657. data/spec/mongoid/monkey_patches_spec.rb +4 -0
  658. data/spec/mongoid/persistable/creatable_spec.rb +181 -220
  659. data/spec/mongoid/persistable/deletable_spec.rb +139 -179
  660. data/spec/mongoid/persistable/destroyable_spec.rb +135 -164
  661. data/spec/mongoid/persistable/incrementable_spec.rb +65 -84
  662. data/spec/mongoid/persistable/logical_spec.rb +48 -61
  663. data/spec/mongoid/persistable/maxable_spec.rb +45 -44
  664. data/spec/mongoid/persistable/minable_spec.rb +45 -44
  665. data/spec/mongoid/persistable/multipliable_spec.rb +54 -69
  666. data/spec/mongoid/persistable/poppable_spec.rb +47 -60
  667. data/spec/mongoid/persistable/pullable_spec.rb +79 -103
  668. data/spec/mongoid/persistable/pushable_spec.rb +106 -131
  669. data/spec/mongoid/persistable/renamable_spec.rb +52 -65
  670. data/spec/mongoid/persistable/savable_spec.rb +152 -189
  671. data/spec/mongoid/persistable/settable_spec.rb +121 -145
  672. data/spec/mongoid/persistable/unsettable_spec.rb +56 -73
  673. data/spec/mongoid/persistable/updatable_spec.rb +185 -232
  674. data/spec/mongoid/persistable/upsertable_spec.rb +66 -77
  675. data/spec/mongoid/persistable_spec.rb +132 -139
  676. data/spec/mongoid/persistence_context_spec.rb +31 -89
  677. data/spec/mongoid/positional_spec.rb +67 -79
  678. data/spec/mongoid/railties/bson_object_id_serializer_spec.rb +0 -3
  679. data/spec/mongoid/railties/console_sandbox_spec.rb +0 -1
  680. data/spec/mongoid/relations/proxy_spec.rb +0 -1
  681. data/spec/mongoid/reloadable_spec.rb +250 -145
  682. data/spec/mongoid/scopable_spec.rb +319 -398
  683. data/spec/mongoid/search_indexable_spec.rb +446 -41
  684. data/spec/mongoid/selectable_spec.rb +36 -51
  685. data/spec/mongoid/serializable_spec.rb +269 -312
  686. data/spec/mongoid/shardable_models.rb +5 -5
  687. data/spec/mongoid/shardable_spec.rb +44 -46
  688. data/spec/mongoid/stateful_spec.rb +55 -75
  689. data/spec/mongoid/tasks/database_rake_spec.rb +138 -141
  690. data/spec/mongoid/tasks/database_spec.rb +80 -98
  691. data/spec/mongoid/tasks/encryption_spec.rb +22 -20
  692. data/spec/mongoid/threaded_spec.rb +57 -83
  693. data/spec/mongoid/timestamps/created/short_spec.rb +12 -16
  694. data/spec/mongoid/timestamps/created_spec.rb +16 -20
  695. data/spec/mongoid/timestamps/timeless_spec.rb +31 -43
  696. data/spec/mongoid/timestamps/updated/short_spec.rb +21 -28
  697. data/spec/mongoid/timestamps/updated_spec.rb +18 -25
  698. data/spec/mongoid/timestamps_spec.rb +171 -188
  699. data/spec/mongoid/timestamps_spec_models.rb +12 -13
  700. data/spec/mongoid/touchable_spec.rb +330 -294
  701. data/spec/mongoid/touchable_spec_models.rb +35 -37
  702. data/spec/mongoid/traversable_spec.rb +435 -471
  703. data/spec/mongoid/validatable/associated_spec.rb +42 -60
  704. data/spec/mongoid/validatable/format_spec.rb +24 -34
  705. data/spec/mongoid/validatable/length_spec.rb +62 -86
  706. data/spec/mongoid/validatable/numericality_spec.rb +114 -23
  707. data/spec/mongoid/validatable/presence_spec.rb +149 -203
  708. data/spec/mongoid/validatable/uniqueness_spec.rb +632 -830
  709. data/spec/mongoid/validatable_spec.rb +71 -103
  710. data/spec/mongoid/warnings_spec.rb +5 -9
  711. data/spec/mongoid_spec.rb +25 -41
  712. data/spec/rails/controller_extension/controller_runtime_spec.rb +45 -49
  713. data/spec/rails/mongoid_spec.rb +15 -15
  714. data/spec/shared/lib/mrss/cluster_config.rb +5 -40
  715. data/spec/shared/lib/mrss/constraints.rb +7 -46
  716. data/spec/shared/lib/mrss/docker_runner.rb +10 -21
  717. data/spec/shared/lib/mrss/eg_config_utils.rb +0 -31
  718. data/spec/shared/lib/mrss/release/candidate.rb +18 -12
  719. data/spec/shared/lib/mrss/server_version_registry.rb +1 -5
  720. data/spec/shared/share/Dockerfile.erb +6 -8
  721. data/spec/shared/shlib/server.sh +0 -50
  722. data/spec/shared/shlib/set_env.sh +4 -10
  723. data/spec/spec_helper.rb +54 -31
  724. data/spec/support/authorization.rb +0 -1
  725. data/spec/support/client_registry.rb +1 -2
  726. data/spec/support/constraints.rb +8 -25
  727. data/spec/support/crypt/models.rb +7 -165
  728. data/spec/support/crypt.rb +6 -9
  729. data/spec/support/expectations.rb +21 -7
  730. data/spec/support/feature_sandbox.rb +1 -4
  731. data/spec/support/helpers.rb +0 -1
  732. data/spec/support/immutable_ids.rb +20 -21
  733. data/spec/support/macros.rb +1 -3
  734. data/spec/support/models/account.rb +4 -5
  735. data/spec/support/models/acolyte.rb +5 -5
  736. data/spec/support/models/actor.rb +3 -3
  737. data/spec/support/models/actress.rb +0 -1
  738. data/spec/support/models/address.rb +11 -11
  739. data/spec/support/models/address_component.rb +1 -1
  740. data/spec/support/models/address_number.rb +1 -1
  741. data/spec/support/models/agency.rb +1 -1
  742. data/spec/support/models/agent.rb +1 -1
  743. data/spec/support/models/album.rb +1 -2
  744. data/spec/support/models/alert.rb +1 -1
  745. data/spec/support/models/animal.rb +4 -5
  746. data/spec/support/models/answer.rb +1 -1
  747. data/spec/support/models/appointment.rb +2 -2
  748. data/spec/support/models/armrest.rb +0 -1
  749. data/spec/support/models/array_field.rb +0 -1
  750. data/spec/support/models/article.rb +0 -1
  751. data/spec/support/models/artist.rb +16 -12
  752. data/spec/support/models/artwork.rb +1 -1
  753. data/spec/support/models/audible_sound.rb +0 -1
  754. data/spec/support/models/audio.rb +2 -2
  755. data/spec/support/models/augmentation.rb +1 -2
  756. data/spec/support/models/author.rb +1 -1
  757. data/spec/support/models/baby.rb +1 -1
  758. data/spec/support/models/band.rb +0 -1
  759. data/spec/support/models/bar.rb +2 -2
  760. data/spec/support/models/basic.rb +0 -1
  761. data/spec/support/models/bed.rb +0 -1
  762. data/spec/support/models/big_palette.rb +0 -1
  763. data/spec/support/models/birthday.rb +3 -5
  764. data/spec/support/models/bolt.rb +0 -1
  765. data/spec/support/models/bomb.rb +1 -1
  766. data/spec/support/models/book.rb +1 -1
  767. data/spec/support/models/breed.rb +1 -1
  768. data/spec/support/models/browser.rb +1 -2
  769. data/spec/support/models/building.rb +0 -1
  770. data/spec/support/models/building_address.rb +1 -1
  771. data/spec/support/models/bus.rb +1 -1
  772. data/spec/support/models/business.rb +2 -2
  773. data/spec/support/models/callback_test.rb +1 -1
  774. data/spec/support/models/canvas.rb +5 -6
  775. data/spec/support/models/car.rb +0 -1
  776. data/spec/support/models/cat.rb +0 -2
  777. data/spec/support/models/catalog.rb +0 -1
  778. data/spec/support/models/category.rb +1 -1
  779. data/spec/support/models/child.rb +1 -1
  780. data/spec/support/models/child_doc.rb +5 -6
  781. data/spec/support/models/church.rb +1 -1
  782. data/spec/support/models/circle.rb +0 -1
  783. data/spec/support/models/circuit.rb +2 -2
  784. data/spec/support/models/circus.rb +0 -1
  785. data/spec/support/models/code.rb +2 -1
  786. data/spec/support/models/coding/pull_request.rb +0 -1
  787. data/spec/support/models/coding.rb +0 -1
  788. data/spec/support/models/comment.rb +0 -1
  789. data/spec/support/models/company.rb +0 -1
  790. data/spec/support/models/consumption_period.rb +0 -1
  791. data/spec/support/models/contextable_item.rb +1 -1
  792. data/spec/support/models/contractor.rb +1 -1
  793. data/spec/support/models/cookie.rb +0 -1
  794. data/spec/support/models/country_code.rb +2 -3
  795. data/spec/support/models/courier_job.rb +2 -2
  796. data/spec/support/models/cover.rb +0 -1
  797. data/spec/support/models/crate.rb +0 -1
  798. data/spec/support/models/customer.rb +0 -1
  799. data/spec/support/models/customer_address.rb +0 -1
  800. data/spec/support/models/deed.rb +1 -1
  801. data/spec/support/models/definition.rb +1 -1
  802. data/spec/support/models/delegating_patient.rb +0 -1
  803. data/spec/support/models/description.rb +0 -1
  804. data/spec/support/models/dictionary.rb +1 -1
  805. data/spec/support/models/division.rb +2 -2
  806. data/spec/support/models/doctor.rb +0 -1
  807. data/spec/support/models/dog.rb +2 -2
  808. data/spec/support/models/dokument.rb +1 -1
  809. data/spec/support/models/draft.rb +0 -1
  810. data/spec/support/models/dragon.rb +1 -1
  811. data/spec/support/models/driver.rb +2 -2
  812. data/spec/support/models/drug.rb +1 -1
  813. data/spec/support/models/dungeon.rb +1 -1
  814. data/spec/support/models/edit.rb +1 -1
  815. data/spec/support/models/email.rb +1 -1
  816. data/spec/support/models/employer.rb +1 -2
  817. data/spec/support/models/entry.rb +1 -1
  818. data/spec/support/models/eraser.rb +0 -1
  819. data/spec/support/models/even.rb +1 -1
  820. data/spec/support/models/event.rb +3 -4
  821. data/spec/support/models/exhibition.rb +1 -1
  822. data/spec/support/models/exhibitor.rb +1 -1
  823. data/spec/support/models/explosion.rb +1 -1
  824. data/spec/support/models/eye.rb +0 -1
  825. data/spec/support/models/eye_bowl.rb +2 -3
  826. data/spec/support/models/face.rb +2 -3
  827. data/spec/support/models/fanatic.rb +1 -1
  828. data/spec/support/models/favorite.rb +1 -1
  829. data/spec/support/models/filesystem.rb +1 -1
  830. data/spec/support/models/fire_hydrant.rb +1 -1
  831. data/spec/support/models/firefox.rb +0 -1
  832. data/spec/support/models/fish.rb +0 -1
  833. data/spec/support/models/folder.rb +0 -2
  834. data/spec/support/models/folder_item.rb +1 -3
  835. data/spec/support/models/fruits.rb +9 -5
  836. data/spec/support/models/game.rb +3 -4
  837. data/spec/support/models/ghost.rb +0 -1
  838. data/spec/support/models/guitar.rb +0 -1
  839. data/spec/support/models/hole.rb +0 -1
  840. data/spec/support/models/home.rb +1 -1
  841. data/spec/support/models/house.rb +2 -2
  842. data/spec/support/models/html_writer.rb +0 -1
  843. data/spec/support/models/id_key.rb +3 -3
  844. data/spec/support/models/idnodef.rb +0 -1
  845. data/spec/support/models/image.rb +0 -1
  846. data/spec/support/models/implant.rb +1 -2
  847. data/spec/support/models/instrument.rb +2 -3
  848. data/spec/support/models/item.rb +2 -2
  849. data/spec/support/models/jar.rb +1 -2
  850. data/spec/support/models/kaleidoscope.rb +1 -1
  851. data/spec/support/models/kangaroo.rb +1 -1
  852. data/spec/support/models/label.rb +2 -2
  853. data/spec/support/models/language.rb +1 -1
  854. data/spec/support/models/lat_lng.rb +0 -1
  855. data/spec/support/models/league.rb +1 -1
  856. data/spec/support/models/learner.rb +0 -1
  857. data/spec/support/models/line_item.rb +1 -1
  858. data/spec/support/models/location.rb +1 -1
  859. data/spec/support/models/login.rb +1 -2
  860. data/spec/support/models/manufacturer.rb +0 -1
  861. data/spec/support/models/meat.rb +1 -1
  862. data/spec/support/models/membership.rb +1 -1
  863. data/spec/support/models/message.rb +1 -2
  864. data/spec/support/models/minim.rb +0 -1
  865. data/spec/support/models/mixed_drink.rb +1 -1
  866. data/spec/support/models/modifier_models.rb +25 -0
  867. data/spec/support/models/mop.rb +0 -1
  868. data/spec/support/models/movie.rb +1 -1
  869. data/spec/support/models/my_hash.rb +1 -2
  870. data/spec/support/models/name.rb +4 -5
  871. data/spec/support/models/name_only.rb +0 -1
  872. data/spec/support/models/node.rb +1 -1
  873. data/spec/support/models/note.rb +3 -3
  874. data/spec/support/models/nut.rb +0 -1
  875. data/spec/support/models/odd.rb +1 -1
  876. data/spec/support/models/order.rb +1 -1
  877. data/spec/support/models/ordered_post.rb +1 -1
  878. data/spec/support/models/ordered_preference.rb +1 -1
  879. data/spec/support/models/oscar.rb +1 -1
  880. data/spec/support/models/other_owner_object.rb +0 -1
  881. data/spec/support/models/override.rb +3 -11
  882. data/spec/support/models/ownable.rb +1 -1
  883. data/spec/support/models/owner.rb +1 -1
  884. data/spec/support/models/pack.rb +0 -1
  885. data/spec/support/models/page.rb +3 -3
  886. data/spec/support/models/page_question.rb +1 -1
  887. data/spec/support/models/palette.rb +2 -2
  888. data/spec/support/models/parent.rb +2 -2
  889. data/spec/support/models/parent_doc.rb +1 -1
  890. data/spec/support/models/passport.rb +0 -1
  891. data/spec/support/models/patient.rb +2 -2
  892. data/spec/support/models/pdf_writer.rb +0 -1
  893. data/spec/support/models/pencil.rb +0 -1
  894. data/spec/support/models/person.rb +32 -28
  895. data/spec/support/models/pet.rb +1 -1
  896. data/spec/support/models/pet_owner.rb +1 -1
  897. data/spec/support/models/phone.rb +1 -2
  898. data/spec/support/models/piano.rb +0 -1
  899. data/spec/support/models/pizza.rb +1 -1
  900. data/spec/support/models/player.rb +5 -5
  901. data/spec/support/models/post.rb +12 -12
  902. data/spec/support/models/post_genre.rb +1 -1
  903. data/spec/support/models/powerup.rb +1 -2
  904. data/spec/support/models/preference.rb +2 -2
  905. data/spec/support/models/princess.rb +1 -1
  906. data/spec/support/models/product.rb +3 -3
  907. data/spec/support/models/profile.rb +2 -1
  908. data/spec/support/models/pronunciation.rb +1 -1
  909. data/spec/support/models/pub.rb +2 -2
  910. data/spec/support/models/publication/encyclopedia.rb +0 -1
  911. data/spec/support/models/publication/review.rb +0 -1
  912. data/spec/support/models/publication.rb +0 -1
  913. data/spec/support/models/purchase.rb +1 -1
  914. data/spec/support/models/purchased_item.rb +1 -1
  915. data/spec/support/models/question.rb +2 -2
  916. data/spec/support/models/quiz.rb +1 -1
  917. data/spec/support/models/rating.rb +1 -1
  918. data/spec/support/models/record.rb +2 -3
  919. data/spec/support/models/registry.rb +1 -1
  920. data/spec/support/models/role.rb +1 -1
  921. data/spec/support/models/root_category.rb +1 -1
  922. data/spec/support/models/sandbox/app/models/app_models_message.rb +0 -1
  923. data/spec/support/models/sandbox/lib/models/lib_models_message.rb +0 -1
  924. data/spec/support/models/sandbox/sandbox_message.rb +0 -1
  925. data/spec/support/models/sandbox/sandbox_user.rb +0 -1
  926. data/spec/support/models/sandbox/subdir/sandbox_comment.rb +0 -1
  927. data/spec/support/models/sandwich.rb +1 -1
  928. data/spec/support/models/scheduler.rb +0 -1
  929. data/spec/support/models/school.rb +0 -1
  930. data/spec/support/models/scribe.rb +1 -1
  931. data/spec/support/models/sealer.rb +0 -1
  932. data/spec/support/models/seat.rb +0 -1
  933. data/spec/support/models/seo.rb +1 -1
  934. data/spec/support/models/series.rb +1 -1
  935. data/spec/support/models/server.rb +1 -1
  936. data/spec/support/models/service.rb +2 -2
  937. data/spec/support/models/shape.rb +3 -3
  938. data/spec/support/models/shelf.rb +1 -1
  939. data/spec/support/models/shield.rb +2 -2
  940. data/spec/support/models/shipment_address.rb +0 -1
  941. data/spec/support/models/shipping_container.rb +1 -1
  942. data/spec/support/models/shipping_pack.rb +0 -1
  943. data/spec/support/models/shirt.rb +0 -1
  944. data/spec/support/models/shop.rb +2 -2
  945. data/spec/support/models/short_agent.rb +0 -1
  946. data/spec/support/models/short_quiz.rb +1 -1
  947. data/spec/support/models/simple.rb +1 -1
  948. data/spec/support/models/slave.rb +1 -1
  949. data/spec/support/models/song.rb +1 -2
  950. data/spec/support/models/sound.rb +2 -2
  951. data/spec/support/models/spacer.rb +0 -1
  952. data/spec/support/models/square.rb +0 -1
  953. data/spec/support/models/staff.rb +0 -1
  954. data/spec/support/models/store_as_dup_test1.rb +2 -2
  955. data/spec/support/models/store_as_dup_test2.rb +1 -1
  956. data/spec/support/models/store_as_dup_test3.rb +2 -2
  957. data/spec/support/models/store_as_dup_test4.rb +1 -1
  958. data/spec/support/models/strategy.rb +0 -1
  959. data/spec/support/models/student.rb +1 -2
  960. data/spec/support/models/sub_item.rb +0 -1
  961. data/spec/support/models/subscription.rb +2 -2
  962. data/spec/support/models/survey.rb +2 -2
  963. data/spec/support/models/symptom.rb +2 -2
  964. data/spec/support/models/system_role.rb +2 -3
  965. data/spec/support/models/tag.rb +2 -2
  966. data/spec/support/models/target.rb +1 -1
  967. data/spec/support/models/template.rb +1 -1
  968. data/spec/support/models/thing.rb +1 -1
  969. data/spec/support/models/threadlocker.rb +0 -1
  970. data/spec/support/models/title.rb +0 -1
  971. data/spec/support/models/tool.rb +3 -3
  972. data/spec/support/models/topping.rb +1 -1
  973. data/spec/support/models/toy.rb +0 -1
  974. data/spec/support/models/track.rb +1 -1
  975. data/spec/support/models/translation.rb +1 -1
  976. data/spec/support/models/tree.rb +2 -3
  977. data/spec/support/models/truck.rb +0 -1
  978. data/spec/support/models/updatable.rb +0 -1
  979. data/spec/support/models/user.rb +3 -4
  980. data/spec/support/models/user_account.rb +3 -3
  981. data/spec/support/models/validation_callback.rb +4 -4
  982. data/spec/support/models/vehicle.rb +2 -3
  983. data/spec/support/models/version.rb +1 -1
  984. data/spec/support/models/vertex.rb +0 -1
  985. data/spec/support/models/vet_visit.rb +1 -1
  986. data/spec/support/models/video.rb +2 -2
  987. data/spec/support/models/video_game.rb +0 -1
  988. data/spec/support/models/washer.rb +0 -1
  989. data/spec/support/models/weapon.rb +1 -2
  990. data/spec/support/models/wiki_page.rb +2 -3
  991. data/spec/support/models/word.rb +2 -2
  992. data/spec/support/models/word_origin.rb +1 -2
  993. data/spec/support/models/writer.rb +3 -3
  994. data/spec/support/rails_mock.rb +7 -12
  995. data/spec/support/shared/time.rb +0 -1
  996. data/spec/support/sinatra_mock.rb +4 -2
  997. data/spec/support/spec_config.rb +19 -18
  998. metadata +14 -14
  999. data/lib/mongoid/errors/in_memory_regexp_timeout.rb +0 -26
  1000. data/lib/mongoid/errors/no_encryption_schema.rb +0 -28
  1001. data/lib/mongoid/field_readable.rb +0 -70
  1002. data/lib/mongoid/matcher/regexp_budget.rb +0 -383
  1003. data/spec/integration/matcher_regexp_timeout_spec.rb +0 -215
  1004. data/spec/integration/query_operator_guard_spec.rb +0 -89
  1005. data/spec/mongoid/encryptable_spec.rb +0 -61
  1006. data/spec/mongoid/matcher/regexp_budget_spec.rb +0 -570
@@ -1,19 +1,17 @@
1
1
  # frozen_string_literal: true
2
- # rubocop:todo all
3
2
 
4
- require "spec_helper"
3
+ require 'spec_helper'
5
4
 
6
5
  describe Mongoid::Contextual::Memory do
7
-
8
- shared_examples "raises an error when no documents" do
9
- context "when there are no matching documents" do
6
+ shared_examples 'raises an error when no documents' do
7
+ context 'when there are no matching documents' do
10
8
  let(:criteria) do
11
9
  Address.all.tap do |crit|
12
10
  crit.documents = []
13
11
  end
14
12
  end
15
13
 
16
- it "returns nil" do
14
+ it 'returns nil' do
17
15
  expect do
18
16
  context.send(method)
19
17
  end.to raise_error(Mongoid::Errors::DocumentNotFound, /Could not find a document of class Address./)
@@ -21,36 +19,33 @@ describe Mongoid::Contextual::Memory do
21
19
  end
22
20
  end
23
21
 
24
- shared_examples "returns nil when no documents" do
25
- context "when there are no matching documents" do
22
+ shared_examples 'returns nil when no documents' do
23
+ context 'when there are no matching documents' do
26
24
  let(:criteria) do
27
25
  Address.all.tap do |crit|
28
26
  crit.documents = []
29
27
  end
30
28
  end
31
29
 
32
- it "returns nil" do
30
+ it 'returns nil' do
33
31
  expect(context.send(method)).to be_nil
34
32
  end
35
33
  end
36
34
  end
37
35
 
38
- [ :blank?, :empty? ].each do |method|
39
-
36
+ %i[blank? empty?].each do |method|
40
37
  describe "##{method}" do
41
-
42
38
  let(:hobrecht) do
43
- Address.new(street: "hobrecht")
39
+ Address.new(street: 'hobrecht')
44
40
  end
45
41
 
46
42
  let(:friedel) do
47
- Address.new(street: "friedel")
43
+ Address.new(street: 'friedel')
48
44
  end
49
45
 
50
- context "when there are matching documents" do
51
-
46
+ context 'when there are matching documents' do
52
47
  let(:criteria) do
53
- Address.where(street: "hobrecht").tap do |crit|
48
+ Address.where(street: 'hobrecht').tap do |crit|
54
49
  crit.documents = [ hobrecht, friedel ]
55
50
  end
56
51
  end
@@ -59,15 +54,14 @@ describe Mongoid::Contextual::Memory do
59
54
  described_class.new(criteria)
60
55
  end
61
56
 
62
- it "returns false" do
57
+ it 'returns false' do
63
58
  expect(context.send(method)).to be false
64
59
  end
65
60
  end
66
61
 
67
- context "when there are no matching documents" do
68
-
62
+ context 'when there are no matching documents' do
69
63
  let(:criteria) do
70
- Address.where(street: "pfluger").tap do |crit|
64
+ Address.where(street: 'pfluger').tap do |crit|
71
65
  crit.documents = [ hobrecht, friedel ]
72
66
  end
73
67
  end
@@ -76,40 +70,38 @@ describe Mongoid::Contextual::Memory do
76
70
  described_class.new(criteria)
77
71
  end
78
72
 
79
- it "returns true" do
73
+ it 'returns true' do
80
74
  expect(context.send(method)).to be true
81
75
  end
82
76
  end
83
77
 
84
78
  context 'when there is a collation on the criteria' do
85
-
86
79
  let(:criteria) do
87
- Address.where(street: "hobrecht").tap do |crit|
80
+ Address.where(street: 'hobrecht').tap do |crit|
88
81
  crit.documents = [ hobrecht, friedel ]
89
82
  end.collation(locale: 'en_US', strength: 2)
90
83
  end
91
84
 
92
- it "raises an exception" do
93
- expect {
85
+ it 'raises an exception' do
86
+ expect do
94
87
  context.send(method)
95
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
88
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
96
89
  end
97
90
  end
98
91
  end
99
92
  end
100
93
 
101
- describe "#count" do
102
-
94
+ describe '#count' do
103
95
  let!(:hobrecht) do
104
- Address.new(street: "hobrecht")
96
+ Address.new(street: 'hobrecht')
105
97
  end
106
98
 
107
99
  let!(:friedel) do
108
- Address.new(street: "friedel")
100
+ Address.new(street: 'friedel')
109
101
  end
110
102
 
111
103
  let(:criteria) do
112
- Address.where(street: "hobrecht").tap do |crit|
104
+ Address.where(street: 'hobrecht').tap do |crit|
113
105
  crit.documents = [ hobrecht, friedel ]
114
106
  end
115
107
  end
@@ -118,107 +110,96 @@ describe Mongoid::Contextual::Memory do
118
110
  described_class.new(criteria)
119
111
  end
120
112
 
121
- context "context when no arguments are provided" do
122
-
123
- it "returns the number of matches" do
113
+ context 'context when no arguments are provided' do
114
+ it 'returns the number of matches' do
124
115
  expect(context.count).to eq(1)
125
116
  end
126
117
  end
127
118
 
128
119
  context 'when there is a collation on the criteria' do
129
-
130
120
  let(:criteria) do
131
- Address.where(street: "hobrecht").tap do |crit|
121
+ Address.where(street: 'hobrecht').tap do |crit|
132
122
  crit.documents = [ hobrecht, friedel ]
133
123
  end.collation(locale: 'en_US', strength: 2)
134
124
  end
135
125
 
136
- it "raises an exception" do
137
- expect {
126
+ it 'raises an exception' do
127
+ expect do
138
128
  context.count
139
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
129
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
140
130
  end
141
131
  end
142
132
 
143
- context "when provided a document" do
144
-
145
- context "when the document matches" do
146
-
133
+ context 'when provided a document' do
134
+ context 'when the document matches' do
147
135
  let(:count) do
148
136
  context.count(hobrecht)
149
137
  end
150
138
 
151
- it "returns 1" do
139
+ it 'returns 1' do
152
140
  expect(count).to eq(1)
153
141
  end
154
142
  end
155
143
 
156
- context "when the document does not match" do
157
-
144
+ context 'when the document does not match' do
158
145
  let(:count) do
159
146
  context.count(friedel)
160
147
  end
161
148
 
162
- it "returns 0" do
149
+ it 'returns 0' do
163
150
  expect(count).to eq(0)
164
151
  end
165
152
  end
166
153
  end
167
154
 
168
- context "when provided a block" do
169
-
170
- context "when the block evals 1 to true" do
171
-
155
+ context 'when provided a block' do
156
+ context 'when the block evals 1 to true' do
172
157
  let(:count) do
173
158
  context.count do |doc|
174
- doc.street == "hobrecht"
159
+ doc.street == 'hobrecht'
175
160
  end
176
161
  end
177
162
 
178
- it "returns 1" do
163
+ it 'returns 1' do
179
164
  expect(count).to eq(1)
180
165
  end
181
166
  end
182
167
 
183
- context "when the block evals none to true" do
184
-
168
+ context 'when the block evals none to true' do
185
169
  let(:count) do
186
170
  context.count do |doc|
187
- doc.street == "friedel"
171
+ doc.street == 'friedel'
188
172
  end
189
173
  end
190
174
 
191
- it "returns 0" do
175
+ it 'returns 0' do
192
176
  expect(count).to eq(0)
193
177
  end
194
178
  end
195
179
  end
196
180
  end
197
181
 
198
- [ :delete, :delete_all ].each do |method|
199
-
182
+ %i[delete delete_all].each do |method|
200
183
  let(:person) do
201
184
  Person.create!
202
185
  end
203
186
 
204
187
  let(:hobrecht) do
205
- person.addresses.create!(street: "hobrecht")
188
+ person.addresses.create!(street: 'hobrecht')
206
189
  end
207
190
 
208
191
  let(:friedel) do
209
- person.addresses.create!(street: "friedel")
192
+ person.addresses.create!(street: 'friedel')
210
193
  end
211
194
 
212
195
  let(:pfluger) do
213
- person.addresses.create!(street: "pfluger")
196
+ person.addresses.create!(street: 'pfluger')
214
197
  end
215
198
 
216
199
  describe "##{method}" do
217
-
218
- context "when embedded a single level" do
219
-
200
+ context 'when embedded a single level' do
220
201
  let(:criteria) do
221
- Address.any_in(street: [ "hobrecht", "friedel" ]).tap do |crit|
202
+ Address.any_in(street: %w[hobrecht friedel]).tap do |crit|
222
203
  crit.documents = [ hobrecht, friedel, pfluger ]
223
204
  end
224
205
  end
@@ -231,47 +212,46 @@ describe Mongoid::Contextual::Memory do
231
212
  context.send(method)
232
213
  end
233
214
 
234
- it "deletes the first matching document" do
215
+ it 'deletes the first matching document' do
235
216
  expect(hobrecht).to be_destroyed
236
217
  end
237
218
 
238
- it "deletes the last matching document" do
219
+ it 'deletes the last matching document' do
239
220
  expect(friedel).to be_destroyed
240
221
  end
241
222
 
242
- it "does not delete non matching docs" do
243
- expect(pfluger).to_not be_destroyed
223
+ it 'does not delete non matching docs' do
224
+ expect(pfluger).not_to be_destroyed
244
225
  end
245
226
 
246
- it "removes the docs from the relation" do
227
+ it 'removes the docs from the relation' do
247
228
  expect(person.addresses).to eq([ pfluger ])
248
229
  end
249
230
 
250
- it "removes the docs from the context" do
231
+ it 'removes the docs from the context' do
251
232
  expect(context.entries).to be_empty
252
233
  end
253
234
 
254
- it "persists the changes to the database" do
235
+ it 'persists the changes to the database' do
255
236
  expect(person.reload.addresses).to eq([ pfluger ])
256
237
  end
257
238
 
258
- it "returns the number of deleted documents" do
239
+ it 'returns the number of deleted documents' do
259
240
  expect(deleted).to eq(2)
260
241
  end
261
242
  end
262
243
 
263
- context "when embedded multiple levels" do
264
-
244
+ context 'when embedded multiple levels' do
265
245
  let!(:home) do
266
- hobrecht.locations.create!(name: "home")
246
+ hobrecht.locations.create!(name: 'home')
267
247
  end
268
248
 
269
249
  let!(:work) do
270
- hobrecht.locations.create!(name: "work")
250
+ hobrecht.locations.create!(name: 'work')
271
251
  end
272
252
 
273
253
  let(:criteria) do
274
- Location.where(name: "work").tap do |crit|
254
+ Location.where(name: 'work').tap do |crit|
275
255
  crit.documents = [ home, work ]
276
256
  end
277
257
  end
@@ -284,68 +264,66 @@ describe Mongoid::Contextual::Memory do
284
264
  context.send(method)
285
265
  end
286
266
 
287
- it "deletes the first matching document" do
267
+ it 'deletes the first matching document' do
288
268
  expect(work).to be_destroyed
289
269
  end
290
270
 
291
- it "does not delete non matching docs" do
292
- expect(home).to_not be_destroyed
271
+ it 'does not delete non matching docs' do
272
+ expect(home).not_to be_destroyed
293
273
  end
294
274
 
295
- it "removes the docs from the relation" do
275
+ it 'removes the docs from the relation' do
296
276
  expect(person.addresses.first.locations).to eq([ home ])
297
277
  end
298
278
 
299
- it "removes the docs from the context" do
279
+ it 'removes the docs from the context' do
300
280
  expect(context.entries).to be_empty
301
281
  end
302
282
 
303
- it "persists the changes to the database" do
283
+ it 'persists the changes to the database' do
304
284
  expect(person.reload.addresses.first.locations).to eq([ home ])
305
285
  end
306
286
 
307
- it "returns the number of deleted documents" do
287
+ it 'returns the number of deleted documents' do
308
288
  expect(deleted).to eq(1)
309
289
  end
310
290
  end
311
291
 
312
292
  context 'when there is a collation on the criteria' do
313
-
314
293
  let(:criteria) do
315
- Address.any_in(street: [ "hobrecht", "friedel" ]).tap do |crit|
294
+ Address.any_in(street: %w[hobrecht friedel]).tap do |crit|
316
295
  crit.documents = [ hobrecht, friedel, pfluger ]
317
296
  end.collation(locale: 'en_US', strength: 2)
318
297
  end
319
298
 
320
- it "raises an exception" do
321
- expect {
299
+ it 'raises an exception' do
300
+ expect do
322
301
  context.send(method)
323
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
302
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
324
303
  end
325
304
  end
326
305
  end
327
306
  end
328
307
 
329
- [ :destroy, :destroy_all ].each do |method|
330
-
308
+ %i[destroy destroy_all].each do |method|
331
309
  let(:person) do
332
310
  Person.create!
333
311
  end
334
312
 
335
313
  let(:hobrecht) do
336
- person.addresses.create!(street: "hobrecht")
314
+ person.addresses.create!(street: 'hobrecht')
337
315
  end
338
316
 
339
317
  let(:friedel) do
340
- person.addresses.create!(street: "friedel")
318
+ person.addresses.create!(street: 'friedel')
341
319
  end
342
320
 
343
321
  let(:pfluger) do
344
- person.addresses.create!(street: "pfluger")
322
+ person.addresses.create!(street: 'pfluger')
345
323
  end
346
324
 
347
325
  let(:criteria) do
348
- Address.any_in(street: [ "hobrecht", "friedel" ]).tap do |crit|
326
+ Address.any_in(street: %w[hobrecht friedel]).tap do |crit|
349
327
  crit.documents = [ hobrecht, friedel, pfluger ]
350
328
  end
351
329
  end
@@ -355,63 +333,60 @@ describe Mongoid::Contextual::Memory do
355
333
  end
356
334
 
357
335
  describe "##{method}" do
358
-
359
336
  context 'when there is no collation on the criteria' do
360
-
361
337
  let!(:destroyed) do
362
338
  context.send(method)
363
339
  end
364
340
 
365
- it "deletes the first matching document" do
341
+ it 'deletes the first matching document' do
366
342
  expect(hobrecht).to be_destroyed
367
343
  end
368
344
 
369
- it "deletes the last matching document" do
345
+ it 'deletes the last matching document' do
370
346
  expect(friedel).to be_destroyed
371
347
  end
372
348
 
373
- it "does not delete non matching docs" do
374
- expect(pfluger).to_not be_destroyed
349
+ it 'does not delete non matching docs' do
350
+ expect(pfluger).not_to be_destroyed
375
351
  end
376
352
 
377
- it "removes the docs from the relation" do
353
+ it 'removes the docs from the relation' do
378
354
  expect(person.addresses).to eq([ pfluger ])
379
355
  end
380
356
 
381
- it "removes the docs from the context" do
357
+ it 'removes the docs from the context' do
382
358
  expect(context.entries).to be_empty
383
359
  end
384
360
 
385
- it "persists the changes to the database" do
361
+ it 'persists the changes to the database' do
386
362
  expect(person.reload.addresses).to eq([ pfluger ])
387
363
  end
388
364
 
389
- it "returns the number of destroyed documents" do
365
+ it 'returns the number of destroyed documents' do
390
366
  expect(destroyed).to eq(2)
391
367
  end
392
368
  end
393
369
 
394
370
  context 'when there is a collation on the criteria' do
395
-
396
371
  let(:criteria) do
397
- Address.any_in(street: [ "hobrecht", "friedel" ]).tap do |crit|
372
+ Address.any_in(street: %w[hobrecht friedel]).tap do |crit|
398
373
  crit.documents = [ hobrecht, friedel, pfluger ]
399
374
  end.collation(locale: 'en_US', strength: 2)
400
375
  end
401
376
 
402
- it "raises an exception" do
403
- expect {
377
+ it 'raises an exception' do
378
+ expect do
404
379
  context.send(method)
405
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
380
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
406
381
  end
407
382
  end
408
383
  end
409
384
  end
410
385
 
411
- describe "#distinct" do
412
- let(:depeche) { Band.create!(name: "Depeche Mode", years: 30, sales: "1E2") }
413
- let(:new_order) { Band.create!(name: "New Order", years: 25, sales: "2E3") }
414
- let(:maniacs) { Band.create!(name: "10,000 Maniacs", years: 20, sales: "1E2") }
386
+ describe '#distinct' do
387
+ let(:depeche) { Band.create!(name: 'Depeche Mode', years: 30, sales: '1E2') }
388
+ let(:new_order) { Band.create!(name: 'New Order', years: 25, sales: '2E3') }
389
+ let(:maniacs) { Band.create!(name: '10,000 Maniacs', years: 20, sales: '1E2') }
415
390
 
416
391
  let(:criteria) do
417
392
  Band.all.tap do |crit|
@@ -423,41 +398,37 @@ describe Mongoid::Contextual::Memory do
423
398
  described_class.new(criteria)
424
399
  end
425
400
 
426
- context "when limiting the result set" do
427
-
401
+ context 'when limiting the result set' do
428
402
  let(:criteria) do
429
- Band.where(name: "Depeche Mode").tap do |crit|
403
+ Band.where(name: 'Depeche Mode').tap do |crit|
430
404
  crit.documents = [ depeche ]
431
405
  end
432
406
  end
433
407
 
434
- it "returns the distinct matching fields" do
435
- expect(context.distinct(:name)).to eq([ "Depeche Mode" ])
408
+ it 'returns the distinct matching fields' do
409
+ expect(context.distinct(:name)).to eq([ 'Depeche Mode' ])
436
410
  end
437
411
  end
438
412
 
439
- context "when not limiting the result set" do
440
-
441
- it "returns the distinct field values" do
442
- expect(context.distinct(:name).sort).to eq([ "10,000 Maniacs", "Depeche Mode", "New Order" ].sort)
413
+ context 'when not limiting the result set' do
414
+ it 'returns the distinct field values' do
415
+ expect(context.distinct(:name).sort).to eq([ '10,000 Maniacs', 'Depeche Mode', 'New Order' ].sort)
443
416
  end
444
417
  end
445
418
 
446
- context "when providing an aliased field" do
447
-
448
- it "returns the distinct field values" do
419
+ context 'when providing an aliased field' do
420
+ it 'returns the distinct field values' do
449
421
  expect(context.distinct(:years).sort).to eq([ 20, 25, 30 ])
450
422
  end
451
423
  end
452
424
 
453
- context "when providing a demongoizable field" do
454
-
455
- it "returns the non-demongoized distinct field values" do
456
- expect(context.distinct(:sales).sort).to eq([ BigDecimal("1E2"), BigDecimal("2E3") ])
425
+ context 'when providing a demongoizable field' do
426
+ it 'returns the non-demongoized distinct field values' do
427
+ expect(context.distinct(:sales).sort).to eq([ BigDecimal('1E2'), BigDecimal('2E3') ])
457
428
  end
458
429
  end
459
430
 
460
- context "when getting a localized field" do
431
+ context 'when getting a localized field' do
461
432
  with_default_i18n_configs
462
433
 
463
434
  before do
@@ -474,38 +445,36 @@ describe Mongoid::Contextual::Memory do
474
445
  end
475
446
  end
476
447
 
477
- context "when getting the field without _translations" do
478
- it "gets the demongoized localized field" do
448
+ context 'when getting the field without _translations' do
449
+ it 'gets the demongoized localized field' do
479
450
  expect(context.distinct(:description)).to eq([ 'deutsch-text' ])
480
451
  end
481
452
  end
482
453
 
483
- context "when getting the field with _translations" do
484
-
485
- it "gets the full hash" do
486
- expect(context.distinct(:description_translations)).to eq([ { "de" => "deutsch-text", "en" => "english-text" } ])
454
+ context 'when getting the field with _translations' do
455
+ it 'gets the full hash' do
456
+ expect(context.distinct(:description_translations)).to eq([ { 'de' => 'deutsch-text',
457
+ 'en' => 'english-text' } ])
487
458
  end
488
459
  end
489
460
 
490
461
  context 'when plucking a specific locale' do
491
-
492
462
  let(:distinct) do
493
463
  context.distinct(:'description.de')
494
464
  end
495
465
 
496
466
  it 'returns the specific translation' do
497
- expect(distinct).to eq([ "deutsch-text" ])
467
+ expect(distinct).to eq([ 'deutsch-text' ])
498
468
  end
499
469
  end
500
470
 
501
471
  context 'when plucking a specific locale from _translations field' do
502
-
503
472
  let(:distinct) do
504
473
  context.distinct(:'description_translations.de')
505
474
  end
506
475
 
507
476
  it 'returns the specific translations' do
508
- expect(distinct).to eq(['deutsch-text'])
477
+ expect(distinct).to eq([ 'deutsch-text' ])
509
478
  end
510
479
  end
511
480
 
@@ -521,62 +490,61 @@ describe Mongoid::Contextual::Memory do
521
490
  context.distinct(:description).first
522
491
  end
523
492
 
524
- it "correctly uses the fallback" do
493
+ it 'correctly uses the fallback' do
525
494
  I18n.locale = :en
526
495
  Dictionary.create!(description: 'english-text')
527
496
  I18n.locale = :he
528
- distinct.should == "english-text"
497
+ distinct.should eq 'english-text'
529
498
  end
530
499
  end
531
500
 
532
- context "when the localized field is embedded" do
501
+ context 'when the localized field is embedded' do
533
502
  with_default_i18n_configs
534
503
 
535
504
  let(:person) do
536
505
  p = Passport.new
537
506
  I18n.locale = :en
538
- p.name = "Neil"
507
+ p.name = 'Neil'
539
508
  I18n.locale = :he
540
- p.name = "Nissim"
509
+ p.name = 'Nissim'
541
510
 
542
- Person.create!(passport: p, employer_id: 12345)
511
+ Person.create!(passport: p, employer_id: 12_345)
543
512
  end
544
513
 
545
514
  let(:criteria) do
546
- Person.where(employer_id: 12345).tap do |crit|
515
+ Person.where(employer_id: 12_345).tap do |crit|
547
516
  crit.documents = [ person ]
548
517
  end
549
518
  end
550
519
 
551
520
  let(:distinct) do
552
- context.distinct("pass.name").first
521
+ context.distinct('pass.name').first
553
522
  end
554
523
 
555
524
  let(:distinct_translations) do
556
- context.distinct("pass.name_translations").first
525
+ context.distinct('pass.name_translations').first
557
526
  end
558
527
 
559
528
  let(:distinct_translations_field) do
560
- context.distinct("pass.name_translations.en").first
529
+ context.distinct('pass.name_translations.en').first
561
530
  end
562
531
 
563
- it "returns the translation for the current locale" do
564
- expect(distinct).to eq("Nissim")
532
+ it 'returns the translation for the current locale' do
533
+ expect(distinct).to eq('Nissim')
565
534
  end
566
535
 
567
- it "returns the full _translation hash" do
568
- expect(distinct_translations).to eq({ "en" => "Neil", "he" => "Nissim" })
536
+ it 'returns the full _translation hash' do
537
+ expect(distinct_translations).to eq({ 'en' => 'Neil', 'he' => 'Nissim' })
569
538
  end
570
539
 
571
- it "returns the translation for the requested locale" do
572
- expect(distinct_translations_field).to eq("Neil")
540
+ it 'returns the translation for the requested locale' do
541
+ expect(distinct_translations_field).to eq('Neil')
573
542
  end
574
543
  end
575
544
  end
576
545
 
577
- context "when getting an embedded field" do
578
-
579
- let(:label) { Label.new(sales: "1E2") }
546
+ context 'when getting an embedded field' do
547
+ let(:label) { Label.new(sales: '1E2') }
580
548
  let!(:band) { Band.create!(label: label) }
581
549
  let(:criteria) do
582
550
  Band.where(_id: band.id).tap do |crit|
@@ -584,45 +552,23 @@ describe Mongoid::Contextual::Memory do
584
552
  end
585
553
  end
586
554
 
587
- it "returns the distinct matching fields" do
588
- expect(context.distinct("label.sales")).to eq([ BigDecimal("1E2") ])
589
- end
590
- end
591
-
592
- context 'when the field name is a method name' do
593
- let!(:person) do
594
- Person.create!(ssn: 'secret-ssn')
595
- end
596
-
597
- let!(:address) do
598
- person.addresses.create!(street: 'hobrecht')
599
- end
600
-
601
- let(:criteria) do
602
- Address.all.tap do |crit|
603
- crit.documents = [ address ]
604
- end
605
- end
606
-
607
- it 'does not call the method' do
608
- expect(address).not_to receive(:destroy)
609
- expect(context.distinct(:destroy)).to eq([ nil ])
555
+ it 'returns the distinct matching fields' do
556
+ expect(context.distinct('label.sales')).to eq([ BigDecimal('1E2') ])
610
557
  end
611
558
  end
612
559
  end
613
560
 
614
- describe "#each" do
615
-
561
+ describe '#each' do
616
562
  let(:hobrecht) do
617
- Address.new(street: "hobrecht")
563
+ Address.new(street: 'hobrecht')
618
564
  end
619
565
 
620
566
  let(:friedel) do
621
- Address.new(street: "friedel")
567
+ Address.new(street: 'friedel')
622
568
  end
623
569
 
624
570
  let(:criteria) do
625
- Address.where(street: "hobrecht").tap do |crit|
571
+ Address.where(street: 'hobrecht').tap do |crit|
626
572
  crit.documents = [ hobrecht, friedel ]
627
573
  end
628
574
  end
@@ -631,65 +577,52 @@ describe Mongoid::Contextual::Memory do
631
577
  described_class.new(criteria)
632
578
  end
633
579
 
634
- context "when skip and limit outside of range" do
635
-
580
+ context 'when skip and limit outside of range' do
636
581
  before do
637
582
  context.skip(10).limit(2)
638
583
  end
639
584
 
640
- it "contains no documents" do
585
+ it 'contains no documents' do
641
586
  expect(context.map(&:street)).to be_empty
642
587
  end
643
588
 
644
- context "when calling next on the enumerator" do
645
-
646
- it "raises a stop iteration error" do
647
- expect {
589
+ context 'when calling next on the enumerator' do
590
+ it 'raises a stop iteration error' do
591
+ expect do
648
592
  context.each.next
649
- }.to raise_error(StopIteration)
593
+ end.to raise_error(StopIteration)
650
594
  end
651
595
  end
652
596
  end
653
597
 
654
- context "when providing a block" do
655
-
656
- it "yields mongoid documents to the block" do
657
- context.each do |doc|
658
- expect(doc).to be_a(Mongoid::Document)
659
- end
598
+ context 'when providing a block' do
599
+ it 'yields mongoid documents to the block' do
600
+ expect(context).to all(be_a(Mongoid::Document))
660
601
  end
661
602
 
662
- it "iterates over the matching documents" do
663
- context.each do |doc|
664
- expect(doc).to eq(hobrecht)
665
- end
603
+ it 'iterates over the matching documents' do
604
+ expect(context).to all(eq(hobrecht))
666
605
  end
667
606
  end
668
607
 
669
- context "when no block is provided" do
670
-
608
+ context 'when no block is provided' do
671
609
  let(:enum) do
672
610
  context.each
673
611
  end
674
612
 
675
- it "returns an enumerator" do
613
+ it 'returns an enumerator' do
676
614
  expect(enum).to be_a(Enumerator)
677
615
  end
678
616
 
679
- context "when iterating over the enumerator" do
680
-
681
- context "when iterating with each" do
682
-
683
- it "yields mongoid documents to the block" do
684
- enum.each do |doc|
685
- expect(doc).to be_a(Mongoid::Document)
686
- end
617
+ context 'when iterating over the enumerator' do
618
+ context 'when iterating with each' do
619
+ it 'yields mongoid documents to the block' do
620
+ expect(enum).to all(be_a(Mongoid::Document))
687
621
  end
688
622
  end
689
623
 
690
- context "when iterating with next" do
691
-
692
- it "yields mongoid documents" do
624
+ context 'when iterating with next' do
625
+ it 'yields mongoid documents' do
693
626
  expect(enum.next).to be_a(Mongoid::Document)
694
627
  end
695
628
  end
@@ -697,54 +630,49 @@ describe Mongoid::Contextual::Memory do
697
630
  end
698
631
 
699
632
  context 'when there is a collation on the criteria' do
700
-
701
633
  let(:criteria) do
702
- Address.where(street: "hobrecht").tap do |crit|
634
+ Address.where(street: 'hobrecht').tap do |crit|
703
635
  crit.documents = [ hobrecht, friedel ]
704
636
  end.collation(locale: 'en_US', strength: 2)
705
637
  end
706
638
 
707
- it "raises an exception" do
708
- expect {
639
+ it 'raises an exception' do
640
+ expect do
709
641
  context.each
710
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
642
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
711
643
  end
712
644
  end
713
645
  end
714
646
 
715
- describe "#exists?" do
716
-
647
+ describe '#exists?' do
717
648
  let(:hobrecht) do
718
- Address.new(street: "hobrecht")
649
+ Address.new(street: 'hobrecht')
719
650
  end
720
651
 
721
652
  let(:friedel) do
722
- Address.new(street: "friedel")
653
+ Address.new(street: 'friedel')
723
654
  end
724
655
 
725
656
  let(:criteria) do
726
- Address.where(street: "hobrecht").tap do |crit|
657
+ Address.where(street: 'hobrecht').tap do |crit|
727
658
  crit.documents = [ hobrecht, friedel ]
728
659
  end
729
660
  end
730
661
 
731
- context "when not passing options" do
732
-
733
- context "when there are matching documents" do
734
-
662
+ context 'when not passing options' do
663
+ context 'when there are matching documents' do
735
664
  let(:context) do
736
665
  described_class.new(criteria)
737
666
  end
738
667
 
739
- it "returns true" do
668
+ it 'returns true' do
740
669
  expect(context).to be_exists
741
670
  end
742
671
  end
743
672
 
744
- context "when there are no matching documents" do
745
-
673
+ context 'when there are no matching documents' do
746
674
  let(:criteria) do
747
- Address.where(street: "pfluger").tap do |crit|
675
+ Address.where(street: 'pfluger').tap do |crit|
748
676
  crit.documents = [ hobrecht, friedel ]
749
677
  end
750
678
  end
@@ -753,147 +681,127 @@ describe Mongoid::Contextual::Memory do
753
681
  described_class.new(criteria)
754
682
  end
755
683
 
756
- it "returns false" do
757
- expect(context).to_not be_exists
684
+ it 'returns false' do
685
+ expect(context).not_to be_exists
758
686
  end
759
687
  end
760
688
 
761
689
  context 'when there is a collation on the criteria' do
762
-
763
690
  let(:criteria) do
764
- Address.where(street: "pfluger").tap do |crit|
691
+ Address.where(street: 'pfluger').tap do |crit|
765
692
  crit.documents = [ hobrecht, friedel ]
766
693
  end.collation(locale: 'en_US', strength: 2)
767
694
  end
768
695
 
769
- it "raises an exception" do
770
- expect {
696
+ it 'raises an exception' do
697
+ expect do
771
698
  context
772
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
699
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
773
700
  end
774
701
  end
775
702
  end
776
703
 
777
- context "when passing an _id" do
778
-
779
- context "when its of type BSON::ObjectId" do
780
-
781
- context "when calling it on an empty criteria" do
782
-
783
- it "returns true" do
704
+ context 'when passing an _id' do
705
+ context 'when its of type BSON::ObjectId' do
706
+ context 'when calling it on an empty criteria' do
707
+ it 'returns true' do
784
708
  expect(criteria.exists?(hobrecht._id)).to be true
785
709
  end
786
710
  end
787
711
 
788
- context "when calling it on a criteria that includes the object" do
789
-
790
- it "returns true" do
712
+ context 'when calling it on a criteria that includes the object' do
713
+ it 'returns true' do
791
714
  expect(criteria.where(street: hobrecht.street).exists?(hobrecht._id)).to be true
792
715
  end
793
716
  end
794
717
 
795
- context "when calling it on a criteria that does not include the object" do
796
-
797
- it "returns false" do
798
- expect(criteria.where(street: "bogus").exists?(hobrecht._id)).to be false
718
+ context 'when calling it on a criteria that does not include the object' do
719
+ it 'returns false' do
720
+ expect(criteria.where(street: 'bogus').exists?(hobrecht._id)).to be false
799
721
  end
800
722
  end
801
723
 
802
- context "when the id does not exist" do
803
-
804
- it "returns false" do
724
+ context 'when the id does not exist' do
725
+ it 'returns false' do
805
726
  expect(criteria.exists?(BSON::ObjectId.new)).to be false
806
727
  end
807
728
  end
808
729
  end
809
730
 
810
- context "when its of type String" do
811
-
812
- context "when the id exists" do
813
-
814
- it "returns true" do
731
+ context 'when its of type String' do
732
+ context 'when the id exists' do
733
+ it 'returns true' do
815
734
  expect(criteria.exists?(hobrecht._id.to_s)).to be true
816
735
  end
817
736
  end
818
737
 
819
- context "when the id does not exist" do
820
-
821
- it "returns false" do
738
+ context 'when the id does not exist' do
739
+ it 'returns false' do
822
740
  expect(criteria.exists?(BSON::ObjectId.new.to_s)).to be false
823
741
  end
824
742
  end
825
743
  end
826
744
  end
827
745
 
828
- context "when passing a hash" do
829
-
830
- context "when calling it on an empty criteria" do
831
-
832
- it "returns true" do
746
+ context 'when passing a hash' do
747
+ context 'when calling it on an empty criteria' do
748
+ it 'returns true' do
833
749
  expect(criteria.exists?(street: hobrecht.street)).to be true
834
750
  end
835
751
  end
836
752
 
837
- context "when calling it on a criteria that includes the object" do
838
-
839
- it "returns true" do
753
+ context 'when calling it on a criteria that includes the object' do
754
+ it 'returns true' do
840
755
  expect(criteria.where(_id: hobrecht._id).exists?(street: hobrecht.street)).to be true
841
756
  end
842
757
  end
843
758
 
844
- context "when calling it on a criteria that does not include the object" do
845
-
846
- it "returns false" do
759
+ context 'when calling it on a criteria that does not include the object' do
760
+ it 'returns false' do
847
761
  expect(criteria.where(_id: BSON::ObjectId.new).exists?(street: hobrecht.street)).to be false
848
762
  end
849
763
  end
850
764
 
851
765
  context "when the conditions don't match" do
852
-
853
- it "returns false" do
854
- expect(criteria.exists?(street: "bogus")).to be false
766
+ it 'returns false' do
767
+ expect(criteria.exists?(street: 'bogus')).to be false
855
768
  end
856
769
  end
857
770
  end
858
771
 
859
- context "when passing false" do
860
-
861
- it "returns false" do
772
+ context 'when passing false' do
773
+ it 'returns false' do
862
774
  expect(criteria.exists?(false)).to be false
863
775
  end
864
776
  end
865
777
 
866
- context "when passing nil" do
867
-
868
- it "returns false" do
778
+ context 'when passing nil' do
779
+ it 'returns false' do
869
780
  expect(criteria.exists?(nil)).to be false
870
781
  end
871
782
  end
872
783
 
873
- context "when the limit is 0" do
874
-
875
- it "returns false" do
784
+ context 'when the limit is 0' do
785
+ it 'returns false' do
876
786
  expect(criteria.limit(0).exists?).to be false
877
787
  end
878
788
  end
879
789
  end
880
790
 
881
- [ :first, :one ].each do |method|
882
-
791
+ %i[first one].each do |method|
883
792
  describe "##{method}" do
884
-
885
793
  let(:method) { method }
886
794
 
887
795
  let(:hobrecht) do
888
- Address.new(street: "hobrecht")
796
+ Address.new(street: 'hobrecht')
889
797
  end
890
798
 
891
799
  let(:friedel) do
892
- Address.new(street: "friedel")
800
+ Address.new(street: 'friedel')
893
801
  end
894
802
 
895
803
  let(:criteria) do
896
- Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
804
+ Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
897
805
  crit.documents = [ hobrecht, friedel ]
898
806
  end
899
807
  end
@@ -902,51 +810,49 @@ describe Mongoid::Contextual::Memory do
902
810
  described_class.new(criteria)
903
811
  end
904
812
 
905
- it "returns the first matching document" do
813
+ it 'returns the first matching document' do
906
814
  expect(context.send(method)).to eq(hobrecht)
907
815
  end
908
816
 
909
- it "returns a list when passing a limit" do
817
+ it 'returns a list when passing a limit' do
910
818
  expect(context.send(method, 2)).to eq([ hobrecht, friedel ])
911
819
  end
912
820
 
913
- it "returns a list when passing 1" do
821
+ it 'returns a list when passing 1' do
914
822
  expect(context.send(method, 1)).to eq([ hobrecht ])
915
823
  end
916
824
 
917
- include_examples "returns nil when no documents"
825
+ include_examples 'returns nil when no documents'
918
826
 
919
827
  context 'when there is a collation on the criteria' do
920
-
921
828
  let(:criteria) do
922
- Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
829
+ Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
923
830
  crit.documents = [ hobrecht, friedel ]
924
831
  end.collation(locale: 'en_US', strength: 2)
925
832
  end
926
833
 
927
- it "raises an exception" do
928
- expect {
834
+ it 'raises an exception' do
835
+ expect do
929
836
  context.send(method)
930
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
837
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
931
838
  end
932
839
  end
933
840
  end
934
841
  end
935
842
 
936
- describe "#first!" do
937
-
843
+ describe '#first!' do
938
844
  let(:method) { :first! }
939
845
 
940
846
  let(:hobrecht) do
941
- Address.new(street: "hobrecht")
847
+ Address.new(street: 'hobrecht')
942
848
  end
943
849
 
944
850
  let(:friedel) do
945
- Address.new(street: "friedel")
851
+ Address.new(street: 'friedel')
946
852
  end
947
853
 
948
854
  let(:criteria) do
949
- Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
855
+ Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
950
856
  crit.documents = [ hobrecht, friedel ]
951
857
  end
952
858
  end
@@ -955,27 +861,26 @@ describe Mongoid::Contextual::Memory do
955
861
  described_class.new(criteria)
956
862
  end
957
863
 
958
- it "returns the first matching document" do
864
+ it 'returns the first matching document' do
959
865
  expect(context.first!).to eq(hobrecht)
960
866
  end
961
867
 
962
- include_examples "raises an error when no documents"
868
+ include_examples 'raises an error when no documents'
963
869
  end
964
870
 
965
- describe "#take" do
966
-
871
+ describe '#take' do
967
872
  let(:method) { :take }
968
873
 
969
874
  let(:hobrecht) do
970
- Address.new(street: "hobrecht")
875
+ Address.new(street: 'hobrecht')
971
876
  end
972
877
 
973
878
  let(:friedel) do
974
- Address.new(street: "friedel")
879
+ Address.new(street: 'friedel')
975
880
  end
976
881
 
977
882
  let(:criteria) do
978
- Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
883
+ Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
979
884
  crit.documents = [ hobrecht, friedel ]
980
885
  end
981
886
  end
@@ -984,50 +889,48 @@ describe Mongoid::Contextual::Memory do
984
889
  described_class.new(criteria)
985
890
  end
986
891
 
987
- it "returns the first matching document" do
892
+ it 'returns the first matching document' do
988
893
  expect(context.take).to eq(hobrecht)
989
894
  end
990
895
 
991
- it "returns an array when passing a limit" do
896
+ it 'returns an array when passing a limit' do
992
897
  expect(context.take(2)).to eq([ hobrecht, friedel ])
993
898
  end
994
899
 
995
- it "returns an array when passing a limit as 1" do
900
+ it 'returns an array when passing a limit as 1' do
996
901
  expect(context.take(1)).to eq([ hobrecht ])
997
902
  end
998
903
 
999
- include_examples "returns nil when no documents"
904
+ include_examples 'returns nil when no documents'
1000
905
 
1001
906
  context 'when there is a collation on the criteria' do
1002
-
1003
907
  let(:criteria) do
1004
- Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
908
+ Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
1005
909
  crit.documents = [ hobrecht, friedel ]
1006
910
  end.collation(locale: 'en_US', strength: 2)
1007
911
  end
1008
912
 
1009
- it "raises an exception" do
1010
- expect {
913
+ it 'raises an exception' do
914
+ expect do
1011
915
  context.take
1012
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
916
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
1013
917
  end
1014
918
  end
1015
919
  end
1016
920
 
1017
- describe "#take!" do
1018
-
921
+ describe '#take!' do
1019
922
  let(:method) { :take! }
1020
923
 
1021
924
  let(:hobrecht) do
1022
- Address.new(street: "hobrecht")
925
+ Address.new(street: 'hobrecht')
1023
926
  end
1024
927
 
1025
928
  let(:friedel) do
1026
- Address.new(street: "friedel")
929
+ Address.new(street: 'friedel')
1027
930
  end
1028
931
 
1029
932
  let(:criteria) do
1030
- Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
933
+ Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
1031
934
  crit.documents = [ hobrecht, friedel ]
1032
935
  end
1033
936
  end
@@ -1036,42 +939,39 @@ describe Mongoid::Contextual::Memory do
1036
939
  described_class.new(criteria)
1037
940
  end
1038
941
 
1039
- it "returns the first matching document" do
942
+ it 'returns the first matching document' do
1040
943
  expect(context.take!).to eq(hobrecht)
1041
944
  end
1042
945
 
1043
- include_examples "raises an error when no documents"
946
+ include_examples 'raises an error when no documents'
1044
947
 
1045
948
  context 'when there is a collation on the criteria' do
1046
-
1047
949
  let(:criteria) do
1048
- Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
950
+ Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
1049
951
  crit.documents = [ hobrecht, friedel ]
1050
952
  end.collation(locale: 'en_US', strength: 2)
1051
953
  end
1052
954
 
1053
- it "raises an exception" do
1054
- expect {
955
+ it 'raises an exception' do
956
+ expect do
1055
957
  context.take
1056
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
958
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
1057
959
  end
1058
960
  end
1059
961
  end
1060
962
 
1061
- describe "#initialize" do
1062
-
1063
- context "when the criteria has no options" do
1064
-
963
+ describe '#initialize' do
964
+ context 'when the criteria has no options' do
1065
965
  let(:hobrecht) do
1066
- Address.new(street: "hobrecht")
966
+ Address.new(street: 'hobrecht')
1067
967
  end
1068
968
 
1069
969
  let(:friedel) do
1070
- Address.new(street: "friedel")
970
+ Address.new(street: 'friedel')
1071
971
  end
1072
972
 
1073
973
  let(:criteria) do
1074
- Address.where(street: "hobrecht").tap do |crit|
974
+ Address.where(street: 'hobrecht').tap do |crit|
1075
975
  crit.documents = [ hobrecht, friedel ]
1076
976
  end
1077
977
  end
@@ -1080,27 +980,26 @@ describe Mongoid::Contextual::Memory do
1080
980
  described_class.new(criteria)
1081
981
  end
1082
982
 
1083
- it "sets the criteria" do
983
+ it 'sets the criteria' do
1084
984
  expect(context.criteria).to eq(criteria)
1085
985
  end
1086
986
 
1087
- it "sets the klass" do
987
+ it 'sets the klass' do
1088
988
  expect(context.klass).to eq(Address)
1089
989
  end
1090
990
 
1091
- it "sets the matching documents" do
991
+ it 'sets the matching documents' do
1092
992
  expect(context.documents).to eq([ hobrecht ])
1093
993
  end
1094
994
  end
1095
995
 
1096
- context "when the criteria skips" do
1097
-
996
+ context 'when the criteria skips' do
1098
997
  let(:hobrecht) do
1099
- Address.new(street: "hobrecht")
998
+ Address.new(street: 'hobrecht')
1100
999
  end
1101
1000
 
1102
1001
  let(:friedel) do
1103
- Address.new(street: "friedel")
1002
+ Address.new(street: 'friedel')
1104
1003
  end
1105
1004
 
1106
1005
  let(:criteria) do
@@ -1113,19 +1012,18 @@ describe Mongoid::Contextual::Memory do
1113
1012
  described_class.new(criteria)
1114
1013
  end
1115
1014
 
1116
- it "limits the matching documents" do
1015
+ it 'limits the matching documents' do
1117
1016
  expect(context).to eq([ friedel ])
1118
1017
  end
1119
1018
  end
1120
1019
 
1121
- context "when the criteria limits" do
1122
-
1020
+ context 'when the criteria limits' do
1123
1021
  let(:hobrecht) do
1124
- Address.new(street: "hobrecht")
1022
+ Address.new(street: 'hobrecht')
1125
1023
  end
1126
1024
 
1127
1025
  let(:friedel) do
1128
- Address.new(street: "friedel")
1026
+ Address.new(street: 'friedel')
1129
1027
  end
1130
1028
 
1131
1029
  let(:criteria) do
@@ -1138,41 +1036,39 @@ describe Mongoid::Contextual::Memory do
1138
1036
  described_class.new(criteria)
1139
1037
  end
1140
1038
 
1141
- it "limits the matching documents" do
1039
+ it 'limits the matching documents' do
1142
1040
  expect(context).to eq([ hobrecht ])
1143
1041
  end
1144
1042
  end
1145
1043
 
1146
1044
  context 'when there is a collation on the criteria' do
1147
-
1148
1045
  let(:criteria) do
1149
1046
  Address.all.limit(1).tap do |crit|
1150
1047
  crit.documents = [ hobrecht, friedel ]
1151
1048
  end.collation(locale: 'en_US', strength: 2)
1152
1049
  end
1153
1050
 
1154
- it "raises an exception" do
1155
- expect {
1051
+ it 'raises an exception' do
1052
+ expect do
1156
1053
  context
1157
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
1054
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
1158
1055
  end
1159
1056
  end
1160
1057
  end
1161
1058
 
1162
- describe "#last" do
1163
-
1059
+ describe '#last' do
1164
1060
  let(:method) { :last }
1165
1061
 
1166
1062
  let(:hobrecht) do
1167
- Address.new(street: "hobrecht")
1063
+ Address.new(street: 'hobrecht')
1168
1064
  end
1169
1065
 
1170
1066
  let(:friedel) do
1171
- Address.new(street: "friedel")
1067
+ Address.new(street: 'friedel')
1172
1068
  end
1173
1069
 
1174
1070
  let(:criteria) do
1175
- Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
1071
+ Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
1176
1072
  crit.documents = [ hobrecht, friedel ]
1177
1073
  end
1178
1074
  end
@@ -1181,49 +1077,48 @@ describe Mongoid::Contextual::Memory do
1181
1077
  described_class.new(criteria)
1182
1078
  end
1183
1079
 
1184
- it "returns the last matching document" do
1080
+ it 'returns the last matching document' do
1185
1081
  expect(context.last).to eq(friedel)
1186
1082
  end
1187
1083
 
1188
- it "returns a list when a limit is passed" do
1084
+ it 'returns a list when a limit is passed' do
1189
1085
  expect(context.last(2)).to eq([ hobrecht, friedel ])
1190
1086
  end
1191
1087
 
1192
- it "returns a list when the limit is 1" do
1088
+ it 'returns a list when the limit is 1' do
1193
1089
  expect(context.last(1)).to eq([ friedel ])
1194
1090
  end
1195
1091
 
1196
- include_examples "returns nil when no documents"
1092
+ include_examples 'returns nil when no documents'
1197
1093
 
1198
1094
  context 'when there is a collation on the criteria' do
1199
-
1200
1095
  let(:criteria) do
1201
- Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
1096
+ Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
1202
1097
  crit.documents = [ hobrecht, friedel ]
1203
1098
  end.collation(locale: 'en_US', strength: 2)
1204
1099
  end
1205
1100
 
1206
- it "raises an exception" do
1207
- expect {
1101
+ it 'raises an exception' do
1102
+ expect do
1208
1103
  context.last
1209
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
1104
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
1210
1105
  end
1211
1106
  end
1212
1107
  end
1213
1108
 
1214
- describe "#last!" do
1109
+ describe '#last!' do
1215
1110
  let(:method) { :last! }
1216
1111
 
1217
1112
  let(:hobrecht) do
1218
- Address.new(street: "hobrecht")
1113
+ Address.new(street: 'hobrecht')
1219
1114
  end
1220
1115
 
1221
1116
  let(:friedel) do
1222
- Address.new(street: "friedel")
1117
+ Address.new(street: 'friedel')
1223
1118
  end
1224
1119
 
1225
1120
  let(:criteria) do
1226
- Address.where(:street.in => [ "hobrecht", "friedel" ]).tap do |crit|
1121
+ Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
1227
1122
  crit.documents = [ hobrecht, friedel ]
1228
1123
  end
1229
1124
  end
@@ -1232,20 +1127,19 @@ describe Mongoid::Contextual::Memory do
1232
1127
  described_class.new(criteria)
1233
1128
  end
1234
1129
 
1235
- it "returns the last matching document" do
1130
+ it 'returns the last matching document' do
1236
1131
  expect(context.last!).to eq(friedel)
1237
1132
  end
1238
1133
 
1239
- include_examples "raises an error when no documents"
1134
+ include_examples 'raises an error when no documents'
1240
1135
  end
1241
1136
 
1242
- [ :second,
1243
- :third,
1244
- :fourth,
1245
- :fifth,
1246
- :second_to_last,
1247
- :third_to_last
1248
- ].each do |meth|
1137
+ %i[second
1138
+ third
1139
+ fourth
1140
+ fifth
1141
+ second_to_last
1142
+ third_to_last].each do |meth|
1249
1143
  describe "##{meth}" do
1250
1144
  let(:method) { meth }
1251
1145
 
@@ -1255,7 +1149,7 @@ describe Mongoid::Contextual::Memory do
1255
1149
  Address.new,
1256
1150
  Address.new,
1257
1151
  Address.new,
1258
- Address.new,
1152
+ Address.new
1259
1153
  ]
1260
1154
  end
1261
1155
 
@@ -1269,11 +1163,11 @@ describe Mongoid::Contextual::Memory do
1269
1163
  described_class.new(criteria)
1270
1164
  end
1271
1165
 
1272
- it "returns the matching document" do
1166
+ it 'returns the matching document' do
1273
1167
  expect(context.send(method)).to eq(addresses.send(method))
1274
1168
  end
1275
1169
 
1276
- include_examples "returns nil when no documents"
1170
+ include_examples 'returns nil when no documents'
1277
1171
  end
1278
1172
 
1279
1173
  describe "##{meth}!" do
@@ -1285,7 +1179,7 @@ describe Mongoid::Contextual::Memory do
1285
1179
  Address.new,
1286
1180
  Address.new,
1287
1181
  Address.new,
1288
- Address.new,
1182
+ Address.new
1289
1183
  ]
1290
1184
  end
1291
1185
 
@@ -1299,30 +1193,27 @@ describe Mongoid::Contextual::Memory do
1299
1193
  described_class.new(criteria)
1300
1194
  end
1301
1195
 
1302
- it "returns the matching document" do
1196
+ it 'returns the matching document' do
1303
1197
  expect(context.send(method)).to eq(addresses.send(meth))
1304
1198
  end
1305
1199
 
1306
- include_examples "raises an error when no documents"
1200
+ include_examples 'raises an error when no documents'
1307
1201
  end
1308
1202
  end
1309
1203
 
1310
- [ :length, :size ].each do |method|
1311
-
1204
+ %i[length size].each do |method|
1312
1205
  describe "##{method}" do
1313
-
1314
1206
  let(:hobrecht) do
1315
- Address.new(street: "hobrecht")
1207
+ Address.new(street: 'hobrecht')
1316
1208
  end
1317
1209
 
1318
1210
  let(:friedel) do
1319
- Address.new(street: "friedel")
1211
+ Address.new(street: 'friedel')
1320
1212
  end
1321
1213
 
1322
- context "when there are matching documents" do
1323
-
1214
+ context 'when there are matching documents' do
1324
1215
  let(:criteria) do
1325
- Address.where(street: "hobrecht").tap do |crit|
1216
+ Address.where(street: 'hobrecht').tap do |crit|
1326
1217
  crit.documents = [ hobrecht, friedel ]
1327
1218
  end
1328
1219
  end
@@ -1331,15 +1222,14 @@ describe Mongoid::Contextual::Memory do
1331
1222
  described_class.new(criteria)
1332
1223
  end
1333
1224
 
1334
- it "returns the number of matches" do
1225
+ it 'returns the number of matches' do
1335
1226
  expect(context.send(method)).to eq(1)
1336
1227
  end
1337
1228
  end
1338
1229
 
1339
- context "when there are no matching documents" do
1340
-
1230
+ context 'when there are no matching documents' do
1341
1231
  let(:criteria) do
1342
- Address.where(street: "pfluger").tap do |crit|
1232
+ Address.where(street: 'pfluger').tap do |crit|
1343
1233
  crit.documents = [ hobrecht, friedel ]
1344
1234
  end
1345
1235
  end
@@ -1348,40 +1238,38 @@ describe Mongoid::Contextual::Memory do
1348
1238
  described_class.new(criteria)
1349
1239
  end
1350
1240
 
1351
- it "returns zero" do
1241
+ it 'returns zero' do
1352
1242
  expect(context.send(method)).to eq(0)
1353
1243
  end
1354
1244
  end
1355
1245
 
1356
1246
  context 'when there is a collation on the criteria' do
1357
-
1358
1247
  let(:criteria) do
1359
- Address.where(street: "hobrecht").tap do |crit|
1248
+ Address.where(street: 'hobrecht').tap do |crit|
1360
1249
  crit.documents = [ hobrecht, friedel ]
1361
1250
  end.collation(locale: 'en_US', strength: 2)
1362
1251
  end
1363
1252
 
1364
- it "raises an exception" do
1365
- expect {
1253
+ it 'raises an exception' do
1254
+ expect do
1366
1255
  context.send(method)
1367
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
1256
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
1368
1257
  end
1369
1258
  end
1370
1259
  end
1371
1260
  end
1372
1261
 
1373
- describe "#limit" do
1374
-
1262
+ describe '#limit' do
1375
1263
  let(:hobrecht) do
1376
- Address.new(street: "hobrecht")
1264
+ Address.new(street: 'hobrecht')
1377
1265
  end
1378
1266
 
1379
1267
  let(:friedel) do
1380
- Address.new(street: "friedel")
1268
+ Address.new(street: 'friedel')
1381
1269
  end
1382
1270
 
1383
1271
  let(:pfluger) do
1384
- Address.new(street: "pfluger")
1272
+ Address.new(street: 'pfluger')
1385
1273
  end
1386
1274
 
1387
1275
  let(:criteria) do
@@ -1395,31 +1283,27 @@ describe Mongoid::Contextual::Memory do
1395
1283
  end
1396
1284
 
1397
1285
  context 'when there is no collation on the criteria' do
1398
-
1399
1286
  let!(:limit) do
1400
1287
  context.limit(2)
1401
1288
  end
1402
1289
 
1403
- it "returns the context" do
1290
+ it 'returns the context' do
1404
1291
  expect(limit).to eq(context)
1405
1292
  end
1406
1293
 
1407
- context "when asking for all documents" do
1408
-
1409
- context "when only a limit exists" do
1410
-
1411
- it "only returns the limited documents" do
1294
+ context 'when asking for all documents' do
1295
+ context 'when only a limit exists' do
1296
+ it 'only returns the limited documents' do
1412
1297
  expect(context.entries).to eq([ hobrecht, friedel ])
1413
1298
  end
1414
1299
  end
1415
1300
 
1416
- context "when a skip and limit exist" do
1417
-
1301
+ context 'when a skip and limit exist' do
1418
1302
  before do
1419
1303
  limit.skip(1)
1420
1304
  end
1421
1305
 
1422
- it "applies the skip before the limit" do
1306
+ it 'applies the skip before the limit' do
1423
1307
  expect(context.entries).to eq([ friedel, pfluger ])
1424
1308
  end
1425
1309
  end
@@ -1427,41 +1311,39 @@ describe Mongoid::Contextual::Memory do
1427
1311
  end
1428
1312
 
1429
1313
  context 'when there is a collation on the criteria' do
1430
-
1431
1314
  let(:criteria) do
1432
1315
  Address.all.tap do |crit|
1433
1316
  crit.documents = [ hobrecht, friedel, pfluger ]
1434
1317
  end.collation(locale: 'en_US', strength: 2)
1435
1318
  end
1436
1319
 
1437
- it "raises an exception" do
1438
- expect {
1320
+ it 'raises an exception' do
1321
+ expect do
1439
1322
  context.limit(2)
1440
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
1323
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
1441
1324
  end
1442
1325
  end
1443
1326
  end
1444
1327
 
1445
- describe "#pluck" do
1446
-
1328
+ describe '#pluck' do
1447
1329
  let(:context) do
1448
1330
  described_class.new(criteria)
1449
1331
  end
1450
1332
 
1451
1333
  let!(:depeche) do
1452
- Band.create!(name: "Depeche Mode", likes: 3)
1334
+ Band.create!(name: 'Depeche Mode', likes: 3)
1453
1335
  end
1454
1336
 
1455
1337
  let!(:tool) do
1456
- Band.create!(name: "Tool", likes: 3)
1338
+ Band.create!(name: 'Tool', likes: 3)
1457
1339
  end
1458
1340
 
1459
1341
  let!(:photek) do
1460
- Band.create!(name: "Photek", likes: 1)
1342
+ Band.create!(name: 'Photek', likes: 1)
1461
1343
  end
1462
1344
 
1463
1345
  let!(:maniacs) do
1464
- Band.create!(name: "10,000 Maniacs", likes: 1, sales: "1E2")
1346
+ Band.create!(name: '10,000 Maniacs', likes: 1, sales: '1E2')
1465
1347
  end
1466
1348
 
1467
1349
  let(:criteria) do
@@ -1470,10 +1352,9 @@ describe Mongoid::Contextual::Memory do
1470
1352
  end
1471
1353
  end
1472
1354
 
1473
- context "when the field is aliased" do
1474
-
1355
+ context 'when the field is aliased' do
1475
1356
  let!(:expensive) do
1476
- Product.create!(price: 100000)
1357
+ Product.create!(price: 100_000)
1477
1358
  end
1478
1359
 
1479
1360
  let!(:cheap) do
@@ -1486,39 +1367,34 @@ describe Mongoid::Contextual::Memory do
1486
1367
  end
1487
1368
  end
1488
1369
 
1489
- context "when using alias_attribute" do
1490
-
1370
+ context 'when using alias_attribute' do
1491
1371
  let(:plucked) do
1492
1372
  context.pluck(:price)
1493
1373
  end
1494
1374
 
1495
- it "uses the aliases" do
1496
- expect(plucked).to eq([ 100000, 1 ])
1375
+ it 'uses the aliases' do
1376
+ expect(plucked).to eq([ 100_000, 1 ])
1497
1377
  end
1498
1378
  end
1499
1379
  end
1500
1380
 
1501
- context "when the criteria matches" do
1502
-
1503
- context "when there are no duplicate values" do
1504
-
1381
+ context 'when the criteria matches' do
1382
+ context 'when there are no duplicate values' do
1505
1383
  let!(:plucked) do
1506
1384
  context.pluck(:name)
1507
1385
  end
1508
1386
 
1509
- it "returns the values" do
1510
- expect(plucked).to contain_exactly("10,000 Maniacs", "Depeche Mode", "Tool", "Photek")
1387
+ it 'returns the values' do
1388
+ expect(plucked).to contain_exactly('10,000 Maniacs', 'Depeche Mode', 'Tool', 'Photek')
1511
1389
  end
1512
1390
 
1513
- context "when subsequently executing the criteria without a pluck" do
1514
-
1515
- it "does not limit the fields" do
1391
+ context 'when subsequently executing the criteria without a pluck' do
1392
+ it 'does not limit the fields' do
1516
1393
  expect(context.first.likes).to eq(3)
1517
1394
  end
1518
1395
  end
1519
1396
 
1520
1397
  context 'when the field is a subdocument' do
1521
-
1522
1398
  context 'when a top-level field and a subdocument field are plucked' do
1523
1399
  let(:criteria) do
1524
1400
  Band.where(name: 'FKA Twigs').tap do |crit|
@@ -1535,8 +1411,8 @@ describe Mongoid::Contextual::Memory do
1535
1411
 
1536
1412
  let(:expected) do
1537
1413
  [
1538
- ["FKA Twigs", []],
1539
- ['FKA Twigs', ["LP1"]]
1414
+ [ 'FKA Twigs', [] ],
1415
+ [ 'FKA Twigs', [ 'LP1' ] ]
1540
1416
  ]
1541
1417
  end
1542
1418
 
@@ -1546,7 +1422,6 @@ describe Mongoid::Contextual::Memory do
1546
1422
  end
1547
1423
 
1548
1424
  context 'when only a subdocument field is plucked' do
1549
-
1550
1425
  let(:criteria) do
1551
1426
  Band.where(name: 'FKA Twigs').tap do |crit|
1552
1427
  crit.documents = [
@@ -1563,7 +1438,7 @@ describe Mongoid::Contextual::Memory do
1563
1438
  let(:expected) do
1564
1439
  [
1565
1440
  [],
1566
- ["LP1"]
1441
+ [ 'LP1' ]
1567
1442
  ]
1568
1443
  end
1569
1444
 
@@ -1574,72 +1449,66 @@ describe Mongoid::Contextual::Memory do
1574
1449
  end
1575
1450
  end
1576
1451
 
1577
- context "when plucking multi-fields" do
1578
-
1452
+ context 'when plucking multi-fields' do
1579
1453
  let(:plucked) do
1580
1454
  context.pluck(:name, :likes)
1581
1455
  end
1582
1456
 
1583
- it "returns the values" do
1584
- expect(plucked).to contain_exactly(["10,000 Maniacs", 1], ["Depeche Mode", 3], ["Tool", 3], ["Photek", 1])
1457
+ it 'returns the values' do
1458
+ expect(plucked).to contain_exactly([ '10,000 Maniacs', 1 ], [ 'Depeche Mode', 3 ], [ 'Tool', 3 ],
1459
+ [ 'Photek', 1 ])
1585
1460
  end
1586
1461
  end
1587
1462
 
1588
- context "when there are duplicate values" do
1589
-
1463
+ context 'when there are duplicate values' do
1590
1464
  let(:plucked) do
1591
1465
  context.pluck(:likes)
1592
1466
  end
1593
1467
 
1594
- it "returns the duplicates" do
1468
+ it 'returns the duplicates' do
1595
1469
  expect(plucked).to contain_exactly(1, 3, 3, 1)
1596
1470
  end
1597
1471
  end
1598
1472
  end
1599
1473
 
1600
- context "when plucking an aliased field" do
1601
-
1474
+ context 'when plucking an aliased field' do
1602
1475
  let(:plucked) do
1603
1476
  context.pluck(:id)
1604
1477
  end
1605
1478
 
1606
- it "returns the field values" do
1479
+ it 'returns the field values' do
1607
1480
  expect(plucked).to eq([ depeche.id, tool.id, photek.id, maniacs.id ])
1608
1481
  end
1609
1482
  end
1610
1483
 
1611
- context "when plucking existent and non-existent fields" do
1612
-
1484
+ context 'when plucking existent and non-existent fields' do
1613
1485
  let(:plucked) do
1614
1486
  context.pluck(:id, :fooz)
1615
1487
  end
1616
1488
 
1617
- it "returns nil for the field that doesnt exist" do
1618
- expect(plucked).to eq([[depeche.id, nil], [tool.id, nil], [photek.id, nil], [maniacs.id, nil] ])
1489
+ it 'returns nil for the field that doesnt exist' do
1490
+ expect(plucked).to eq([ [ depeche.id, nil ], [ tool.id, nil ], [ photek.id, nil ], [ maniacs.id, nil ] ])
1619
1491
  end
1620
1492
  end
1621
1493
 
1622
- context "when plucking a field that doesnt exist" do
1623
-
1624
- context "when pluck one field" do
1625
-
1494
+ context 'when plucking a field that doesnt exist' do
1495
+ context 'when pluck one field' do
1626
1496
  let(:plucked) do
1627
1497
  context.pluck(:foo)
1628
1498
  end
1629
1499
 
1630
- it "returns an array with nil values" do
1631
- expect(plucked).to eq([nil, nil, nil, nil])
1500
+ it 'returns an array with nil values' do
1501
+ expect(plucked).to eq([ nil, nil, nil, nil ])
1632
1502
  end
1633
1503
  end
1634
1504
 
1635
- context "when pluck multiple fields" do
1636
-
1505
+ context 'when pluck multiple fields' do
1637
1506
  let(:plucked) do
1638
1507
  context.pluck(:foo, :bar)
1639
1508
  end
1640
1509
 
1641
- it "returns an array of arrays with nil values" do
1642
- expect(plucked).to eq([[nil, nil], [nil, nil], [nil, nil], [nil, nil]])
1510
+ it 'returns an array of arrays with nil values' do
1511
+ expect(plucked).to eq([ [ nil, nil ], [ nil, nil ], [ nil, nil ], [ nil, nil ] ])
1643
1512
  end
1644
1513
  end
1645
1514
  end
@@ -1662,7 +1531,6 @@ describe Mongoid::Contextual::Memory do
1662
1531
  end
1663
1532
 
1664
1533
  context 'when plucking the entire field' do
1665
-
1666
1534
  let(:plucked) do
1667
1535
  context.pluck(:description)
1668
1536
  end
@@ -1680,16 +1548,16 @@ describe Mongoid::Contextual::Memory do
1680
1548
  end
1681
1549
 
1682
1550
  it 'returns the full translations hash to _translations' do
1683
- expect(plucked_translations.first).to eq({"de"=>"deutsch-text", "en"=>"english-text"})
1551
+ expect(plucked_translations.first).to eq({ 'de' => 'deutsch-text', 'en' => 'english-text' })
1684
1552
  end
1685
1553
 
1686
1554
  it 'returns both' do
1687
- expect(plucked_translations_both.first).to eq([{"de"=>"deutsch-text", "en"=>"english-text"}, "deutsch-text"])
1555
+ expect(plucked_translations_both.first).to eq([ { 'de' => 'deutsch-text', 'en' => 'english-text' },
1556
+ 'deutsch-text' ])
1688
1557
  end
1689
1558
  end
1690
1559
 
1691
1560
  context 'when plucking a specific locale' do
1692
-
1693
1561
  let(:plucked) do
1694
1562
  context.pluck(:'description.de')
1695
1563
  end
@@ -1700,7 +1568,6 @@ describe Mongoid::Contextual::Memory do
1700
1568
  end
1701
1569
 
1702
1570
  context 'when plucking a specific locale from _translations field' do
1703
-
1704
1571
  let(:plucked) do
1705
1572
  context.pluck(:'description_translations.de')
1706
1573
  end
@@ -1722,251 +1589,140 @@ describe Mongoid::Contextual::Memory do
1722
1589
  context.pluck(:description).first
1723
1590
  end
1724
1591
 
1725
- it "correctly uses the fallback" do
1592
+ it 'correctly uses the fallback' do
1726
1593
  I18n.locale = :en
1727
1594
  Dictionary.create!(description: 'english-text')
1728
1595
  I18n.locale = :he
1729
- plucked.should == "english-text"
1596
+ plucked.should eq 'english-text'
1730
1597
  end
1731
1598
  end
1732
1599
 
1733
- context "when the localized field is embedded" do
1600
+ context 'when the localized field is embedded' do
1734
1601
  with_default_i18n_configs
1735
1602
 
1736
1603
  before do
1737
1604
  p = Passport.new
1738
1605
  I18n.locale = :en
1739
- p.name = "Neil"
1606
+ p.name = 'Neil'
1740
1607
  I18n.locale = :he
1741
- p.name = "Nissim"
1608
+ p.name = 'Nissim'
1742
1609
 
1743
- Person.create!(passport: p, employer_id: 12345)
1610
+ Person.create!(passport: p, employer_id: 12_345)
1744
1611
  end
1745
1612
 
1746
1613
  let(:plucked) do
1747
- Person.where(employer_id: 12345).pluck("pass.name").first
1614
+ Person.where(employer_id: 12_345).pluck('pass.name').first
1748
1615
  end
1749
1616
 
1750
1617
  let(:plucked_translations) do
1751
- Person.where(employer_id: 12345).pluck("pass.name_translations").first
1618
+ Person.where(employer_id: 12_345).pluck('pass.name_translations').first
1752
1619
  end
1753
1620
 
1754
1621
  let(:plucked_translations_field) do
1755
- Person.where(employer_id: 12345).pluck("pass.name_translations.en").first
1622
+ Person.where(employer_id: 12_345).pluck('pass.name_translations.en').first
1756
1623
  end
1757
1624
 
1758
- it "returns the translation for the current locale" do
1759
- expect(plucked).to eq("Nissim")
1625
+ it 'returns the translation for the current locale' do
1626
+ expect(plucked).to eq('Nissim')
1760
1627
  end
1761
1628
 
1762
- it "returns the full _translation hash" do
1763
- expect(plucked_translations).to eq({ "en" => "Neil", "he" => "Nissim" })
1629
+ it 'returns the full _translation hash' do
1630
+ expect(plucked_translations).to eq({ 'en' => 'Neil', 'he' => 'Nissim' })
1764
1631
  end
1765
1632
 
1766
- it "returns the translation for the requested locale" do
1767
- expect(plucked_translations_field).to eq("Neil")
1633
+ it 'returns the translation for the requested locale' do
1634
+ expect(plucked_translations_field).to eq('Neil')
1768
1635
  end
1769
1636
  end
1770
1637
  end
1771
1638
 
1772
1639
  context 'when plucking a field to be demongoized' do
1773
-
1774
1640
  let(:plucked) do
1775
1641
  Band.where(name: maniacs.name).pluck(:sales)
1776
1642
  end
1777
1643
 
1778
1644
  with_config_values :map_big_decimal_to_decimal128, true, false do
1779
-
1780
- it "demongoizes the field" do
1645
+ it 'demongoizes the field' do
1781
1646
  expect(plucked.first).to be_a(BigDecimal)
1782
- expect(plucked.first).to eq(BigDecimal("1E2"))
1647
+ expect(plucked.first).to eq(BigDecimal('1E2'))
1783
1648
  end
1784
1649
  end
1785
1650
  end
1786
1651
 
1787
- context "when plucking an embedded field" do
1788
- let(:label) { Label.new(sales: "1E2") }
1652
+ context 'when plucking an embedded field' do
1653
+ let(:label) { Label.new(sales: '1E2') }
1789
1654
  let!(:band) { Band.create!(label: label) }
1790
1655
 
1791
1656
  let(:plucked) do
1792
1657
  Band.where(_id: band.id).tap do |crit|
1793
1658
  crit.documents = [ band ]
1794
- end.pluck("label.sales")
1659
+ end.pluck('label.sales')
1795
1660
  end
1796
1661
 
1797
- it "demongoizes the field" do
1798
- expect(plucked).to eq([ BigDecimal("1E2") ])
1662
+ it 'demongoizes the field' do
1663
+ expect(plucked).to eq([ BigDecimal('1E2') ])
1799
1664
  end
1800
1665
  end
1801
1666
 
1802
- context "when plucking an embeds_many field" do
1803
- let(:label) { Label.new(sales: "1E2") }
1804
- let!(:band) { Band.create!(labels: [label]) }
1667
+ context 'when plucking an embeds_many field' do
1668
+ let(:label) { Label.new(sales: '1E2') }
1669
+ let!(:band) { Band.create!(labels: [ label ]) }
1805
1670
 
1806
- let(:plucked) { Band.where(_id: band.id).pluck("labels.sales") }
1671
+ let(:plucked) { Band.where(_id: band.id).pluck('labels.sales') }
1807
1672
 
1808
- it "demongoizes the field" do
1809
- expect(plucked.first).to eq([ BigDecimal("1E2") ])
1673
+ it 'demongoizes the field' do
1674
+ expect(plucked.first).to eq([ BigDecimal('1E2') ])
1810
1675
  end
1811
1676
  end
1812
1677
 
1813
- context "when plucking a nonexistent embedded field" do
1814
- let(:label) { Label.new(sales: "1E2") }
1678
+ context 'when plucking a nonexistent embedded field' do
1679
+ let(:label) { Label.new(sales: '1E2') }
1815
1680
  let!(:band) { Band.create!(label: label) }
1816
1681
 
1817
1682
  let(:plucked) do
1818
1683
  Band.where(_id: band.id).tap do |crit|
1819
1684
  crit.documents = [ band ]
1820
- end.pluck("label.qwerty")
1685
+ end.pluck('label.qwerty')
1821
1686
  end
1822
1687
 
1823
- it "returns nil" do
1688
+ it 'returns nil' do
1824
1689
  expect(plucked.first).to eq(nil)
1825
1690
  end
1826
1691
  end
1827
1692
 
1828
- context "when plucking deeply nested arrays/embedded associations" do
1829
-
1693
+ context 'when plucking deeply nested arrays/embedded associations' do
1830
1694
  let(:criteria) do
1831
1695
  Person.all.tap do |crit|
1832
1696
  crit.documents = [
1833
- Person.create!(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 2 } } ]))) ]),
1834
- Person.create!(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 2 } } ]))) ]),
1835
- Person.create!(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 3 } } ]))) ]),
1697
+ Person.create!(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
1698
+ { y: { z: 2 } } ]))) ]),
1699
+ Person.create!(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
1700
+ { y: { z: 2 } } ]))) ]),
1701
+ Person.create!(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
1702
+ { y: { z: 3 } } ]))) ])
1836
1703
  ]
1837
1704
  end
1838
1705
  end
1839
1706
 
1840
1707
  let(:plucked) do
1841
- context.pluck("addresses.code.deepest.array.y.z")
1708
+ context.pluck('addresses.code.deepest.array.y.z')
1842
1709
  end
1843
1710
 
1844
- it "returns the correct hash" do
1711
+ it 'returns the correct hash' do
1845
1712
  expect(plucked).to eq([
1846
- [ [ 1, 2 ] ], [ [ 1, 2 ] ], [ [ 1, 3 ] ]
1847
- ])
1848
- end
1849
- end
1850
-
1851
- context 'when plucking a dynamic attribute' do
1852
- let(:criteria) do
1853
- Band.all.tap do |crit|
1854
- crit.documents = [ Band.create!(name: 'Depeche Mode', mood: 'dark') ]
1855
- end
1856
- end
1857
-
1858
- it 'returns the value from the attributes' do
1859
- expect(context.pluck(:mood)).to eq([ 'dark' ])
1860
- end
1861
- end
1862
-
1863
- context 'when the field name is a method name' do
1864
- let!(:person) do
1865
- Person.create!(ssn: 'secret-ssn')
1866
- end
1867
-
1868
- let!(:address) do
1869
- person.addresses.create!(street: 'hobrecht')
1870
- end
1871
-
1872
- let(:criteria) do
1873
- Address.all.tap do |crit|
1874
- crit.documents = [ address ]
1875
- end
1876
- end
1877
-
1878
- it 'does not call the method' do
1879
- expect(address).not_to receive(:destroy)
1880
- expect(context.pluck(:destroy)).to eq([ nil ])
1881
- end
1882
-
1883
- it 'does not return the attributes hash' do
1884
- expect(context.pluck(:attributes)).to eq([ nil ])
1885
- end
1886
-
1887
- it 'does not traverse to the parent document' do
1888
- expect(context.pluck('_root.ssn')).to eq([ nil ])
1889
- end
1890
-
1891
- it 'does not destroy the parent document' do
1892
- expect(context.pluck('_root.destroy')).to eq([ nil ])
1893
- expect(Person.where(_id: person.id).count).to eq(1)
1894
- end
1895
- end
1896
-
1897
- context 'when plucking a belongs_to association' do
1898
- let!(:band) do
1899
- Band.create!(name: 'Depeche Mode')
1900
- end
1901
-
1902
- let!(:artist) do
1903
- Artist.create!(band: band)
1904
- end
1905
-
1906
- let(:criteria) do
1907
- Artist.all.tap do |crit|
1908
- crit.documents = [ artist ]
1909
- end
1910
- end
1911
-
1912
- it 'traverses to the associated document' do
1913
- expect(context.pluck('band.name')).to eq([ 'Depeche Mode' ])
1914
- end
1915
-
1916
- it 'returns the document for the association name' do
1917
- expect(context.pluck(:band)).to eq([ band ])
1918
- end
1919
-
1920
- it 'returns the id for the foreign key' do
1921
- expect(context.pluck(:band_id)).to eq([ band.id ])
1922
- end
1923
- end
1924
-
1925
- context 'when plucking the foreign key of a many to many association' do
1926
- let!(:preference) do
1927
- Preference.create!(name: 'nature')
1928
- end
1929
-
1930
- let!(:person) do
1931
- Person.create!(preferences: [ preference ])
1932
- end
1933
-
1934
- let(:criteria) do
1935
- Person.all.tap do |crit|
1936
- crit.documents = [ person ]
1937
- end
1938
- end
1939
-
1940
- it 'returns the stored ids' do
1941
- expect(context.pluck(:preference_ids)).to eq([ [ preference.id ] ])
1942
- end
1943
- end
1944
-
1945
- context 'when the field path has an empty segment' do
1946
- let!(:band) do
1947
- Band.create!(name: 'Depeche Mode', label: Label.new(name: 'Mute'))
1948
- end
1949
-
1950
- let(:criteria) do
1951
- Band.all.tap do |crit|
1952
- crit.documents = [ band ]
1953
- end
1954
- end
1955
-
1956
- it 'returns nil' do
1957
- expect(context.pluck('label..name')).to eq([ nil ])
1713
+ [ [ 1, 2 ] ], [ [ 1, 2 ] ], [ [ 1, 3 ] ]
1714
+ ])
1958
1715
  end
1959
1716
  end
1960
1717
  end
1961
1718
 
1962
- describe "#pick" do
1963
-
1719
+ describe '#pick' do
1964
1720
  let(:depeche) do
1965
- Band.create!(name: "Depeche Mode", likes: 3)
1721
+ Band.create!(name: 'Depeche Mode', likes: 3)
1966
1722
  end
1967
1723
 
1968
1724
  let(:tool) do
1969
- Band.create!(name: "Tool", likes: 3)
1725
+ Band.create!(name: 'Tool', likes: 3)
1970
1726
  end
1971
1727
 
1972
1728
  let(:criteria) do
@@ -1979,30 +1735,27 @@ describe Mongoid::Contextual::Memory do
1979
1735
  described_class.new(criteria)
1980
1736
  end
1981
1737
 
1982
- context "when picking a field" do
1983
-
1738
+ context 'when picking a field' do
1984
1739
  let(:picked) do
1985
1740
  context.pick(:name)
1986
1741
  end
1987
1742
 
1988
- it "returns one element" do
1989
- expect(picked).to eq("Depeche Mode")
1743
+ it 'returns one element' do
1744
+ expect(picked).to eq('Depeche Mode')
1990
1745
  end
1991
1746
  end
1992
1747
 
1993
- context "when picking multiple fields" do
1994
-
1748
+ context 'when picking multiple fields' do
1995
1749
  let(:picked) do
1996
1750
  context.pick(:name, :likes)
1997
1751
  end
1998
1752
 
1999
- it "returns an array" do
2000
- expect(picked).to eq([ "Depeche Mode", 3 ])
1753
+ it 'returns an array' do
1754
+ expect(picked).to eq([ 'Depeche Mode', 3 ])
2001
1755
  end
2002
1756
  end
2003
1757
 
2004
- context "when no documents to pick" do
2005
-
1758
+ context 'when no documents to pick' do
2006
1759
  let(:criteria) do
2007
1760
  Band.all.tap do |crit|
2008
1761
  crit.documents = []
@@ -2013,62 +1766,46 @@ describe Mongoid::Contextual::Memory do
2013
1766
  context.pick(:name)
2014
1767
  end
2015
1768
 
2016
- it "returns nil" do
1769
+ it 'returns nil' do
2017
1770
  expect(picked).to be_nil
2018
1771
  end
2019
1772
  end
2020
-
2021
- context 'when the field name is a method name' do
2022
- let!(:person) do
2023
- Person.create!(ssn: 'secret-ssn')
2024
- end
2025
-
2026
- let!(:address) do
2027
- person.addresses.create!(street: 'hobrecht')
2028
- end
2029
-
2030
- let(:criteria) do
2031
- Address.all.tap do |crit|
2032
- crit.documents = [ address ]
2033
- end
2034
- end
2035
-
2036
- it 'does not call the method' do
2037
- expect(address).not_to receive(:destroy)
2038
- expect(context.pick(:destroy)).to be_nil
2039
- end
2040
- end
2041
1773
  end
2042
1774
 
2043
- describe "#tally" do
2044
- let(:fans1) { [ Fanatic.new(age:1), Fanatic.new(age:2) ] }
2045
- let(:fans2) { [ Fanatic.new(age:1), Fanatic.new(age:2) ] }
2046
- let(:fans3) { [ Fanatic.new(age:1), Fanatic.new(age:3) ] }
1775
+ describe '#tally' do
1776
+ let(:fans1) { [ Fanatic.new(age: 1), Fanatic.new(age: 2) ] }
1777
+ let(:fans2) { [ Fanatic.new(age: 1), Fanatic.new(age: 2) ] }
1778
+ let(:fans3) { [ Fanatic.new(age: 1), Fanatic.new(age: 3) ] }
2047
1779
 
2048
- let(:genres1) { [ { x: 1, y: { z: 1 } }, { x: 2, y: { z: 2 } }, { y: 3 } ]}
2049
- let(:genres2) { [ { x: 1, y: { z: 1 } }, { x: 2, y: { z: 2 } }, { y: 4 } ]}
2050
- let(:genres3) { [ { x: 1, y: { z: 1 } }, { x: 3, y: { z: 3 } }, { y: 5 } ]}
1780
+ let(:genres1) { [ { x: 1, y: { z: 1 } }, { x: 2, y: { z: 2 } }, { y: 3 } ] }
1781
+ let(:genres2) { [ { x: 1, y: { z: 1 } }, { x: 2, y: { z: 2 } }, { y: 4 } ] }
1782
+ let(:genres3) { [ { x: 1, y: { z: 1 } }, { x: 3, y: { z: 3 } }, { y: 5 } ] }
2051
1783
 
2052
- let(:label1) { Label.new(name: "Atlantic") }
2053
- let(:label2) { Label.new(name: "Atlantic") }
2054
- let(:label3) { Label.new(name: "Columbia") }
1784
+ let(:label1) { Label.new(name: 'Atlantic') }
1785
+ let(:label2) { Label.new(name: 'Atlantic') }
1786
+ let(:label3) { Label.new(name: 'Columbia') }
2055
1787
 
2056
-
2057
- let(:band1) { Band.new(origin: "tally", name: "Depeche Mode", years: 30, sales: "1E2", label: label1, genres: genres1) }
2058
- let(:band2) { Band.new(origin: "tally", name: "New Order", years: 30, sales: "2E3", label: label2, genres: genres2) }
2059
- let(:band3) { Band.new(origin: "tally", name: "10,000 Maniacs", years: 30, sales: "1E2", label: label3, genres: genres3) }
2060
- let(:band4) { Band.new(origin: "tally2", fanatics: fans1, genres: [1, 2]) }
2061
- let(:band5) { Band.new(origin: "tally2", fanatics: fans2, genres: [1, 2]) }
2062
- let(:band6) { Band.new(origin: "tally2", fanatics: fans3, genres: [1, 3]) }
1788
+ let(:band1) do
1789
+ Band.new(origin: 'tally', name: 'Depeche Mode', years: 30, sales: '1E2', label: label1, genres: genres1)
1790
+ end
1791
+ let(:band2) do
1792
+ Band.new(origin: 'tally', name: 'New Order', years: 30, sales: '2E3', label: label2, genres: genres2)
1793
+ end
1794
+ let(:band3) do
1795
+ Band.new(origin: 'tally', name: '10,000 Maniacs', years: 30, sales: '1E2', label: label3, genres: genres3)
1796
+ end
1797
+ let(:band4) { Band.new(origin: 'tally2', fanatics: fans1, genres: [ 1, 2 ]) }
1798
+ let(:band5) { Band.new(origin: 'tally2', fanatics: fans2, genres: [ 1, 2 ]) }
1799
+ let(:band6) { Band.new(origin: 'tally2', fanatics: fans3, genres: [ 1, 3 ]) }
2063
1800
 
2064
1801
  let(:criteria) do
2065
- Band.where(origin: "tally").all.tap do |crit|
1802
+ Band.where(origin: 'tally').all.tap do |crit|
2066
1803
  crit.documents = [ band1, band2, band3 ]
2067
1804
  end
2068
1805
  end
2069
1806
 
2070
1807
  let(:criteria2) do
2071
- Band.where(origin: "tally2").tap do |crit|
1808
+ Band.where(origin: 'tally2').tap do |crit|
2072
1809
  crit.documents = [ band4, band5, band6 ]
2073
1810
  end
2074
1811
  end
@@ -2081,40 +1818,45 @@ describe Mongoid::Contextual::Memory do
2081
1818
  described_class.new(criteria2)
2082
1819
  end
2083
1820
 
2084
- context "when tallying a string" do
1821
+ context 'when tallying a string' do
2085
1822
  let(:tally) do
2086
1823
  context.tally(:name)
2087
1824
  end
2088
1825
 
2089
- it "returns the correct hash" do
2090
- expect(tally).to eq("Depeche Mode" => 1, "New Order" => 1, "10,000 Maniacs" => 1)
1826
+ it 'returns the correct hash' do
1827
+ expect(tally).to eq('Depeche Mode' => 1, 'New Order' => 1, '10,000 Maniacs' => 1)
2091
1828
  end
2092
1829
  end
2093
1830
 
2094
- context "using an aliased field" do
1831
+ context 'using an aliased field' do
2095
1832
  let(:tally) do
2096
1833
  context.tally(:years)
2097
1834
  end
2098
1835
 
2099
- it "returns the correct hash" do
1836
+ it 'returns the correct hash' do
2100
1837
  expect(tally).to eq(30 => 3)
2101
1838
  end
2102
1839
  end
2103
1840
 
2104
- context "when tallying a demongoizable field" do
1841
+ context 'when tallying a demongoizable field' do
2105
1842
  let(:tally) do
2106
1843
  context.tally(:sales)
2107
1844
  end
2108
1845
 
2109
- it "returns the correct hash" do
2110
- expect(tally).to eq(BigDecimal("1E2") => 2, BigDecimal("2E3") => 1)
1846
+ it 'returns the correct hash' do
1847
+ expect(tally).to eq(BigDecimal('1E2') => 2, BigDecimal('2E3') => 1)
2111
1848
  end
2112
1849
  end
2113
1850
 
2114
- context "when tallying a localized field" do
1851
+ context 'when tallying a localized field' do
2115
1852
  with_default_i18n_configs
2116
1853
 
2117
1854
  let(:d1) { Dictionary.new(description: 'en1') }
1855
+ let(:criteria) do
1856
+ Dictionary.all.tap do |crit|
1857
+ crit.documents = [ d1, d2, d3, d4 ]
1858
+ end
1859
+ end
2118
1860
  let(:d2) { Dictionary.new(description: 'en1') }
2119
1861
  let(:d3) { Dictionary.new(description: 'en1') }
2120
1862
  let(:d4) { Dictionary.new(description: 'en2') }
@@ -2133,57 +1875,56 @@ describe Mongoid::Contextual::Memory do
2133
1875
  I18n.locale = :en
2134
1876
  end
2135
1877
 
2136
- let(:criteria) do
2137
- Dictionary.all.tap do |crit|
2138
- crit.documents = [ d1, d2, d3, d4 ]
2139
- end
2140
- end
2141
-
2142
- context "when getting the demongoized field" do
1878
+ context 'when getting the demongoized field' do
2143
1879
  let(:tallied) do
2144
1880
  context.tally(:description)
2145
1881
  end
2146
1882
 
2147
- it "returns the translation for the current locale" do
2148
- expect(tallied).to eq("en1" => 3, "en2" => 1)
1883
+ it 'returns the translation for the current locale' do
1884
+ expect(tallied).to eq('en1' => 3, 'en2' => 1)
2149
1885
  end
2150
1886
  end
2151
1887
 
2152
- context "when getting a specific locale" do
1888
+ context 'when getting a specific locale' do
2153
1889
  let(:tallied) do
2154
- context.tally("description.de")
1890
+ context.tally('description.de')
2155
1891
  end
2156
1892
 
2157
- it "returns the translation for the the specific locale" do
2158
- expect(tallied).to eq("de1" => 2, "de2" => 1, "de3" => 1)
1893
+ it 'returns the translation for the the specific locale' do
1894
+ expect(tallied).to eq('de1' => 2, 'de2' => 1, 'de3' => 1)
2159
1895
  end
2160
1896
  end
2161
1897
 
2162
- context "when getting the full hash" do
1898
+ context 'when getting the full hash' do
2163
1899
  let(:tallied) do
2164
- context.tally("description_translations")
1900
+ context.tally('description_translations')
2165
1901
  end
2166
1902
 
2167
- it "returns the correct hash" do
1903
+ it 'returns the correct hash' do
2168
1904
  expect(tallied).to eq(
2169
- {"de" => "de1", "en" => "en1" } => 2,
2170
- {"de" => "de2", "en" => "en1" } => 1,
2171
- {"de" => "de3", "en" => "en2" } => 1
1905
+ { 'de' => 'de1', 'en' => 'en1' } => 2,
1906
+ { 'de' => 'de2', 'en' => 'en1' } => 1,
1907
+ { 'de' => 'de3', 'en' => 'en2' } => 1
2172
1908
  )
2173
1909
  end
2174
1910
  end
2175
1911
  end
2176
1912
 
2177
- context "when tallying an embedded localized field" do
1913
+ context 'when tallying an embedded localized field' do
2178
1914
  with_default_i18n_configs
2179
1915
 
2180
1916
  let(:person1) { Person.create!(addresses: [ address1a, address1b ]) }
1917
+ let(:criteria) do
1918
+ Person.all.tap do |crit|
1919
+ crit.documents = [ person1, person2 ]
1920
+ end
1921
+ end
2181
1922
  let(:person2) { Person.create!(addresses: [ address2a, address2b ]) }
2182
1923
 
2183
- let(:address1a) { Address.new(name: "en1") }
2184
- let(:address1b) { Address.new(name: "en2") }
2185
- let(:address2a) { Address.new(name: "en1") }
2186
- let(:address2b) { Address.new(name: "en3") }
1924
+ let(:address1a) { Address.new(name: 'en1') }
1925
+ let(:address1b) { Address.new(name: 'en2') }
1926
+ let(:address2a) { Address.new(name: 'en1') }
1927
+ let(:address2b) { Address.new(name: 'en3') }
2187
1928
 
2188
1929
  before do
2189
1930
  I18n.locale = :en
@@ -2192,153 +1933,141 @@ describe Mongoid::Contextual::Memory do
2192
1933
  address2a
2193
1934
  address2b
2194
1935
  I18n.locale = :de
2195
- address1a.name = "de1"
2196
- address1b.name = "de2"
2197
- address2a.name = "de1"
2198
- address2b.name = "de3"
1936
+ address1a.name = 'de1'
1937
+ address1b.name = 'de2'
1938
+ address2a.name = 'de1'
1939
+ address2b.name = 'de3'
2199
1940
  person1
2200
1941
  person2
2201
1942
  I18n.locale = :en
2202
1943
  end
2203
1944
 
2204
- let(:criteria) do
2205
- Person.all.tap do |crit|
2206
- crit.documents = [ person1, person2 ]
2207
- end
2208
- end
2209
-
2210
- context "when getting the demongoized field" do
1945
+ context 'when getting the demongoized field' do
2211
1946
  let(:tallied) do
2212
- context.tally("addresses.name")
1947
+ context.tally('addresses.name')
2213
1948
  end
2214
1949
 
2215
- it "returns the translation for the current locale" do
1950
+ it 'returns the translation for the current locale' do
2216
1951
  expect(tallied).to eq(
2217
- [ "en1", "en2" ] => 1,
2218
- [ "en1", "en3" ] => 1,
1952
+ %w[en1 en2] => 1,
1953
+ %w[en1 en3] => 1
2219
1954
  )
2220
1955
  end
2221
1956
  end
2222
1957
 
2223
- context "when getting a specific locale" do
1958
+ context 'when getting a specific locale' do
2224
1959
  let(:tallied) do
2225
- context.tally("addresses.name.de")
1960
+ context.tally('addresses.name.de')
2226
1961
  end
2227
1962
 
2228
- it "returns the translation for the the specific locale" do
1963
+ it 'returns the translation for the the specific locale' do
2229
1964
  expect(tallied).to eq(
2230
- [ "de1", "de2" ] => 1,
2231
- [ "de1", "de3" ] => 1,
1965
+ %w[de1 de2] => 1,
1966
+ %w[de1 de3] => 1
2232
1967
  )
2233
1968
  end
2234
1969
  end
2235
1970
 
2236
- context "when getting the full hash" do
1971
+ context 'when getting the full hash' do
2237
1972
  let(:tallied) do
2238
- context.tally("addresses.name_translations")
1973
+ context.tally('addresses.name_translations')
2239
1974
  end
2240
1975
 
2241
- it "returns the correct hash" do
1976
+ it 'returns the correct hash' do
2242
1977
  expect(tallied).to eq(
2243
- [{ "de" => "de1", "en" => "en1" }, { "de" => "de2", "en" => "en2" }] => 1,
2244
- [{ "de" => "de1", "en" => "en1" }, { "de" => "de3", "en" => "en3" }] => 1,
1978
+ [ { 'de' => 'de1', 'en' => 'en1' }, { 'de' => 'de2', 'en' => 'en2' } ] => 1,
1979
+ [ { 'de' => 'de1', 'en' => 'en1' }, { 'de' => 'de3', 'en' => 'en3' } ] => 1
2245
1980
  )
2246
1981
  end
2247
1982
  end
2248
1983
  end
2249
1984
 
2250
- context "when tallying an embedded field" do
1985
+ context 'when tallying an embedded field' do
2251
1986
  let(:tally) do
2252
- context.tally("label.name")
1987
+ context.tally('label.name')
2253
1988
  end
2254
1989
 
2255
- it "returns the correct hash" do
2256
- expect(tally).to eq("Atlantic" => 2, "Columbia" => 1)
1990
+ it 'returns the correct hash' do
1991
+ expect(tally).to eq('Atlantic' => 2, 'Columbia' => 1)
2257
1992
  end
2258
1993
  end
2259
1994
 
2260
- context "when tallying an element in an embeds_many field" do
2261
-
1995
+ context 'when tallying an element in an embeds_many field' do
2262
1996
  let(:tally) do
2263
- context2.tally("fanatics.age")
1997
+ context2.tally('fanatics.age')
2264
1998
  end
2265
1999
 
2266
- it "returns the correct hash" do
2000
+ it 'returns the correct hash' do
2267
2001
  expect(tally).to eq(
2268
- [1, 2] => 2,
2269
- [1, 3] => 1
2002
+ [ 1, 2 ] => 2,
2003
+ [ 1, 3 ] => 1
2270
2004
  )
2271
2005
  end
2272
2006
  end
2273
2007
 
2274
- context "when tallying an embeds_many field" do
2275
-
2008
+ context 'when tallying an embeds_many field' do
2276
2009
  let(:tally) do
2277
- context2.tally("fanatics")
2010
+ context2.tally('fanatics')
2278
2011
  end
2279
2012
 
2280
- it "returns the correct hash" do
2013
+ it 'returns the correct hash' do
2281
2014
  expect(tally).to eq(
2282
2015
  fans1 => 1,
2283
2016
  fans2 => 1,
2284
- fans3 => 1,
2017
+ fans3 => 1
2285
2018
  )
2286
2019
  end
2287
2020
  end
2288
2021
 
2289
- context "when tallying a field of type array" do
2290
-
2022
+ context 'when tallying a field of type array' do
2291
2023
  let(:tally) do
2292
- context2.tally("genres")
2024
+ context2.tally('genres')
2293
2025
  end
2294
2026
 
2295
- it "returns the correct hash" do
2027
+ it 'returns the correct hash' do
2296
2028
  expect(tally).to eq(
2297
- [1, 2] => 2,
2298
- [1, 3] => 1
2029
+ [ 1, 2 ] => 2,
2030
+ [ 1, 3 ] => 1
2299
2031
  )
2300
2032
  end
2301
2033
  end
2302
2034
 
2303
- context "when tallying an element from an array of hashes" do
2304
-
2035
+ context 'when tallying an element from an array of hashes' do
2305
2036
  let(:tally) do
2306
- context.tally("genres.x")
2037
+ context.tally('genres.x')
2307
2038
  end
2308
2039
 
2309
- it "returns the correct hash without the nil keys" do
2040
+ it 'returns the correct hash without the nil keys' do
2310
2041
  expect(tally).to eq(
2311
- [1, 2] => 2,
2312
- [1, 3] => 1
2042
+ [ 1, 2 ] => 2,
2043
+ [ 1, 3 ] => 1
2313
2044
  )
2314
2045
  end
2315
2046
  end
2316
2047
 
2317
- context "when tallying an element from an array of hashes; with duplicate" do
2318
-
2319
- let(:band4) { Band.new(origin: "tally", genres: [ { x: 1 }, {x: 1} ] ) }
2048
+ context 'when tallying an element from an array of hashes; with duplicate' do
2049
+ let(:band4) { Band.new(origin: 'tally', genres: [ { x: 1 }, { x: 1 } ]) }
2320
2050
 
2321
2051
  let(:criteria) do
2322
- Band.where(origin: "tally").all.tap do |crit|
2052
+ Band.where(origin: 'tally').all.tap do |crit|
2323
2053
  crit.documents = [ band1, band2, band3, band4 ]
2324
2054
  end
2325
2055
  end
2326
2056
 
2327
2057
  let(:tally) do
2328
- context.tally("genres.x")
2058
+ context.tally('genres.x')
2329
2059
  end
2330
2060
 
2331
- it "returns the correct hash without the nil keys" do
2061
+ it 'returns the correct hash without the nil keys' do
2332
2062
  expect(tally).to eq(
2333
- [1, 2] => 2,
2334
- [1, 3] => 1,
2335
- [1, 1] => 1,
2063
+ [ 1, 2 ] => 2,
2064
+ [ 1, 3 ] => 1,
2065
+ [ 1, 1 ] => 1
2336
2066
  )
2337
2067
  end
2338
2068
  end
2339
2069
 
2340
- context "when tallying an aliased field of type array" do
2341
-
2070
+ context 'when tallying an aliased field of type array' do
2342
2071
  let(:person1) { Person.new(array: [ 1, 2 ]) }
2343
2072
  let(:person2) { Person.new(array: [ 1, 3 ]) }
2344
2073
 
@@ -2349,50 +2078,56 @@ describe Mongoid::Contextual::Memory do
2349
2078
  end
2350
2079
 
2351
2080
  let(:tally) do
2352
- context.tally("array")
2081
+ context.tally('array')
2353
2082
  end
2354
2083
 
2355
- it "returns the correct hash" do
2084
+ it 'returns the correct hash' do
2356
2085
  expect(tally).to eq(
2357
- [1, 2] => 1,
2358
- [1, 3] => 1
2086
+ [ 1, 2 ] => 1,
2087
+ [ 1, 3 ] => 1
2359
2088
  )
2360
2089
  end
2361
2090
  end
2362
2091
 
2363
- context "when going multiple levels deep in arrays" do
2364
-
2092
+ context 'when going multiple levels deep in arrays' do
2365
2093
  let(:tally) do
2366
- context.tally("genres.y.z")
2094
+ context.tally('genres.y.z')
2367
2095
  end
2368
2096
 
2369
- it "returns the correct hash" do
2097
+ it 'returns the correct hash' do
2370
2098
  expect(tally).to eq(
2371
- [1, 2] => 2,
2372
- [1, 3] => 1
2099
+ [ 1, 2 ] => 2,
2100
+ [ 1, 3 ] => 1
2373
2101
  )
2374
2102
  end
2375
2103
  end
2376
2104
 
2377
- context "when going multiple levels deep in an array" do
2378
-
2105
+ context 'when going multiple levels deep in an array' do
2379
2106
  let(:tally) do
2380
- context.tally("genres.y.z")
2107
+ context.tally('genres.y.z')
2381
2108
  end
2382
2109
 
2383
- it "returns the correct hash" do
2110
+ it 'returns the correct hash' do
2384
2111
  expect(tally).to eq(
2385
- [1, 2] => 2,
2386
- [1, 3] => 1
2112
+ [ 1, 2 ] => 2,
2113
+ [ 1, 3 ] => 1
2387
2114
  )
2388
2115
  end
2389
2116
  end
2390
2117
 
2391
- context "when tallying deeply nested arrays/embedded associations" do
2392
-
2393
- let(:person1) { Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 2 } } ]))) ]) }
2394
- let(:person2) { Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 2 } } ]))) ]) }
2395
- let(:person3) { Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 3 } } ]))) ]) }
2118
+ context 'when tallying deeply nested arrays/embedded associations' do
2119
+ let(:person1) do
2120
+ Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
2121
+ { y: { z: 2 } } ]))) ])
2122
+ end
2123
+ let(:person2) do
2124
+ Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
2125
+ { y: { z: 2 } } ]))) ])
2126
+ end
2127
+ let(:person3) do
2128
+ Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
2129
+ { y: { z: 3 } } ]))) ])
2130
+ end
2396
2131
 
2397
2132
  let(:criteria) do
2398
2133
  Person.all.tap do |crit|
@@ -2401,10 +2136,10 @@ describe Mongoid::Contextual::Memory do
2401
2136
  end
2402
2137
 
2403
2138
  let(:tally) do
2404
- context.tally("addresses.code.deepest.array.y.z")
2139
+ context.tally('addresses.code.deepest.array.y.z')
2405
2140
  end
2406
2141
 
2407
- it "returns the correct hash" do
2142
+ it 'returns the correct hash' do
2408
2143
  expect(tally).to eq(
2409
2144
  [ [ 1, 2 ] ] => 2,
2410
2145
  [ [ 1, 3 ] ] => 1
@@ -2412,21 +2147,23 @@ describe Mongoid::Contextual::Memory do
2412
2147
  end
2413
2148
  end
2414
2149
 
2415
- context "when tallying deeply nested arrays/embedded associations" do
2416
-
2150
+ context 'when tallying deeply nested arrays/embedded associations' do
2417
2151
  let(:person1) do
2418
2152
  Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 2 } } ]))),
2419
- Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 2 } } ]))) ])
2153
+ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
2154
+ { y: { z: 2 } } ]))) ])
2420
2155
  end
2421
2156
 
2422
2157
  let(:person2) do
2423
2158
  Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 2 } } ]))),
2424
- Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 2 } } ]))) ])
2159
+ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
2160
+ { y: { z: 2 } } ]))) ])
2425
2161
  end
2426
2162
 
2427
2163
  let(:person3) do
2428
2164
  Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 3 } } ]))),
2429
- Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 3 } } ]))) ])
2165
+ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
2166
+ { y: { z: 3 } } ]))) ])
2430
2167
  end
2431
2168
 
2432
2169
  let(:criteria) do
@@ -2436,10 +2173,10 @@ describe Mongoid::Contextual::Memory do
2436
2173
  end
2437
2174
 
2438
2175
  let(:tally) do
2439
- context.tally("addresses.code.deepest.array.y.z")
2176
+ context.tally('addresses.code.deepest.array.y.z')
2440
2177
  end
2441
2178
 
2442
- it "returns the correct hash" do
2179
+ it 'returns the correct hash' do
2443
2180
  expect(tally).to eq(
2444
2181
  [ [ 1, 2 ], [ 1, 2 ] ] => 2,
2445
2182
  [ [ 1, 3 ], [ 1, 3 ] ] => 1
@@ -2447,12 +2184,11 @@ describe Mongoid::Contextual::Memory do
2447
2184
  end
2448
2185
  end
2449
2186
 
2450
- context "when some keys are missing" do
2451
-
2187
+ context 'when some keys are missing' do
2452
2188
  let(:criteria) do
2453
- Band.where(origin: "tally").all.tap do |crit|
2189
+ Band.where(origin: 'tally').all.tap do |crit|
2454
2190
  crit.documents = [ band1, band2, band3 ]
2455
- 3.times{ crit.documents << Band.new(origin: "tally") }
2191
+ 3.times { crit.documents << Band.new(origin: 'tally') }
2456
2192
  end
2457
2193
  end
2458
2194
 
@@ -2460,20 +2196,26 @@ describe Mongoid::Contextual::Memory do
2460
2196
  context.tally(:name)
2461
2197
  end
2462
2198
 
2463
- it "returns the correct hash" do
2199
+ it 'returns the correct hash' do
2464
2200
  expect(tally).to eq(
2465
- "Depeche Mode" => 1,
2466
- "New Order" => 1,
2467
- "10,000 Maniacs" => 1,
2201
+ 'Depeche Mode' => 1,
2202
+ 'New Order' => 1,
2203
+ '10,000 Maniacs' => 1,
2468
2204
  nil => 3
2469
2205
  )
2470
2206
  end
2471
2207
  end
2472
2208
 
2473
- context "when the first element is an embeds_one" do
2474
- let(:person1) { Person.create!(name: Name.new(translations: [ Translation.new(language: 1), Translation.new(language: 2) ])) }
2475
- let(:person2) { Person.create!(name: Name.new(translations: [ Translation.new(language: 1), Translation.new(language: 2) ])) }
2476
- let(:person3) { Person.create!(name: Name.new(translations: [ Translation.new(language: 1), Translation.new(language: 3) ])) }
2209
+ context 'when the first element is an embeds_one' do
2210
+ let(:person1) do
2211
+ Person.create!(name: Name.new(translations: [ Translation.new(language: 1), Translation.new(language: 2) ]))
2212
+ end
2213
+ let(:person2) do
2214
+ Person.create!(name: Name.new(translations: [ Translation.new(language: 1), Translation.new(language: 2) ]))
2215
+ end
2216
+ let(:person3) do
2217
+ Person.create!(name: Name.new(translations: [ Translation.new(language: 1), Translation.new(language: 3) ]))
2218
+ end
2477
2219
 
2478
2220
  let(:criteria) do
2479
2221
  Person.all.tap do |crit|
@@ -2482,45 +2224,19 @@ describe Mongoid::Contextual::Memory do
2482
2224
  end
2483
2225
 
2484
2226
  let(:tally) do
2485
- context.tally("name.translations.language")
2227
+ context.tally('name.translations.language')
2486
2228
  end
2487
2229
 
2488
- it "returns the correct hash" do
2230
+ it 'returns the correct hash' do
2489
2231
  expect(tally).to eq(
2490
- [1, 2] => 2,
2491
- [1, 3] => 1
2232
+ [ 1, 2 ] => 2,
2233
+ [ 1, 3 ] => 1
2492
2234
  )
2493
2235
  end
2494
2236
  end
2495
-
2496
- context 'when the field name is a method name' do
2497
- let!(:person) do
2498
- Person.create!(ssn: 'secret-ssn')
2499
- end
2500
-
2501
- let!(:address) do
2502
- person.addresses.create!(street: 'hobrecht')
2503
- end
2504
-
2505
- let(:criteria) do
2506
- Address.all.tap do |crit|
2507
- crit.documents = [ address ]
2508
- end
2509
- end
2510
-
2511
- it 'does not call the method' do
2512
- expect(address).not_to receive(:destroy)
2513
- expect(context.tally(:destroy)).to eq(nil => 1)
2514
- end
2515
-
2516
- it 'does not disclose the parent document fields' do
2517
- expect(context.tally('_root.ssn')).to eq(nil => 1)
2518
- end
2519
- end
2520
2237
  end
2521
2238
 
2522
2239
  describe '#inc' do
2523
-
2524
2240
  let(:criteria) do
2525
2241
  Address.all.tap do |crit|
2526
2242
  crit.documents = [ Address.new(number: 1),
@@ -2534,22 +2250,21 @@ describe Mongoid::Contextual::Memory do
2534
2250
  end
2535
2251
 
2536
2252
  it 'increases each member' do
2537
- expect(context.inc(number: 10).collect(&:number)).to eql([11, 12, 13])
2253
+ expect(context.inc(number: 10).collect(&:number)).to eql([ 11, 12, 13 ])
2538
2254
  end
2539
2255
  end
2540
2256
 
2541
- describe "#skip" do
2542
-
2257
+ describe '#skip' do
2543
2258
  let(:hobrecht) do
2544
- Address.new(street: "hobrecht")
2259
+ Address.new(street: 'hobrecht')
2545
2260
  end
2546
2261
 
2547
2262
  let(:friedel) do
2548
- Address.new(street: "friedel")
2263
+ Address.new(street: 'friedel')
2549
2264
  end
2550
2265
 
2551
2266
  let(:pfluger) do
2552
- Address.new(street: "pfluger")
2267
+ Address.new(street: 'pfluger')
2553
2268
  end
2554
2269
 
2555
2270
  let(:criteria) do
@@ -2563,31 +2278,27 @@ describe Mongoid::Contextual::Memory do
2563
2278
  end
2564
2279
 
2565
2280
  context 'when there is no collation on the criteria' do
2566
-
2567
2281
  let!(:skip) do
2568
2282
  context.skip(1)
2569
2283
  end
2570
2284
 
2571
- it "returns the context" do
2285
+ it 'returns the context' do
2572
2286
  expect(skip).to eq(context)
2573
2287
  end
2574
2288
 
2575
- context "when asking for all documents" do
2576
-
2577
- context "when only a skip exists" do
2578
-
2579
- it "skips the correct number" do
2289
+ context 'when asking for all documents' do
2290
+ context 'when only a skip exists' do
2291
+ it 'skips the correct number' do
2580
2292
  expect(context.entries).to eq([ friedel, pfluger ])
2581
2293
  end
2582
2294
  end
2583
2295
 
2584
- context "when a skip and limit exist" do
2585
-
2296
+ context 'when a skip and limit exist' do
2586
2297
  before do
2587
2298
  skip.limit(1)
2588
2299
  end
2589
2300
 
2590
- it "applies the skip before the limit" do
2301
+ it 'applies the skip before the limit' do
2591
2302
  expect(context.entries).to eq([ friedel ])
2592
2303
  end
2593
2304
  end
@@ -2595,33 +2306,31 @@ describe Mongoid::Contextual::Memory do
2595
2306
  end
2596
2307
 
2597
2308
  context 'when there is a collation on the criteria' do
2598
-
2599
2309
  let(:criteria) do
2600
2310
  Address.all.tap do |crit|
2601
2311
  crit.documents = [ hobrecht, friedel, pfluger ]
2602
2312
  end.collation(locale: 'en_US', strength: 2)
2603
2313
  end
2604
2314
 
2605
- it "raises an exception" do
2606
- expect {
2315
+ it 'raises an exception' do
2316
+ expect do
2607
2317
  context.skip(1)
2608
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
2318
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
2609
2319
  end
2610
2320
  end
2611
2321
  end
2612
2322
 
2613
- describe "#sort" do
2614
-
2323
+ describe '#sort' do
2615
2324
  let(:hobrecht) do
2616
- Address.new(street: "hobrecht", number: 9, name: "hobrecht")
2325
+ Address.new(street: 'hobrecht', number: 9, name: 'hobrecht')
2617
2326
  end
2618
2327
 
2619
2328
  let(:friedel) do
2620
- Address.new(street: "friedel", number: 1, name: "friedel")
2329
+ Address.new(street: 'friedel', number: 1, name: 'friedel')
2621
2330
  end
2622
2331
 
2623
2332
  let(:pfluger) do
2624
- Address.new(street: "pfluger", number: 5, name: "pfluger")
2333
+ Address.new(street: 'pfluger', number: 5, name: 'pfluger')
2625
2334
  end
2626
2335
 
2627
2336
  let(:criteria) do
@@ -2634,42 +2343,37 @@ describe Mongoid::Contextual::Memory do
2634
2343
  described_class.new(criteria)
2635
2344
  end
2636
2345
 
2637
- context "when providing a single field sort" do
2638
-
2639
- context "when the sort is ascending" do
2640
-
2346
+ context 'when providing a single field sort' do
2347
+ context 'when the sort is ascending' do
2641
2348
  let!(:sorted) do
2642
2349
  context.sort(street: 1)
2643
2350
  end
2644
2351
 
2645
- it "sorts the documents" do
2352
+ it 'sorts the documents' do
2646
2353
  expect(context.entries).to eq([ friedel, hobrecht, pfluger ])
2647
2354
  end
2648
2355
 
2649
- it "returns the context" do
2356
+ it 'returns the context' do
2650
2357
  expect(sorted).to eq(context)
2651
2358
  end
2652
2359
  end
2653
2360
 
2654
- context "when the sort is descending" do
2655
-
2656
- context "when sorting on a string" do
2657
-
2361
+ context 'when the sort is descending' do
2362
+ context 'when sorting on a string' do
2658
2363
  let!(:sorted) do
2659
2364
  context.sort(street: -1)
2660
2365
  end
2661
2366
 
2662
- it "sorts the documents" do
2367
+ it 'sorts the documents' do
2663
2368
  expect(context.entries).to eq([ pfluger, hobrecht, friedel ])
2664
2369
  end
2665
2370
 
2666
- it "returns the context" do
2371
+ it 'returns the context' do
2667
2372
  expect(sorted).to eq(context)
2668
2373
  end
2669
2374
  end
2670
2375
 
2671
- context "when sorting on a time" do
2672
-
2376
+ context 'when sorting on a time' do
2673
2377
  before do
2674
2378
  pfluger.move_in = 30.days.ago
2675
2379
  hobrecht.move_in = 25.days.ago
@@ -2679,25 +2383,24 @@ describe Mongoid::Contextual::Memory do
2679
2383
  context.sort(move_in: -1)
2680
2384
  end
2681
2385
 
2682
- it "sorts the documents" do
2386
+ it 'sorts the documents' do
2683
2387
  expect(context.entries).to eq([ friedel, hobrecht, pfluger ])
2684
2388
  end
2685
2389
 
2686
- it "returns the context" do
2390
+ it 'returns the context' do
2687
2391
  expect(sorted).to eq(context)
2688
2392
  end
2689
2393
  end
2690
2394
  end
2691
2395
  end
2692
2396
 
2693
- context "when providing multiple sort fields" do
2694
-
2397
+ context 'when providing multiple sort fields' do
2695
2398
  let(:lenau) do
2696
- Address.new(street: "lenau", number: 5, name: "lenau")
2399
+ Address.new(street: 'lenau', number: 5, name: 'lenau')
2697
2400
  end
2698
2401
 
2699
2402
  let(:kampuchea_krom) do
2700
- Address.new(street: "kampuchea krom", number: 5, name: "kampuchea krom")
2403
+ Address.new(street: 'kampuchea krom', number: 5, name: 'kampuchea krom')
2701
2404
  end
2702
2405
 
2703
2406
  before do
@@ -2705,101 +2408,94 @@ describe Mongoid::Contextual::Memory do
2705
2408
  criteria.documents.unshift(kampuchea_krom)
2706
2409
  end
2707
2410
 
2708
- context "when the sort is ascending" do
2709
-
2411
+ context 'when the sort is ascending' do
2710
2412
  let!(:sorted) do
2711
2413
  context.sort(number: 1, street: 1)
2712
2414
  end
2713
2415
 
2714
- it "sorts the documents" do
2416
+ it 'sorts the documents' do
2715
2417
  expect(context.entries).to eq([ friedel, kampuchea_krom, lenau, pfluger, hobrecht ])
2716
2418
  end
2717
2419
 
2718
- it "returns the context" do
2420
+ it 'returns the context' do
2719
2421
  expect(sorted).to eq(context)
2720
2422
  end
2721
2423
  end
2722
2424
 
2723
- context "when the sort is descending" do
2724
-
2425
+ context 'when the sort is descending' do
2725
2426
  let!(:sorted) do
2726
2427
  context.sort(number: -1, street: -1)
2727
2428
  end
2728
2429
 
2729
- it "sorts the documents" do
2430
+ it 'sorts the documents' do
2730
2431
  expect(context.entries).to eq([ hobrecht, pfluger, lenau, kampuchea_krom, friedel ])
2731
2432
  end
2732
2433
 
2733
- it "returns the context" do
2434
+ it 'returns the context' do
2734
2435
  expect(sorted).to eq(context)
2735
2436
  end
2736
2437
  end
2737
2438
  end
2738
2439
 
2739
- context "when the field is nil" do
2740
-
2440
+ context 'when the field is nil' do
2741
2441
  let!(:sorted) do
2742
2442
  context.sort(state: 1)
2743
2443
  end
2744
2444
 
2745
- it "does not sort the documents" do
2445
+ it 'does not sort the documents' do
2746
2446
  expect(context.entries).to eq([ hobrecht, friedel, pfluger ])
2747
2447
  end
2748
2448
 
2749
- it "returns the context" do
2449
+ it 'returns the context' do
2750
2450
  expect(sorted).to eq(context)
2751
2451
  end
2752
2452
  end
2753
2453
 
2754
- context "with localized field" do
2755
-
2454
+ context 'with localized field' do
2756
2455
  let!(:sorted) do
2757
- context.sort("name.en" => 1)
2456
+ context.sort('name.en' => 1)
2758
2457
  end
2759
2458
 
2760
- it "sorts the documents" do
2459
+ it 'sorts the documents' do
2761
2460
  expect(context.entries).to eq([ friedel, hobrecht, pfluger ])
2762
2461
  end
2763
2462
  end
2764
2463
 
2765
2464
  context 'when there is a collation on the criteria' do
2766
-
2767
2465
  let(:criteria) do
2768
2466
  Address.all.tap do |crit|
2769
2467
  crit.documents = [ hobrecht, friedel, pfluger ]
2770
2468
  end.collation(locale: 'en_US', strength: 2)
2771
2469
  end
2772
2470
 
2773
- it "raises an exception" do
2774
- expect {
2471
+ it 'raises an exception' do
2472
+ expect do
2775
2473
  context.sort(state: 1)
2776
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
2474
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
2777
2475
  end
2778
2476
  end
2779
2477
  end
2780
2478
 
2781
- describe "#update" do
2782
-
2479
+ describe '#update' do
2783
2480
  let(:person) do
2784
2481
  Person.create!
2785
2482
  end
2786
2483
 
2787
2484
  let(:hobrecht) do
2788
- person.addresses.create!(street: "hobrecht")
2485
+ person.addresses.create!(street: 'hobrecht')
2789
2486
  end
2790
2487
 
2791
2488
  let(:friedel) do
2792
- person.addresses.create!(street: "friedel")
2489
+ person.addresses.create!(street: 'friedel')
2793
2490
  end
2794
2491
 
2795
2492
  let(:pfluger) do
2796
- person.addresses.create!(street: "pfluger")
2493
+ person.addresses.create!(street: 'pfluger')
2797
2494
  end
2798
2495
 
2799
- context "when the documents are embedded one level" do
2800
-
2496
+ context 'when the documents are embedded one level' do
2801
2497
  let(:criteria) do
2802
- Address.any_in(street: [ "hobrecht", "friedel" ]).tap do |crit|
2498
+ Address.any_in(street: %w[hobrecht friedel]).tap do |crit|
2803
2499
  crit.documents = [ hobrecht, friedel, pfluger ]
2804
2500
  end
2805
2501
  end
@@ -2808,60 +2504,56 @@ describe Mongoid::Contextual::Memory do
2808
2504
  described_class.new(criteria)
2809
2505
  end
2810
2506
 
2811
- context "when attributes are provided" do
2812
-
2507
+ context 'when attributes are provided' do
2813
2508
  before do
2814
2509
  context.update(number: 5)
2815
2510
  end
2816
2511
 
2817
- it "updates the first matching document" do
2512
+ it 'updates the first matching document' do
2818
2513
  expect(hobrecht.number).to eq(5)
2819
2514
  end
2820
2515
 
2821
- it "does not update the last matching document" do
2516
+ it 'does not update the last matching document' do
2822
2517
  expect(friedel.number).to be_nil
2823
2518
  end
2824
2519
 
2825
- it "does not update non matching docs" do
2520
+ it 'does not update non matching docs' do
2826
2521
  expect(pfluger.number).to be_nil
2827
2522
  end
2828
2523
 
2829
- context "when reloading the embedded documents" do
2830
-
2831
- it "updates the first matching document" do
2524
+ context 'when reloading the embedded documents' do
2525
+ it 'updates the first matching document' do
2832
2526
  expect(hobrecht.reload.number).to eq(5)
2833
2527
  end
2834
2528
 
2835
- it "updates the last matching document" do
2529
+ it 'updates the last matching document' do
2836
2530
  expect(friedel.reload.number).to be_nil
2837
2531
  end
2838
2532
 
2839
- it "does not update non matching docs" do
2533
+ it 'does not update non matching docs' do
2840
2534
  expect(pfluger.reload.number).to be_nil
2841
2535
  end
2842
2536
  end
2843
2537
  end
2844
2538
 
2845
- context "when no attributes are provided" do
2846
-
2847
- it "returns false" do
2539
+ context 'when no attributes are provided' do
2540
+ it 'returns false' do
2848
2541
  expect(context.update).to be false
2849
2542
  end
2850
2543
  end
2851
2544
  end
2852
2545
 
2853
- context "when the documents are embedded multiple levels" do
2854
-
2546
+ context 'when the documents are embedded multiple levels' do
2855
2547
  let!(:home) do
2856
- hobrecht.locations.create!(name: "home")
2548
+ hobrecht.locations.create!(name: 'home')
2857
2549
  end
2858
2550
 
2859
2551
  let!(:work) do
2860
- hobrecht.locations.create!(name: "work")
2552
+ hobrecht.locations.create!(name: 'work')
2861
2553
  end
2862
2554
 
2863
2555
  let(:criteria) do
2864
- Location.where(name: "work").tap do |crit|
2556
+ Location.where(name: 'work').tap do |crit|
2865
2557
  crit.documents = [ home, work ]
2866
2558
  end
2867
2559
  end
@@ -2870,87 +2562,80 @@ describe Mongoid::Contextual::Memory do
2870
2562
  described_class.new(criteria)
2871
2563
  end
2872
2564
 
2873
- context "when attributes are provided" do
2874
-
2565
+ context 'when attributes are provided' do
2875
2566
  before do
2876
2567
  context.update(number: 5)
2877
2568
  end
2878
2569
 
2879
- it "updates the first matching document" do
2570
+ it 'updates the first matching document' do
2880
2571
  expect(work.number).to eq(5)
2881
2572
  end
2882
2573
 
2883
- it "does not update non matching docs" do
2574
+ it 'does not update non matching docs' do
2884
2575
  expect(home.number).to be_nil
2885
2576
  end
2886
2577
 
2887
- context "when reloading the embedded documents" do
2888
-
2889
- it "updates the first matching document" do
2578
+ context 'when reloading the embedded documents' do
2579
+ it 'updates the first matching document' do
2890
2580
  expect(work.reload.number).to eq(5)
2891
2581
  end
2892
2582
 
2893
- it "does not update non matching docs" do
2583
+ it 'does not update non matching docs' do
2894
2584
  expect(home.reload.number).to be_nil
2895
2585
  end
2896
2586
  end
2897
2587
  end
2898
2588
 
2899
- context "when no attributes are provided" do
2900
-
2901
- it "returns false" do
2589
+ context 'when no attributes are provided' do
2590
+ it 'returns false' do
2902
2591
  expect(context.update).to be false
2903
2592
  end
2904
2593
  end
2905
2594
  end
2906
2595
 
2907
2596
  context 'when there is a collation on the criteria' do
2908
-
2909
2597
  let(:criteria) do
2910
2598
  Address.all.collation(locale: 'en_US', strength: 2)
2911
2599
  end
2912
2600
 
2913
- it "raises an exception" do
2914
- expect {
2601
+ it 'raises an exception' do
2602
+ expect do
2915
2603
  context.update
2916
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
2604
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
2917
2605
  end
2918
2606
  end
2919
2607
  end
2920
2608
 
2921
- describe "#update_all" do
2922
-
2609
+ describe '#update_all' do
2923
2610
  let(:person) do
2924
2611
  Person.create!
2925
2612
  end
2926
2613
 
2927
2614
  let(:hobrecht) do
2928
- person.addresses.create!(street: "hobrecht")
2615
+ person.addresses.create!(street: 'hobrecht')
2929
2616
  end
2930
2617
 
2931
2618
  let(:friedel) do
2932
- person.addresses.create!(street: "friedel")
2619
+ person.addresses.create!(street: 'friedel')
2933
2620
  end
2934
2621
 
2935
2622
  let(:pfluger) do
2936
- person.addresses.create!(street: "pfluger")
2623
+ person.addresses.create!(street: 'pfluger')
2937
2624
  end
2938
2625
 
2939
2626
  context 'when there is a collation on the criteria' do
2940
-
2941
2627
  let(:criteria) do
2942
2628
  Address.all.collation(locale: 'en_US', strength: 2)
2943
2629
  end
2944
2630
 
2945
- it "raises an exception" do
2946
- expect {
2631
+ it 'raises an exception' do
2632
+ expect do
2947
2633
  context.update_all({})
2948
- }.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
2634
+ end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
2949
2635
  end
2950
2636
  end
2951
2637
 
2952
- context "when the documents are empty" do
2953
-
2638
+ context 'when the documents are empty' do
2954
2639
  let(:person_two) do
2955
2640
  Person.create!
2956
2641
  end
@@ -2963,15 +2648,14 @@ describe Mongoid::Contextual::Memory do
2963
2648
  described_class.new(criteria)
2964
2649
  end
2965
2650
 
2966
- it "returns false" do
2651
+ it 'returns false' do
2967
2652
  expect(context.update_all({})).to be false
2968
2653
  end
2969
2654
  end
2970
2655
 
2971
- context "when the documents are embedded one level" do
2972
-
2656
+ context 'when the documents are embedded one level' do
2973
2657
  let(:criteria) do
2974
- Address.any_in(street: [ "hobrecht", "friedel" ]).tap do |crit|
2658
+ Address.any_in(street: %w[hobrecht friedel]).tap do |crit|
2975
2659
  crit.documents = [ hobrecht, friedel, pfluger ]
2976
2660
  end
2977
2661
  end
@@ -2980,90 +2664,84 @@ describe Mongoid::Contextual::Memory do
2980
2664
  described_class.new(criteria)
2981
2665
  end
2982
2666
 
2983
- context "when providing aliased fields" do
2984
-
2667
+ context 'when providing aliased fields' do
2985
2668
  before do
2986
- context.update_all(suite: "10B")
2669
+ context.update_all(suite: '10B')
2987
2670
  end
2988
2671
 
2989
- it "updates the first matching document" do
2990
- expect(hobrecht.suite).to eq("10B")
2672
+ it 'updates the first matching document' do
2673
+ expect(hobrecht.suite).to eq('10B')
2991
2674
  end
2992
2675
 
2993
- it "updates the last matching document" do
2994
- expect(friedel.suite).to eq("10B")
2676
+ it 'updates the last matching document' do
2677
+ expect(friedel.suite).to eq('10B')
2995
2678
  end
2996
2679
 
2997
- it "does not update non matching docs" do
2680
+ it 'does not update non matching docs' do
2998
2681
  expect(pfluger.suite).to be_nil
2999
2682
  end
3000
2683
  end
3001
2684
 
3002
- context "when attributes are provided" do
3003
-
2685
+ context 'when attributes are provided' do
3004
2686
  before do
3005
2687
  context.update_all(number: 5)
3006
2688
  end
3007
2689
 
3008
- it "updates the first matching document" do
2690
+ it 'updates the first matching document' do
3009
2691
  expect(hobrecht.number).to eq(5)
3010
2692
  end
3011
2693
 
3012
- it "updates the last matching document" do
2694
+ it 'updates the last matching document' do
3013
2695
  expect(friedel.number).to eq(5)
3014
2696
  end
3015
2697
 
3016
- it "does not update non matching docs" do
2698
+ it 'does not update non matching docs' do
3017
2699
  expect(pfluger.number).to be_nil
3018
2700
  end
3019
2701
 
3020
- context "when reloading the embedded documents" do
3021
-
3022
- it "updates the first matching document" do
2702
+ context 'when reloading the embedded documents' do
2703
+ it 'updates the first matching document' do
3023
2704
  expect(hobrecht.reload.number).to eq(5)
3024
2705
  end
3025
2706
 
3026
- it "updates the last matching document" do
2707
+ it 'updates the last matching document' do
3027
2708
  expect(friedel.reload.number).to eq(5)
3028
2709
  end
3029
2710
 
3030
- it "does not update non matching docs" do
2711
+ it 'does not update non matching docs' do
3031
2712
  expect(pfluger.reload.number).to be_nil
3032
2713
  end
3033
2714
  end
3034
2715
 
3035
- context "when updating the documents a second time" do
3036
-
2716
+ context 'when updating the documents a second time' do
3037
2717
  before do
3038
2718
  context.update_all(number: 5)
3039
2719
  end
3040
2720
 
3041
- it "does not error on the update" do
2721
+ it 'does not error on the update' do
3042
2722
  expect(hobrecht.number).to eq(5)
3043
2723
  end
3044
2724
  end
3045
2725
  end
3046
2726
 
3047
- context "when no attributes are provided" do
3048
-
3049
- it "returns false" do
2727
+ context 'when no attributes are provided' do
2728
+ it 'returns false' do
3050
2729
  expect(context.update_all).to be false
3051
2730
  end
3052
2731
  end
3053
2732
  end
3054
2733
 
3055
- context "when the documents are embedded multiple levels" do
3056
-
2734
+ context 'when the documents are embedded multiple levels' do
3057
2735
  let!(:home) do
3058
- hobrecht.locations.create!(name: "home")
2736
+ hobrecht.locations.create!(name: 'home')
3059
2737
  end
3060
2738
 
3061
2739
  let!(:work) do
3062
- hobrecht.locations.create!(name: "work")
2740
+ hobrecht.locations.create!(name: 'work')
3063
2741
  end
3064
2742
 
3065
2743
  let(:criteria) do
3066
- Location.where(name: "work").tap do |crit|
2744
+ Location.where(name: 'work').tap do |crit|
3067
2745
  crit.documents = [ home, work ]
3068
2746
  end
3069
2747
  end
@@ -3072,35 +2750,32 @@ describe Mongoid::Contextual::Memory do
3072
2750
  described_class.new(criteria)
3073
2751
  end
3074
2752
 
3075
- context "when attributes are provided" do
3076
-
2753
+ context 'when attributes are provided' do
3077
2754
  before do
3078
2755
  context.update_all(number: 5)
3079
2756
  end
3080
2757
 
3081
- it "updates the first matching document" do
2758
+ it 'updates the first matching document' do
3082
2759
  expect(work.number).to eq(5)
3083
2760
  end
3084
2761
 
3085
- it "does not update non matching docs" do
2762
+ it 'does not update non matching docs' do
3086
2763
  expect(home.number).to be_nil
3087
2764
  end
3088
2765
 
3089
- context "when reloading the embedded documents" do
3090
-
3091
- it "updates the first matching document" do
2766
+ context 'when reloading the embedded documents' do
2767
+ it 'updates the first matching document' do
3092
2768
  expect(work.reload.number).to eq(5)
3093
2769
  end
3094
2770
 
3095
- it "does not update non matching docs" do
2771
+ it 'does not update non matching docs' do
3096
2772
  expect(home.reload.number).to be_nil
3097
2773
  end
3098
2774
  end
3099
2775
  end
3100
2776
 
3101
- context "when no attributes are provided" do
3102
-
3103
- it "returns false" do
2777
+ context 'when no attributes are provided' do
2778
+ it 'returns false' do
3104
2779
  expect(context.update_all).to be false
3105
2780
  end
3106
2781
  end