mongoid 9.0.11 → 9.1.0

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