mongoid 9.0.12 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1006) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -8
  3. data/README.md +5 -11
  4. data/Rakefile +35 -38
  5. data/lib/config/locales/en.yml +11 -45
  6. data/lib/mongoid/association/accessors.rb +19 -26
  7. data/lib/mongoid/association/bindable.rb +43 -45
  8. data/lib/mongoid/association/builders.rb +18 -15
  9. data/lib/mongoid/association/constrainable.rb +3 -5
  10. data/lib/mongoid/association/depending.rb +38 -46
  11. data/lib/mongoid/association/eager.rb +47 -13
  12. data/lib/mongoid/association/eager_loadable.rb +152 -24
  13. data/lib/mongoid/association/embedded/batchable.rb +28 -30
  14. data/lib/mongoid/association/embedded/cyclic.rb +8 -11
  15. data/lib/mongoid/association/embedded/eager.rb +1 -6
  16. data/lib/mongoid/association/embedded/embedded_in/binding.rb +6 -9
  17. data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -3
  18. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -0
  19. data/lib/mongoid/association/embedded/embedded_in.rb +25 -22
  20. data/lib/mongoid/association/embedded/embeds_many/binding.rb +0 -2
  21. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +2 -3
  22. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +1 -1
  23. data/lib/mongoid/association/embedded/embeds_many.rb +24 -21
  24. data/lib/mongoid/association/embedded/embeds_one/binding.rb +0 -2
  25. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +2 -6
  26. data/lib/mongoid/association/embedded/embeds_one.rb +20 -18
  27. data/lib/mongoid/association/embedded.rb +0 -1
  28. data/lib/mongoid/association/macros.rb +3 -7
  29. data/lib/mongoid/association/many.rb +75 -3
  30. data/lib/mongoid/association/marshalable.rb +0 -3
  31. data/lib/mongoid/association/nested/many.rb +23 -47
  32. data/lib/mongoid/association/nested/nested_buildable.rb +6 -23
  33. data/lib/mongoid/association/nested/one.rb +4 -7
  34. data/lib/mongoid/association/nested.rb +1 -3
  35. data/lib/mongoid/association/one.rb +0 -3
  36. data/lib/mongoid/association/options.rb +8 -7
  37. data/lib/mongoid/association/referenced/auto_save.rb +0 -2
  38. data/lib/mongoid/association/referenced/belongs_to/binding.rb +11 -15
  39. data/lib/mongoid/association/referenced/belongs_to/buildable.rb +23 -5
  40. data/lib/mongoid/association/referenced/belongs_to/eager.rb +1 -3
  41. data/lib/mongoid/association/referenced/belongs_to.rb +48 -43
  42. data/lib/mongoid/association/referenced/counter_cache.rb +5 -10
  43. data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +0 -2
  44. data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +8 -4
  45. data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +0 -3
  46. data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +52 -47
  47. data/lib/mongoid/association/referenced/has_many/binding.rb +0 -2
  48. data/lib/mongoid/association/referenced/has_many/buildable.rb +11 -5
  49. data/lib/mongoid/association/referenced/has_many/eager.rb +0 -3
  50. data/lib/mongoid/association/referenced/has_many/enumerable.rb +107 -38
  51. data/lib/mongoid/association/referenced/has_many/proxy.rb +11 -106
  52. data/lib/mongoid/association/referenced/has_many.rb +30 -24
  53. data/lib/mongoid/association/referenced/has_one/binding.rb +0 -2
  54. data/lib/mongoid/association/referenced/has_one/buildable.rb +11 -9
  55. data/lib/mongoid/association/referenced/has_one/eager.rb +0 -3
  56. data/lib/mongoid/association/referenced/has_one.rb +26 -21
  57. data/lib/mongoid/association/referenced/syncable.rb +30 -34
  58. data/lib/mongoid/association/referenced.rb +0 -1
  59. data/lib/mongoid/association/reflections.rb +0 -3
  60. data/lib/mongoid/association/relatable.rb +69 -83
  61. data/lib/mongoid/association.rb +12 -15
  62. data/lib/mongoid/atomic/modifiers.rb +65 -25
  63. data/lib/mongoid/atomic/paths/embedded/many.rb +4 -7
  64. data/lib/mongoid/atomic/paths/embedded/one.rb +2 -4
  65. data/lib/mongoid/atomic/paths/embedded.rb +3 -6
  66. data/lib/mongoid/atomic/paths/root.rb +1 -4
  67. data/lib/mongoid/atomic/paths.rb +2 -3
  68. data/lib/mongoid/atomic.rb +0 -3
  69. data/lib/mongoid/attributes/dynamic.rb +6 -7
  70. data/lib/mongoid/attributes/nested.rb +8 -10
  71. data/lib/mongoid/attributes/projector.rb +7 -20
  72. data/lib/mongoid/attributes/readonly.rb +6 -11
  73. data/lib/mongoid/attributes.rb +18 -34
  74. data/lib/mongoid/cacheable.rb +24 -6
  75. data/lib/mongoid/clients/factory.rb +12 -15
  76. data/lib/mongoid/clients/options.rb +2 -5
  77. data/lib/mongoid/clients/sessions.rb +50 -60
  78. data/lib/mongoid/clients/storage_options.rb +1 -4
  79. data/lib/mongoid/clients/validators/storage.rb +2 -3
  80. data/lib/mongoid/clients/validators.rb +1 -2
  81. data/lib/mongoid/clients.rb +8 -11
  82. data/lib/mongoid/collection_configurable.rb +10 -22
  83. data/lib/mongoid/composable.rb +30 -34
  84. data/lib/mongoid/config/defaults.rb +7 -4
  85. data/lib/mongoid/config/encryption.rb +19 -39
  86. data/lib/mongoid/config/environment.rb +7 -16
  87. data/lib/mongoid/config/introspection.rb +14 -16
  88. data/lib/mongoid/config/options.rb +16 -10
  89. data/lib/mongoid/config/validators/async_query_executor.rb +3 -6
  90. data/lib/mongoid/config/validators/client.rb +12 -15
  91. data/lib/mongoid/config/validators/option.rb +3 -5
  92. data/lib/mongoid/config/validators.rb +3 -4
  93. data/lib/mongoid/config.rb +127 -84
  94. data/lib/mongoid/contextual/aggregable/memory.rb +4 -9
  95. data/lib/mongoid/contextual/aggregable/mongo.rb +20 -22
  96. data/lib/mongoid/contextual/aggregable/none.rb +2 -4
  97. data/lib/mongoid/contextual/aggregable.rb +5 -7
  98. data/lib/mongoid/contextual/atomic.rb +20 -24
  99. data/lib/mongoid/contextual/command.rb +0 -3
  100. data/lib/mongoid/contextual/map_reduce.rb +12 -16
  101. data/lib/mongoid/contextual/memory.rb +76 -80
  102. data/lib/mongoid/contextual/mongo/documents_loader.rb +2 -3
  103. data/lib/mongoid/contextual/mongo.rb +169 -85
  104. data/lib/mongoid/contextual/none.rb +9 -9
  105. data/lib/mongoid/contextual/queryable.rb +1 -4
  106. data/lib/mongoid/contextual.rb +18 -7
  107. data/lib/mongoid/copyable.rb +7 -9
  108. data/lib/mongoid/criteria/findable.rb +5 -7
  109. data/lib/mongoid/criteria/includable.rb +37 -8
  110. data/lib/mongoid/criteria/inspectable.rb +2 -5
  111. data/lib/mongoid/criteria/marshalable.rb +4 -8
  112. data/lib/mongoid/criteria/modifiable.rb +3 -11
  113. data/lib/mongoid/criteria/options.rb +0 -3
  114. data/lib/mongoid/criteria/permission.rb +34 -37
  115. data/lib/mongoid/criteria/queryable/aggregable.rb +9 -10
  116. data/lib/mongoid/criteria/queryable/expandable.rb +4 -9
  117. data/lib/mongoid/criteria/queryable/extensions/array.rb +7 -10
  118. data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +3 -5
  119. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -4
  120. data/lib/mongoid/criteria/queryable/extensions/date.rb +2 -6
  121. data/lib/mongoid/criteria/queryable/extensions/date_time.rb +3 -7
  122. data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -4
  123. data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +20 -11
  124. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +15 -11
  125. data/lib/mongoid/criteria/queryable/extensions/object.rb +7 -8
  126. data/lib/mongoid/criteria/queryable/extensions/range.rb +6 -9
  127. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +10 -12
  128. data/lib/mongoid/criteria/queryable/extensions/set.rb +4 -6
  129. data/lib/mongoid/criteria/queryable/extensions/string.rb +5 -9
  130. data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -7
  131. data/lib/mongoid/criteria/queryable/extensions/time.rb +2 -6
  132. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +2 -12
  133. data/lib/mongoid/criteria/queryable/extensions.rb +18 -21
  134. data/lib/mongoid/criteria/queryable/key.rb +12 -18
  135. data/lib/mongoid/criteria/queryable/macroable.rb +0 -3
  136. data/lib/mongoid/criteria/queryable/mergeable.rb +31 -43
  137. data/lib/mongoid/criteria/queryable/optional.rb +17 -18
  138. data/lib/mongoid/criteria/queryable/options.rb +20 -9
  139. data/lib/mongoid/criteria/queryable/pipeline.rb +6 -9
  140. data/lib/mongoid/criteria/queryable/selectable.rb +130 -301
  141. data/lib/mongoid/criteria/queryable/selector.rb +20 -29
  142. data/lib/mongoid/criteria/queryable/smash.rb +1 -6
  143. data/lib/mongoid/criteria/queryable/storable.rb +20 -39
  144. data/lib/mongoid/criteria/queryable.rb +25 -15
  145. data/lib/mongoid/criteria/scopable.rb +5 -11
  146. data/lib/mongoid/criteria/translator.rb +5 -8
  147. data/lib/mongoid/criteria.rb +109 -54
  148. data/lib/mongoid/deprecable.rb +1 -4
  149. data/lib/mongoid/deprecation.rb +2 -6
  150. data/lib/mongoid/document.rb +1 -1
  151. data/lib/mongoid/encryptable.rb +1 -48
  152. data/lib/mongoid/equality.rb +4 -5
  153. data/lib/mongoid/errors/ambiguous_relationship.rb +2 -5
  154. data/lib/mongoid/errors/attribute_not_loaded.rb +1 -4
  155. data/lib/mongoid/errors/callback.rb +1 -4
  156. data/lib/mongoid/errors/create_collection_failure.rb +8 -11
  157. data/lib/mongoid/errors/criteria_argument_required.rb +2 -5
  158. data/lib/mongoid/errors/delete_restriction.rb +1 -4
  159. data/lib/mongoid/errors/document_not_destroyed.rb +1 -4
  160. data/lib/mongoid/errors/document_not_found.rb +16 -21
  161. data/lib/mongoid/errors/drop_collection_failure.rb +7 -10
  162. data/lib/mongoid/errors/empty_config_file.rb +1 -4
  163. data/lib/mongoid/errors/immutable_attribute.rb +1 -4
  164. data/lib/mongoid/errors/in_memory_collation_not_supported.rb +1 -4
  165. data/lib/mongoid/errors/invalid_async_query_executor.rb +2 -5
  166. data/lib/mongoid/errors/invalid_auto_encryption_configuration.rb +2 -5
  167. data/lib/mongoid/errors/invalid_collection.rb +1 -3
  168. data/lib/mongoid/errors/invalid_config_file.rb +1 -4
  169. data/lib/mongoid/errors/invalid_config_option.rb +2 -5
  170. data/lib/mongoid/errors/invalid_dependent_strategy.rb +6 -10
  171. data/lib/mongoid/errors/invalid_discriminator_key_target.rb +2 -4
  172. data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +1 -4
  173. data/lib/mongoid/errors/invalid_elem_match_operator.rb +5 -9
  174. data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +1 -4
  175. data/lib/mongoid/errors/invalid_estimated_count_scoping.rb +1 -4
  176. data/lib/mongoid/errors/invalid_expression_operator.rb +3 -7
  177. data/lib/mongoid/errors/invalid_field.rb +2 -5
  178. data/lib/mongoid/errors/invalid_field_operator.rb +5 -9
  179. data/lib/mongoid/errors/invalid_field_option.rb +2 -5
  180. data/lib/mongoid/errors/invalid_field_type.rb +1 -4
  181. data/lib/mongoid/errors/invalid_find.rb +1 -4
  182. data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +1 -4
  183. data/lib/mongoid/errors/invalid_includes.rb +3 -6
  184. data/lib/mongoid/errors/invalid_index.rb +1 -4
  185. data/lib/mongoid/errors/invalid_options.rb +1 -4
  186. data/lib/mongoid/errors/invalid_path.rb +1 -4
  187. data/lib/mongoid/errors/invalid_persistence_option.rb +4 -7
  188. data/lib/mongoid/errors/invalid_query.rb +6 -11
  189. data/lib/mongoid/errors/invalid_relation.rb +10 -13
  190. data/lib/mongoid/errors/invalid_relation_option.rb +4 -7
  191. data/lib/mongoid/errors/invalid_scope.rb +1 -4
  192. data/lib/mongoid/errors/invalid_session_nesting.rb +0 -3
  193. data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +2 -4
  194. data/lib/mongoid/errors/invalid_storage_options.rb +1 -4
  195. data/lib/mongoid/errors/invalid_time.rb +1 -4
  196. data/lib/mongoid/errors/invalid_transaction_nesting.rb +0 -3
  197. data/lib/mongoid/errors/inverse_not_found.rb +1 -4
  198. data/lib/mongoid/errors/mixed_client_configuration.rb +1 -4
  199. data/lib/mongoid/errors/mixed_relations.rb +1 -3
  200. data/lib/mongoid/errors/mongoid_error.rb +7 -11
  201. data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -4
  202. data/lib/mongoid/errors/no_client_config.rb +1 -4
  203. data/lib/mongoid/errors/no_client_database.rb +1 -4
  204. data/lib/mongoid/errors/no_client_hosts.rb +1 -4
  205. data/lib/mongoid/errors/no_clients_config.rb +1 -4
  206. data/lib/mongoid/errors/no_default_client.rb +1 -4
  207. data/lib/mongoid/errors/no_environment.rb +1 -4
  208. data/lib/mongoid/errors/no_map_reduce_output.rb +1 -4
  209. data/lib/mongoid/errors/no_metadata.rb +1 -4
  210. data/lib/mongoid/errors/no_parent.rb +1 -4
  211. data/lib/mongoid/errors/readonly_attribute.rb +1 -4
  212. data/lib/mongoid/errors/readonly_document.rb +1 -4
  213. data/lib/mongoid/errors/rollback.rb +0 -2
  214. data/lib/mongoid/errors/scope_overwrite.rb +2 -4
  215. data/lib/mongoid/errors/sessions_not_supported.rb +0 -3
  216. data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -3
  217. data/lib/mongoid/errors/transaction_error.rb +0 -3
  218. data/lib/mongoid/errors/transactions_not_supported.rb +0 -3
  219. data/lib/mongoid/errors/unknown_attribute.rb +1 -4
  220. data/lib/mongoid/errors/unknown_model.rb +1 -4
  221. data/lib/mongoid/errors/unregistered_class.rb +1 -1
  222. data/lib/mongoid/errors/unsaved_document.rb +1 -3
  223. data/lib/mongoid/errors/unsupported_isolation_level.rb +22 -0
  224. data/lib/mongoid/errors/unsupported_javascript.rb +1 -4
  225. data/lib/mongoid/errors/validations.rb +3 -5
  226. data/lib/mongoid/errors.rb +72 -74
  227. data/lib/mongoid/evolvable.rb +0 -3
  228. data/lib/mongoid/extensions/array.rb +5 -7
  229. data/lib/mongoid/extensions/big_decimal.rb +6 -7
  230. data/lib/mongoid/extensions/binary.rb +3 -6
  231. data/lib/mongoid/extensions/boolean.rb +4 -7
  232. data/lib/mongoid/extensions/bson_document.rb +28 -0
  233. data/lib/mongoid/extensions/date.rb +10 -14
  234. data/lib/mongoid/extensions/date_time.rb +2 -6
  235. data/lib/mongoid/extensions/decimal128.rb +1 -5
  236. data/lib/mongoid/extensions/false_class.rb +3 -5
  237. data/lib/mongoid/extensions/float.rb +5 -10
  238. data/lib/mongoid/extensions/hash.rb +5 -10
  239. data/lib/mongoid/extensions/integer.rb +5 -10
  240. data/lib/mongoid/extensions/module.rb +1 -4
  241. data/lib/mongoid/extensions/nil_class.rb +0 -1
  242. data/lib/mongoid/extensions/object.rb +9 -14
  243. data/lib/mongoid/extensions/object_id.rb +2 -6
  244. data/lib/mongoid/extensions/range.rb +14 -15
  245. data/lib/mongoid/extensions/raw_value.rb +0 -3
  246. data/lib/mongoid/extensions/regexp.rb +3 -6
  247. data/lib/mongoid/extensions/set.rb +3 -4
  248. data/lib/mongoid/extensions/string.rb +8 -12
  249. data/lib/mongoid/extensions/symbol.rb +3 -7
  250. data/lib/mongoid/extensions/time.rb +24 -26
  251. data/lib/mongoid/extensions/time_with_zone.rb +4 -7
  252. data/lib/mongoid/extensions/true_class.rb +3 -5
  253. data/lib/mongoid/extensions.rb +26 -26
  254. data/lib/mongoid/factory.rb +5 -9
  255. data/lib/mongoid/fields/encrypted.rb +0 -1
  256. data/lib/mongoid/fields/foreign_key.rb +9 -10
  257. data/lib/mongoid/fields/localized.rb +12 -12
  258. data/lib/mongoid/fields/standard.rb +5 -7
  259. data/lib/mongoid/fields/validators/macro.rb +23 -34
  260. data/lib/mongoid/fields/validators.rb +1 -2
  261. data/lib/mongoid/fields.rb +151 -58
  262. data/lib/mongoid/findable.rb +82 -53
  263. data/lib/mongoid/indexable/specification.rb +20 -6
  264. data/lib/mongoid/indexable/validators/options.rb +33 -40
  265. data/lib/mongoid/indexable.rb +41 -52
  266. data/lib/mongoid/inspectable.rb +4 -7
  267. data/lib/mongoid/interceptable.rb +41 -40
  268. data/lib/mongoid/loadable.rb +17 -18
  269. data/lib/mongoid/loggable.rb +4 -8
  270. data/lib/mongoid/matchable.rb +1 -8
  271. data/lib/mongoid/matcher/all.rb +2 -5
  272. data/lib/mongoid/matcher/and.rb +0 -3
  273. data/lib/mongoid/matcher/bits.rb +13 -8
  274. data/lib/mongoid/matcher/bits_all_clear.rb +1 -3
  275. data/lib/mongoid/matcher/bits_all_set.rb +1 -3
  276. data/lib/mongoid/matcher/bits_any_clear.rb +1 -3
  277. data/lib/mongoid/matcher/bits_any_set.rb +1 -3
  278. data/lib/mongoid/matcher/elem_match.rb +13 -15
  279. data/lib/mongoid/matcher/elem_match_expression.rb +0 -3
  280. data/lib/mongoid/matcher/eq.rb +0 -3
  281. data/lib/mongoid/matcher/eq_impl.rb +12 -17
  282. data/lib/mongoid/matcher/eq_impl_with_regexp.rb +4 -2
  283. data/lib/mongoid/matcher/exists.rb +1 -4
  284. data/lib/mongoid/matcher/expression.rb +5 -10
  285. data/lib/mongoid/matcher/expression_operator.rb +1 -3
  286. data/lib/mongoid/matcher/field_expression.rb +10 -13
  287. data/lib/mongoid/matcher/field_operator.rb +4 -6
  288. data/lib/mongoid/matcher/gt.rb +0 -3
  289. data/lib/mongoid/matcher/gte.rb +0 -3
  290. data/lib/mongoid/matcher/in.rb +9 -12
  291. data/lib/mongoid/matcher/lt.rb +0 -3
  292. data/lib/mongoid/matcher/lte.rb +0 -3
  293. data/lib/mongoid/matcher/mod.rb +4 -8
  294. data/lib/mongoid/matcher/ne.rb +0 -3
  295. data/lib/mongoid/matcher/nin.rb +0 -3
  296. data/lib/mongoid/matcher/nor.rb +1 -6
  297. data/lib/mongoid/matcher/not.rb +0 -3
  298. data/lib/mongoid/matcher/or.rb +0 -3
  299. data/lib/mongoid/matcher/regex.rb +12 -11
  300. data/lib/mongoid/matcher/size.rb +2 -5
  301. data/lib/mongoid/matcher/type.rb +32 -37
  302. data/lib/mongoid/matcher.rb +7 -16
  303. data/lib/mongoid/model_resolver.rb +1 -0
  304. data/lib/mongoid/persistable/creatable.rb +23 -7
  305. data/lib/mongoid/persistable/deletable.rb +6 -7
  306. data/lib/mongoid/persistable/destroyable.rb +2 -6
  307. data/lib/mongoid/persistable/incrementable.rb +1 -3
  308. data/lib/mongoid/persistable/logical.rb +3 -5
  309. data/lib/mongoid/persistable/maxable.rb +2 -4
  310. data/lib/mongoid/persistable/minable.rb +2 -4
  311. data/lib/mongoid/persistable/multipliable.rb +1 -3
  312. data/lib/mongoid/persistable/poppable.rb +2 -4
  313. data/lib/mongoid/persistable/pullable.rb +3 -5
  314. data/lib/mongoid/persistable/pushable.rb +5 -7
  315. data/lib/mongoid/persistable/renamable.rb +1 -3
  316. data/lib/mongoid/persistable/savable.rb +0 -3
  317. data/lib/mongoid/persistable/settable.rb +4 -13
  318. data/lib/mongoid/persistable/unsettable.rb +1 -3
  319. data/lib/mongoid/persistable/updatable.rb +16 -24
  320. data/lib/mongoid/persistable/upsertable.rb +8 -10
  321. data/lib/mongoid/persistable.rb +28 -27
  322. data/lib/mongoid/persistence_context.rb +34 -76
  323. data/lib/mongoid/pluckable.rb +0 -2
  324. data/lib/mongoid/positional.rb +5 -11
  325. data/lib/mongoid/railtie.rb +16 -22
  326. data/lib/mongoid/railties/console_sandbox.rb +6 -8
  327. data/lib/mongoid/railties/controller_runtime.rb +7 -11
  328. data/lib/mongoid/railties/database.rake +42 -44
  329. data/lib/mongoid/scopable.rb +23 -31
  330. data/lib/mongoid/search_indexable.rb +337 -14
  331. data/lib/mongoid/selectable.rb +1 -3
  332. data/lib/mongoid/serializable.rb +6 -8
  333. data/lib/mongoid/shardable.rb +8 -17
  334. data/lib/mongoid/stateful.rb +5 -10
  335. data/lib/mongoid/stringified_symbol.rb +5 -9
  336. data/lib/mongoid/tasks/database.rake +31 -32
  337. data/lib/mongoid/tasks/database.rb +37 -53
  338. data/lib/mongoid/tasks/encryption.rb +10 -15
  339. data/lib/mongoid/threaded/lifecycle.rb +6 -9
  340. data/lib/mongoid/threaded.rb +132 -69
  341. data/lib/mongoid/timestamps/created/short.rb +2 -3
  342. data/lib/mongoid/timestamps/created.rb +1 -2
  343. data/lib/mongoid/timestamps/short.rb +0 -1
  344. data/lib/mongoid/timestamps/timeless.rb +8 -13
  345. data/lib/mongoid/timestamps/updated/short.rb +2 -3
  346. data/lib/mongoid/timestamps/updated.rb +2 -5
  347. data/lib/mongoid/timestamps.rb +4 -6
  348. data/lib/mongoid/touchable.rb +19 -11
  349. data/lib/mongoid/traversable.rb +3 -2
  350. data/lib/mongoid/validatable/associated.rb +1 -5
  351. data/lib/mongoid/validatable/format.rb +0 -2
  352. data/lib/mongoid/validatable/length.rb +0 -2
  353. data/lib/mongoid/validatable/localizable.rb +0 -3
  354. data/lib/mongoid/validatable/macros.rb +0 -2
  355. data/lib/mongoid/validatable/numericality.rb +24 -3
  356. data/lib/mongoid/validatable/presence.rb +8 -10
  357. data/lib/mongoid/validatable/queryable.rb +0 -3
  358. data/lib/mongoid/validatable/uniqueness.rb +12 -14
  359. data/lib/mongoid/validatable.rb +15 -20
  360. data/lib/mongoid/version.rb +1 -1
  361. data/lib/mongoid/warnings.rb +10 -11
  362. data/lib/mongoid.rb +30 -34
  363. data/lib/rails/generators/mongoid/config/config_generator.rb +2 -4
  364. data/lib/rails/generators/mongoid/config/templates/mongoid.rb +4 -5
  365. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +2 -2
  366. data/lib/rails/generators/mongoid/model/model_generator.rb +5 -8
  367. data/lib/rails/generators/mongoid_generator.rb +6 -10
  368. data/lib/rails/mongoid.rb +1 -3
  369. data/spec/integration/active_job_spec.rb +1 -2
  370. data/spec/integration/app_spec.rb +142 -185
  371. data/spec/integration/associations/belongs_to_spec.rb +30 -28
  372. data/spec/integration/associations/embedded_dirty_spec.rb +0 -1
  373. data/spec/integration/associations/embedded_spec.rb +41 -43
  374. data/spec/integration/associations/embeds_many_spec.rb +46 -29
  375. data/spec/integration/associations/embeds_one_spec.rb +2 -1
  376. data/spec/integration/associations/foreign_key_spec.rb +10 -11
  377. data/spec/integration/associations/foreign_key_spec_models.rb +8 -9
  378. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +18 -30
  379. data/spec/integration/associations/has_many_spec.rb +17 -18
  380. data/spec/integration/associations/has_one_spec.rb +42 -45
  381. data/spec/integration/associations/nested_attributes_assignment_spec.rb +36 -39
  382. data/spec/integration/associations/reverse_population_spec.rb +4 -5
  383. data/spec/integration/associations/reverse_population_spec_models.rb +0 -1
  384. data/spec/integration/associations/scope_option_spec.rb +18 -20
  385. data/spec/integration/atomic/modifiers_spec.rb +72 -52
  386. data/spec/integration/bson_regexp_raw_spec.rb +2 -3
  387. data/spec/integration/caching_spec.rb +68 -0
  388. data/spec/integration/callbacks_models.rb +11 -9
  389. data/spec/integration/callbacks_spec.rb +78 -80
  390. data/spec/integration/contextual/empty_spec.rb +19 -20
  391. data/spec/integration/criteria/alias_query_spec.rb +12 -19
  392. data/spec/integration/criteria/date_field_spec.rb +1 -2
  393. data/spec/integration/criteria/default_scope_spec.rb +23 -18
  394. data/spec/integration/criteria/logical_spec.rb +18 -19
  395. data/spec/integration/criteria/range_spec.rb +77 -86
  396. data/spec/integration/criteria/raw_value_spec.rb +122 -109
  397. data/spec/integration/criteria/time_with_zone_spec.rb +33 -24
  398. data/spec/integration/discriminator_key_spec.rb +85 -85
  399. data/spec/integration/discriminator_value_spec.rb +70 -73
  400. data/spec/integration/document_spec.rb +9 -10
  401. data/spec/integration/dots_and_dollars_spec.rb +105 -130
  402. data/spec/integration/encryption_spec.rb +8 -160
  403. data/spec/integration/i18n_fallbacks_spec.rb +7 -8
  404. data/spec/integration/isolation_state_spec.rb +241 -0
  405. data/spec/integration/matcher_examples_spec.rb +145 -168
  406. data/spec/integration/matcher_operator_data/in.yml +6 -6
  407. data/spec/integration/matcher_operator_data/regex.yml +0 -21
  408. data/spec/integration/matcher_operator_spec.rb +16 -26
  409. data/spec/integration/matcher_spec.rb +31 -32
  410. data/spec/integration/persistence/collection_options_spec.rb +0 -2
  411. data/spec/integration/persistence/range_field_spec.rb +24 -2
  412. data/spec/integration/server_query_spec.rb +43 -37
  413. data/spec/integration/shardable_spec.rb +10 -11
  414. data/spec/integration/stringified_symbol_field_spec.rb +28 -43
  415. data/spec/lite_spec_helper.rb +11 -12
  416. data/spec/mongoid/association/accessors_spec.rb +197 -285
  417. data/spec/mongoid/association/auto_save_spec.rb +62 -93
  418. data/spec/mongoid/association/builders_spec.rb +121 -74
  419. data/spec/mongoid/association/constrainable_spec.rb +9 -22
  420. data/spec/mongoid/association/counter_cache_spec.rb +71 -104
  421. data/spec/mongoid/association/depending_spec.rb +166 -208
  422. data/spec/mongoid/association/eager_spec.rb +416 -80
  423. data/spec/mongoid/association/embedded/cyclic_spec.rb +36 -48
  424. data/spec/mongoid/association/embedded/dirty_spec.rb +15 -20
  425. data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +36 -54
  426. data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +8 -15
  427. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +135 -175
  428. data/spec/mongoid/association/embedded/embedded_in_spec.rb +25 -127
  429. data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +9 -14
  430. data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +38 -51
  431. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +1151 -1340
  432. data/spec/mongoid/association/embedded/embeds_many_models.rb +17 -17
  433. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +11 -11
  434. data/spec/mongoid/association/embedded/embeds_many_spec.rb +25 -138
  435. data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +15 -23
  436. data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +18 -26
  437. data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +204 -273
  438. data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +0 -1
  439. data/spec/mongoid/association/embedded/embeds_one_models.rb +0 -1
  440. data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +5 -6
  441. data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -143
  442. data/spec/mongoid/association/macros_spec.rb +213 -300
  443. data/spec/mongoid/association/nested/many_spec.rb +51 -73
  444. data/spec/mongoid/association/nested/one_spec.rb +56 -80
  445. data/spec/mongoid/association/options_spec.rb +187 -310
  446. data/spec/mongoid/association/polymorphic_spec.rb +35 -53
  447. data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +55 -76
  448. data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +36 -41
  449. data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +81 -101
  450. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +258 -345
  451. data/spec/mongoid/association/referenced/belongs_to_models.rb +4 -3
  452. data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +3 -4
  453. data/spec/mongoid/association/referenced/belongs_to_spec.rb +91 -294
  454. data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +42 -56
  455. data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +41 -32
  456. data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +36 -42
  457. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +8 -9
  458. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +771 -1023
  459. data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +9 -9
  460. data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +5 -6
  461. data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +59 -177
  462. data/spec/mongoid/association/referenced/has_many/binding_spec.rb +29 -43
  463. data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +53 -53
  464. data/spec/mongoid/association/referenced/has_many/eager_spec.rb +104 -67
  465. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +431 -675
  466. data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -2
  467. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +173 -156
  468. data/spec/mongoid/association/referenced/has_many_models.rb +1 -2
  469. data/spec/mongoid/association/referenced/has_many_query_spec.rb +3 -4
  470. data/spec/mongoid/association/referenced/has_many_spec.rb +44 -188
  471. data/spec/mongoid/association/referenced/has_one/binding_spec.rb +26 -38
  472. data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +28 -29
  473. data/spec/mongoid/association/referenced/has_one/eager_spec.rb +29 -42
  474. data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +270 -332
  475. data/spec/mongoid/association/referenced/has_one_models.rb +1 -2
  476. data/spec/mongoid/association/referenced/has_one_query_spec.rb +3 -4
  477. data/spec/mongoid/association/referenced/has_one_spec.rb +40 -188
  478. data/spec/mongoid/association/reflections_spec.rb +14 -24
  479. data/spec/mongoid/association/syncable_spec.rb +102 -125
  480. data/spec/mongoid/association_spec.rb +47 -70
  481. data/spec/mongoid/atomic/modifiers_spec.rb +184 -197
  482. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +39 -52
  483. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +35 -49
  484. data/spec/mongoid/atomic/paths/root_spec.rb +9 -15
  485. data/spec/mongoid/atomic/paths_spec.rb +81 -117
  486. data/spec/mongoid/atomic_spec.rb +156 -171
  487. data/spec/mongoid/attributes/dynamic_spec.rb +5 -6
  488. data/spec/mongoid/attributes/nested_spec.rb +1221 -1888
  489. data/spec/mongoid/attributes/nested_spec_models.rb +8 -9
  490. data/spec/mongoid/attributes/projector_spec.rb +2 -6
  491. data/spec/mongoid/attributes/readonly_spec.rb +73 -97
  492. data/spec/mongoid/attributes_spec.rb +669 -826
  493. data/spec/mongoid/cacheable_spec.rb +74 -44
  494. data/spec/mongoid/changeable_spec.rb +591 -733
  495. data/spec/mongoid/clients/factory_spec.rb +122 -154
  496. data/spec/mongoid/clients/options_spec.rb +40 -59
  497. data/spec/mongoid/clients/sessions_spec.rb +25 -44
  498. data/spec/mongoid/clients/transactions_spec.rb +33 -50
  499. data/spec/mongoid/clients/transactions_spec_models.rb +3 -4
  500. data/spec/mongoid/clients_spec.rb +265 -355
  501. data/spec/mongoid/collection_configurable_spec.rb +9 -12
  502. data/spec/mongoid/composable_spec.rb +2 -9
  503. data/spec/mongoid/config/defaults_spec.rb +24 -49
  504. data/spec/mongoid/config/encryption_spec.rb +53 -284
  505. data/spec/mongoid/config/environment_spec.rb +30 -40
  506. data/spec/mongoid/config/introspection_spec.rb +42 -37
  507. data/spec/mongoid/config/options_spec.rb +14 -21
  508. data/spec/mongoid/config_spec.rb +145 -195
  509. data/spec/mongoid/contextual/aggregable/memory_spec.rb +98 -226
  510. data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +4 -7
  511. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +149 -187
  512. data/spec/mongoid/contextual/aggregable/none_spec.rb +14 -16
  513. data/spec/mongoid/contextual/atomic_spec.rb +223 -271
  514. data/spec/mongoid/contextual/map_reduce_spec.rb +110 -138
  515. data/spec/mongoid/contextual/memory_spec.rb +706 -1031
  516. data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +12 -13
  517. data/spec/mongoid/contextual/mongo_spec.rb +1008 -1213
  518. data/spec/mongoid/contextual/none_spec.rb +54 -59
  519. data/spec/mongoid/contextual/short_circuit_spec.rb +139 -0
  520. data/spec/mongoid/copyable_spec.rb +254 -300
  521. data/spec/mongoid/copyable_spec_models.rb +0 -1
  522. data/spec/mongoid/criteria/findable_spec.rb +322 -387
  523. data/spec/mongoid/criteria/includable_spec.rb +421 -372
  524. data/spec/mongoid/criteria/includable_spec_models.rb +16 -7
  525. data/spec/mongoid/criteria/inspectable_spec.rb +11 -14
  526. data/spec/mongoid/criteria/marshalable_spec.rb +11 -14
  527. data/spec/mongoid/criteria/modifiable_spec.rb +366 -512
  528. data/spec/mongoid/criteria/options_spec.rb +2 -7
  529. data/spec/mongoid/criteria/queryable/aggregable_spec.rb +112 -141
  530. data/spec/mongoid/criteria/queryable/expandable_spec.rb +8 -11
  531. data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +127 -184
  532. data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +123 -60
  533. data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +84 -117
  534. data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +44 -65
  535. data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +86 -108
  536. data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +94 -33
  537. data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +103 -138
  538. data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +95 -34
  539. data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +25 -38
  540. data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +26 -28
  541. data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +32 -54
  542. data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +136 -130
  543. data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +16 -24
  544. data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +15 -24
  545. data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +12 -19
  546. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +46 -63
  547. data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +28 -42
  548. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +73 -96
  549. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +71 -92
  550. data/spec/mongoid/criteria/queryable/key_spec.rb +32 -36
  551. data/spec/mongoid/criteria/queryable/mergeable_spec.rb +44 -49
  552. data/spec/mongoid/criteria/queryable/optional_spec.rb +373 -486
  553. data/spec/mongoid/criteria/queryable/options_spec.rb +172 -123
  554. data/spec/mongoid/criteria/queryable/pipeline_spec.rb +65 -87
  555. data/spec/mongoid/criteria/queryable/queryable_spec.rb +41 -53
  556. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +576 -682
  557. data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +7 -11
  558. data/spec/mongoid/criteria/queryable/selectable_spec.rb +807 -998
  559. data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +154 -391
  560. data/spec/mongoid/criteria/queryable/selector_spec.rb +294 -390
  561. data/spec/mongoid/criteria/queryable/smash_spec.rb +6 -11
  562. data/spec/mongoid/criteria/queryable/storable_spec.rb +54 -81
  563. data/spec/mongoid/criteria/queryable_mql_spec.rb +92 -0
  564. data/spec/mongoid/criteria/scopable_spec.rb +102 -138
  565. data/spec/mongoid/criteria/translator_spec.rb +59 -60
  566. data/spec/mongoid/criteria_projection_spec.rb +81 -99
  567. data/spec/mongoid/criteria_spec.rb +935 -952
  568. data/spec/mongoid/document_fields_spec.rb +28 -30
  569. data/spec/mongoid/document_persistence_context_spec.rb +13 -15
  570. data/spec/mongoid/document_query_spec.rb +9 -12
  571. data/spec/mongoid/document_spec.rb +317 -409
  572. data/spec/mongoid/equality_spec.rb +69 -102
  573. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +8 -11
  574. data/spec/mongoid/errors/attribute_not_loaded_spec.rb +7 -10
  575. data/spec/mongoid/errors/callback_spec.rb +8 -11
  576. data/spec/mongoid/errors/delete_restriction_spec.rb +5 -8
  577. data/spec/mongoid/errors/document_not_destroyed_spec.rb +7 -10
  578. data/spec/mongoid/errors/document_not_found_spec.rb +51 -61
  579. data/spec/mongoid/errors/invalid_collection_spec.rb +9 -13
  580. data/spec/mongoid/errors/invalid_config_file_spec.rb +8 -11
  581. data/spec/mongoid/errors/invalid_config_option_spec.rb +8 -11
  582. data/spec/mongoid/errors/invalid_field_option_spec.rb +7 -10
  583. data/spec/mongoid/errors/invalid_field_spec.rb +10 -11
  584. data/spec/mongoid/errors/invalid_field_type_spec.rb +9 -12
  585. data/spec/mongoid/errors/invalid_find_spec.rb +8 -11
  586. data/spec/mongoid/errors/invalid_includes_spec.rb +9 -13
  587. data/spec/mongoid/errors/invalid_index_spec.rb +8 -11
  588. data/spec/mongoid/errors/invalid_options_spec.rb +8 -11
  589. data/spec/mongoid/errors/invalid_path_spec.rb +7 -10
  590. data/spec/mongoid/errors/invalid_relation_spec.rb +15 -16
  591. data/spec/mongoid/errors/invalid_scope_spec.rb +8 -11
  592. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -6
  593. data/spec/mongoid/errors/invalid_storage_options_spec.rb +8 -11
  594. data/spec/mongoid/errors/invalid_time_spec.rb +8 -11
  595. data/spec/mongoid/errors/inverse_not_found_spec.rb +9 -12
  596. data/spec/mongoid/errors/mixed_client_configuration_spec.rb +9 -12
  597. data/spec/mongoid/errors/mixed_relations_spec.rb +8 -11
  598. data/spec/mongoid/errors/mongoid_error_spec.rb +21 -24
  599. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +6 -9
  600. data/spec/mongoid/errors/no_client_config_spec.rb +7 -10
  601. data/spec/mongoid/errors/no_client_database_spec.rb +9 -12
  602. data/spec/mongoid/errors/no_client_hosts_spec.rb +9 -12
  603. data/spec/mongoid/errors/no_clients_config_spec.rb +7 -10
  604. data/spec/mongoid/errors/no_environment_spec.rb +8 -11
  605. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +8 -11
  606. data/spec/mongoid/errors/no_metadata_spec.rb +7 -10
  607. data/spec/mongoid/errors/no_parent_spec.rb +7 -10
  608. data/spec/mongoid/errors/readonly_attribute_spec.rb +7 -10
  609. data/spec/mongoid/errors/readonly_document_spec.rb +6 -9
  610. data/spec/mongoid/errors/scope_overwrite_spec.rb +9 -12
  611. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +9 -12
  612. data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -8
  613. data/spec/mongoid/errors/unsaved_document_spec.rb +8 -11
  614. data/spec/mongoid/errors/unsupported_javascript_spec.rb +9 -12
  615. data/spec/mongoid/errors/validations_spec.rb +11 -14
  616. data/spec/mongoid/extensions/array_spec.rb +70 -92
  617. data/spec/mongoid/extensions/big_decimal_spec.rb +233 -313
  618. data/spec/mongoid/extensions/binary_spec.rb +21 -32
  619. data/spec/mongoid/extensions/boolean_spec.rb +52 -75
  620. data/spec/mongoid/extensions/date_class_mongoize_spec.rb +43 -54
  621. data/spec/mongoid/extensions/date_spec.rb +26 -38
  622. data/spec/mongoid/extensions/date_time_spec.rb +22 -32
  623. data/spec/mongoid/extensions/decimal128_spec.rb +12 -18
  624. data/spec/mongoid/extensions/false_class_spec.rb +10 -17
  625. data/spec/mongoid/extensions/float_spec.rb +40 -61
  626. data/spec/mongoid/extensions/hash_spec.rb +46 -64
  627. data/spec/mongoid/extensions/integer_spec.rb +40 -61
  628. data/spec/mongoid/extensions/module_spec.rb +13 -18
  629. data/spec/mongoid/extensions/nil_class_spec.rb +2 -5
  630. data/spec/mongoid/extensions/object_id_spec.rb +159 -247
  631. data/spec/mongoid/extensions/object_spec.rb +31 -47
  632. data/spec/mongoid/extensions/range_spec.rb +112 -115
  633. data/spec/mongoid/extensions/raw_value_spec.rb +10 -12
  634. data/spec/mongoid/extensions/regexp_spec.rb +23 -36
  635. data/spec/mongoid/extensions/set_spec.rb +38 -49
  636. data/spec/mongoid/extensions/string_spec.rb +118 -167
  637. data/spec/mongoid/extensions/stringified_symbol_spec.rb +29 -43
  638. data/spec/mongoid/extensions/symbol_spec.rb +12 -20
  639. data/spec/mongoid/extensions/time_spec.rb +160 -202
  640. data/spec/mongoid/extensions/time_with_zone_spec.rb +79 -105
  641. data/spec/mongoid/extensions/true_class_spec.rb +10 -17
  642. data/spec/mongoid/factory_spec.rb +125 -148
  643. data/spec/mongoid/fields/foreign_key_spec.rb +124 -169
  644. data/spec/mongoid/fields/localized_spec.rb +140 -185
  645. data/spec/mongoid/fields/standard_spec.rb +43 -59
  646. data/spec/mongoid/fields_spec.rb +751 -620
  647. data/spec/mongoid/findable_spec.rb +260 -228
  648. data/spec/mongoid/indexable/specification_spec.rb +42 -58
  649. data/spec/mongoid/indexable_spec.rb +260 -264
  650. data/spec/mongoid/inspectable_spec.rb +45 -55
  651. data/spec/mongoid/interceptable_spec.rb +784 -922
  652. data/spec/mongoid/interceptable_spec_models.rb +35 -35
  653. data/spec/mongoid/loading_spec.rb +47 -43
  654. data/spec/mongoid/loggable_spec.rb +3 -6
  655. data/spec/mongoid/matcher/extract_attribute_spec.rb +2 -6
  656. data/spec/mongoid/mongoizable_spec.rb +81 -90
  657. data/spec/mongoid/monkey_patches_spec.rb +4 -0
  658. data/spec/mongoid/persistable/creatable_spec.rb +181 -220
  659. data/spec/mongoid/persistable/deletable_spec.rb +139 -179
  660. data/spec/mongoid/persistable/destroyable_spec.rb +135 -164
  661. data/spec/mongoid/persistable/incrementable_spec.rb +65 -84
  662. data/spec/mongoid/persistable/logical_spec.rb +48 -61
  663. data/spec/mongoid/persistable/maxable_spec.rb +45 -44
  664. data/spec/mongoid/persistable/minable_spec.rb +45 -44
  665. data/spec/mongoid/persistable/multipliable_spec.rb +54 -69
  666. data/spec/mongoid/persistable/poppable_spec.rb +47 -60
  667. data/spec/mongoid/persistable/pullable_spec.rb +79 -103
  668. data/spec/mongoid/persistable/pushable_spec.rb +106 -131
  669. data/spec/mongoid/persistable/renamable_spec.rb +52 -65
  670. data/spec/mongoid/persistable/savable_spec.rb +152 -189
  671. data/spec/mongoid/persistable/settable_spec.rb +121 -145
  672. data/spec/mongoid/persistable/unsettable_spec.rb +56 -73
  673. data/spec/mongoid/persistable/updatable_spec.rb +185 -232
  674. data/spec/mongoid/persistable/upsertable_spec.rb +66 -77
  675. data/spec/mongoid/persistable_spec.rb +132 -139
  676. data/spec/mongoid/persistence_context_spec.rb +31 -89
  677. data/spec/mongoid/positional_spec.rb +67 -79
  678. data/spec/mongoid/railties/bson_object_id_serializer_spec.rb +0 -3
  679. data/spec/mongoid/railties/console_sandbox_spec.rb +0 -1
  680. data/spec/mongoid/relations/proxy_spec.rb +0 -1
  681. data/spec/mongoid/reloadable_spec.rb +250 -145
  682. data/spec/mongoid/scopable_spec.rb +319 -398
  683. data/spec/mongoid/search_indexable_spec.rb +446 -41
  684. data/spec/mongoid/selectable_spec.rb +36 -51
  685. data/spec/mongoid/serializable_spec.rb +269 -312
  686. data/spec/mongoid/shardable_models.rb +5 -5
  687. data/spec/mongoid/shardable_spec.rb +44 -46
  688. data/spec/mongoid/stateful_spec.rb +55 -75
  689. data/spec/mongoid/tasks/database_rake_spec.rb +138 -141
  690. data/spec/mongoid/tasks/database_spec.rb +80 -98
  691. data/spec/mongoid/tasks/encryption_spec.rb +22 -20
  692. data/spec/mongoid/threaded_spec.rb +57 -83
  693. data/spec/mongoid/timestamps/created/short_spec.rb +12 -16
  694. data/spec/mongoid/timestamps/created_spec.rb +16 -20
  695. data/spec/mongoid/timestamps/timeless_spec.rb +31 -43
  696. data/spec/mongoid/timestamps/updated/short_spec.rb +21 -28
  697. data/spec/mongoid/timestamps/updated_spec.rb +18 -25
  698. data/spec/mongoid/timestamps_spec.rb +171 -188
  699. data/spec/mongoid/timestamps_spec_models.rb +12 -13
  700. data/spec/mongoid/touchable_spec.rb +330 -294
  701. data/spec/mongoid/touchable_spec_models.rb +35 -37
  702. data/spec/mongoid/traversable_spec.rb +435 -471
  703. data/spec/mongoid/validatable/associated_spec.rb +42 -60
  704. data/spec/mongoid/validatable/format_spec.rb +24 -34
  705. data/spec/mongoid/validatable/length_spec.rb +62 -86
  706. data/spec/mongoid/validatable/numericality_spec.rb +114 -23
  707. data/spec/mongoid/validatable/presence_spec.rb +149 -203
  708. data/spec/mongoid/validatable/uniqueness_spec.rb +632 -830
  709. data/spec/mongoid/validatable_spec.rb +71 -103
  710. data/spec/mongoid/warnings_spec.rb +5 -9
  711. data/spec/mongoid_spec.rb +25 -41
  712. data/spec/rails/controller_extension/controller_runtime_spec.rb +45 -49
  713. data/spec/rails/mongoid_spec.rb +15 -15
  714. data/spec/shared/lib/mrss/cluster_config.rb +5 -40
  715. data/spec/shared/lib/mrss/constraints.rb +7 -46
  716. data/spec/shared/lib/mrss/docker_runner.rb +10 -21
  717. data/spec/shared/lib/mrss/eg_config_utils.rb +0 -31
  718. data/spec/shared/lib/mrss/release/candidate.rb +18 -12
  719. data/spec/shared/lib/mrss/server_version_registry.rb +1 -5
  720. data/spec/shared/share/Dockerfile.erb +6 -8
  721. data/spec/shared/shlib/server.sh +0 -50
  722. data/spec/shared/shlib/set_env.sh +4 -10
  723. data/spec/spec_helper.rb +54 -31
  724. data/spec/support/authorization.rb +0 -1
  725. data/spec/support/client_registry.rb +1 -2
  726. data/spec/support/constraints.rb +8 -25
  727. data/spec/support/crypt/models.rb +7 -165
  728. data/spec/support/crypt.rb +6 -9
  729. data/spec/support/expectations.rb +21 -7
  730. data/spec/support/feature_sandbox.rb +1 -4
  731. data/spec/support/helpers.rb +0 -1
  732. data/spec/support/immutable_ids.rb +20 -21
  733. data/spec/support/macros.rb +1 -3
  734. data/spec/support/models/account.rb +4 -5
  735. data/spec/support/models/acolyte.rb +5 -5
  736. data/spec/support/models/actor.rb +3 -3
  737. data/spec/support/models/actress.rb +0 -1
  738. data/spec/support/models/address.rb +11 -11
  739. data/spec/support/models/address_component.rb +1 -1
  740. data/spec/support/models/address_number.rb +1 -1
  741. data/spec/support/models/agency.rb +1 -1
  742. data/spec/support/models/agent.rb +1 -1
  743. data/spec/support/models/album.rb +1 -2
  744. data/spec/support/models/alert.rb +1 -1
  745. data/spec/support/models/animal.rb +4 -5
  746. data/spec/support/models/answer.rb +1 -1
  747. data/spec/support/models/appointment.rb +2 -2
  748. data/spec/support/models/armrest.rb +0 -1
  749. data/spec/support/models/array_field.rb +0 -1
  750. data/spec/support/models/article.rb +0 -1
  751. data/spec/support/models/artist.rb +16 -12
  752. data/spec/support/models/artwork.rb +1 -1
  753. data/spec/support/models/audible_sound.rb +0 -1
  754. data/spec/support/models/audio.rb +2 -2
  755. data/spec/support/models/augmentation.rb +1 -2
  756. data/spec/support/models/author.rb +1 -1
  757. data/spec/support/models/baby.rb +1 -1
  758. data/spec/support/models/band.rb +0 -1
  759. data/spec/support/models/bar.rb +2 -2
  760. data/spec/support/models/basic.rb +0 -1
  761. data/spec/support/models/bed.rb +0 -1
  762. data/spec/support/models/big_palette.rb +0 -1
  763. data/spec/support/models/birthday.rb +3 -5
  764. data/spec/support/models/bolt.rb +0 -1
  765. data/spec/support/models/bomb.rb +1 -1
  766. data/spec/support/models/book.rb +1 -1
  767. data/spec/support/models/breed.rb +1 -1
  768. data/spec/support/models/browser.rb +1 -2
  769. data/spec/support/models/building.rb +0 -1
  770. data/spec/support/models/building_address.rb +1 -1
  771. data/spec/support/models/bus.rb +1 -1
  772. data/spec/support/models/business.rb +2 -2
  773. data/spec/support/models/callback_test.rb +1 -1
  774. data/spec/support/models/canvas.rb +5 -6
  775. data/spec/support/models/car.rb +0 -1
  776. data/spec/support/models/cat.rb +0 -2
  777. data/spec/support/models/catalog.rb +0 -1
  778. data/spec/support/models/category.rb +1 -1
  779. data/spec/support/models/child.rb +1 -1
  780. data/spec/support/models/child_doc.rb +5 -6
  781. data/spec/support/models/church.rb +1 -1
  782. data/spec/support/models/circle.rb +0 -1
  783. data/spec/support/models/circuit.rb +2 -2
  784. data/spec/support/models/circus.rb +0 -1
  785. data/spec/support/models/code.rb +2 -1
  786. data/spec/support/models/coding/pull_request.rb +0 -1
  787. data/spec/support/models/coding.rb +0 -1
  788. data/spec/support/models/comment.rb +0 -1
  789. data/spec/support/models/company.rb +0 -1
  790. data/spec/support/models/consumption_period.rb +0 -1
  791. data/spec/support/models/contextable_item.rb +1 -1
  792. data/spec/support/models/contractor.rb +1 -1
  793. data/spec/support/models/cookie.rb +0 -1
  794. data/spec/support/models/country_code.rb +2 -3
  795. data/spec/support/models/courier_job.rb +2 -2
  796. data/spec/support/models/cover.rb +0 -1
  797. data/spec/support/models/crate.rb +0 -1
  798. data/spec/support/models/customer.rb +0 -1
  799. data/spec/support/models/customer_address.rb +0 -1
  800. data/spec/support/models/deed.rb +1 -1
  801. data/spec/support/models/definition.rb +1 -1
  802. data/spec/support/models/delegating_patient.rb +0 -1
  803. data/spec/support/models/description.rb +0 -1
  804. data/spec/support/models/dictionary.rb +1 -1
  805. data/spec/support/models/division.rb +2 -2
  806. data/spec/support/models/doctor.rb +0 -1
  807. data/spec/support/models/dog.rb +2 -2
  808. data/spec/support/models/dokument.rb +1 -1
  809. data/spec/support/models/draft.rb +0 -1
  810. data/spec/support/models/dragon.rb +1 -1
  811. data/spec/support/models/driver.rb +2 -2
  812. data/spec/support/models/drug.rb +1 -1
  813. data/spec/support/models/dungeon.rb +1 -1
  814. data/spec/support/models/edit.rb +1 -1
  815. data/spec/support/models/email.rb +1 -1
  816. data/spec/support/models/employer.rb +1 -2
  817. data/spec/support/models/entry.rb +1 -1
  818. data/spec/support/models/eraser.rb +0 -1
  819. data/spec/support/models/even.rb +1 -1
  820. data/spec/support/models/event.rb +3 -4
  821. data/spec/support/models/exhibition.rb +1 -1
  822. data/spec/support/models/exhibitor.rb +1 -1
  823. data/spec/support/models/explosion.rb +1 -1
  824. data/spec/support/models/eye.rb +0 -1
  825. data/spec/support/models/eye_bowl.rb +2 -3
  826. data/spec/support/models/face.rb +2 -3
  827. data/spec/support/models/fanatic.rb +1 -1
  828. data/spec/support/models/favorite.rb +1 -1
  829. data/spec/support/models/filesystem.rb +1 -1
  830. data/spec/support/models/fire_hydrant.rb +1 -1
  831. data/spec/support/models/firefox.rb +0 -1
  832. data/spec/support/models/fish.rb +0 -1
  833. data/spec/support/models/folder.rb +0 -2
  834. data/spec/support/models/folder_item.rb +1 -3
  835. data/spec/support/models/fruits.rb +9 -5
  836. data/spec/support/models/game.rb +3 -4
  837. data/spec/support/models/ghost.rb +0 -1
  838. data/spec/support/models/guitar.rb +0 -1
  839. data/spec/support/models/hole.rb +0 -1
  840. data/spec/support/models/home.rb +1 -1
  841. data/spec/support/models/house.rb +2 -2
  842. data/spec/support/models/html_writer.rb +0 -1
  843. data/spec/support/models/id_key.rb +3 -3
  844. data/spec/support/models/idnodef.rb +0 -1
  845. data/spec/support/models/image.rb +0 -1
  846. data/spec/support/models/implant.rb +1 -2
  847. data/spec/support/models/instrument.rb +2 -3
  848. data/spec/support/models/item.rb +2 -2
  849. data/spec/support/models/jar.rb +1 -2
  850. data/spec/support/models/kaleidoscope.rb +1 -1
  851. data/spec/support/models/kangaroo.rb +1 -1
  852. data/spec/support/models/label.rb +2 -2
  853. data/spec/support/models/language.rb +1 -1
  854. data/spec/support/models/lat_lng.rb +0 -1
  855. data/spec/support/models/league.rb +1 -1
  856. data/spec/support/models/learner.rb +0 -1
  857. data/spec/support/models/line_item.rb +1 -1
  858. data/spec/support/models/location.rb +1 -1
  859. data/spec/support/models/login.rb +1 -2
  860. data/spec/support/models/manufacturer.rb +0 -1
  861. data/spec/support/models/meat.rb +1 -1
  862. data/spec/support/models/membership.rb +1 -1
  863. data/spec/support/models/message.rb +1 -2
  864. data/spec/support/models/minim.rb +0 -1
  865. data/spec/support/models/mixed_drink.rb +1 -1
  866. data/spec/support/models/modifier_models.rb +25 -0
  867. data/spec/support/models/mop.rb +0 -1
  868. data/spec/support/models/movie.rb +1 -1
  869. data/spec/support/models/my_hash.rb +1 -2
  870. data/spec/support/models/name.rb +4 -5
  871. data/spec/support/models/name_only.rb +0 -1
  872. data/spec/support/models/node.rb +1 -1
  873. data/spec/support/models/note.rb +3 -3
  874. data/spec/support/models/nut.rb +0 -1
  875. data/spec/support/models/odd.rb +1 -1
  876. data/spec/support/models/order.rb +1 -1
  877. data/spec/support/models/ordered_post.rb +1 -1
  878. data/spec/support/models/ordered_preference.rb +1 -1
  879. data/spec/support/models/oscar.rb +1 -1
  880. data/spec/support/models/other_owner_object.rb +0 -1
  881. data/spec/support/models/override.rb +3 -11
  882. data/spec/support/models/ownable.rb +1 -1
  883. data/spec/support/models/owner.rb +1 -1
  884. data/spec/support/models/pack.rb +0 -1
  885. data/spec/support/models/page.rb +3 -3
  886. data/spec/support/models/page_question.rb +1 -1
  887. data/spec/support/models/palette.rb +2 -2
  888. data/spec/support/models/parent.rb +2 -2
  889. data/spec/support/models/parent_doc.rb +1 -1
  890. data/spec/support/models/passport.rb +0 -1
  891. data/spec/support/models/patient.rb +2 -2
  892. data/spec/support/models/pdf_writer.rb +0 -1
  893. data/spec/support/models/pencil.rb +0 -1
  894. data/spec/support/models/person.rb +32 -28
  895. data/spec/support/models/pet.rb +1 -1
  896. data/spec/support/models/pet_owner.rb +1 -1
  897. data/spec/support/models/phone.rb +1 -2
  898. data/spec/support/models/piano.rb +0 -1
  899. data/spec/support/models/pizza.rb +1 -1
  900. data/spec/support/models/player.rb +5 -5
  901. data/spec/support/models/post.rb +12 -12
  902. data/spec/support/models/post_genre.rb +1 -1
  903. data/spec/support/models/powerup.rb +1 -2
  904. data/spec/support/models/preference.rb +2 -2
  905. data/spec/support/models/princess.rb +1 -1
  906. data/spec/support/models/product.rb +3 -3
  907. data/spec/support/models/profile.rb +2 -1
  908. data/spec/support/models/pronunciation.rb +1 -1
  909. data/spec/support/models/pub.rb +2 -2
  910. data/spec/support/models/publication/encyclopedia.rb +0 -1
  911. data/spec/support/models/publication/review.rb +0 -1
  912. data/spec/support/models/publication.rb +0 -1
  913. data/spec/support/models/purchase.rb +1 -1
  914. data/spec/support/models/purchased_item.rb +1 -1
  915. data/spec/support/models/question.rb +2 -2
  916. data/spec/support/models/quiz.rb +1 -1
  917. data/spec/support/models/rating.rb +1 -1
  918. data/spec/support/models/record.rb +2 -3
  919. data/spec/support/models/registry.rb +1 -1
  920. data/spec/support/models/role.rb +1 -1
  921. data/spec/support/models/root_category.rb +1 -1
  922. data/spec/support/models/sandbox/app/models/app_models_message.rb +0 -1
  923. data/spec/support/models/sandbox/lib/models/lib_models_message.rb +0 -1
  924. data/spec/support/models/sandbox/sandbox_message.rb +0 -1
  925. data/spec/support/models/sandbox/sandbox_user.rb +0 -1
  926. data/spec/support/models/sandbox/subdir/sandbox_comment.rb +0 -1
  927. data/spec/support/models/sandwich.rb +1 -1
  928. data/spec/support/models/scheduler.rb +0 -1
  929. data/spec/support/models/school.rb +0 -1
  930. data/spec/support/models/scribe.rb +1 -1
  931. data/spec/support/models/sealer.rb +0 -1
  932. data/spec/support/models/seat.rb +0 -1
  933. data/spec/support/models/seo.rb +1 -1
  934. data/spec/support/models/series.rb +1 -1
  935. data/spec/support/models/server.rb +1 -1
  936. data/spec/support/models/service.rb +2 -2
  937. data/spec/support/models/shape.rb +3 -3
  938. data/spec/support/models/shelf.rb +1 -1
  939. data/spec/support/models/shield.rb +2 -2
  940. data/spec/support/models/shipment_address.rb +0 -1
  941. data/spec/support/models/shipping_container.rb +1 -1
  942. data/spec/support/models/shipping_pack.rb +0 -1
  943. data/spec/support/models/shirt.rb +0 -1
  944. data/spec/support/models/shop.rb +2 -2
  945. data/spec/support/models/short_agent.rb +0 -1
  946. data/spec/support/models/short_quiz.rb +1 -1
  947. data/spec/support/models/simple.rb +1 -1
  948. data/spec/support/models/slave.rb +1 -1
  949. data/spec/support/models/song.rb +1 -2
  950. data/spec/support/models/sound.rb +2 -2
  951. data/spec/support/models/spacer.rb +0 -1
  952. data/spec/support/models/square.rb +0 -1
  953. data/spec/support/models/staff.rb +0 -1
  954. data/spec/support/models/store_as_dup_test1.rb +2 -2
  955. data/spec/support/models/store_as_dup_test2.rb +1 -1
  956. data/spec/support/models/store_as_dup_test3.rb +2 -2
  957. data/spec/support/models/store_as_dup_test4.rb +1 -1
  958. data/spec/support/models/strategy.rb +0 -1
  959. data/spec/support/models/student.rb +1 -2
  960. data/spec/support/models/sub_item.rb +0 -1
  961. data/spec/support/models/subscription.rb +2 -2
  962. data/spec/support/models/survey.rb +2 -2
  963. data/spec/support/models/symptom.rb +2 -2
  964. data/spec/support/models/system_role.rb +2 -3
  965. data/spec/support/models/tag.rb +2 -2
  966. data/spec/support/models/target.rb +1 -1
  967. data/spec/support/models/template.rb +1 -1
  968. data/spec/support/models/thing.rb +1 -1
  969. data/spec/support/models/threadlocker.rb +0 -1
  970. data/spec/support/models/title.rb +0 -1
  971. data/spec/support/models/tool.rb +3 -3
  972. data/spec/support/models/topping.rb +1 -1
  973. data/spec/support/models/toy.rb +0 -1
  974. data/spec/support/models/track.rb +1 -1
  975. data/spec/support/models/translation.rb +1 -1
  976. data/spec/support/models/tree.rb +2 -3
  977. data/spec/support/models/truck.rb +0 -1
  978. data/spec/support/models/updatable.rb +0 -1
  979. data/spec/support/models/user.rb +3 -4
  980. data/spec/support/models/user_account.rb +3 -3
  981. data/spec/support/models/validation_callback.rb +4 -4
  982. data/spec/support/models/vehicle.rb +2 -3
  983. data/spec/support/models/version.rb +1 -1
  984. data/spec/support/models/vertex.rb +0 -1
  985. data/spec/support/models/vet_visit.rb +1 -1
  986. data/spec/support/models/video.rb +2 -2
  987. data/spec/support/models/video_game.rb +0 -1
  988. data/spec/support/models/washer.rb +0 -1
  989. data/spec/support/models/weapon.rb +1 -2
  990. data/spec/support/models/wiki_page.rb +2 -3
  991. data/spec/support/models/word.rb +2 -2
  992. data/spec/support/models/word_origin.rb +1 -2
  993. data/spec/support/models/writer.rb +3 -3
  994. data/spec/support/rails_mock.rb +7 -12
  995. data/spec/support/shared/time.rb +0 -1
  996. data/spec/support/sinatra_mock.rb +4 -2
  997. data/spec/support/spec_config.rb +19 -18
  998. metadata +14 -14
  999. data/lib/mongoid/errors/in_memory_regexp_timeout.rb +0 -26
  1000. data/lib/mongoid/errors/no_encryption_schema.rb +0 -28
  1001. data/lib/mongoid/field_readable.rb +0 -70
  1002. data/lib/mongoid/matcher/regexp_budget.rb +0 -383
  1003. data/spec/integration/matcher_regexp_timeout_spec.rb +0 -215
  1004. data/spec/integration/query_operator_guard_spec.rb +0 -89
  1005. data/spec/mongoid/encryptable_spec.rb +0 -61
  1006. data/spec/mongoid/matcher/regexp_budget_spec.rb +0 -570
@@ -1,36 +1,30 @@
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::Criteria::Queryable::Selectable do
7
-
8
6
  let(:query) do
9
- Mongoid::Query.new("id" => "_id")
7
+ Mongoid::Query.new('id' => '_id')
10
8
  end
11
9
 
12
10
  shared_examples_for 'returns a cloned query' do
13
-
14
- it "returns a cloned query" do
15
- expect(selection).to_not equal(query)
11
+ it 'returns a cloned query' do
12
+ expect(selection).not_to equal(query)
16
13
  end
17
14
  end
18
15
 
19
16
  # Hoisting means the operator can be elided, for example
20
17
  # Foo.and(a: 1) produces simply {'a' => 1}.
21
18
  shared_examples_for 'a hoisting logical operation' do
22
-
23
19
  let(:query) do
24
20
  Mongoid::Query.new
25
21
  end
26
22
 
27
- context "when provided a single criterion" do
28
-
23
+ context 'when provided a single criterion' do
29
24
  shared_examples_for 'adds the conditions to top level' do
30
-
31
- it "adds the conditions to top level" do
25
+ it 'adds the conditions to top level' do
32
26
  expect(selection.selector).to eq(
33
- "field" => [ 1, 2 ]
27
+ 'field' => [ 1, 2 ]
34
28
  )
35
29
  end
36
30
 
@@ -45,7 +39,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
45
39
 
46
40
  context 'when the criterion is wrapped in an array' do
47
41
  let(:selection) do
48
- query.send(tested_method, [{field: [ 1, 2 ] }])
42
+ query.send(tested_method, [ { field: [ 1, 2 ] } ])
49
43
  end
50
44
 
51
45
  it_behaves_like 'adds the conditions to top level'
@@ -53,7 +47,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
53
47
 
54
48
  context 'when the criterion is wrapped in a deep array with nil elements' do
55
49
  let(:selection) do
56
- query.send(tested_method, [[[{field: [ 1, 2 ] }]], [nil]])
50
+ query.send(tested_method, [ [ [ { field: [ 1, 2 ] } ] ], [ nil ] ])
57
51
  end
58
52
 
59
53
  it_behaves_like 'adds the conditions to top level'
@@ -74,19 +68,15 @@ describe Mongoid::Criteria::Queryable::Selectable do
74
68
  it 'combines' do
75
69
  expect(result.selector).to eq(
76
70
  'hello' => 'world',
77
- 'foo' => 'bar',
71
+ 'foo' => 'bar'
78
72
  )
79
73
  end
80
74
  end
81
75
 
82
- context "when provided a single criterion that is handled via Key" do
83
-
76
+ context 'when provided a single criterion that is handled via Key' do
84
77
  shared_examples_for 'adds the conditions to top level' do
85
-
86
- it "adds the conditions to top level" do
87
- expect(selection.selector).to eq({
88
- "field" => {'$gt' => 3},
89
- })
78
+ it 'adds the conditions to top level' do
79
+ expect(selection.selector).to eq({ 'field' => { '$gt' => 3 } })
90
80
  end
91
81
 
92
82
  it_behaves_like 'returns a cloned query'
@@ -100,7 +90,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
100
90
 
101
91
  context 'when the criterion is wrapped in an array' do
102
92
  let(:selection) do
103
- query.send(tested_method, [{ :field.gt => 3 }])
93
+ query.send(tested_method, [ { :field.gt => 3 } ])
104
94
  end
105
95
 
106
96
  it_behaves_like 'adds the conditions to top level'
@@ -108,7 +98,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
108
98
 
109
99
  context 'when the criterion is wrapped in a deep array with nil elements' do
110
100
  let(:selection) do
111
- query.send(tested_method, [[[{ :field.gt => 3 }]], [nil]])
101
+ query.send(tested_method, [ [ [ { :field.gt => 3 } ] ], [ nil ] ])
112
102
  end
113
103
 
114
104
  it_behaves_like 'adds the conditions to top level'
@@ -120,9 +110,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
120
110
  end
121
111
 
122
112
  it 'adds the conditions' do
123
- expect(selection.selector).to eq({
124
- "field" => {'$gte' => Time.new(2020, 1, 1)},
125
- })
113
+ expect(selection.selector).to eq({ 'field' => { '$gte' => Time.new(2020, 1, 1) } })
126
114
  end
127
115
 
128
116
  it 'keeps argument type' do
@@ -136,9 +124,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
136
124
  end
137
125
 
138
126
  it 'adds the conditions' do
139
- expect(selection.selector).to eq({
140
- "field" => {'$gte' => Time.utc(2020, 1, 1)},
141
- })
127
+ expect(selection.selector).to eq({ 'field' => { '$gte' => Time.utc(2020, 1, 1) } })
142
128
  end
143
129
 
144
130
  it 'converts argument to a time' do
@@ -152,9 +138,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
152
138
  end
153
139
 
154
140
  it 'adds the conditions' do
155
- expect(selection.selector).to eq({
156
- "field" => {'$gte' => Time.utc(2020, 1, 1)},
157
- })
141
+ expect(selection.selector).to eq({ 'field' => { '$gte' => Time.utc(2020, 1, 1) } })
158
142
  end
159
143
 
160
144
  it 'converts argument to a time' do
@@ -163,52 +147,38 @@ describe Mongoid::Criteria::Queryable::Selectable do
163
147
  end
164
148
  end
165
149
 
166
- context "when provided a nested criterion" do
167
-
150
+ context 'when provided a nested criterion' do
168
151
  let(:selection) do
169
152
  query.send(tested_method, :test.elem_match => { :field.in => [ 1, 2 ] })
170
153
  end
171
154
 
172
- it "builds the correct selector" do
173
- expect(selection.selector).to eq({
174
- "test" => { "$elemMatch" => { "field" => { "$in" => [ 1, 2 ] }}}
175
- })
155
+ it 'builds the correct selector' do
156
+ expect(selection.selector).to eq({ 'test' => { '$elemMatch' => { 'field' => { '$in' => [ 1, 2 ] } } } })
176
157
  end
177
158
 
178
159
  it_behaves_like 'returns a cloned query'
179
160
  end
180
161
 
181
- context "when chaining the criteria" do
182
-
183
- context "when the criteria are for different fields" do
184
-
162
+ context 'when chaining the criteria' do
163
+ context 'when the criteria are for different fields' do
185
164
  let(:selection) do
186
165
  query.and(first: [ 1, 2 ]).send(tested_method, second: [ 3, 4 ])
187
166
  end
188
167
 
189
- it "adds the conditions to top level" do
190
- expect(selection.selector).to eq({
191
- "first" => [ 1, 2 ],
192
- "second" => [ 3, 4 ],
193
- })
168
+ it 'adds the conditions to top level' do
169
+ expect(selection.selector).to eq({ 'first' => [ 1, 2 ], 'second' => [ 3, 4 ] })
194
170
  end
195
171
 
196
172
  it_behaves_like 'returns a cloned query'
197
173
  end
198
174
 
199
- context "when the criteria are on the same field" do
200
-
175
+ context 'when the criteria are on the same field' do
201
176
  let(:selection) do
202
177
  query.and(first: [ 1, 2 ]).send(tested_method, first: [ 3, 4 ])
203
178
  end
204
179
 
205
- it "combines via $and operator" do
206
- expect(selection.selector).to eq({
207
- "first" => [ 1, 2 ],
208
- "$and" => [
209
- { "first" => [ 3, 4 ] }
210
- ]
211
- })
180
+ it 'combines via $and operator' do
181
+ expect(selection.selector).to eq({ 'first' => [ 1, 2 ], '$and' => [ { 'first' => [ 3, 4 ] } ] })
212
182
  end
213
183
 
214
184
  it_behaves_like 'returns a cloned query'
@@ -219,24 +189,23 @@ describe Mongoid::Criteria::Queryable::Selectable do
219
189
  # Non-hoisting means the operator is always present, for example
220
190
  # Foo.or(a: 1) produces {'$or' => [{'a' => 1}]}.
221
191
  shared_examples_for 'a non-hoisting logical operation' do
222
-
223
192
  context 'when there is a single predicate' do
224
193
  let(:query) do
225
194
  Mongoid::Query.new.send(tested_method, hello: 'world')
226
195
  end
227
196
 
228
197
  it 'adds the predicate' do
229
- expect(query.selector).to eq(expected_operator => [{'hello' => 'world'}])
198
+ expect(query.selector).to eq(expected_operator => [ { 'hello' => 'world' } ])
230
199
  end
231
200
  end
232
201
 
233
202
  context 'when the single predicate is wrapped in an array' do
234
203
  let(:query) do
235
- Mongoid::Query.new.send(tested_method, [{hello: 'world'}])
204
+ Mongoid::Query.new.send(tested_method, [ { hello: 'world' } ])
236
205
  end
237
206
 
238
207
  it 'adds the predicate' do
239
- expect(query.selector).to eq(expected_operator => [{'hello' => 'world'}])
208
+ expect(query.selector).to eq(expected_operator => [ { 'hello' => 'world' } ])
240
209
  end
241
210
  end
242
211
 
@@ -254,7 +223,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
254
223
  it 'combines' do
255
224
  # This is used for $or / $nor, the two conditions should remain
256
225
  # as separate hashes
257
- expect(result.selector).to eq(expected_operator => [{'hello' => 'world'}, {'foo' => 'bar'}])
226
+ expect(result.selector).to eq(expected_operator => [ { 'hello' => 'world' }, { 'foo' => 'bar' } ])
258
227
  end
259
228
  end
260
229
 
@@ -268,7 +237,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
268
237
  end
269
238
 
270
239
  let(:other2) do
271
- {bar: 42}
240
+ { bar: 42 }
272
241
  end
273
242
 
274
243
  let(:other3) do
@@ -279,72 +248,67 @@ describe Mongoid::Criteria::Queryable::Selectable do
279
248
 
280
249
  it 'combines' do
281
250
  expect(result.selector).to eq(expected_operator => [
282
- {'hello' => 'world'},
283
- {'foo' => 'bar'},
284
- {'bar' => 42},
285
- {'a' => 2},
286
- ])
251
+ { 'hello' => 'world' },
252
+ { 'foo' => 'bar' },
253
+ { 'bar' => 42 },
254
+ { 'a' => 2 }
255
+ ])
287
256
  end
288
257
  end
289
258
  end
290
259
 
291
- describe "#and" do
292
-
260
+ describe '#and' do
293
261
  let(:tested_method) { :and }
294
262
  let(:expected_operator) { '$and' }
295
263
 
296
264
  it_behaves_like 'a hoisting logical operation'
297
265
 
298
- context "when provided no criterion" do
299
-
266
+ context 'when provided no criterion' do
300
267
  let(:selection) do
301
268
  query.and
302
269
  end
303
270
 
304
- it "does not add any criterion" do
271
+ it 'does not add any criterion' do
305
272
  expect(selection.selector).to eq({})
306
273
  end
307
274
 
308
- it "returns the query" do
275
+ it 'returns the query' do
309
276
  expect(selection).to eq(query)
310
277
  end
311
278
 
312
279
  it_behaves_like 'returns a cloned query'
313
280
  end
314
281
 
315
- context "when provided nil" do
316
-
282
+ context 'when provided nil' do
317
283
  let(:selection) do
318
284
  query.and(nil)
319
285
  end
320
286
 
321
- it "does not add any criterion" do
287
+ it 'does not add any criterion' do
322
288
  expect(selection.selector).to eq({})
323
289
  end
324
290
 
325
- it "returns the query" do
291
+ it 'returns the query' do
326
292
  expect(selection).to eq(query)
327
293
  end
328
294
 
329
295
  it_behaves_like 'returns a cloned query'
330
296
  end
331
297
 
332
- context "when provided multiple criteria" do
333
-
334
- context "when the criterion is already included" do
335
-
298
+ context 'when provided multiple criteria' do
299
+ context 'when the criterion is already included' do
336
300
  context 'simple criterion' do
337
301
  let(:selection) do
338
302
  query.and({ first: [ 1, 2 ] }).and({ first: [ 1, 2 ] })
339
303
  end
340
304
 
341
- it "adds all conditions" do
305
+ it 'adds all conditions' do
342
306
  expect(selection.selector).to eq({
343
- 'first' => [1, 2],
344
- "$and" => [
345
- { "first" => [ 1, 2 ] }
346
- ]
347
- })
307
+ 'first' => [ 1, 2 ],
308
+ '$and' => [
309
+ { 'first' => [ 1, 2 ] }
310
+ ]
311
+ })
348
312
  end
349
313
 
350
314
  it_behaves_like 'returns a cloned query'
@@ -355,13 +319,13 @@ describe Mongoid::Criteria::Queryable::Selectable do
355
319
  query.and({ first: [ 1, 2 ] }).and(:first.gt => 3)
356
320
  end
357
321
 
358
- it "adds all conditions" do
322
+ it 'adds all conditions' do
359
323
  expect(selection.selector).to eq({
360
- 'first' => [1, 2],
361
- "$and" => [
362
- { "first" => {'$gt' => 3} }
363
- ]
364
- })
324
+ 'first' => [ 1, 2 ],
325
+ '$and' => [
326
+ { 'first' => { '$gt' => 3 } }
327
+ ]
328
+ })
365
329
  end
366
330
 
367
331
  it_behaves_like 'returns a cloned query'
@@ -372,46 +336,44 @@ describe Mongoid::Criteria::Queryable::Selectable do
372
336
  query.and(:first.lt => 5).and(:first.gt => 3)
373
337
  end
374
338
 
375
- it "adds all conditions" do
339
+ it 'adds all conditions' do
376
340
  expect(selection.selector).to eq({
377
- 'first' => {'$lt' => 5, '$gt' => 3},
378
- })
341
+ 'first' => { '$lt' => 5, '$gt' => 3 }
342
+ })
379
343
  end
380
344
 
381
345
  it_behaves_like 'returns a cloned query'
382
346
  end
383
347
  end
384
348
 
385
- context "when the new criteria are for different fields" do
386
-
349
+ context 'when the new criteria are for different fields' do
387
350
  let(:selection) do
388
351
  query.and({ first: [ 1, 2 ] }, { second: [ 3, 4 ] })
389
352
  end
390
353
 
391
- it "adds all conditions to top level" do
354
+ it 'adds all conditions to top level' do
392
355
  expect(selection.selector).to eq({
393
- "first" => [ 1, 2 ],
394
- "second" => [ 3, 4 ],
395
- })
356
+ 'first' => [ 1, 2 ],
357
+ 'second' => [ 3, 4 ]
358
+ })
396
359
  end
397
360
 
398
361
  it_behaves_like 'returns a cloned query'
399
362
  end
400
363
 
401
- context "when the new criteria are for the same field" do
402
-
364
+ context 'when the new criteria are for the same field' do
403
365
  context 'when criteria are simple' do
404
366
  let(:selection) do
405
367
  query.and({ first: [ 1, 2 ] }, { first: [ 3, 4 ] })
406
368
  end
407
369
 
408
- it "combines via $and operator" do
370
+ it 'combines via $and operator' do
409
371
  expect(selection.selector).to eq({
410
- "first" => [ 1, 2 ],
411
- "$and" => [
412
- { "first" => [ 3, 4 ] }
413
- ]
414
- })
372
+ 'first' => [ 1, 2 ],
373
+ '$and' => [
374
+ { 'first' => [ 3, 4 ] }
375
+ ]
376
+ })
415
377
  end
416
378
 
417
379
  it_behaves_like 'returns a cloned query'
@@ -421,26 +383,26 @@ describe Mongoid::Criteria::Queryable::Selectable do
421
383
  shared_examples 'behave correctly' do
422
384
  let(:selection) do
423
385
  query.and(
424
- { field: {first_operator => [ 1, 2 ] }},
425
- { field: {second_operator => [ 3, 4 ] }},
386
+ { field: { first_operator => [ 1, 2 ] } },
387
+ { field: { second_operator => [ 3, 4 ] } }
426
388
  )
427
389
  end
428
390
 
429
- it "combines via $and operator and stringifies all keys" do
391
+ it 'combines via $and operator and stringifies all keys' do
430
392
  expect(selection.selector).to eq({
431
- "field" => {'$in' => [ 1, 2 ]},
432
- "$and" => [
433
- { "field" => {'$in' => [ 3, 4 ] }}
434
- ]
435
- })
393
+ 'field' => { '$in' => [ 1, 2 ] },
394
+ '$and' => [
395
+ { 'field' => { '$in' => [ 3, 4 ] } }
396
+ ]
397
+ })
436
398
  end
437
399
  end
438
400
 
439
401
  [
440
- ['$in', '$in'],
441
- [:$in, '$in'],
442
- ['$in', :$in],
443
- [:$in, :$in],
402
+ [ '$in', '$in' ],
403
+ [ :$in, '$in' ],
404
+ [ '$in', :$in ],
405
+ %i[$in $in]
444
406
  ].each do |first_operator, second_operator|
445
407
  context "when first operator is #{first_operator.inspect} and second operator is #{second_operator.inspect}" do
446
408
  let(:first_operator) { first_operator }
@@ -453,11 +415,10 @@ describe Mongoid::Criteria::Queryable::Selectable do
453
415
 
454
416
  context 'when criteria are handled via Key' do
455
417
  shared_examples_for 'adds the conditions to top level' do
456
-
457
- it "adds the conditions to top level" do
418
+ it 'adds the conditions to top level' do
458
419
  expect(selection.selector).to eq({
459
- "field" => {'$gt' => 3, '$lt' => 5},
460
- })
420
+ 'field' => { '$gt' => 3, '$lt' => 5 }
421
+ })
461
422
  end
462
423
 
463
424
  it_behaves_like 'returns a cloned query'
@@ -473,7 +434,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
473
434
 
474
435
  context 'criteria are provided in separate hashes' do
475
436
  let(:selection) do
476
- query.send(tested_method, {:field.gt => 3}, {:field.lt => 5})
437
+ query.send(tested_method, { :field.gt => 3 }, { :field.lt => 5 })
477
438
  end
478
439
 
479
440
  it_behaves_like 'adds the conditions to top level'
@@ -481,7 +442,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
481
442
 
482
443
  context 'when the criterion is wrapped in an array' do
483
444
  let(:selection) do
484
- query.send(tested_method, [:field.gt => 3], [:field.lt => 5])
445
+ query.send(tested_method, [ { :field.gt => 3 } ], [ { :field.lt => 5 } ])
485
446
  end
486
447
 
487
448
  it_behaves_like 'adds the conditions to top level'
@@ -490,34 +451,31 @@ describe Mongoid::Criteria::Queryable::Selectable do
490
451
 
491
452
  context 'when criteria are simple and handled via Key' do
492
453
  shared_examples_for 'combines conditions with $and' do
493
-
494
- it "combines conditions with $and" do
454
+ it 'combines conditions with $and' do
495
455
  expect(selection.selector).to eq({
496
- "field" => 3,
497
- '$and' => ['field' => {'$lt' => 5}],
498
- })
456
+ 'field' => 3,
457
+ '$and' => [ { 'field' => { '$lt' => 5 } } ]
458
+ })
499
459
  end
500
460
 
501
461
  it_behaves_like 'returns a cloned query'
502
462
  end
503
463
 
504
464
  shared_examples_for 'combines conditions with $eq' do
505
-
506
- it "combines conditions with $eq" do
465
+ it 'combines conditions with $eq' do
507
466
  expect(selection.selector).to eq({
508
- "field" => {'$eq' => 3, '$lt' => 5},
509
- })
467
+ 'field' => { '$eq' => 3, '$lt' => 5 }
468
+ })
510
469
  end
511
470
 
512
471
  it_behaves_like 'returns a cloned query'
513
472
  end
514
473
 
515
474
  shared_examples_for 'combines conditions with $regex' do
516
-
517
- it "combines conditions with $regex" do
475
+ it 'combines conditions with $regex' do
518
476
  expect(selection.selector).to eq({
519
- "field" => {'$regex' => /t/, '$lt' => 5},
520
- })
477
+ 'field' => { '$regex' => /t/, '$lt' => 5 }
478
+ })
521
479
  end
522
480
 
523
481
  it_behaves_like 'returns a cloned query'
@@ -543,7 +501,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
543
501
 
544
502
  context 'criteria are provided in separate hashes' do
545
503
  let(:selection) do
546
- query.send(tested_method, {:field => 3}, {:field.lt => 5})
504
+ query.send(tested_method, { field: 3 }, { :field.lt => 5 })
547
505
  end
548
506
 
549
507
  it_behaves_like 'combines conditions with $and'
@@ -551,7 +509,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
551
509
 
552
510
  context 'when the criterion is wrapped in an array' do
553
511
  let(:selection) do
554
- query.send(tested_method, [:field => 3], [:field.lt => 5])
512
+ query.send(tested_method, [ { field: 3 } ], [ { :field.lt => 5 } ])
555
513
  end
556
514
 
557
515
  it_behaves_like 'combines conditions with $and'
@@ -560,34 +518,31 @@ describe Mongoid::Criteria::Queryable::Selectable do
560
518
 
561
519
  context 'when criteria are handled via Key and simple' do
562
520
  shared_examples_for 'combines conditions with $and' do
563
-
564
- it "combines conditions with $and" do
521
+ it 'combines conditions with $and' do
565
522
  expect(selection.selector).to eq({
566
- "field" => {'$gt' => 3},
567
- '$and' => ['field' => 5],
568
- })
523
+ 'field' => { '$gt' => 3 },
524
+ '$and' => [ { 'field' => 5 } ]
525
+ })
569
526
  end
570
527
 
571
528
  it_behaves_like 'returns a cloned query'
572
529
  end
573
530
 
574
531
  shared_examples_for 'combines conditions with $eq' do
575
-
576
- it "combines conditions with $eq" do
532
+ it 'combines conditions with $eq' do
577
533
  expect(selection.selector).to eq({
578
- "field" => {'$gt' => 3, '$eq' => 5},
579
- })
534
+ 'field' => { '$gt' => 3, '$eq' => 5 }
535
+ })
580
536
  end
581
537
 
582
538
  it_behaves_like 'returns a cloned query'
583
539
  end
584
540
 
585
541
  shared_examples_for 'combines conditions with $regex' do
586
-
587
- it "combines conditions with $regex" do
542
+ it 'combines conditions with $regex' do
588
543
  expect(selection.selector).to eq({
589
- "field" => {'$gt' => 3, '$regex' => /t/},
590
- })
544
+ 'field' => { '$gt' => 3, '$regex' => /t/ }
545
+ })
591
546
  end
592
547
 
593
548
  it_behaves_like 'returns a cloned query'
@@ -613,7 +568,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
613
568
 
614
569
  context 'criteria are provided in separate hashes' do
615
570
  let(:selection) do
616
- query.send(tested_method, {:field.gt => 3}, {:field => 5})
571
+ query.send(tested_method, { :field.gt => 3 }, { field: 5 })
617
572
  end
618
573
 
619
574
  it_behaves_like 'combines conditions with $and'
@@ -621,7 +576,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
621
576
 
622
577
  context 'when the criterion is wrapped in an array' do
623
578
  let(:selection) do
624
- query.send(tested_method, [:field.gt => 3], [:field => 5])
579
+ query.send(tested_method, [ { :field.gt => 3 } ], [ { field: 5 } ])
625
580
  end
626
581
 
627
582
  it_behaves_like 'combines conditions with $and'
@@ -638,7 +593,6 @@ describe Mongoid::Criteria::Queryable::Selectable do
638
593
  let(:result) { query.and(other) }
639
594
 
640
595
  context 'different fields' do
641
-
642
596
  let(:other) do
643
597
  Mongoid::Query.new.where(foo: 'bar')
644
598
  end
@@ -649,13 +603,12 @@ describe Mongoid::Criteria::Queryable::Selectable do
649
603
  end
650
604
 
651
605
  context 'same field' do
652
-
653
606
  let(:other) do
654
607
  Mongoid::Query.new.where(hello: /bar/)
655
608
  end
656
609
 
657
610
  it 'combines fields with $and' do
658
- expect(result.selector).to eq('hello' => 'world', '$and' => [{'hello' => /bar/}])
611
+ expect(result.selector).to eq('hello' => 'world', '$and' => [ { 'hello' => /bar/ } ])
659
612
  end
660
613
  end
661
614
  end
@@ -670,7 +623,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
670
623
  end
671
624
 
672
625
  let(:other2) do
673
- {bar: 42}
626
+ { bar: 42 }
674
627
  end
675
628
 
676
629
  let(:other3) do
@@ -681,10 +634,9 @@ describe Mongoid::Criteria::Queryable::Selectable do
681
634
 
682
635
  it 'combines' do
683
636
  expect(result.selector).to eq('hello' => 'world',
684
- 'foo' => 'bar',
685
- 'bar' => 42,
686
- 'a' => 2,
687
- )
637
+ 'foo' => 'bar',
638
+ 'bar' => 42,
639
+ 'a' => 2)
688
640
  end
689
641
  end
690
642
 
@@ -696,7 +648,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
696
648
  end
697
649
 
698
650
  let(:expected) do
699
- {'created_at' => {'$gt' => time.utc}}
651
+ { 'created_at' => { '$gt' => time.utc } }
700
652
  end
701
653
 
702
654
  it 'combines and evolves' do
@@ -709,7 +661,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
709
661
  let(:selector) { scope.selector }
710
662
 
711
663
  it 'adds most recent criterion as $and' do
712
- expect(selector).to eq('foo' => 1, '$and' => [{'foo' => 2}])
664
+ expect(selector).to eq('foo' => 1, '$and' => [ { 'foo' => 2 } ])
713
665
  end
714
666
  end
715
667
 
@@ -765,10 +717,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
765
717
  end
766
718
 
767
719
  it 'adds new conditions to top level' do
768
- selection.selector.should == {
769
- 'foo' => 'bar',
770
- 'hello' => 'world',
771
- }
720
+ selection.selector.should eq({ 'foo' => 'bar', 'hello' => 'world' })
772
721
  end
773
722
  end
774
723
 
@@ -778,128 +727,117 @@ describe Mongoid::Criteria::Queryable::Selectable do
778
727
  end
779
728
 
780
729
  it 'adds new conditions to top level' do
781
- selection.selector.should == {
782
- 'foo' => 'bar',
783
- 'hello' => 'world',
784
- }
730
+ selection.selector.should eq({ 'foo' => 'bar', 'hello' => 'world' })
785
731
  end
786
732
  end
787
733
 
788
734
  context 'when complex criteria conditions are given' do
789
735
  let(:selection) do
790
- base_selection.and(query.or([one: 'one'], [two: 'two']))
736
+ base_selection.and(query.or([ { one: 'one' } ], [ { two: 'two' } ]))
791
737
  end
792
738
 
793
739
  it 'adds new conditions to top level' do
794
- selection.selector.should == {
795
- 'foo' => 'bar',
796
- '$or' => [
797
- {'one' => 'one'},
798
- {'two' => 'two'},
799
- ],
800
- }
740
+ selection.selector.should eq(
741
+ { 'foo' => 'bar',
742
+ '$or' => [
743
+ { 'one' => 'one' },
744
+ { 'two' => 'two' }
745
+ ] }
746
+ )
801
747
  end
802
748
  end
803
749
  end
804
750
  end
805
751
 
806
752
  shared_examples '$or/$nor' do
807
-
808
753
  it_behaves_like 'a non-hoisting logical operation'
809
754
 
810
- context "when provided no arguments" do
811
-
755
+ context 'when provided no arguments' do
812
756
  let(:selection) do
813
757
  query.send(tested_method)
814
758
  end
815
759
 
816
760
  it_behaves_like 'returns a cloned query'
817
761
 
818
- it "does not add any criteria" do
762
+ it 'does not add any criteria' do
819
763
  expect(selection.selector).to eq({})
820
764
  end
821
765
 
822
- it "returns the query" do
766
+ it 'returns the query' do
823
767
  expect(selection).to eq(query)
824
768
  end
825
769
  end
826
770
 
827
- context "when provided nil" do
828
-
771
+ context 'when provided nil' do
829
772
  let(:selection) do
830
773
  query.send(tested_method, nil)
831
774
  end
832
775
 
833
776
  it_behaves_like 'returns a cloned query'
834
777
 
835
- it "does not add any criteria" do
778
+ it 'does not add any criteria' do
836
779
  expect(selection.selector).to eq({})
837
780
  end
838
781
 
839
- it "returns the query" do
782
+ it 'returns the query' do
840
783
  expect(selection).to eq(query)
841
784
  end
842
785
  end
843
786
 
844
- context "when provided a single criterion" do
845
-
787
+ context 'when provided a single criterion' do
846
788
  let(:selection) do
847
789
  query.send(tested_method, field: [ 1, 2 ])
848
790
  end
849
791
 
850
792
  it_behaves_like 'returns a cloned query'
851
793
 
852
- it "adds the $or/$nor selector" do
794
+ it 'adds the $or/$nor selector' do
853
795
  expect(selection.selector).to eq({
854
- expected_operator => [{ "field" => [ 1, 2 ] }]
855
- })
796
+ expected_operator => [ { 'field' => [ 1, 2 ] } ]
797
+ })
856
798
  end
857
799
 
858
800
  context 'when the criterion is wrapped in array' do
859
-
860
801
  let(:selection) do
861
- query.send(tested_method, [{ field: [ 1, 2 ] }])
802
+ query.send(tested_method, [ { field: [ 1, 2 ] } ])
862
803
  end
863
804
 
864
805
  it_behaves_like 'returns a cloned query'
865
806
 
866
- it "adds the $or/$nor selector" do
807
+ it 'adds the $or/$nor selector' do
867
808
  expect(selection.selector).to eq({
868
- expected_operator => [{ "field" => [ 1, 2 ] }]
869
- })
809
+ expected_operator => [ { 'field' => [ 1, 2 ] } ]
810
+ })
870
811
  end
871
812
 
872
813
  context 'when the array has nil as one of the elements' do
873
-
874
814
  let(:selection) do
875
- query.send(tested_method, [{ field: [ 1, 2 ] }, nil])
815
+ query.send(tested_method, [ { field: [ 1, 2 ] }, nil ])
876
816
  end
877
817
 
878
818
  it_behaves_like 'returns a cloned query'
879
819
 
880
- it "adds the $or/$nor selector ignoring the nil element" do
820
+ it 'adds the $or/$nor selector ignoring the nil element' do
881
821
  expect(selection.selector).to eq({
882
- expected_operator => [{ "field" => [ 1, 2 ] }]
883
- })
822
+ expected_operator => [ { 'field' => [ 1, 2 ] } ]
823
+ })
884
824
  end
885
825
  end
886
826
  end
887
827
 
888
828
  context 'when query already has a condition on another field' do
889
-
890
829
  let(:selection) do
891
830
  query.where(foo: 'bar').send(tested_method, field: [ 1, 2 ])
892
831
  end
893
832
 
894
833
  it 'moves original conditions under $or/$nor' do
895
834
  expect(selection.selector).to eq({
896
- expected_operator => [{'foo' => 'bar'}, { "field" => [ 1, 2 ] }]
897
- })
835
+ expected_operator => [ { 'foo' => 'bar' }, { 'field' => [ 1, 2 ] } ]
836
+ })
898
837
  end
899
838
  end
900
839
 
901
840
  context 'when query already has an $or/$nor condition and another condition' do
902
-
903
841
  let(:selection) do
904
842
  query.send(tested_method, field: [ 1, 2 ]).where(foo: 'bar').send(tested_method, test: 1)
905
843
  end
@@ -908,49 +846,46 @@ describe Mongoid::Criteria::Queryable::Selectable do
908
846
  expect(selection.selector).to eq(
909
847
  expected_operator => [
910
848
  {
911
- expected_operator => [{ "field" => [ 1, 2 ] }],
912
- 'foo' => 'bar',
849
+ expected_operator => [ { 'field' => [ 1, 2 ] } ],
850
+ 'foo' => 'bar'
913
851
  },
914
- {'test' => 1},
852
+ { 'test' => 1 }
915
853
  ]
916
854
  )
917
855
  end
918
856
  end
919
857
  end
920
858
 
921
- context "when provided multiple criteria" do
922
-
923
- context "when the criteria are for different fields" do
924
-
859
+ context 'when provided multiple criteria' do
860
+ context 'when the criteria are for different fields' do
925
861
  let(:selection) do
926
862
  query.send(tested_method, { first: [ 1, 2 ] }, { second: [ 3, 4 ] })
927
863
  end
928
864
 
929
865
  it_behaves_like 'returns a cloned query'
930
866
 
931
- it "adds the $or/$nor selector" do
867
+ it 'adds the $or/$nor selector' do
932
868
  expect(selection.selector).to eq({
933
- expected_operator => [
934
- { "first" => [ 1, 2 ] },
935
- { "second" => [ 3, 4 ] }
936
- ]
937
- })
869
+ expected_operator => [
870
+ { 'first' => [ 1, 2 ] },
871
+ { 'second' => [ 3, 4 ] }
872
+ ]
873
+ })
938
874
  end
939
875
  end
940
876
 
941
- context "when the criteria uses a Key instance" do
942
-
877
+ context 'when the criteria uses a Key instance' do
943
878
  let(:selection) do
944
879
  query.send(tested_method, { first: [ 1, 2 ] }, { :second.gt => 3 })
945
880
  end
946
881
 
947
- it "adds the $or/$nor selector" do
882
+ it 'adds the $or/$nor selector' do
948
883
  expect(selection.selector).to eq({
949
- expected_operator => [
950
- { "first" => [ 1, 2 ] },
951
- { "second" => { "$gt" => 3 }}
952
- ]
953
- })
884
+ expected_operator => [
885
+ { 'first' => [ 1, 2 ] },
886
+ { 'second' => { '$gt' => 3 } }
887
+ ]
888
+ })
954
889
  end
955
890
 
956
891
  it_behaves_like 'returns a cloned query'
@@ -962,8 +897,8 @@ describe Mongoid::Criteria::Queryable::Selectable do
962
897
 
963
898
  it 'adds the conditions' do
964
899
  expect(selection.selector).to eq(expected_operator => [
965
- "field" => {'$gte' => Time.new(2020, 1, 1)},
966
- ])
900
+ { 'field' => { '$gte' => Time.new(2020, 1, 1) } }
901
+ ])
967
902
  end
968
903
 
969
904
  it 'keeps the type' do
@@ -978,8 +913,8 @@ describe Mongoid::Criteria::Queryable::Selectable do
978
913
 
979
914
  it 'adds the conditions' do
980
915
  expect(selection.selector).to eq(expected_operator => [
981
- "field" => {'$gte' => Time.utc(2020, 1, 1)},
982
- ])
916
+ { 'field' => { '$gte' => Time.utc(2020, 1, 1) } }
917
+ ])
983
918
  end
984
919
 
985
920
  it 'converts argument to a time' do
@@ -994,8 +929,8 @@ describe Mongoid::Criteria::Queryable::Selectable do
994
929
 
995
930
  it 'adds the conditions' do
996
931
  expect(selection.selector).to eq(expected_operator => [
997
- "field" => {'$gte' => Time.utc(2020, 1, 1)},
998
- ])
932
+ { 'field' => { '$gte' => Time.utc(2020, 1, 1) } }
933
+ ])
999
934
  end
1000
935
 
1001
936
  it 'converts argument to a time' do
@@ -1004,41 +939,38 @@ describe Mongoid::Criteria::Queryable::Selectable do
1004
939
  end
1005
940
  end
1006
941
 
1007
- context "when a criterion has an aliased field" do
1008
-
942
+ context 'when a criterion has an aliased field' do
1009
943
  let(:selection) do
1010
944
  query.send(tested_method, { id: 1 })
1011
945
  end
1012
946
 
1013
- it "adds the $or/$nor selector and aliases the field" do
947
+ it 'adds the $or/$nor selector and aliases the field' do
1014
948
  expect(selection.selector).to eq({
1015
- expected_operator => [ { "_id" => 1 } ]
1016
- })
949
+ expected_operator => [ { '_id' => 1 } ]
950
+ })
1017
951
  end
1018
952
 
1019
953
  it_behaves_like 'returns a cloned query'
1020
954
  end
1021
955
 
1022
- context "when a criterion is wrapped in an array" do
1023
-
956
+ context 'when a criterion is wrapped in an array' do
1024
957
  let(:selection) do
1025
- query.send(tested_method, [{ first: [ 1, 2 ] }, { :second.gt => 3 }])
958
+ query.send(tested_method, [ { first: [ 1, 2 ] }, { :second.gt => 3 } ])
1026
959
  end
1027
960
 
1028
961
  it_behaves_like 'returns a cloned query'
1029
962
 
1030
- it "adds the $or/$nor selector" do
963
+ it 'adds the $or/$nor selector' do
1031
964
  expect(selection.selector).to eq({
1032
- expected_operator => [
1033
- { "first" => [ 1, 2 ] },
1034
- { "second" => { "$gt" => 3 }}
1035
- ]
1036
- })
965
+ expected_operator => [
966
+ { 'first' => [ 1, 2 ] },
967
+ { 'second' => { '$gt' => 3 } }
968
+ ]
969
+ })
1037
970
  end
1038
971
  end
1039
972
 
1040
- context "when the criteria are on the same field" do
1041
-
973
+ context 'when the criteria are on the same field' do
1042
974
  context 'simple criteria' do
1043
975
  let(:selection) do
1044
976
  query.send(tested_method, { first: [ 1, 2 ] }, { first: [ 3, 4 ] })
@@ -1046,13 +978,13 @@ describe Mongoid::Criteria::Queryable::Selectable do
1046
978
 
1047
979
  it_behaves_like 'returns a cloned query'
1048
980
 
1049
- it "appends both $or/$nor expressions" do
981
+ it 'appends both $or/$nor expressions' do
1050
982
  expect(selection.selector).to eq({
1051
- expected_operator => [
1052
- { "first" => [ 1, 2 ] },
1053
- { "first" => [ 3, 4 ] }
1054
- ]
1055
- })
983
+ expected_operator => [
984
+ { 'first' => [ 1, 2 ] },
985
+ { 'first' => [ 3, 4 ] }
986
+ ]
987
+ })
1056
988
  end
1057
989
  end
1058
990
 
@@ -1063,86 +995,82 @@ describe Mongoid::Criteria::Queryable::Selectable do
1063
995
 
1064
996
  it_behaves_like 'returns a cloned query'
1065
997
 
1066
- it "adds all criteria" do
998
+ it 'adds all criteria' do
1067
999
  expect(selection.selector).to eq({
1068
- expected_operator => [
1069
- { "first" => {'$gt' => 3, '$lt' => 5} },
1070
- ]
1071
- })
1000
+ expected_operator => [
1001
+ { 'first' => { '$gt' => 3, '$lt' => 5 } }
1002
+ ]
1003
+ })
1072
1004
  end
1073
1005
  end
1074
1006
 
1075
1007
  context 'Key criteria as multiple arguments' do
1076
1008
  let(:selection) do
1077
- query.send(tested_method, {:first.gt => 3}, {:first.lt => 5})
1009
+ query.send(tested_method, { :first.gt => 3 }, { :first.lt => 5 })
1078
1010
  end
1079
1011
 
1080
1012
  it_behaves_like 'returns a cloned query'
1081
1013
 
1082
- it "adds all criteria" do
1014
+ it 'adds all criteria' do
1083
1015
  expect(selection.selector).to eq({
1084
- expected_operator => [
1085
- { "first" => {'$gt' => 3} },
1086
- { "first" => {'$lt' => 5} },
1087
- ]
1088
- })
1016
+ expected_operator => [
1017
+ { 'first' => { '$gt' => 3 } },
1018
+ { 'first' => { '$lt' => 5 } }
1019
+ ]
1020
+ })
1089
1021
  end
1090
1022
  end
1091
1023
  end
1092
1024
  end
1093
1025
 
1094
- context "when chaining the criterion" do
1095
-
1096
- context "when the criterion are for different fields" do
1097
-
1026
+ context 'when chaining the criterion' do
1027
+ context 'when the criterion are for different fields' do
1098
1028
  let(:selection) do
1099
1029
  query.send(tested_method, first: [ 1, 2 ]).send(tested_method, second: [ 3, 4 ])
1100
1030
  end
1101
1031
 
1102
1032
  it_behaves_like 'returns a cloned query'
1103
1033
 
1104
- it "adds the $or/$nor selectors" do
1034
+ it 'adds the $or/$nor selectors' do
1105
1035
  expect(selection.selector).to eq({
1106
- expected_operator => [
1107
- { "first" => [ 1, 2 ] },
1108
- { "second" => [ 3, 4 ] }
1109
- ]
1110
- })
1036
+ expected_operator => [
1037
+ { 'first' => [ 1, 2 ] },
1038
+ { 'second' => [ 3, 4 ] }
1039
+ ]
1040
+ })
1111
1041
  end
1112
1042
  end
1113
1043
 
1114
- context "when the criterion are on the same field" do
1115
-
1044
+ context 'when the criterion are on the same field' do
1116
1045
  let(:selection) do
1117
1046
  query.send(tested_method, first: [ 1, 2 ]).send(tested_method, first: [ 3, 4 ])
1118
1047
  end
1119
1048
 
1120
1049
  it_behaves_like 'returns a cloned query'
1121
1050
 
1122
- it "appends both $or/$nor expressions" do
1051
+ it 'appends both $or/$nor expressions' do
1123
1052
  expect(selection.selector).to eq({
1124
- expected_operator => [
1125
- { "first" => [ 1, 2 ] },
1126
- { "first" => [ 3, 4 ] }
1127
- ]
1128
- })
1053
+ expected_operator => [
1054
+ { 'first' => [ 1, 2 ] },
1055
+ { 'first' => [ 3, 4 ] }
1056
+ ]
1057
+ })
1129
1058
  end
1130
1059
  end
1131
1060
  end
1132
1061
 
1133
1062
  context 'when giving multiple conditions in one call on the same key with symbol operator' do
1134
-
1135
1063
  context 'non-regexp argument' do
1136
1064
  let(:selection) do
1137
1065
  query.send(tested_method, field: 1, :field.gt => 0)
1138
1066
  end
1139
1067
 
1140
1068
  it 'combines conditions with $eq' do
1141
- selection.selector.should == {
1142
- expected_operator => [
1143
- 'field' => {'$eq' => 1, '$gt' => 0},
1144
- ]
1145
- }
1069
+ selection.selector.should eq(
1070
+ { expected_operator => [
1071
+ { 'field' => { '$eq' => 1, '$gt' => 0 } }
1072
+ ] }
1073
+ )
1146
1074
  end
1147
1075
  end
1148
1076
 
@@ -1152,35 +1080,31 @@ describe Mongoid::Criteria::Queryable::Selectable do
1152
1080
  end
1153
1081
 
1154
1082
  it 'combines conditions with $regex' do
1155
- selection.selector.should == {
1156
- expected_operator => [
1157
- 'field' => {'$regex' => /t/, '$gt' => 0},
1158
- ]
1159
- }
1083
+ selection.selector.should eq(
1084
+ { expected_operator => [
1085
+ { 'field' => { '$regex' => /t/, '$gt' => 0 } }
1086
+ ] }
1087
+ )
1160
1088
  end
1161
1089
  end
1162
-
1163
1090
  end
1164
1091
  end
1165
1092
 
1166
- describe "#or" do
1167
-
1093
+ describe '#or' do
1168
1094
  let(:tested_method) { :or }
1169
1095
  let(:expected_operator) { '$or' }
1170
1096
 
1171
1097
  it_behaves_like '$or/$nor'
1172
1098
  end
1173
1099
 
1174
- describe "#nor" do
1175
-
1100
+ describe '#nor' do
1176
1101
  let(:tested_method) { :nor }
1177
1102
  let(:expected_operator) { '$nor' }
1178
1103
 
1179
1104
  it_behaves_like '$or/$nor'
1180
1105
  end
1181
1106
 
1182
- describe "#any_of" do
1183
-
1107
+ describe '#any_of' do
1184
1108
  let(:tested_method) { :any_of }
1185
1109
  let(:expected_operator) { '$or' }
1186
1110
 
@@ -1198,7 +1122,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
1198
1122
  end
1199
1123
 
1200
1124
  let(:other2) do
1201
- {bar: 42}
1125
+ { bar: 42 }
1202
1126
  end
1203
1127
 
1204
1128
  let(:other3) do
@@ -1211,96 +1135,89 @@ describe Mongoid::Criteria::Queryable::Selectable do
1211
1135
  expect(result.selector).to eq(
1212
1136
  'hello' => 'world',
1213
1137
  expected_operator => [
1214
- {'foo' => 'bar'},
1215
- {'bar' => 42},
1216
- {'a' => 2},
1217
- ],
1138
+ { 'foo' => 'bar' },
1139
+ { 'bar' => 42 },
1140
+ { 'a' => 2 }
1141
+ ]
1218
1142
  )
1219
1143
  end
1220
1144
  end
1221
1145
 
1222
- context "when provided no arguments" do
1223
-
1146
+ context 'when provided no arguments' do
1224
1147
  let(:selection) do
1225
1148
  query.any_of
1226
1149
  end
1227
1150
 
1228
1151
  it_behaves_like 'returns a cloned query'
1229
1152
 
1230
- it "does not add any criteria" do
1153
+ it 'does not add any criteria' do
1231
1154
  expect(selection.selector).to eq({})
1232
1155
  end
1233
1156
 
1234
- it "returns the query" do
1157
+ it 'returns the query' do
1235
1158
  expect(selection).to eq(query)
1236
1159
  end
1237
1160
  end
1238
1161
 
1239
- context "when provided nil" do
1240
-
1162
+ context 'when provided nil' do
1241
1163
  let(:selection) do
1242
1164
  query.any_of(nil)
1243
1165
  end
1244
1166
 
1245
1167
  it_behaves_like 'returns a cloned query'
1246
1168
 
1247
- it "does not add any criteria" do
1169
+ it 'does not add any criteria' do
1248
1170
  expect(selection.selector).to eq({})
1249
1171
  end
1250
1172
 
1251
- it "returns the query" do
1173
+ it 'returns the query' do
1252
1174
  expect(selection).to eq(query)
1253
1175
  end
1254
1176
  end
1255
1177
 
1256
- context "when provided a single criterion" do
1257
-
1178
+ context 'when provided a single criterion' do
1258
1179
  let(:selection) do
1259
1180
  query.any_of(field: [ 1, 2 ])
1260
1181
  end
1261
1182
 
1262
1183
  it_behaves_like 'returns a cloned query'
1263
1184
 
1264
- it "adds the $or selector" do
1185
+ it 'adds the $or selector' do
1265
1186
  expect(selection.selector).to eq(
1266
- "field" => [ 1, 2 ],
1187
+ 'field' => [ 1, 2 ]
1267
1188
  )
1268
1189
  end
1269
1190
 
1270
1191
  context 'when the criterion is wrapped in array' do
1271
-
1272
1192
  let(:selection) do
1273
- query.any_of([{ field: [ 1, 2 ] }])
1193
+ query.any_of([ { field: [ 1, 2 ] } ])
1274
1194
  end
1275
1195
 
1276
1196
  it_behaves_like 'returns a cloned query'
1277
1197
 
1278
- it "adds the condition" do
1198
+ it 'adds the condition' do
1279
1199
  expect(selection.selector).to eq(
1280
- "field" => [ 1, 2 ],
1200
+ 'field' => [ 1, 2 ]
1281
1201
  )
1282
1202
  end
1283
1203
 
1284
1204
  context 'when the array has nil as one of the elements' do
1285
-
1286
1205
  let(:selection) do
1287
- query.any_of([{ field: [ 1, 2 ] }, nil])
1206
+ query.any_of([ { field: [ 1, 2 ] }, nil ])
1288
1207
  end
1289
1208
 
1290
1209
  it_behaves_like 'returns a cloned query'
1291
1210
 
1292
- it "adds the $or selector ignoring the nil element" do
1211
+ it 'adds the $or selector ignoring the nil element' do
1293
1212
  expect(selection.selector).to eq(
1294
- "field" => [ 1, 2 ],
1213
+ 'field' => [ 1, 2 ]
1295
1214
  )
1296
1215
  end
1297
1216
  end
1298
1217
  end
1299
1218
 
1300
1219
  context 'when query already has a condition on another field' do
1301
-
1302
1220
  context 'when there is one argument' do
1303
-
1304
1221
  let(:selection) do
1305
1222
  query.where(foo: 'bar').any_of(field: [ 1, 2 ])
1306
1223
  end
@@ -1308,106 +1225,100 @@ describe Mongoid::Criteria::Queryable::Selectable do
1308
1225
  it 'adds the new condition' do
1309
1226
  expect(selection.selector).to eq(
1310
1227
  'foo' => 'bar',
1311
- 'field' => [1, 2],
1228
+ 'field' => [ 1, 2 ]
1312
1229
  )
1313
1230
  end
1314
1231
  end
1315
1232
 
1316
1233
  context 'when there are multiple arguments' do
1317
-
1318
1234
  let(:selection) do
1319
- query.where(foo: 'bar').any_of({field: [ 1, 2 ]}, {hello: 'world'})
1235
+ query.where(foo: 'bar').any_of({ field: [ 1, 2 ] }, { hello: 'world' })
1320
1236
  end
1321
1237
 
1322
1238
  it 'adds the new condition' do
1323
1239
  expect(selection.selector).to eq(
1324
1240
  'foo' => 'bar',
1325
1241
  '$or' => [
1326
- {'field' => [1, 2]},
1327
- {'hello' => 'world'},
1328
- ],
1242
+ { 'field' => [ 1, 2 ] },
1243
+ { 'hello' => 'world' }
1244
+ ]
1329
1245
  )
1330
1246
  end
1331
1247
  end
1332
1248
  end
1333
1249
 
1334
1250
  context 'when query already has an $or condition and another condition' do
1335
-
1336
1251
  let(:selection) do
1337
1252
  query.or(field: [ 1, 2 ]).where(foo: 'bar').any_of(test: 1)
1338
1253
  end
1339
1254
 
1340
1255
  it 'adds the new condition' do
1341
1256
  expect(selection.selector).to eq(
1342
- '$or' => [{'field' => [1, 2]}],
1257
+ '$or' => [ { 'field' => [ 1, 2 ] } ],
1343
1258
  'foo' => 'bar',
1344
- 'test' => 1,
1259
+ 'test' => 1
1345
1260
  )
1346
1261
  end
1347
1262
  end
1348
1263
 
1349
1264
  context 'when any_of has multiple arguments' do
1350
-
1351
1265
  let(:selection) do
1352
- query.or(field: [ 1, 2 ]).where(foo: 'bar').any_of({a: 1}, {b: 2})
1266
+ query.or(field: [ 1, 2 ]).where(foo: 'bar').any_of({ a: 1 }, { b: 2 })
1353
1267
  end
1354
1268
 
1355
1269
  it 'adds the new condition to top level' do
1356
1270
  expect(selection.selector).to eq(
1357
- '$or' => [{'field' => [1, 2]}],
1271
+ '$or' => [ { 'field' => [ 1, 2 ] } ],
1358
1272
  'foo' => 'bar',
1359
- '$and' => [{'$or' => [{'a' => 1}, {'b' => 2}]}],
1273
+ '$and' => [ { '$or' => [ { 'a' => 1 }, { 'b' => 2 } ] } ]
1360
1274
  )
1361
1275
  end
1362
1276
 
1363
1277
  context 'when query already has a top-level $and' do
1364
1278
  let(:selection) do
1365
- query.or(field: [ 1, 2 ]).where('$and' => [foo: 'bar']).any_of({a: 1}, {b: 2})
1279
+ query.or(field: [ 1, 2 ]).where('$and' => [ { foo: 'bar' } ]).any_of({ a: 1 }, { b: 2 })
1366
1280
  end
1367
1281
 
1368
1282
  it 'adds the new condition to top level $and' do
1369
1283
  expect(selection.selector).to eq(
1370
- '$or' => [{'field' => [1, 2]}],
1371
- '$and' => [{'foo' => 'bar'}, {'$or' => [{'a' => 1}, {'b' => 2}]}],
1284
+ '$or' => [ { 'field' => [ 1, 2 ] } ],
1285
+ '$and' => [ { 'foo' => 'bar' }, { '$or' => [ { 'a' => 1 }, { 'b' => 2 } ] } ]
1372
1286
  )
1373
1287
  end
1374
1288
  end
1375
1289
  end
1376
1290
  end
1377
1291
 
1378
- context "when provided multiple criteria" do
1379
-
1380
- context "when the criteria are for different fields" do
1381
-
1292
+ context 'when provided multiple criteria' do
1293
+ context 'when the criteria are for different fields' do
1382
1294
  let(:selection) do
1383
1295
  query.any_of({ first: [ 1, 2 ] }, { second: [ 3, 4 ] })
1384
1296
  end
1385
1297
 
1386
1298
  it_behaves_like 'returns a cloned query'
1387
1299
 
1388
- it "adds the $or selector" do
1300
+ it 'adds the $or selector' do
1389
1301
  expect(selection.selector).to eq({
1390
- "$or" => [
1391
- { "first" => [ 1, 2 ] },
1392
- { "second" => [ 3, 4 ] }
1393
- ]
1394
- })
1302
+ '$or' => [
1303
+ { 'first' => [ 1, 2 ] },
1304
+ { 'second' => [ 3, 4 ] }
1305
+ ]
1306
+ })
1395
1307
  end
1396
1308
  end
1397
1309
 
1398
- context "when the criteria uses a Key instance" do
1399
-
1310
+ context 'when the criteria uses a Key instance' do
1400
1311
  let(:selection) do
1401
1312
  query.any_of({ first: [ 1, 2 ] }, { :second.gt => 3 })
1402
1313
  end
1403
1314
 
1404
- it "adds the $or selector" do
1315
+ it 'adds the $or selector' do
1405
1316
  expect(selection.selector).to eq({
1406
- "$or" => [
1407
- { "first" => [ 1, 2 ] },
1408
- { "second" => { "$gt" => 3 }}
1409
- ]
1410
- })
1317
+ '$or' => [
1318
+ { 'first' => [ 1, 2 ] },
1319
+ { 'second' => { '$gt' => 3 } }
1320
+ ]
1321
+ })
1411
1322
  end
1412
1323
 
1413
1324
  it_behaves_like 'returns a cloned query'
@@ -1415,42 +1326,39 @@ describe Mongoid::Criteria::Queryable::Selectable do
1415
1326
 
1416
1327
  context 'when criteria are simple and handled via Key' do
1417
1328
  shared_examples_for 'adds conditions with $or' do
1418
-
1419
- it "adds conditions with $or" do
1329
+ it 'adds conditions with $or' do
1420
1330
  expect(selection.selector).to eq({
1421
- '$or' => [
1422
- {'field' => 3},
1423
- {'field' => {'$lt' => 5}},
1424
- ],
1425
- })
1331
+ '$or' => [
1332
+ { 'field' => 3 },
1333
+ { 'field' => { '$lt' => 5 } }
1334
+ ]
1335
+ })
1426
1336
  end
1427
1337
 
1428
1338
  it_behaves_like 'returns a cloned query'
1429
1339
  end
1430
1340
 
1431
1341
  shared_examples_for 'combines conditions with $eq' do
1432
-
1433
- it "combines conditions with $eq" do
1342
+ it 'combines conditions with $eq' do
1434
1343
  expect(selection.selector).to eq({
1435
- 'field' => {
1436
- '$eq' => 3,
1437
- '$lt' => 5,
1438
- },
1439
- })
1344
+ 'field' => {
1345
+ '$eq' => 3,
1346
+ '$lt' => 5
1347
+ }
1348
+ })
1440
1349
  end
1441
1350
 
1442
1351
  it_behaves_like 'returns a cloned query'
1443
1352
  end
1444
1353
 
1445
1354
  shared_examples_for 'combines conditions with $regex' do
1446
-
1447
- it "combines conditions with $regex" do
1355
+ it 'combines conditions with $regex' do
1448
1356
  expect(selection.selector).to eq({
1449
- 'field' => {
1450
- '$regex' => /t/,
1451
- '$lt' => 5,
1452
- },
1453
- })
1357
+ 'field' => {
1358
+ '$regex' => /t/,
1359
+ '$lt' => 5
1360
+ }
1361
+ })
1454
1362
  end
1455
1363
 
1456
1364
  it_behaves_like 'returns a cloned query'
@@ -1476,7 +1384,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
1476
1384
 
1477
1385
  context 'criteria are provided in separate hashes' do
1478
1386
  let(:selection) do
1479
- query.send(tested_method, {:field => 3}, {:field.lt => 5})
1387
+ query.send(tested_method, { field: 3 }, { :field.lt => 5 })
1480
1388
  end
1481
1389
 
1482
1390
  it_behaves_like 'adds conditions with $or'
@@ -1484,7 +1392,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
1484
1392
 
1485
1393
  context 'when the criterion is wrapped in an array' do
1486
1394
  let(:selection) do
1487
- query.send(tested_method, [:field => 3], [:field.lt => 5])
1395
+ query.send(tested_method, [ { field: 3 } ], [ { :field.lt => 5 } ])
1488
1396
  end
1489
1397
 
1490
1398
  it_behaves_like 'adds conditions with $or'
@@ -1493,24 +1401,22 @@ describe Mongoid::Criteria::Queryable::Selectable do
1493
1401
 
1494
1402
  context 'when criteria are handled via Key and simple' do
1495
1403
  shared_examples_for 'adds conditions with $or' do
1496
-
1497
- it "adds conditions with $or" do
1404
+ it 'adds conditions with $or' do
1498
1405
  expect(selection.selector).to eq({
1499
- '$or' => [
1500
- {'field' => {'$gt' => 3}},
1501
- {'field' => 5},
1502
- ],
1503
- })
1406
+ '$or' => [
1407
+ { 'field' => { '$gt' => 3 } },
1408
+ { 'field' => 5 }
1409
+ ]
1410
+ })
1504
1411
  end
1505
1412
 
1506
1413
  it_behaves_like 'returns a cloned query'
1507
1414
  end
1508
1415
 
1509
1416
  shared_examples_for 'combines conditions with $eq' do
1510
-
1511
- it "combines conditions with $eq" do
1417
+ it 'combines conditions with $eq' do
1512
1418
  expect(selection.selector).to eq(
1513
- 'field' => {'$gt' => 3, '$eq' => 5},
1419
+ 'field' => { '$gt' => 3, '$eq' => 5 }
1514
1420
  )
1515
1421
  end
1516
1422
 
@@ -1518,10 +1424,9 @@ describe Mongoid::Criteria::Queryable::Selectable do
1518
1424
  end
1519
1425
 
1520
1426
  shared_examples_for 'combines conditions with $regex' do
1521
-
1522
- it "combines conditions with $regex" do
1427
+ it 'combines conditions with $regex' do
1523
1428
  expect(selection.selector).to eq(
1524
- 'field' => {'$gt' => 3, '$regex' => /t/},
1429
+ 'field' => { '$gt' => 3, '$regex' => /t/ }
1525
1430
  )
1526
1431
  end
1527
1432
 
@@ -1548,7 +1453,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
1548
1453
 
1549
1454
  context 'criteria are provided in separate hashes' do
1550
1455
  let(:selection) do
1551
- query.send(tested_method, {:field.gt => 3}, {:field => 5})
1456
+ query.send(tested_method, { :field.gt => 3 }, { field: 5 })
1552
1457
  end
1553
1458
 
1554
1459
  it_behaves_like 'adds conditions with $or'
@@ -1556,95 +1461,89 @@ describe Mongoid::Criteria::Queryable::Selectable do
1556
1461
 
1557
1462
  context 'when the criterion is wrapped in an array' do
1558
1463
  let(:selection) do
1559
- query.send(tested_method, [:field.gt => 3], [:field => 5])
1464
+ query.send(tested_method, [ { :field.gt => 3 } ], [ { field: 5 } ])
1560
1465
  end
1561
1466
 
1562
1467
  it_behaves_like 'adds conditions with $or'
1563
1468
  end
1564
1469
  end
1565
1470
 
1566
- context "when a criterion has an aliased field" do
1567
-
1471
+ context 'when a criterion has an aliased field' do
1568
1472
  let(:selection) do
1569
1473
  query.any_of({ id: 1 })
1570
1474
  end
1571
1475
 
1572
- it "adds the $or selector and aliases the field" do
1476
+ it 'adds the $or selector and aliases the field' do
1573
1477
  expect(selection.selector).to eq(
1574
- "_id" => 1,
1478
+ '_id' => 1
1575
1479
  )
1576
1480
  end
1577
1481
 
1578
1482
  it_behaves_like 'returns a cloned query'
1579
1483
  end
1580
1484
 
1581
- context "when a criterion is wrapped in an array" do
1582
-
1485
+ context 'when a criterion is wrapped in an array' do
1583
1486
  let(:selection) do
1584
- query.any_of([{ first: [ 1, 2 ] }, { :second.gt => 3 }])
1487
+ query.any_of([ { first: [ 1, 2 ] }, { :second.gt => 3 } ])
1585
1488
  end
1586
1489
 
1587
1490
  it_behaves_like 'returns a cloned query'
1588
1491
 
1589
- it "adds the $or selector" do
1492
+ it 'adds the $or selector' do
1590
1493
  expect(selection.selector).to eq({
1591
- "$or" => [
1592
- { "first" => [ 1, 2 ] },
1593
- { "second" => { "$gt" => 3 }}
1594
- ]
1595
- })
1494
+ '$or' => [
1495
+ { 'first' => [ 1, 2 ] },
1496
+ { 'second' => { '$gt' => 3 } }
1497
+ ]
1498
+ })
1596
1499
  end
1597
1500
  end
1598
1501
 
1599
- context "when the criteria are on the same field" do
1600
-
1502
+ context 'when the criteria are on the same field' do
1601
1503
  let(:selection) do
1602
1504
  query.any_of({ first: [ 1, 2 ] }, { first: [ 3, 4 ] })
1603
1505
  end
1604
1506
 
1605
1507
  it_behaves_like 'returns a cloned query'
1606
1508
 
1607
- it "appends both $or expressions" do
1509
+ it 'appends both $or expressions' do
1608
1510
  expect(selection.selector).to eq({
1609
- "$or" => [
1610
- { "first" => [ 1, 2 ] },
1611
- { "first" => [ 3, 4 ] }
1612
- ]
1613
- })
1511
+ '$or' => [
1512
+ { 'first' => [ 1, 2 ] },
1513
+ { 'first' => [ 3, 4 ] }
1514
+ ]
1515
+ })
1614
1516
  end
1615
1517
  end
1616
1518
  end
1617
1519
 
1618
- context "when chaining the criteria" do
1619
-
1620
- context "when the criteria are for different fields" do
1621
-
1520
+ context 'when chaining the criteria' do
1521
+ context 'when the criteria are for different fields' do
1622
1522
  let(:selection) do
1623
1523
  query.any_of(first: [ 1, 2 ]).any_of(second: [ 3, 4 ])
1624
1524
  end
1625
1525
 
1626
1526
  it_behaves_like 'returns a cloned query'
1627
1527
 
1628
- it "adds the conditions separately" do
1528
+ it 'adds the conditions separately' do
1629
1529
  expect(selection.selector).to eq(
1630
- "first" => [ 1, 2 ],
1631
- "second" => [ 3, 4 ],
1530
+ 'first' => [ 1, 2 ],
1531
+ 'second' => [ 3, 4 ]
1632
1532
  )
1633
1533
  end
1634
1534
  end
1635
1535
 
1636
- context "when the criteria are on the same field" do
1637
-
1536
+ context 'when the criteria are on the same field' do
1638
1537
  let(:selection) do
1639
1538
  query.any_of(first: [ 1, 2 ]).any_of(first: [ 3, 4 ])
1640
1539
  end
1641
1540
 
1642
1541
  it_behaves_like 'returns a cloned query'
1643
1542
 
1644
- it "adds the conditions separately" do
1543
+ it 'adds the conditions separately' do
1645
1544
  expect(selection.selector).to eq(
1646
- "first" => [ 1, 2 ],
1647
- '$and' => [{"first" => [ 3, 4 ]}],
1545
+ 'first' => [ 1, 2 ],
1546
+ '$and' => [ { 'first' => [ 3, 4 ] } ]
1648
1547
  )
1649
1548
  end
1650
1549
  end
@@ -1652,66 +1551,66 @@ describe Mongoid::Criteria::Queryable::Selectable do
1652
1551
 
1653
1552
  context 'when using multiple criteria and symbol operators' do
1654
1553
  context 'when using fields that meaningfully evolve values' do
1655
-
1656
1554
  let(:query) do
1657
- Dictionary.any_of({a: 1}, :published.gt => Date.new(2020, 2, 3))
1555
+ Dictionary.any_of({ a: 1 }, :published.gt => Date.new(2020, 2, 3))
1658
1556
  end
1659
1557
 
1660
1558
  it 'generates the expected query' do
1661
- query.selector.should == {'$or' => [
1662
- {'a' => 1},
1663
- # Date instance is converted to a Time instance in local time,
1664
- # because we are querying on a Time field and dates are interpreted
1665
- # in local time when assigning to Time fields
1666
- {'published' => {'$gt' => Time.zone.local(2020, 2, 3)}},
1667
- ]}
1559
+ query.selector.should eq(
1560
+ { '$or' => [
1561
+ { 'a' => 1 },
1562
+ # Date instance is converted to a Time instance in local time,
1563
+ # because we are querying on a Time field and dates are interpreted
1564
+ # in local time when assigning to Time fields
1565
+ { 'published' => { '$gt' => Time.zone.local(2020, 2, 3) } }
1566
+ ] }
1567
+ )
1668
1568
  end
1669
1569
  end
1670
1570
 
1671
1571
  context 'when using fields that do not meaningfully evolve values' do
1672
-
1673
1572
  let(:query) do
1674
- Dictionary.any_of({a: 1}, :submitted_on.gt => Date.new(2020, 2, 3))
1573
+ Dictionary.any_of({ a: 1 }, :submitted_on.gt => Date.new(2020, 2, 3))
1675
1574
  end
1676
1575
 
1677
1576
  it 'generates the expected query' do
1678
- query.selector.should == {'$or' => [
1679
- {'a' => 1},
1680
- # Date instance is converted to a Time instance in UTC,
1681
- # because we are querying on a Date field and dates are interpreted
1682
- # in UTC when persisted as dates by Mongoid
1683
- {'submitted_on' => {'$gt' => Time.utc(2020, 2, 3)}},
1684
- ]}
1577
+ query.selector.should eq(
1578
+ { '$or' => [
1579
+ { 'a' => 1 },
1580
+ # Date instance is converted to a Time instance in UTC,
1581
+ # because we are querying on a Date field and dates are interpreted
1582
+ # in UTC when persisted as dates by Mongoid
1583
+ { 'submitted_on' => { '$gt' => Time.utc(2020, 2, 3) } }
1584
+ ] }
1585
+ )
1685
1586
  end
1686
1587
  end
1687
1588
  end
1688
1589
  end
1689
1590
 
1690
- describe "#not" do
1691
-
1692
- context "when provided no criterion" do
1693
-
1591
+ describe '#not' do
1592
+ context 'when provided no criterion' do
1694
1593
  let(:selection) do
1695
1594
  query.not
1696
1595
  end
1697
1596
 
1698
- it "does not add any criterion" do
1597
+ it 'does not add any criterion' do
1699
1598
  expect(selection.selector).to eq({})
1700
1599
  end
1701
1600
 
1702
- it "returns the query" do
1601
+ it 'returns the query' do
1703
1602
  expect(selection).to eq(query)
1704
1603
  end
1705
1604
 
1706
- it "returns a cloned query" do
1605
+ it 'returns a cloned query' do
1707
1606
  expect(selection).not_to equal(query)
1708
1607
  end
1709
1608
 
1710
1609
  it 'does not mutate receiver' do
1711
- expect(query.negating).to be nil
1610
+ expect(query.negating).to be_nil
1712
1611
 
1713
1612
  selection
1714
- expect(query.negating).to be nil
1613
+ expect(query.negating).to be_nil
1715
1614
  end
1716
1615
 
1717
1616
  shared_examples_for 'negates the next condition' do
@@ -1719,269 +1618,252 @@ describe Mongoid::Criteria::Queryable::Selectable do
1719
1618
  query.not.send(query_method, field: [ 1, 2 ])
1720
1619
  end
1721
1620
 
1722
- it "negates the next condition" do
1621
+ it 'negates the next condition' do
1723
1622
  expect(selection.selector).to eq(
1724
- { "field" => { "$not" => { operator => [ 1, 2 ] }}}
1623
+ { 'field' => { '$not' => { operator => [ 1, 2 ] } } }
1725
1624
  )
1726
1625
  end
1727
1626
 
1728
1627
  it_behaves_like 'returns a cloned query'
1729
1628
 
1730
- it "removes the negation on the clone" do
1731
- expect(selection).to_not be_negating
1629
+ it 'removes the negation on the clone' do
1630
+ expect(selection).not_to be_negating
1732
1631
  end
1733
1632
  end
1734
1633
 
1735
- context "when the next condition is #all" do
1634
+ context 'when the next condition is #all' do
1736
1635
  let(:query_method) { :all }
1737
1636
  let(:operator) { '$all' }
1738
1637
 
1739
1638
  it_behaves_like 'negates the next condition'
1740
1639
  end
1741
1640
 
1742
- context "when the next condition is #in" do
1641
+ context 'when the next condition is #in' do
1743
1642
  let(:query_method) { :in }
1744
1643
  let(:operator) { '$in' }
1745
1644
 
1746
1645
  it_behaves_like 'negates the next condition'
1747
1646
  end
1748
1647
 
1749
- context "when the next condition is #nin" do
1648
+ context 'when the next condition is #nin' do
1750
1649
  let(:query_method) { :nin }
1751
1650
  let(:operator) { '$nin' }
1752
1651
 
1753
1652
  it_behaves_like 'negates the next condition'
1754
1653
  end
1755
1654
 
1756
- context "when the following criteria is a gt method" do
1757
-
1655
+ context 'when the following criteria is a gt method' do
1758
1656
  let(:selection) do
1759
1657
  query.not.gt(age: 50)
1760
1658
  end
1761
1659
 
1762
- it "negates the gt selection" do
1660
+ it 'negates the gt selection' do
1763
1661
  expect(selection.selector).to eq(
1764
- { "age" => { "$not" => { "$gt" => 50 }}}
1662
+ { 'age' => { '$not' => { '$gt' => 50 } } }
1765
1663
  )
1766
1664
  end
1767
1665
 
1768
1666
  it_behaves_like 'returns a cloned query'
1769
1667
 
1770
- it "removes the negation on the clone" do
1771
- expect(selection).to_not be_negating
1668
+ it 'removes the negation on the clone' do
1669
+ expect(selection).not_to be_negating
1772
1670
  end
1773
1671
  end
1774
1672
 
1775
- context "when the criteria uses Key" do
1776
-
1673
+ context 'when the criteria uses Key' do
1777
1674
  let(:selection) do
1778
1675
  query.not(:age.gt => 50)
1779
1676
  end
1780
1677
 
1781
- it "negates the gt selection" do
1678
+ it 'negates the gt selection' do
1782
1679
  expect(selection.selector).to eq(
1783
- '$and' => ['$nor' => ['age' => {'$gt' => 50}]]
1680
+ '$and' => [ { '$nor' => [ { 'age' => { '$gt' => 50 } } ] } ]
1784
1681
  )
1785
1682
  end
1786
1683
 
1787
1684
  it_behaves_like 'returns a cloned query'
1788
1685
 
1789
- it "removes the negation on the clone" do
1790
- expect(selection).to_not be_negating
1686
+ it 'removes the negation on the clone' do
1687
+ expect(selection).not_to be_negating
1791
1688
  end
1792
1689
  end
1793
1690
 
1794
- context "when the following criteria is a where" do
1795
-
1691
+ context 'when the following criteria is a where' do
1796
1692
  let(:selection) do
1797
1693
  query.not.where(field: 1, :other.in => [ 1, 2 ])
1798
1694
  end
1799
1695
 
1800
- it "negates the selection with an operator" do
1696
+ it 'negates the selection with an operator' do
1801
1697
  expect(selection.selector).to eq(
1802
- { "field" => { "$ne" => 1 }, "other" => { "$not" => { "$in" => [ 1, 2 ] }}}
1698
+ { 'field' => { '$ne' => 1 }, 'other' => { '$not' => { '$in' => [ 1, 2 ] } } }
1803
1699
  )
1804
1700
  end
1805
1701
 
1806
1702
  it_behaves_like 'returns a cloned query'
1807
1703
 
1808
- it "removes the negation on the clone" do
1809
- expect(selection).to_not be_negating
1704
+ it 'removes the negation on the clone' do
1705
+ expect(selection).not_to be_negating
1810
1706
  end
1811
1707
  end
1812
1708
 
1813
- context "when the following criteria is a where with a regexp" do
1814
-
1709
+ context 'when the following criteria is a where with a regexp' do
1815
1710
  let(:selection) do
1816
1711
  query.not.where(field: 1, other: /test/)
1817
1712
  end
1818
1713
 
1819
- it "negates the selection with an operator" do
1714
+ it 'negates the selection with an operator' do
1820
1715
  expect(selection.selector).to eq(
1821
- { "field" => { "$ne" => 1 }, "other" => { "$not" => /test/ } }
1716
+ { 'field' => { '$ne' => 1 }, 'other' => { '$not' => /test/ } }
1822
1717
  )
1823
1718
  end
1824
1719
 
1825
1720
  it_behaves_like 'returns a cloned query'
1826
1721
 
1827
- it "removes the negation on the clone" do
1828
- expect(selection).to_not be_negating
1722
+ it 'removes the negation on the clone' do
1723
+ expect(selection).not_to be_negating
1829
1724
  end
1830
1725
  end
1831
1726
 
1832
1727
  context 'when the following criteria uses string were form' do
1833
- # String criteria compile to $where, which requires the opt-in.
1834
- config_override :allow_unsafe_query_operators, true
1835
-
1836
1728
  let(:selection) do
1837
1729
  query.not.where('hello world')
1838
1730
  end
1839
1731
 
1840
- it "negates the selection with an operator" do
1732
+ it 'negates the selection with an operator' do
1841
1733
  expect(selection.selector).to eq(
1842
- '$and' => [{'$nor' => [{'$where' => 'hello world'}]}]
1734
+ '$and' => [ { '$nor' => [ { '$where' => 'hello world' } ] } ]
1843
1735
  )
1844
1736
  end
1845
1737
 
1846
1738
  it_behaves_like 'returns a cloned query'
1847
1739
 
1848
- it "removes the negation on the clone" do
1849
- expect(selection).to_not be_negating
1740
+ it 'removes the negation on the clone' do
1741
+ expect(selection).not_to be_negating
1850
1742
  end
1851
-
1852
1743
  end
1853
1744
  end
1854
1745
 
1855
- context "when provided nil" do
1856
-
1746
+ context 'when provided nil' do
1857
1747
  let(:selection) do
1858
1748
  query.not(nil)
1859
1749
  end
1860
1750
 
1861
- it "does not add any criterion" do
1751
+ it 'does not add any criterion' do
1862
1752
  expect(selection.selector).to eq({})
1863
1753
  end
1864
1754
 
1865
- it "returns the query" do
1755
+ it 'returns the query' do
1866
1756
  expect(selection).to eq(query)
1867
1757
  end
1868
1758
 
1869
1759
  it_behaves_like 'returns a cloned query'
1870
1760
  end
1871
1761
 
1872
- context "when provided a single criterion" do
1873
-
1762
+ context 'when provided a single criterion' do
1874
1763
  let(:selection) do
1875
1764
  query.not(field: /test/)
1876
1765
  end
1877
1766
 
1878
- it "adds the $not selector" do
1767
+ it 'adds the $not selector' do
1879
1768
  expect(selection.selector).to eq({
1880
- "field" => { "$not" => /test/ }
1881
- })
1769
+ 'field' => { '$not' => /test/ }
1770
+ })
1882
1771
  end
1883
1772
 
1884
1773
  it_behaves_like 'returns a cloned query'
1885
1774
  end
1886
1775
 
1887
- context "when negating a field in the original selector" do
1776
+ context 'when negating a field in the original selector' do
1888
1777
  let(:query) do
1889
- Mongoid::Query.new("id" => "_id").where(field: 'foo')
1778
+ Mongoid::Query.new('id' => '_id').where(field: 'foo')
1890
1779
  end
1891
1780
 
1892
1781
  let(:selection) do
1893
1782
  query.not(field: 'bar')
1894
1783
  end
1895
1784
 
1896
- it "combines the conditions" do
1785
+ it 'combines the conditions' do
1897
1786
  expect(selection.selector).to eq({
1898
- "field" => 'foo',
1899
- '$and' => [{'$nor' => [{ "field" => 'bar' }]}],
1900
- })
1787
+ 'field' => 'foo',
1788
+ '$and' => [ { '$nor' => [ { 'field' => 'bar' } ] } ]
1789
+ })
1901
1790
  end
1902
1791
 
1903
1792
  it_behaves_like 'returns a cloned query'
1904
1793
  end
1905
1794
 
1906
- context "when provided multiple criteria" do
1907
-
1908
- context "when the criteria are for different fields" do
1909
-
1795
+ context 'when provided multiple criteria' do
1796
+ context 'when the criteria are for different fields' do
1910
1797
  let(:selection) do
1911
1798
  query.not(first: /1/, second: /2/)
1912
1799
  end
1913
1800
 
1914
- it "adds the $not selectors" do
1801
+ it 'adds the $not selectors' do
1915
1802
  expect(selection.selector).to eq({
1916
- "first" => { "$not" => /1/ },
1917
- "second" => { "$not" => /2/ }
1918
- })
1803
+ 'first' => { '$not' => /1/ },
1804
+ 'second' => { '$not' => /2/ }
1805
+ })
1919
1806
  end
1920
1807
 
1921
1808
  it_behaves_like 'returns a cloned query'
1922
1809
  end
1923
1810
 
1924
- context "when the criteria are given in separate arguments" do
1925
-
1811
+ context 'when the criteria are given in separate arguments' do
1926
1812
  let(:selection) do
1927
- query.not({first: /1/}, {second: /2/})
1813
+ query.not({ first: /1/ }, { second: /2/ })
1928
1814
  end
1929
1815
 
1930
- it "adds the $not selectors" do
1816
+ it 'adds the $not selectors' do
1931
1817
  expect(selection.selector).to eq({
1932
- "first" => { "$not" => /1/ },
1933
- "second" => { "$not" => /2/ }
1934
- })
1818
+ 'first' => { '$not' => /1/ },
1819
+ 'second' => { '$not' => /2/ }
1820
+ })
1935
1821
  end
1936
1822
 
1937
1823
  it_behaves_like 'returns a cloned query'
1938
1824
  end
1939
1825
  end
1940
1826
 
1941
- context "when chaining the criterion" do
1942
-
1943
- context "when the criterion are for different fields" do
1944
-
1827
+ context 'when chaining the criterion' do
1828
+ context 'when the criterion are for different fields' do
1945
1829
  let(:selection) do
1946
1830
  query.not(first: /1/).not(second: /2/)
1947
1831
  end
1948
1832
 
1949
- it "adds the $not selectors" do
1833
+ it 'adds the $not selectors' do
1950
1834
  expect(selection.selector).to eq({
1951
- "first" => { "$not" => /1/ },
1952
- "second" => { "$not" => /2/ }
1953
- })
1835
+ 'first' => { '$not' => /1/ },
1836
+ 'second' => { '$not' => /2/ }
1837
+ })
1954
1838
  end
1955
1839
 
1956
1840
  it_behaves_like 'returns a cloned query'
1957
1841
  end
1958
1842
 
1959
- context "when the criterion are on the same field" do
1960
-
1843
+ context 'when the criterion are on the same field' do
1961
1844
  let(:selection) do
1962
1845
  query.not(first: /1/).not(first: /2/)
1963
1846
  end
1964
1847
 
1965
- it "combines conditions" do
1848
+ it 'combines conditions' do
1966
1849
  expect(selection.selector).to eq(
1967
- "first" => { "$not" => /1/ },
1968
- '$and' => [{'$nor' => [{'first' => /2/}]}],
1850
+ 'first' => { '$not' => /1/ },
1851
+ '$and' => [ { '$nor' => [ { 'first' => /2/ } ] } ]
1969
1852
  )
1970
1853
  end
1971
1854
 
1972
1855
  it_behaves_like 'returns a cloned query'
1973
1856
  end
1974
1857
 
1975
- context "when the criterion are a double negative" do
1976
-
1858
+ context 'when the criterion are a double negative' do
1977
1859
  let(:selection) do
1978
1860
  query.not.where(:first.not => /1/)
1979
1861
  end
1980
1862
 
1981
- it "does not double the $not selector" do
1863
+ it 'does not double the $not selector' do
1982
1864
  expect(selection.selector).to eq({
1983
- "first" => { "$not" => /1/ }
1984
- })
1865
+ 'first' => { '$not' => /1/ }
1866
+ })
1985
1867
  end
1986
1868
 
1987
1869
  it_behaves_like 'returns a cloned query'
@@ -2000,7 +1882,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
2000
1882
  let(:result) { query.not(other) }
2001
1883
 
2002
1884
  it 'combines' do
2003
- expect(result.selector).to eq('hello' => 'world', 'foo' => {'$ne' => 'bar'})
1885
+ expect(result.selector).to eq('hello' => 'world', 'foo' => { '$ne' => 'bar' })
2004
1886
  end
2005
1887
  end
2006
1888
 
@@ -2017,7 +1899,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
2017
1899
 
2018
1900
  it 'combines fields into top level criteria' do
2019
1901
  expect(result.selector).to eq('hello' => 'world',
2020
- 'a' => {'$ne' => 1}, 'b' => {'$ne' => 2})
1902
+ 'a' => { '$ne' => 1 }, 'b' => { '$ne' => 2 })
2021
1903
  end
2022
1904
  end
2023
1905
 
@@ -2027,14 +1909,15 @@ describe Mongoid::Criteria::Queryable::Selectable do
2027
1909
  end
2028
1910
 
2029
1911
  let(:other) do
2030
- Mongoid::Query.new.where('$nor' => [{a: 1, b: 2}])
1912
+ Mongoid::Query.new.where('$nor' => [ { a: 1, b: 2 } ])
2031
1913
  end
2032
1914
 
2033
1915
  let(:result) { query.not(other) }
2034
1916
 
2035
1917
  it 'combines with $and of $nor' do
2036
- expect(result.selector).to eq('hello' => 'world', '$and' => [{'$nor' => [{
2037
- '$nor' => [{'a' => 1, 'b' => 2}]}]}])
1918
+ expect(result.selector).to eq('hello' => 'world', '$and' => [ { '$nor' => [ {
1919
+ '$nor' => [ { 'a' => 1, 'b' => 2 } ]
1920
+ } ] } ])
2038
1921
  end
2039
1922
  end
2040
1923
 
@@ -2048,7 +1931,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
2048
1931
  end
2049
1932
 
2050
1933
  let(:other2) do
2051
- {bar: 42}
1934
+ { bar: 42 }
2052
1935
  end
2053
1936
 
2054
1937
  let(:other3) do
@@ -2059,26 +1942,24 @@ describe Mongoid::Criteria::Queryable::Selectable do
2059
1942
 
2060
1943
  it 'combines' do
2061
1944
  expect(result.selector).to eq('hello' => 'world',
2062
- 'foo' => {'$ne' => 'bar'},
2063
- 'bar' => {'$ne' => 42},
2064
- 'a' => {'$ne' => 2},
2065
- )
1945
+ 'foo' => { '$ne' => 'bar' },
1946
+ 'bar' => { '$ne' => 42 },
1947
+ 'a' => { '$ne' => 2 })
2066
1948
  end
2067
1949
  end
2068
1950
 
2069
1951
  context 'when giving multiple conditions in one call on the same key with symbol operator' do
2070
-
2071
1952
  context 'non-regexp argument' do
2072
1953
  let(:selection) do
2073
1954
  query.not(field: 1, :field.gt => 0)
2074
1955
  end
2075
1956
 
2076
1957
  it 'combines conditions with $eq' do
2077
- selection.selector.should == {
2078
- '$and' => ['$nor' => [
2079
- 'field' => {'$eq' => 1, '$gt' => 0},
2080
- ]]
2081
- }
1958
+ selection.selector.should eq(
1959
+ '$and' => [ { '$nor' => [
1960
+ { 'field' => { '$eq' => 1, '$gt' => 0 } }
1961
+ ] } ]
1962
+ )
2082
1963
  end
2083
1964
  end
2084
1965
 
@@ -2088,39 +1969,40 @@ describe Mongoid::Criteria::Queryable::Selectable do
2088
1969
  end
2089
1970
 
2090
1971
  it 'combines conditions with $regex' do
2091
- selection.selector.should == {
2092
- '$and' => ['$nor' => [
2093
- 'field' => {'$regex' => /t/, '$gt' => 0},
2094
- ]]
2095
- }
1972
+ selection.selector.should eq(
1973
+ '$and' => [ { '$nor' => [
1974
+ { 'field' => { '$regex' => /t/, '$gt' => 0 } }
1975
+ ] } ]
1976
+ )
2096
1977
  end
2097
1978
  end
2098
1979
  end
2099
1980
 
2100
1981
  # This test confirms that MONGOID-5097 has been repaired.
2101
- context "when using exists on a field of type Time" do
1982
+ context 'when using exists on a field of type Time' do
2102
1983
  let(:criteria) do
2103
- Dictionary.any_of({:published.exists => true}, published: nil)
1984
+ Dictionary.any_of({ :published.exists => true }, published: nil)
2104
1985
  end
2105
1986
 
2106
1987
  it "doesn't raise an error" do
2107
1988
  expect do
2108
1989
  criteria
2109
- end.to_not raise_error
1990
+ end.not_to raise_error
2110
1991
  end
2111
1992
 
2112
- it "generates the correct selector" do
1993
+ it 'generates the correct selector' do
2113
1994
  expect(criteria.selector).to eq({
2114
- "$or" => [ {
2115
- "published" => { "$exists" => true }
2116
- }, {
2117
- "published" => nil
2118
- } ] } )
1995
+ '$or' => [ {
1996
+ 'published' => { '$exists' => true }
1997
+ }, {
1998
+ 'published' => nil
1999
+ } ]
2000
+ })
2119
2001
  end
2120
2002
  end
2121
2003
  end
2122
2004
 
2123
- describe "#none_of" do
2005
+ describe '#none_of' do
2124
2006
  context 'when argument is a mix of Criteria and hashes' do
2125
2007
  let(:query) { Mongoid::Query.new.where(hello: 'world') }
2126
2008
  let(:other1) { Mongoid::Query.new.where(foo: 'bar') }
@@ -2133,72 +2015,72 @@ describe Mongoid::Criteria::Queryable::Selectable do
2133
2015
  expect(result.selector).to eq(
2134
2016
  'hello' => 'world',
2135
2017
  '$nor' => [
2136
- {'foo' => 'bar'},
2137
- {'bar' => 42},
2138
- {'a' => 2},
2139
- ],
2018
+ { 'foo' => 'bar' },
2019
+ { 'bar' => 42 },
2020
+ { 'a' => 2 }
2021
+ ]
2140
2022
  )
2141
2023
  end
2142
2024
  end
2143
2025
 
2144
- context "when provided no arguments" do
2026
+ context 'when provided no arguments' do
2145
2027
  let(:selection) { query.none_of }
2146
2028
 
2147
2029
  it_behaves_like 'returns a cloned query'
2148
2030
 
2149
- it "does not add any criteria" do
2031
+ it 'does not add any criteria' do
2150
2032
  expect(selection.selector).to eq({})
2151
2033
  end
2152
2034
 
2153
- it "returns the query" do
2035
+ it 'returns the query' do
2154
2036
  expect(selection).to eq(query)
2155
2037
  end
2156
2038
  end
2157
2039
 
2158
- context "when provided nil" do
2040
+ context 'when provided nil' do
2159
2041
  let(:selection) { query.none_of(nil) }
2160
2042
 
2161
2043
  it_behaves_like 'returns a cloned query'
2162
2044
 
2163
- it "does not add any criteria" do
2045
+ it 'does not add any criteria' do
2164
2046
  expect(selection.selector).to eq({})
2165
2047
  end
2166
2048
 
2167
- it "returns the query" do
2049
+ it 'returns the query' do
2168
2050
  expect(selection).to eq(query)
2169
2051
  end
2170
2052
  end
2171
2053
 
2172
- context "when provided a single criterion" do
2054
+ context 'when provided a single criterion' do
2173
2055
  let(:selection) { query.none_of(field: [ 1, 2 ]) }
2174
2056
 
2175
2057
  it_behaves_like 'returns a cloned query'
2176
2058
 
2177
2059
  it 'adds the $nor selector' do
2178
2060
  expect(selection.selector).to eq(
2179
- '$nor' => [ { 'field' => [ 1, 2 ] } ],
2061
+ '$nor' => [ { 'field' => [ 1, 2 ] } ]
2180
2062
  )
2181
2063
  end
2182
2064
 
2183
2065
  context 'when the criterion is wrapped in array' do
2184
- let(:selection) { query.none_of([{ field: [ 1, 2 ] }]) }
2066
+ let(:selection) { query.none_of([ { field: [ 1, 2 ] } ]) }
2185
2067
 
2186
2068
  it_behaves_like 'returns a cloned query'
2187
2069
 
2188
2070
  it 'adds the condition' do
2189
2071
  expect(selection.selector).to eq(
2190
- '$nor' => [ { 'field' => [ 1, 2 ] } ],
2072
+ '$nor' => [ { 'field' => [ 1, 2 ] } ]
2191
2073
  )
2192
2074
  end
2193
2075
 
2194
2076
  context 'when the array has nil as one of the elements' do
2195
- let(:selection) { query.none_of([{ field: [ 1, 2 ] }, nil]) }
2077
+ let(:selection) { query.none_of([ { field: [ 1, 2 ] }, nil ]) }
2196
2078
 
2197
2079
  it_behaves_like 'returns a cloned query'
2198
2080
 
2199
2081
  it 'adds the $nor selector ignoring the nil element' do
2200
2082
  expect(selection.selector).to eq(
2201
- '$nor' => [ { 'field' => [ 1, 2 ] } ],
2083
+ '$nor' => [ { 'field' => [ 1, 2 ] } ]
2202
2084
  )
2203
2085
  end
2204
2086
  end
@@ -2211,7 +2093,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
2211
2093
  it 'adds the new condition' do
2212
2094
  expect(selection.selector).to eq(
2213
2095
  'foo' => 'bar',
2214
- '$nor' => [ { 'field' => [1, 2] } ],
2096
+ '$nor' => [ { 'field' => [ 1, 2 ] } ]
2215
2097
  )
2216
2098
  end
2217
2099
  end
@@ -2225,9 +2107,9 @@ describe Mongoid::Criteria::Queryable::Selectable do
2225
2107
  expect(selection.selector).to eq(
2226
2108
  'foo' => 'bar',
2227
2109
  '$nor' => [
2228
- { 'field' => [1, 2] },
2229
- { 'hello' => 'world' },
2230
- ],
2110
+ { 'field' => [ 1, 2 ] },
2111
+ { 'hello' => 'world' }
2112
+ ]
2231
2113
  )
2232
2114
  end
2233
2115
  end
@@ -2240,7 +2122,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
2240
2122
 
2241
2123
  it 'adds the new condition' do
2242
2124
  expect(selection.selector).to eq(
2243
- '$nor' => [ { 'field' => [1, 2] } ],
2125
+ '$nor' => [ { 'field' => [ 1, 2 ] } ],
2244
2126
  'foo' => 'bar',
2245
2127
  '$and' => [ { '$nor' => [ { 'test' => 1 } ] } ]
2246
2128
  )
@@ -2249,65 +2131,65 @@ describe Mongoid::Criteria::Queryable::Selectable do
2249
2131
 
2250
2132
  context 'when none_of has multiple arguments' do
2251
2133
  let(:selection) do
2252
- query.nor(field: [ 1, 2 ]).where(foo: 'bar').none_of({a: 1}, {b: 2})
2134
+ query.nor(field: [ 1, 2 ]).where(foo: 'bar').none_of({ a: 1 }, { b: 2 })
2253
2135
  end
2254
2136
 
2255
2137
  it 'adds the new condition to top level' do
2256
2138
  expect(selection.selector).to eq(
2257
2139
  'foo' => 'bar',
2258
- '$nor' => [ { 'field' => [1, 2] } ],
2140
+ '$nor' => [ { 'field' => [ 1, 2 ] } ],
2259
2141
  '$and' => [ { '$nor' => [ { 'a' => 1 }, { 'b' => 2 } ] } ]
2260
2142
  )
2261
2143
  end
2262
2144
 
2263
2145
  context 'when query already has a top-level $and' do
2264
2146
  let(:selection) do
2265
- query.nor(field: [ 1, 2 ]).where('$and' => [foo: 'bar']).none_of({a: 1}, {b: 2})
2147
+ query.nor(field: [ 1, 2 ]).where('$and' => [ { foo: 'bar' } ]).none_of({ a: 1 }, { b: 2 })
2266
2148
  end
2267
2149
 
2268
2150
  it 'adds the new condition to top level $and' do
2269
2151
  expect(selection.selector).to eq(
2270
- '$nor' => [ { 'field' => [1, 2] } ],
2152
+ '$nor' => [ { 'field' => [ 1, 2 ] } ],
2271
2153
  '$and' => [
2272
2154
  { 'foo' => 'bar' },
2273
2155
  { '$nor' => [ { 'a' => 1 }, { 'b' => 2 } ] }
2274
- ],
2156
+ ]
2275
2157
  )
2276
2158
  end
2277
2159
  end
2278
2160
  end
2279
2161
  end
2280
2162
 
2281
- context "when provided multiple criteria" do
2282
- context "when the criteria are for different fields" do
2163
+ context 'when provided multiple criteria' do
2164
+ context 'when the criteria are for different fields' do
2283
2165
  let(:selection) do
2284
2166
  query.none_of({ first: [ 1, 2 ] }, { second: [ 3, 4 ] })
2285
2167
  end
2286
2168
 
2287
2169
  it_behaves_like 'returns a cloned query'
2288
2170
 
2289
- it "adds the $nor selector" do
2171
+ it 'adds the $nor selector' do
2290
2172
  expect(selection.selector).to eq({
2291
- "$nor" => [
2292
- { "first" => [ 1, 2 ] },
2293
- { "second" => [ 3, 4 ] }
2294
- ]
2295
- })
2173
+ '$nor' => [
2174
+ { 'first' => [ 1, 2 ] },
2175
+ { 'second' => [ 3, 4 ] }
2176
+ ]
2177
+ })
2296
2178
  end
2297
2179
  end
2298
2180
 
2299
- context "when the criteria uses a Key instance" do
2181
+ context 'when the criteria uses a Key instance' do
2300
2182
  let(:selection) do
2301
2183
  query.none_of({ first: [ 1, 2 ] }, { :second.gt => 3 })
2302
2184
  end
2303
2185
 
2304
- it "adds the $nor selector" do
2186
+ it 'adds the $nor selector' do
2305
2187
  expect(selection.selector).to eq({
2306
- "$nor" => [
2307
- { "first" => [ 1, 2 ] },
2308
- { "second" => { "$gt" => 3 }}
2309
- ]
2310
- })
2188
+ '$nor' => [
2189
+ { 'first' => [ 1, 2 ] },
2190
+ { 'second' => { '$gt' => 3 } }
2191
+ ]
2192
+ })
2311
2193
  end
2312
2194
 
2313
2195
  it_behaves_like 'returns a cloned query'
@@ -2315,23 +2197,23 @@ describe Mongoid::Criteria::Queryable::Selectable do
2315
2197
 
2316
2198
  context 'when criteria are simple and handled via Key' do
2317
2199
  shared_examples_for 'adds conditions with $nor' do
2318
- it "adds conditions with $nor" do
2200
+ it 'adds conditions with $nor' do
2319
2201
  expect(selection.selector).to eq({
2320
- '$nor' => [
2321
- {'field' => 3},
2322
- {'field' => {'$lt' => 5}},
2323
- ],
2324
- })
2202
+ '$nor' => [
2203
+ { 'field' => 3 },
2204
+ { 'field' => { '$lt' => 5 } }
2205
+ ]
2206
+ })
2325
2207
  end
2326
2208
 
2327
2209
  it_behaves_like 'returns a cloned query'
2328
2210
  end
2329
2211
 
2330
2212
  shared_examples_for 'combines conditions with $eq' do
2331
- it "combines conditions with $eq" do
2213
+ it 'combines conditions with $eq' do
2332
2214
  expect(selection.selector).to eq({
2333
- '$nor' => [ { 'field' => { '$eq' => 3, '$lt' => 5 } } ]
2334
- })
2215
+ '$nor' => [ { 'field' => { '$eq' => 3, '$lt' => 5 } } ]
2216
+ })
2335
2217
  end
2336
2218
 
2337
2219
  it_behaves_like 'returns a cloned query'
@@ -2340,8 +2222,8 @@ describe Mongoid::Criteria::Queryable::Selectable do
2340
2222
  shared_examples_for 'combines conditions with $regex' do
2341
2223
  it 'combines conditions with $regex' do
2342
2224
  expect(selection.selector).to eq({
2343
- '$nor' => [ { 'field' => { '$regex' => /t/, '$lt' => 5 } } ]
2344
- })
2225
+ '$nor' => [ { 'field' => { '$regex' => /t/, '$lt' => 5 } } ]
2226
+ })
2345
2227
  end
2346
2228
 
2347
2229
  it_behaves_like 'returns a cloned query'
@@ -2350,22 +2232,26 @@ describe Mongoid::Criteria::Queryable::Selectable do
2350
2232
  context 'criteria are provided in the same hash' do
2351
2233
  context 'non-regexp argument' do
2352
2234
  let(:selection) { query.none_of(:field => 3, :field.lt => 5) }
2235
+
2353
2236
  it_behaves_like 'combines conditions with $eq'
2354
2237
  end
2355
2238
 
2356
2239
  context 'regexp argument' do
2357
2240
  let(:selection) { query.none_of(:field => /t/, :field.lt => 5) }
2241
+
2358
2242
  it_behaves_like 'combines conditions with $regex'
2359
2243
  end
2360
2244
  end
2361
2245
 
2362
2246
  context 'criteria are provided in separate hashes' do
2363
- let(:selection) { query.none_of({:field => 3}, {:field.lt => 5}) }
2247
+ let(:selection) { query.none_of({ field: 3 }, { :field.lt => 5 }) }
2248
+
2364
2249
  it_behaves_like 'adds conditions with $nor'
2365
2250
  end
2366
2251
 
2367
2252
  context 'when the criterion is wrapped in an array' do
2368
- let(:selection) { query.none_of([:field => 3], [:field.lt => 5]) }
2253
+ let(:selection) { query.none_of([ { field: 3 } ], [ { :field.lt => 5 } ]) }
2254
+
2369
2255
  it_behaves_like 'adds conditions with $nor'
2370
2256
  end
2371
2257
  end
@@ -2374,11 +2260,11 @@ describe Mongoid::Criteria::Queryable::Selectable do
2374
2260
  shared_examples_for 'adds conditions with $nor' do
2375
2261
  it 'adds conditions with $nor' do
2376
2262
  expect(selection.selector).to eq({
2377
- '$nor' => [
2378
- { 'field' => { '$gt' => 3 } },
2379
- { 'field' => 5 },
2380
- ],
2381
- })
2263
+ '$nor' => [
2264
+ { 'field' => { '$gt' => 3 } },
2265
+ { 'field' => 5 }
2266
+ ]
2267
+ })
2382
2268
  end
2383
2269
 
2384
2270
  it_behaves_like 'returns a cloned query'
@@ -2387,7 +2273,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
2387
2273
  shared_examples_for 'combines conditions with $eq' do
2388
2274
  it 'combines conditions with $eq' do
2389
2275
  expect(selection.selector).to eq(
2390
- '$nor' => [ { 'field' => {'$gt' => 3, '$eq' => 5} } ],
2276
+ '$nor' => [ { 'field' => { '$gt' => 3, '$eq' => 5 } } ]
2391
2277
  )
2392
2278
  end
2393
2279
 
@@ -2397,7 +2283,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
2397
2283
  shared_examples_for 'combines conditions with $regex' do
2398
2284
  it 'combines conditions with $regex' do
2399
2285
  expect(selection.selector).to eq(
2400
- '$nor' => [ { 'field' => {'$gt' => 3, '$regex' => /t/} } ],
2286
+ '$nor' => [ { 'field' => { '$gt' => 3, '$regex' => /t/ } } ]
2401
2287
  )
2402
2288
  end
2403
2289
 
@@ -2407,22 +2293,26 @@ describe Mongoid::Criteria::Queryable::Selectable do
2407
2293
  context 'criteria are provided in the same hash' do
2408
2294
  context 'non-regexp argument' do
2409
2295
  let(:selection) { query.none_of(:field.gt => 3, :field => 5) }
2296
+
2410
2297
  it_behaves_like 'combines conditions with $eq'
2411
2298
  end
2412
2299
 
2413
2300
  context 'regexp argument' do
2414
2301
  let(:selection) { query.none_of(:field.gt => 3, :field => /t/) }
2302
+
2415
2303
  it_behaves_like 'combines conditions with $regex'
2416
2304
  end
2417
2305
  end
2418
2306
 
2419
2307
  context 'criteria are provided in separate hashes' do
2420
- let(:selection) { query.none_of({:field.gt => 3}, {:field => 5}) }
2308
+ let(:selection) { query.none_of({ :field.gt => 3 }, { field: 5 }) }
2309
+
2421
2310
  it_behaves_like 'adds conditions with $nor'
2422
2311
  end
2423
2312
 
2424
2313
  context 'when the criterion is wrapped in an array' do
2425
- let(:selection) { query.none_of([:field.gt => 3], [:field => 5]) }
2314
+ let(:selection) { query.none_of([ { :field.gt => 3 } ], [ { field: 5 } ]) }
2315
+
2426
2316
  it_behaves_like 'adds conditions with $nor'
2427
2317
  end
2428
2318
  end
@@ -2431,7 +2321,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
2431
2321
  let(:selection) { query.none_of({ id: 1 }) }
2432
2322
 
2433
2323
  it 'adds the $nor selector and aliases the field' do
2434
- expect(selection.selector).to eq('$nor' => [{ '_id' => 1 }])
2324
+ expect(selection.selector).to eq('$nor' => [ { '_id' => 1 } ])
2435
2325
  end
2436
2326
 
2437
2327
  it_behaves_like 'returns a cloned query'
@@ -2439,22 +2329,22 @@ describe Mongoid::Criteria::Queryable::Selectable do
2439
2329
 
2440
2330
  context 'when a criterion is wrapped in an array' do
2441
2331
  let(:selection) do
2442
- query.none_of([{ first: [ 1, 2 ] }, { :second.gt => 3 }])
2332
+ query.none_of([ { first: [ 1, 2 ] }, { :second.gt => 3 } ])
2443
2333
  end
2444
2334
 
2445
2335
  it_behaves_like 'returns a cloned query'
2446
2336
 
2447
2337
  it 'adds the $ nor selector' do
2448
2338
  expect(selection.selector).to eq({
2449
- '$nor' => [
2450
- { 'first' => [ 1, 2 ] },
2451
- { 'second' => { '$gt' => 3 }}
2452
- ]
2453
- })
2339
+ '$nor' => [
2340
+ { 'first' => [ 1, 2 ] },
2341
+ { 'second' => { '$gt' => 3 } }
2342
+ ]
2343
+ })
2454
2344
  end
2455
2345
  end
2456
2346
 
2457
- context "when the criteria are on the same field" do
2347
+ context 'when the criteria are on the same field' do
2458
2348
  let(:selection) do
2459
2349
  query.none_of({ first: [ 1, 2 ] }, { first: [ 3, 4 ] })
2460
2350
  end
@@ -2463,11 +2353,11 @@ describe Mongoid::Criteria::Queryable::Selectable do
2463
2353
 
2464
2354
  it 'appends both $nor expressions' do
2465
2355
  expect(selection.selector).to eq({
2466
- "$nor" => [
2467
- { "first" => [ 1, 2 ] },
2468
- { "first" => [ 3, 4 ] }
2469
- ]
2470
- })
2356
+ '$nor' => [
2357
+ { 'first' => [ 1, 2 ] },
2358
+ { 'first' => [ 3, 4 ] }
2359
+ ]
2360
+ })
2471
2361
  end
2472
2362
  end
2473
2363
  end
@@ -2483,12 +2373,12 @@ describe Mongoid::Criteria::Queryable::Selectable do
2483
2373
  it 'adds the conditions separately' do
2484
2374
  expect(selection.selector).to eq(
2485
2375
  '$nor' => [ { 'first' => [ 1, 2 ] } ],
2486
- '$and' => [ { '$nor' => [ { 'second' => [ 3, 4 ] } ] } ],
2376
+ '$and' => [ { '$nor' => [ { 'second' => [ 3, 4 ] } ] } ]
2487
2377
  )
2488
2378
  end
2489
2379
  end
2490
2380
 
2491
- context "when the criteria are on the same field" do
2381
+ context 'when the criteria are on the same field' do
2492
2382
  let(:selection) do
2493
2383
  query.none_of(first: [ 1, 2 ]).none_of(first: [ 3, 4 ])
2494
2384
  end
@@ -2507,33 +2397,37 @@ describe Mongoid::Criteria::Queryable::Selectable do
2507
2397
  context 'when using multiple criteria and symbol operators' do
2508
2398
  context 'when using fields that meaningfully evolve values' do
2509
2399
  let(:query) do
2510
- Dictionary.none_of({a: 1}, :published.gt => Date.new(2020, 2, 3))
2400
+ Dictionary.none_of({ a: 1 }, :published.gt => Date.new(2020, 2, 3))
2511
2401
  end
2512
2402
 
2513
2403
  it 'generates the expected query' do
2514
- query.selector.should == {'$nor' => [
2515
- {'a' => 1},
2516
- # Date instance is converted to a Time instance in local time,
2517
- # because we are querying on a Time field and dates are interpreted
2518
- # in local time when assigning to Time fields
2519
- {'published' => {'$gt' => Time.zone.local(2020, 2, 3) } },
2520
- ] }
2404
+ query.selector.should eq(
2405
+ { '$nor' => [
2406
+ { 'a' => 1 },
2407
+ # Date instance is converted to a Time instance in local time,
2408
+ # because we are querying on a Time field and dates are interpreted
2409
+ # in local time when assigning to Time fields
2410
+ { 'published' => { '$gt' => Time.zone.local(2020, 2, 3) } }
2411
+ ] }
2412
+ )
2521
2413
  end
2522
2414
  end
2523
2415
 
2524
2416
  context 'when using fields that do not meaningfully evolve values' do
2525
2417
  let(:query) do
2526
- Dictionary.none_of({a: 1}, :submitted_on.gt => Date.new(2020, 2, 3))
2418
+ Dictionary.none_of({ a: 1 }, :submitted_on.gt => Date.new(2020, 2, 3))
2527
2419
  end
2528
2420
 
2529
2421
  it 'generates the expected query' do
2530
- query.selector.should == {'$nor' => [
2531
- {'a' => 1},
2532
- # Date instance is converted to a Time instance in UTC,
2533
- # because we are querying on a Date field and dates are interpreted
2534
- # in UTC when persisted as dates by Mongoid
2535
- {'submitted_on' => {'$gt' => Time.utc(2020, 2, 3)}},
2536
- ]}
2422
+ query.selector.should eq(
2423
+ { '$nor' => [
2424
+ { 'a' => 1 },
2425
+ # Date instance is converted to a Time instance in UTC,
2426
+ # because we are querying on a Date field and dates are interpreted
2427
+ # in UTC when persisted as dates by Mongoid
2428
+ { 'submitted_on' => { '$gt' => Time.utc(2020, 2, 3) } }
2429
+ ] }
2430
+ )
2537
2431
  end
2538
2432
  end
2539
2433
  end