mongoid 9.0.11 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (997) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -8
  3. data/README.md +5 -11
  4. data/Rakefile +35 -38
  5. data/lib/config/locales/en.yml +11 -0
  6. data/lib/mongoid/association/accessors.rb +19 -26
  7. data/lib/mongoid/association/bindable.rb +43 -45
  8. data/lib/mongoid/association/builders.rb +18 -15
  9. data/lib/mongoid/association/constrainable.rb +3 -5
  10. data/lib/mongoid/association/depending.rb +34 -38
  11. data/lib/mongoid/association/eager.rb +47 -13
  12. data/lib/mongoid/association/eager_loadable.rb +152 -24
  13. data/lib/mongoid/association/embedded/batchable.rb +28 -30
  14. data/lib/mongoid/association/embedded/cyclic.rb +8 -11
  15. data/lib/mongoid/association/embedded/eager.rb +1 -6
  16. data/lib/mongoid/association/embedded/embedded_in/binding.rb +6 -9
  17. data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -3
  18. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -0
  19. data/lib/mongoid/association/embedded/embedded_in.rb +25 -22
  20. data/lib/mongoid/association/embedded/embeds_many/binding.rb +0 -2
  21. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +2 -3
  22. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +1 -1
  23. data/lib/mongoid/association/embedded/embeds_many.rb +24 -21
  24. data/lib/mongoid/association/embedded/embeds_one/binding.rb +0 -2
  25. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +2 -6
  26. data/lib/mongoid/association/embedded/embeds_one.rb +20 -18
  27. data/lib/mongoid/association/embedded.rb +0 -1
  28. data/lib/mongoid/association/macros.rb +3 -7
  29. data/lib/mongoid/association/many.rb +75 -3
  30. data/lib/mongoid/association/marshalable.rb +0 -3
  31. data/lib/mongoid/association/nested/many.rb +18 -13
  32. data/lib/mongoid/association/nested/nested_buildable.rb +6 -9
  33. data/lib/mongoid/association/nested/one.rb +4 -7
  34. data/lib/mongoid/association/nested.rb +1 -3
  35. data/lib/mongoid/association/one.rb +0 -3
  36. data/lib/mongoid/association/options.rb +8 -7
  37. data/lib/mongoid/association/referenced/auto_save.rb +0 -2
  38. data/lib/mongoid/association/referenced/belongs_to/binding.rb +11 -15
  39. data/lib/mongoid/association/referenced/belongs_to/buildable.rb +23 -5
  40. data/lib/mongoid/association/referenced/belongs_to/eager.rb +1 -3
  41. data/lib/mongoid/association/referenced/belongs_to.rb +48 -43
  42. data/lib/mongoid/association/referenced/counter_cache.rb +5 -10
  43. data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +0 -2
  44. data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +8 -4
  45. data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +0 -3
  46. data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +52 -47
  47. data/lib/mongoid/association/referenced/has_many/binding.rb +0 -2
  48. data/lib/mongoid/association/referenced/has_many/buildable.rb +11 -5
  49. data/lib/mongoid/association/referenced/has_many/eager.rb +0 -3
  50. data/lib/mongoid/association/referenced/has_many/enumerable.rb +107 -38
  51. data/lib/mongoid/association/referenced/has_many/proxy.rb +10 -6
  52. data/lib/mongoid/association/referenced/has_many.rb +30 -24
  53. data/lib/mongoid/association/referenced/has_one/binding.rb +0 -2
  54. data/lib/mongoid/association/referenced/has_one/buildable.rb +11 -9
  55. data/lib/mongoid/association/referenced/has_one/eager.rb +0 -3
  56. data/lib/mongoid/association/referenced/has_one.rb +26 -21
  57. data/lib/mongoid/association/referenced/syncable.rb +30 -34
  58. data/lib/mongoid/association/referenced.rb +0 -1
  59. data/lib/mongoid/association/reflections.rb +0 -3
  60. data/lib/mongoid/association/relatable.rb +69 -66
  61. data/lib/mongoid/association.rb +12 -15
  62. data/lib/mongoid/atomic/modifiers.rb +65 -25
  63. data/lib/mongoid/atomic/paths/embedded/many.rb +4 -7
  64. data/lib/mongoid/atomic/paths/embedded/one.rb +2 -4
  65. data/lib/mongoid/atomic/paths/embedded.rb +3 -6
  66. data/lib/mongoid/atomic/paths/root.rb +1 -4
  67. data/lib/mongoid/atomic/paths.rb +2 -3
  68. data/lib/mongoid/atomic.rb +0 -3
  69. data/lib/mongoid/attributes/dynamic.rb +6 -7
  70. data/lib/mongoid/attributes/nested.rb +8 -10
  71. data/lib/mongoid/attributes/projector.rb +7 -20
  72. data/lib/mongoid/attributes/readonly.rb +6 -11
  73. data/lib/mongoid/attributes.rb +18 -34
  74. data/lib/mongoid/cacheable.rb +24 -6
  75. data/lib/mongoid/clients/factory.rb +12 -15
  76. data/lib/mongoid/clients/options.rb +2 -5
  77. data/lib/mongoid/clients/sessions.rb +50 -60
  78. data/lib/mongoid/clients/storage_options.rb +1 -4
  79. data/lib/mongoid/clients/validators/storage.rb +2 -3
  80. data/lib/mongoid/clients/validators.rb +1 -2
  81. data/lib/mongoid/clients.rb +8 -11
  82. data/lib/mongoid/collection_configurable.rb +10 -14
  83. data/lib/mongoid/composable.rb +30 -34
  84. data/lib/mongoid/config/defaults.rb +7 -4
  85. data/lib/mongoid/config/encryption.rb +1 -3
  86. data/lib/mongoid/config/environment.rb +7 -16
  87. data/lib/mongoid/config/introspection.rb +14 -16
  88. data/lib/mongoid/config/options.rb +16 -10
  89. data/lib/mongoid/config/validators/async_query_executor.rb +3 -6
  90. data/lib/mongoid/config/validators/client.rb +12 -15
  91. data/lib/mongoid/config/validators/option.rb +3 -5
  92. data/lib/mongoid/config/validators.rb +3 -4
  93. data/lib/mongoid/config.rb +132 -42
  94. data/lib/mongoid/contextual/aggregable/memory.rb +2 -4
  95. data/lib/mongoid/contextual/aggregable/mongo.rb +20 -22
  96. data/lib/mongoid/contextual/aggregable/none.rb +2 -4
  97. data/lib/mongoid/contextual/aggregable.rb +5 -7
  98. data/lib/mongoid/contextual/atomic.rb +20 -24
  99. data/lib/mongoid/contextual/command.rb +0 -3
  100. data/lib/mongoid/contextual/map_reduce.rb +12 -16
  101. data/lib/mongoid/contextual/memory.rb +72 -65
  102. data/lib/mongoid/contextual/mongo/documents_loader.rb +2 -3
  103. data/lib/mongoid/contextual/mongo.rb +169 -85
  104. data/lib/mongoid/contextual/none.rb +9 -9
  105. data/lib/mongoid/contextual/queryable.rb +1 -4
  106. data/lib/mongoid/contextual.rb +18 -7
  107. data/lib/mongoid/copyable.rb +7 -9
  108. data/lib/mongoid/criteria/findable.rb +5 -7
  109. data/lib/mongoid/criteria/includable.rb +37 -8
  110. data/lib/mongoid/criteria/inspectable.rb +2 -5
  111. data/lib/mongoid/criteria/marshalable.rb +4 -8
  112. data/lib/mongoid/criteria/modifiable.rb +3 -11
  113. data/lib/mongoid/criteria/options.rb +0 -3
  114. data/lib/mongoid/criteria/permission.rb +34 -37
  115. data/lib/mongoid/criteria/queryable/aggregable.rb +9 -10
  116. data/lib/mongoid/criteria/queryable/expandable.rb +4 -9
  117. data/lib/mongoid/criteria/queryable/extensions/array.rb +7 -10
  118. data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +3 -5
  119. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -4
  120. data/lib/mongoid/criteria/queryable/extensions/date.rb +2 -6
  121. data/lib/mongoid/criteria/queryable/extensions/date_time.rb +3 -7
  122. data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -4
  123. data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +20 -11
  124. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +15 -11
  125. data/lib/mongoid/criteria/queryable/extensions/object.rb +7 -8
  126. data/lib/mongoid/criteria/queryable/extensions/range.rb +6 -9
  127. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +10 -12
  128. data/lib/mongoid/criteria/queryable/extensions/set.rb +4 -6
  129. data/lib/mongoid/criteria/queryable/extensions/string.rb +5 -9
  130. data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -7
  131. data/lib/mongoid/criteria/queryable/extensions/time.rb +2 -6
  132. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +2 -12
  133. data/lib/mongoid/criteria/queryable/extensions.rb +18 -21
  134. data/lib/mongoid/criteria/queryable/key.rb +12 -18
  135. data/lib/mongoid/criteria/queryable/macroable.rb +0 -3
  136. data/lib/mongoid/criteria/queryable/mergeable.rb +31 -39
  137. data/lib/mongoid/criteria/queryable/optional.rb +17 -18
  138. data/lib/mongoid/criteria/queryable/options.rb +20 -9
  139. data/lib/mongoid/criteria/queryable/pipeline.rb +6 -9
  140. data/lib/mongoid/criteria/queryable/selectable.rb +131 -193
  141. data/lib/mongoid/criteria/queryable/selector.rb +20 -29
  142. data/lib/mongoid/criteria/queryable/smash.rb +1 -6
  143. data/lib/mongoid/criteria/queryable/storable.rb +20 -39
  144. data/lib/mongoid/criteria/queryable.rb +25 -15
  145. data/lib/mongoid/criteria/scopable.rb +5 -11
  146. data/lib/mongoid/criteria/translator.rb +5 -8
  147. data/lib/mongoid/criteria.rb +109 -54
  148. data/lib/mongoid/deprecable.rb +1 -4
  149. data/lib/mongoid/deprecation.rb +2 -6
  150. data/lib/mongoid/document.rb +1 -1
  151. data/lib/mongoid/encryptable.rb +1 -2
  152. data/lib/mongoid/equality.rb +4 -5
  153. data/lib/mongoid/errors/ambiguous_relationship.rb +2 -5
  154. data/lib/mongoid/errors/attribute_not_loaded.rb +1 -4
  155. data/lib/mongoid/errors/callback.rb +1 -4
  156. data/lib/mongoid/errors/create_collection_failure.rb +8 -11
  157. data/lib/mongoid/errors/criteria_argument_required.rb +2 -5
  158. data/lib/mongoid/errors/delete_restriction.rb +1 -4
  159. data/lib/mongoid/errors/document_not_destroyed.rb +1 -4
  160. data/lib/mongoid/errors/document_not_found.rb +16 -21
  161. data/lib/mongoid/errors/drop_collection_failure.rb +7 -10
  162. data/lib/mongoid/errors/empty_config_file.rb +1 -4
  163. data/lib/mongoid/errors/immutable_attribute.rb +1 -4
  164. data/lib/mongoid/errors/in_memory_collation_not_supported.rb +1 -4
  165. data/lib/mongoid/errors/invalid_async_query_executor.rb +2 -5
  166. data/lib/mongoid/errors/invalid_auto_encryption_configuration.rb +2 -5
  167. data/lib/mongoid/errors/invalid_collection.rb +1 -3
  168. data/lib/mongoid/errors/invalid_config_file.rb +1 -4
  169. data/lib/mongoid/errors/invalid_config_option.rb +2 -5
  170. data/lib/mongoid/errors/invalid_dependent_strategy.rb +6 -10
  171. data/lib/mongoid/errors/invalid_discriminator_key_target.rb +2 -4
  172. data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +1 -4
  173. data/lib/mongoid/errors/invalid_elem_match_operator.rb +5 -9
  174. data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +1 -4
  175. data/lib/mongoid/errors/invalid_estimated_count_scoping.rb +1 -4
  176. data/lib/mongoid/errors/invalid_expression_operator.rb +3 -7
  177. data/lib/mongoid/errors/invalid_field.rb +2 -5
  178. data/lib/mongoid/errors/invalid_field_operator.rb +5 -9
  179. data/lib/mongoid/errors/invalid_field_option.rb +2 -5
  180. data/lib/mongoid/errors/invalid_field_type.rb +1 -4
  181. data/lib/mongoid/errors/invalid_find.rb +1 -4
  182. data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +1 -4
  183. data/lib/mongoid/errors/invalid_includes.rb +3 -6
  184. data/lib/mongoid/errors/invalid_index.rb +1 -4
  185. data/lib/mongoid/errors/invalid_options.rb +1 -4
  186. data/lib/mongoid/errors/invalid_path.rb +1 -4
  187. data/lib/mongoid/errors/invalid_persistence_option.rb +4 -7
  188. data/lib/mongoid/errors/invalid_query.rb +6 -11
  189. data/lib/mongoid/errors/invalid_relation.rb +10 -13
  190. data/lib/mongoid/errors/invalid_relation_option.rb +4 -7
  191. data/lib/mongoid/errors/invalid_scope.rb +1 -4
  192. data/lib/mongoid/errors/invalid_session_nesting.rb +0 -3
  193. data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +2 -4
  194. data/lib/mongoid/errors/invalid_storage_options.rb +1 -4
  195. data/lib/mongoid/errors/invalid_time.rb +1 -4
  196. data/lib/mongoid/errors/invalid_transaction_nesting.rb +0 -3
  197. data/lib/mongoid/errors/inverse_not_found.rb +1 -4
  198. data/lib/mongoid/errors/mixed_client_configuration.rb +1 -4
  199. data/lib/mongoid/errors/mixed_relations.rb +1 -3
  200. data/lib/mongoid/errors/mongoid_error.rb +7 -11
  201. data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -4
  202. data/lib/mongoid/errors/no_client_config.rb +1 -4
  203. data/lib/mongoid/errors/no_client_database.rb +1 -4
  204. data/lib/mongoid/errors/no_client_hosts.rb +1 -4
  205. data/lib/mongoid/errors/no_clients_config.rb +1 -4
  206. data/lib/mongoid/errors/no_default_client.rb +1 -4
  207. data/lib/mongoid/errors/no_environment.rb +1 -4
  208. data/lib/mongoid/errors/no_map_reduce_output.rb +1 -4
  209. data/lib/mongoid/errors/no_metadata.rb +1 -4
  210. data/lib/mongoid/errors/no_parent.rb +1 -4
  211. data/lib/mongoid/errors/readonly_attribute.rb +1 -4
  212. data/lib/mongoid/errors/readonly_document.rb +1 -4
  213. data/lib/mongoid/errors/rollback.rb +0 -2
  214. data/lib/mongoid/errors/scope_overwrite.rb +2 -4
  215. data/lib/mongoid/errors/sessions_not_supported.rb +0 -3
  216. data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -3
  217. data/lib/mongoid/errors/transaction_error.rb +0 -3
  218. data/lib/mongoid/errors/transactions_not_supported.rb +0 -3
  219. data/lib/mongoid/errors/unknown_attribute.rb +1 -4
  220. data/lib/mongoid/errors/unknown_model.rb +1 -4
  221. data/lib/mongoid/errors/unregistered_class.rb +1 -1
  222. data/lib/mongoid/errors/unsaved_document.rb +1 -3
  223. data/lib/mongoid/errors/unsupported_isolation_level.rb +22 -0
  224. data/lib/mongoid/errors/unsupported_javascript.rb +1 -4
  225. data/lib/mongoid/errors/validations.rb +3 -5
  226. data/lib/mongoid/errors.rb +72 -72
  227. data/lib/mongoid/evolvable.rb +0 -3
  228. data/lib/mongoid/extensions/array.rb +5 -7
  229. data/lib/mongoid/extensions/big_decimal.rb +6 -7
  230. data/lib/mongoid/extensions/binary.rb +3 -6
  231. data/lib/mongoid/extensions/boolean.rb +4 -7
  232. data/lib/mongoid/extensions/bson_document.rb +28 -0
  233. data/lib/mongoid/extensions/date.rb +10 -14
  234. data/lib/mongoid/extensions/date_time.rb +2 -6
  235. data/lib/mongoid/extensions/decimal128.rb +1 -5
  236. data/lib/mongoid/extensions/false_class.rb +3 -5
  237. data/lib/mongoid/extensions/float.rb +5 -10
  238. data/lib/mongoid/extensions/hash.rb +5 -10
  239. data/lib/mongoid/extensions/integer.rb +5 -10
  240. data/lib/mongoid/extensions/module.rb +1 -4
  241. data/lib/mongoid/extensions/nil_class.rb +0 -1
  242. data/lib/mongoid/extensions/object.rb +9 -14
  243. data/lib/mongoid/extensions/object_id.rb +2 -6
  244. data/lib/mongoid/extensions/range.rb +14 -15
  245. data/lib/mongoid/extensions/raw_value.rb +0 -3
  246. data/lib/mongoid/extensions/regexp.rb +3 -6
  247. data/lib/mongoid/extensions/set.rb +3 -4
  248. data/lib/mongoid/extensions/string.rb +8 -12
  249. data/lib/mongoid/extensions/symbol.rb +3 -7
  250. data/lib/mongoid/extensions/time.rb +24 -26
  251. data/lib/mongoid/extensions/time_with_zone.rb +4 -7
  252. data/lib/mongoid/extensions/true_class.rb +3 -5
  253. data/lib/mongoid/extensions.rb +26 -26
  254. data/lib/mongoid/factory.rb +5 -9
  255. data/lib/mongoid/fields/encrypted.rb +0 -1
  256. data/lib/mongoid/fields/foreign_key.rb +9 -10
  257. data/lib/mongoid/fields/localized.rb +12 -12
  258. data/lib/mongoid/fields/standard.rb +5 -7
  259. data/lib/mongoid/fields/validators/macro.rb +23 -34
  260. data/lib/mongoid/fields/validators.rb +1 -2
  261. data/lib/mongoid/fields.rb +151 -58
  262. data/lib/mongoid/findable.rb +82 -53
  263. data/lib/mongoid/indexable/specification.rb +20 -6
  264. data/lib/mongoid/indexable/validators/options.rb +33 -40
  265. data/lib/mongoid/indexable.rb +26 -25
  266. data/lib/mongoid/inspectable.rb +4 -7
  267. data/lib/mongoid/interceptable.rb +41 -40
  268. data/lib/mongoid/loadable.rb +17 -18
  269. data/lib/mongoid/loggable.rb +4 -8
  270. data/lib/mongoid/matchable.rb +0 -2
  271. data/lib/mongoid/matcher/all.rb +2 -5
  272. data/lib/mongoid/matcher/and.rb +0 -3
  273. data/lib/mongoid/matcher/bits.rb +13 -8
  274. data/lib/mongoid/matcher/bits_all_clear.rb +1 -3
  275. data/lib/mongoid/matcher/bits_all_set.rb +1 -3
  276. data/lib/mongoid/matcher/bits_any_clear.rb +1 -3
  277. data/lib/mongoid/matcher/bits_any_set.rb +1 -3
  278. data/lib/mongoid/matcher/elem_match.rb +13 -15
  279. data/lib/mongoid/matcher/elem_match_expression.rb +0 -3
  280. data/lib/mongoid/matcher/eq.rb +0 -3
  281. data/lib/mongoid/matcher/eq_impl.rb +12 -17
  282. data/lib/mongoid/matcher/eq_impl_with_regexp.rb +4 -7
  283. data/lib/mongoid/matcher/exists.rb +1 -4
  284. data/lib/mongoid/matcher/expression.rb +5 -10
  285. data/lib/mongoid/matcher/expression_operator.rb +1 -3
  286. data/lib/mongoid/matcher/field_expression.rb +10 -13
  287. data/lib/mongoid/matcher/field_operator.rb +4 -6
  288. data/lib/mongoid/matcher/gt.rb +0 -3
  289. data/lib/mongoid/matcher/gte.rb +0 -3
  290. data/lib/mongoid/matcher/in.rb +9 -12
  291. data/lib/mongoid/matcher/lt.rb +0 -3
  292. data/lib/mongoid/matcher/lte.rb +0 -3
  293. data/lib/mongoid/matcher/mod.rb +4 -8
  294. data/lib/mongoid/matcher/ne.rb +0 -3
  295. data/lib/mongoid/matcher/nin.rb +0 -3
  296. data/lib/mongoid/matcher/nor.rb +1 -6
  297. data/lib/mongoid/matcher/not.rb +0 -3
  298. data/lib/mongoid/matcher/or.rb +0 -3
  299. data/lib/mongoid/matcher/regex.rb +11 -14
  300. data/lib/mongoid/matcher/size.rb +2 -5
  301. data/lib/mongoid/matcher/type.rb +32 -37
  302. data/lib/mongoid/matcher.rb +7 -15
  303. data/lib/mongoid/model_resolver.rb +1 -0
  304. data/lib/mongoid/persistable/creatable.rb +23 -7
  305. data/lib/mongoid/persistable/deletable.rb +6 -7
  306. data/lib/mongoid/persistable/destroyable.rb +2 -6
  307. data/lib/mongoid/persistable/incrementable.rb +1 -3
  308. data/lib/mongoid/persistable/logical.rb +3 -5
  309. data/lib/mongoid/persistable/maxable.rb +2 -4
  310. data/lib/mongoid/persistable/minable.rb +2 -4
  311. data/lib/mongoid/persistable/multipliable.rb +1 -3
  312. data/lib/mongoid/persistable/poppable.rb +2 -4
  313. data/lib/mongoid/persistable/pullable.rb +3 -5
  314. data/lib/mongoid/persistable/pushable.rb +5 -7
  315. data/lib/mongoid/persistable/renamable.rb +1 -3
  316. data/lib/mongoid/persistable/savable.rb +0 -3
  317. data/lib/mongoid/persistable/settable.rb +4 -13
  318. data/lib/mongoid/persistable/unsettable.rb +1 -3
  319. data/lib/mongoid/persistable/updatable.rb +16 -24
  320. data/lib/mongoid/persistable/upsertable.rb +8 -10
  321. data/lib/mongoid/persistable.rb +28 -27
  322. data/lib/mongoid/persistence_context.rb +34 -41
  323. data/lib/mongoid/pluckable.rb +0 -2
  324. data/lib/mongoid/positional.rb +5 -11
  325. data/lib/mongoid/railtie.rb +16 -22
  326. data/lib/mongoid/railties/console_sandbox.rb +6 -8
  327. data/lib/mongoid/railties/controller_runtime.rb +7 -11
  328. data/lib/mongoid/railties/database.rake +42 -44
  329. data/lib/mongoid/scopable.rb +23 -31
  330. data/lib/mongoid/search_indexable.rb +330 -0
  331. data/lib/mongoid/selectable.rb +1 -3
  332. data/lib/mongoid/serializable.rb +6 -8
  333. data/lib/mongoid/shardable.rb +8 -17
  334. data/lib/mongoid/stateful.rb +5 -10
  335. data/lib/mongoid/stringified_symbol.rb +5 -9
  336. data/lib/mongoid/tasks/database.rake +31 -32
  337. data/lib/mongoid/tasks/database.rb +28 -30
  338. data/lib/mongoid/tasks/encryption.rb +10 -15
  339. data/lib/mongoid/threaded/lifecycle.rb +6 -9
  340. data/lib/mongoid/threaded.rb +132 -32
  341. data/lib/mongoid/timestamps/created/short.rb +2 -3
  342. data/lib/mongoid/timestamps/created.rb +1 -2
  343. data/lib/mongoid/timestamps/short.rb +0 -1
  344. data/lib/mongoid/timestamps/timeless.rb +8 -13
  345. data/lib/mongoid/timestamps/updated/short.rb +2 -3
  346. data/lib/mongoid/timestamps/updated.rb +2 -5
  347. data/lib/mongoid/timestamps.rb +4 -6
  348. data/lib/mongoid/touchable.rb +19 -11
  349. data/lib/mongoid/traversable.rb +3 -2
  350. data/lib/mongoid/validatable/associated.rb +1 -5
  351. data/lib/mongoid/validatable/format.rb +0 -2
  352. data/lib/mongoid/validatable/length.rb +0 -2
  353. data/lib/mongoid/validatable/localizable.rb +0 -3
  354. data/lib/mongoid/validatable/macros.rb +0 -2
  355. data/lib/mongoid/validatable/numericality.rb +24 -3
  356. data/lib/mongoid/validatable/presence.rb +8 -10
  357. data/lib/mongoid/validatable/queryable.rb +0 -3
  358. data/lib/mongoid/validatable/uniqueness.rb +12 -14
  359. data/lib/mongoid/validatable.rb +15 -20
  360. data/lib/mongoid/version.rb +1 -1
  361. data/lib/mongoid/warnings.rb +10 -11
  362. data/lib/mongoid.rb +30 -34
  363. data/lib/rails/generators/mongoid/config/config_generator.rb +2 -4
  364. data/lib/rails/generators/mongoid/config/templates/mongoid.rb +4 -5
  365. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +2 -2
  366. data/lib/rails/generators/mongoid/model/model_generator.rb +5 -8
  367. data/lib/rails/generators/mongoid_generator.rb +6 -10
  368. data/lib/rails/mongoid.rb +1 -3
  369. data/spec/integration/active_job_spec.rb +1 -2
  370. data/spec/integration/app_spec.rb +142 -178
  371. data/spec/integration/associations/belongs_to_spec.rb +30 -28
  372. data/spec/integration/associations/embedded_dirty_spec.rb +0 -1
  373. data/spec/integration/associations/embedded_spec.rb +41 -43
  374. data/spec/integration/associations/embeds_many_spec.rb +46 -29
  375. data/spec/integration/associations/embeds_one_spec.rb +2 -1
  376. data/spec/integration/associations/foreign_key_spec.rb +10 -11
  377. data/spec/integration/associations/foreign_key_spec_models.rb +8 -9
  378. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +16 -13
  379. data/spec/integration/associations/has_many_spec.rb +17 -18
  380. data/spec/integration/associations/has_one_spec.rb +42 -45
  381. data/spec/integration/associations/nested_attributes_assignment_spec.rb +36 -39
  382. data/spec/integration/associations/reverse_population_spec.rb +4 -5
  383. data/spec/integration/associations/reverse_population_spec_models.rb +0 -1
  384. data/spec/integration/associations/scope_option_spec.rb +18 -20
  385. data/spec/integration/atomic/modifiers_spec.rb +72 -52
  386. data/spec/integration/bson_regexp_raw_spec.rb +2 -3
  387. data/spec/integration/caching_spec.rb +68 -0
  388. data/spec/integration/callbacks_models.rb +11 -9
  389. data/spec/integration/callbacks_spec.rb +78 -80
  390. data/spec/integration/contextual/empty_spec.rb +19 -20
  391. data/spec/integration/criteria/alias_query_spec.rb +12 -19
  392. data/spec/integration/criteria/date_field_spec.rb +1 -2
  393. data/spec/integration/criteria/default_scope_spec.rb +23 -18
  394. data/spec/integration/criteria/logical_spec.rb +18 -19
  395. data/spec/integration/criteria/range_spec.rb +77 -86
  396. data/spec/integration/criteria/raw_value_spec.rb +122 -109
  397. data/spec/integration/criteria/time_with_zone_spec.rb +33 -24
  398. data/spec/integration/discriminator_key_spec.rb +85 -85
  399. data/spec/integration/discriminator_value_spec.rb +70 -73
  400. data/spec/integration/document_spec.rb +9 -10
  401. data/spec/integration/dots_and_dollars_spec.rb +104 -119
  402. data/spec/integration/encryption_spec.rb +8 -11
  403. data/spec/integration/i18n_fallbacks_spec.rb +7 -8
  404. data/spec/integration/isolation_state_spec.rb +241 -0
  405. data/spec/integration/matcher_examples_spec.rb +145 -168
  406. data/spec/integration/matcher_operator_data/in.yml +6 -6
  407. data/spec/integration/matcher_operator_spec.rb +16 -26
  408. data/spec/integration/matcher_spec.rb +31 -32
  409. data/spec/integration/persistence/collection_options_spec.rb +0 -2
  410. data/spec/integration/persistence/range_field_spec.rb +24 -2
  411. data/spec/integration/server_query_spec.rb +43 -37
  412. data/spec/integration/shardable_spec.rb +10 -11
  413. data/spec/integration/stringified_symbol_field_spec.rb +28 -43
  414. data/spec/lite_spec_helper.rb +11 -12
  415. data/spec/mongoid/association/accessors_spec.rb +197 -285
  416. data/spec/mongoid/association/auto_save_spec.rb +62 -93
  417. data/spec/mongoid/association/builders_spec.rb +121 -74
  418. data/spec/mongoid/association/constrainable_spec.rb +9 -22
  419. data/spec/mongoid/association/counter_cache_spec.rb +71 -104
  420. data/spec/mongoid/association/depending_spec.rb +166 -208
  421. data/spec/mongoid/association/eager_spec.rb +416 -80
  422. data/spec/mongoid/association/embedded/cyclic_spec.rb +36 -48
  423. data/spec/mongoid/association/embedded/dirty_spec.rb +15 -20
  424. data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +36 -54
  425. data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +8 -15
  426. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +135 -175
  427. data/spec/mongoid/association/embedded/embedded_in_spec.rb +25 -127
  428. data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +9 -14
  429. data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +38 -51
  430. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +1151 -1340
  431. data/spec/mongoid/association/embedded/embeds_many_models.rb +17 -17
  432. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +11 -11
  433. data/spec/mongoid/association/embedded/embeds_many_spec.rb +25 -138
  434. data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +15 -23
  435. data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +18 -26
  436. data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +204 -273
  437. data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +0 -1
  438. data/spec/mongoid/association/embedded/embeds_one_models.rb +0 -1
  439. data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +5 -6
  440. data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -143
  441. data/spec/mongoid/association/macros_spec.rb +213 -300
  442. data/spec/mongoid/association/nested/many_spec.rb +51 -73
  443. data/spec/mongoid/association/nested/one_spec.rb +56 -80
  444. data/spec/mongoid/association/options_spec.rb +187 -310
  445. data/spec/mongoid/association/polymorphic_spec.rb +35 -53
  446. data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +55 -76
  447. data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +36 -41
  448. data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +81 -101
  449. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +258 -345
  450. data/spec/mongoid/association/referenced/belongs_to_models.rb +4 -3
  451. data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +3 -4
  452. data/spec/mongoid/association/referenced/belongs_to_spec.rb +91 -294
  453. data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +42 -56
  454. data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +41 -32
  455. data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +36 -42
  456. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +8 -9
  457. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +771 -975
  458. data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +9 -9
  459. data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +5 -6
  460. data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +59 -177
  461. data/spec/mongoid/association/referenced/has_many/binding_spec.rb +29 -43
  462. data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +53 -53
  463. data/spec/mongoid/association/referenced/has_many/eager_spec.rb +104 -67
  464. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +431 -675
  465. data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -2
  466. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +173 -11
  467. data/spec/mongoid/association/referenced/has_many_models.rb +1 -2
  468. data/spec/mongoid/association/referenced/has_many_query_spec.rb +3 -4
  469. data/spec/mongoid/association/referenced/has_many_spec.rb +44 -188
  470. data/spec/mongoid/association/referenced/has_one/binding_spec.rb +26 -38
  471. data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +28 -29
  472. data/spec/mongoid/association/referenced/has_one/eager_spec.rb +29 -42
  473. data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +270 -332
  474. data/spec/mongoid/association/referenced/has_one_models.rb +1 -2
  475. data/spec/mongoid/association/referenced/has_one_query_spec.rb +3 -4
  476. data/spec/mongoid/association/referenced/has_one_spec.rb +40 -188
  477. data/spec/mongoid/association/reflections_spec.rb +14 -24
  478. data/spec/mongoid/association/syncable_spec.rb +102 -125
  479. data/spec/mongoid/association_spec.rb +47 -70
  480. data/spec/mongoid/atomic/modifiers_spec.rb +184 -197
  481. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +39 -52
  482. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +35 -49
  483. data/spec/mongoid/atomic/paths/root_spec.rb +9 -15
  484. data/spec/mongoid/atomic/paths_spec.rb +81 -117
  485. data/spec/mongoid/atomic_spec.rb +156 -171
  486. data/spec/mongoid/attributes/dynamic_spec.rb +5 -6
  487. data/spec/mongoid/attributes/nested_spec.rb +1219 -1692
  488. data/spec/mongoid/attributes/nested_spec_models.rb +8 -9
  489. data/spec/mongoid/attributes/projector_spec.rb +2 -6
  490. data/spec/mongoid/attributes/readonly_spec.rb +73 -97
  491. data/spec/mongoid/attributes_spec.rb +669 -826
  492. data/spec/mongoid/cacheable_spec.rb +74 -44
  493. data/spec/mongoid/changeable_spec.rb +591 -733
  494. data/spec/mongoid/clients/factory_spec.rb +122 -154
  495. data/spec/mongoid/clients/options_spec.rb +40 -59
  496. data/spec/mongoid/clients/sessions_spec.rb +25 -44
  497. data/spec/mongoid/clients/transactions_spec.rb +33 -50
  498. data/spec/mongoid/clients/transactions_spec_models.rb +3 -4
  499. data/spec/mongoid/clients_spec.rb +265 -355
  500. data/spec/mongoid/collection_configurable_spec.rb +9 -12
  501. data/spec/mongoid/composable_spec.rb +2 -9
  502. data/spec/mongoid/config/defaults_spec.rb +24 -31
  503. data/spec/mongoid/config/encryption_spec.rb +54 -57
  504. data/spec/mongoid/config/environment_spec.rb +30 -40
  505. data/spec/mongoid/config/introspection_spec.rb +42 -37
  506. data/spec/mongoid/config/options_spec.rb +14 -21
  507. data/spec/mongoid/config_spec.rb +145 -195
  508. data/spec/mongoid/contextual/aggregable/memory_spec.rb +98 -135
  509. data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +4 -7
  510. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +149 -187
  511. data/spec/mongoid/contextual/aggregable/none_spec.rb +14 -16
  512. data/spec/mongoid/contextual/atomic_spec.rb +223 -271
  513. data/spec/mongoid/contextual/map_reduce_spec.rb +110 -138
  514. data/spec/mongoid/contextual/memory_spec.rb +706 -854
  515. data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +12 -13
  516. data/spec/mongoid/contextual/mongo_spec.rb +1008 -1213
  517. data/spec/mongoid/contextual/none_spec.rb +54 -59
  518. data/spec/mongoid/contextual/short_circuit_spec.rb +139 -0
  519. data/spec/mongoid/copyable_spec.rb +254 -300
  520. data/spec/mongoid/copyable_spec_models.rb +0 -1
  521. data/spec/mongoid/criteria/findable_spec.rb +322 -387
  522. data/spec/mongoid/criteria/includable_spec.rb +421 -372
  523. data/spec/mongoid/criteria/includable_spec_models.rb +16 -7
  524. data/spec/mongoid/criteria/inspectable_spec.rb +11 -14
  525. data/spec/mongoid/criteria/marshalable_spec.rb +11 -14
  526. data/spec/mongoid/criteria/modifiable_spec.rb +366 -512
  527. data/spec/mongoid/criteria/options_spec.rb +2 -7
  528. data/spec/mongoid/criteria/queryable/aggregable_spec.rb +112 -141
  529. data/spec/mongoid/criteria/queryable/expandable_spec.rb +8 -11
  530. data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +127 -184
  531. data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +123 -60
  532. data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +84 -117
  533. data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +44 -65
  534. data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +86 -108
  535. data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +94 -33
  536. data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +103 -138
  537. data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +95 -34
  538. data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +25 -38
  539. data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +26 -28
  540. data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +32 -54
  541. data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +136 -130
  542. data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +16 -24
  543. data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +15 -24
  544. data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +12 -19
  545. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +46 -63
  546. data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +28 -42
  547. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +73 -96
  548. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +71 -92
  549. data/spec/mongoid/criteria/queryable/key_spec.rb +32 -36
  550. data/spec/mongoid/criteria/queryable/mergeable_spec.rb +44 -49
  551. data/spec/mongoid/criteria/queryable/optional_spec.rb +373 -486
  552. data/spec/mongoid/criteria/queryable/options_spec.rb +172 -123
  553. data/spec/mongoid/criteria/queryable/pipeline_spec.rb +65 -87
  554. data/spec/mongoid/criteria/queryable/queryable_spec.rb +41 -53
  555. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +576 -680
  556. data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +7 -11
  557. data/spec/mongoid/criteria/queryable/selectable_spec.rb +807 -998
  558. data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +154 -191
  559. data/spec/mongoid/criteria/queryable/selector_spec.rb +294 -390
  560. data/spec/mongoid/criteria/queryable/smash_spec.rb +6 -11
  561. data/spec/mongoid/criteria/queryable/storable_spec.rb +54 -81
  562. data/spec/mongoid/criteria/queryable_mql_spec.rb +92 -0
  563. data/spec/mongoid/criteria/scopable_spec.rb +102 -138
  564. data/spec/mongoid/criteria/translator_spec.rb +59 -60
  565. data/spec/mongoid/criteria_projection_spec.rb +81 -99
  566. data/spec/mongoid/criteria_spec.rb +935 -950
  567. data/spec/mongoid/document_fields_spec.rb +28 -30
  568. data/spec/mongoid/document_persistence_context_spec.rb +13 -15
  569. data/spec/mongoid/document_query_spec.rb +9 -12
  570. data/spec/mongoid/document_spec.rb +317 -409
  571. data/spec/mongoid/equality_spec.rb +69 -102
  572. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +8 -11
  573. data/spec/mongoid/errors/attribute_not_loaded_spec.rb +7 -10
  574. data/spec/mongoid/errors/callback_spec.rb +8 -11
  575. data/spec/mongoid/errors/delete_restriction_spec.rb +5 -8
  576. data/spec/mongoid/errors/document_not_destroyed_spec.rb +7 -10
  577. data/spec/mongoid/errors/document_not_found_spec.rb +51 -61
  578. data/spec/mongoid/errors/invalid_collection_spec.rb +9 -13
  579. data/spec/mongoid/errors/invalid_config_file_spec.rb +8 -11
  580. data/spec/mongoid/errors/invalid_config_option_spec.rb +8 -11
  581. data/spec/mongoid/errors/invalid_field_option_spec.rb +7 -10
  582. data/spec/mongoid/errors/invalid_field_spec.rb +10 -11
  583. data/spec/mongoid/errors/invalid_field_type_spec.rb +9 -12
  584. data/spec/mongoid/errors/invalid_find_spec.rb +8 -11
  585. data/spec/mongoid/errors/invalid_includes_spec.rb +9 -13
  586. data/spec/mongoid/errors/invalid_index_spec.rb +8 -11
  587. data/spec/mongoid/errors/invalid_options_spec.rb +8 -11
  588. data/spec/mongoid/errors/invalid_path_spec.rb +7 -10
  589. data/spec/mongoid/errors/invalid_relation_spec.rb +15 -16
  590. data/spec/mongoid/errors/invalid_scope_spec.rb +8 -11
  591. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -6
  592. data/spec/mongoid/errors/invalid_storage_options_spec.rb +8 -11
  593. data/spec/mongoid/errors/invalid_time_spec.rb +8 -11
  594. data/spec/mongoid/errors/inverse_not_found_spec.rb +9 -12
  595. data/spec/mongoid/errors/mixed_client_configuration_spec.rb +9 -12
  596. data/spec/mongoid/errors/mixed_relations_spec.rb +8 -11
  597. data/spec/mongoid/errors/mongoid_error_spec.rb +21 -24
  598. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +6 -9
  599. data/spec/mongoid/errors/no_client_config_spec.rb +7 -10
  600. data/spec/mongoid/errors/no_client_database_spec.rb +9 -12
  601. data/spec/mongoid/errors/no_client_hosts_spec.rb +9 -12
  602. data/spec/mongoid/errors/no_clients_config_spec.rb +7 -10
  603. data/spec/mongoid/errors/no_environment_spec.rb +8 -11
  604. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +8 -11
  605. data/spec/mongoid/errors/no_metadata_spec.rb +7 -10
  606. data/spec/mongoid/errors/no_parent_spec.rb +7 -10
  607. data/spec/mongoid/errors/readonly_attribute_spec.rb +7 -10
  608. data/spec/mongoid/errors/readonly_document_spec.rb +6 -9
  609. data/spec/mongoid/errors/scope_overwrite_spec.rb +9 -12
  610. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +9 -12
  611. data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -8
  612. data/spec/mongoid/errors/unsaved_document_spec.rb +8 -11
  613. data/spec/mongoid/errors/unsupported_javascript_spec.rb +9 -12
  614. data/spec/mongoid/errors/validations_spec.rb +11 -14
  615. data/spec/mongoid/extensions/array_spec.rb +70 -92
  616. data/spec/mongoid/extensions/big_decimal_spec.rb +233 -313
  617. data/spec/mongoid/extensions/binary_spec.rb +21 -32
  618. data/spec/mongoid/extensions/boolean_spec.rb +52 -75
  619. data/spec/mongoid/extensions/date_class_mongoize_spec.rb +43 -54
  620. data/spec/mongoid/extensions/date_spec.rb +26 -38
  621. data/spec/mongoid/extensions/date_time_spec.rb +22 -32
  622. data/spec/mongoid/extensions/decimal128_spec.rb +12 -18
  623. data/spec/mongoid/extensions/false_class_spec.rb +10 -17
  624. data/spec/mongoid/extensions/float_spec.rb +40 -61
  625. data/spec/mongoid/extensions/hash_spec.rb +46 -64
  626. data/spec/mongoid/extensions/integer_spec.rb +40 -61
  627. data/spec/mongoid/extensions/module_spec.rb +13 -18
  628. data/spec/mongoid/extensions/nil_class_spec.rb +2 -5
  629. data/spec/mongoid/extensions/object_id_spec.rb +159 -247
  630. data/spec/mongoid/extensions/object_spec.rb +31 -47
  631. data/spec/mongoid/extensions/range_spec.rb +112 -115
  632. data/spec/mongoid/extensions/raw_value_spec.rb +10 -12
  633. data/spec/mongoid/extensions/regexp_spec.rb +23 -36
  634. data/spec/mongoid/extensions/set_spec.rb +38 -49
  635. data/spec/mongoid/extensions/string_spec.rb +118 -167
  636. data/spec/mongoid/extensions/stringified_symbol_spec.rb +29 -43
  637. data/spec/mongoid/extensions/symbol_spec.rb +12 -20
  638. data/spec/mongoid/extensions/time_spec.rb +160 -202
  639. data/spec/mongoid/extensions/time_with_zone_spec.rb +79 -105
  640. data/spec/mongoid/extensions/true_class_spec.rb +10 -17
  641. data/spec/mongoid/factory_spec.rb +125 -148
  642. data/spec/mongoid/fields/foreign_key_spec.rb +124 -169
  643. data/spec/mongoid/fields/localized_spec.rb +140 -185
  644. data/spec/mongoid/fields/standard_spec.rb +43 -59
  645. data/spec/mongoid/fields_spec.rb +751 -620
  646. data/spec/mongoid/findable_spec.rb +260 -228
  647. data/spec/mongoid/indexable/specification_spec.rb +42 -58
  648. data/spec/mongoid/indexable_spec.rb +260 -264
  649. data/spec/mongoid/inspectable_spec.rb +45 -55
  650. data/spec/mongoid/interceptable_spec.rb +784 -922
  651. data/spec/mongoid/interceptable_spec_models.rb +35 -35
  652. data/spec/mongoid/loading_spec.rb +47 -43
  653. data/spec/mongoid/loggable_spec.rb +3 -6
  654. data/spec/mongoid/matcher/extract_attribute_spec.rb +2 -6
  655. data/spec/mongoid/mongoizable_spec.rb +81 -90
  656. data/spec/mongoid/monkey_patches_spec.rb +4 -0
  657. data/spec/mongoid/persistable/creatable_spec.rb +181 -220
  658. data/spec/mongoid/persistable/deletable_spec.rb +139 -179
  659. data/spec/mongoid/persistable/destroyable_spec.rb +135 -164
  660. data/spec/mongoid/persistable/incrementable_spec.rb +65 -84
  661. data/spec/mongoid/persistable/logical_spec.rb +48 -61
  662. data/spec/mongoid/persistable/maxable_spec.rb +45 -44
  663. data/spec/mongoid/persistable/minable_spec.rb +45 -44
  664. data/spec/mongoid/persistable/multipliable_spec.rb +54 -69
  665. data/spec/mongoid/persistable/poppable_spec.rb +47 -60
  666. data/spec/mongoid/persistable/pullable_spec.rb +79 -103
  667. data/spec/mongoid/persistable/pushable_spec.rb +106 -131
  668. data/spec/mongoid/persistable/renamable_spec.rb +52 -65
  669. data/spec/mongoid/persistable/savable_spec.rb +152 -189
  670. data/spec/mongoid/persistable/settable_spec.rb +121 -145
  671. data/spec/mongoid/persistable/unsettable_spec.rb +56 -73
  672. data/spec/mongoid/persistable/updatable_spec.rb +185 -232
  673. data/spec/mongoid/persistable/upsertable_spec.rb +66 -77
  674. data/spec/mongoid/persistable_spec.rb +132 -139
  675. data/spec/mongoid/persistence_context_spec.rb +31 -89
  676. data/spec/mongoid/positional_spec.rb +67 -79
  677. data/spec/mongoid/railties/bson_object_id_serializer_spec.rb +0 -3
  678. data/spec/mongoid/railties/console_sandbox_spec.rb +0 -1
  679. data/spec/mongoid/relations/proxy_spec.rb +0 -1
  680. data/spec/mongoid/reloadable_spec.rb +250 -145
  681. data/spec/mongoid/scopable_spec.rb +319 -398
  682. data/spec/mongoid/search_indexable_spec.rb +446 -41
  683. data/spec/mongoid/selectable_spec.rb +36 -51
  684. data/spec/mongoid/serializable_spec.rb +269 -312
  685. data/spec/mongoid/shardable_models.rb +5 -5
  686. data/spec/mongoid/shardable_spec.rb +44 -46
  687. data/spec/mongoid/stateful_spec.rb +55 -75
  688. data/spec/mongoid/tasks/database_rake_spec.rb +138 -141
  689. data/spec/mongoid/tasks/database_spec.rb +80 -80
  690. data/spec/mongoid/tasks/encryption_spec.rb +22 -20
  691. data/spec/mongoid/threaded_spec.rb +57 -83
  692. data/spec/mongoid/timestamps/created/short_spec.rb +12 -16
  693. data/spec/mongoid/timestamps/created_spec.rb +16 -20
  694. data/spec/mongoid/timestamps/timeless_spec.rb +31 -43
  695. data/spec/mongoid/timestamps/updated/short_spec.rb +21 -28
  696. data/spec/mongoid/timestamps/updated_spec.rb +18 -25
  697. data/spec/mongoid/timestamps_spec.rb +171 -188
  698. data/spec/mongoid/timestamps_spec_models.rb +12 -13
  699. data/spec/mongoid/touchable_spec.rb +330 -294
  700. data/spec/mongoid/touchable_spec_models.rb +35 -37
  701. data/spec/mongoid/traversable_spec.rb +435 -471
  702. data/spec/mongoid/validatable/associated_spec.rb +42 -60
  703. data/spec/mongoid/validatable/format_spec.rb +24 -34
  704. data/spec/mongoid/validatable/length_spec.rb +62 -86
  705. data/spec/mongoid/validatable/numericality_spec.rb +114 -23
  706. data/spec/mongoid/validatable/presence_spec.rb +149 -203
  707. data/spec/mongoid/validatable/uniqueness_spec.rb +632 -830
  708. data/spec/mongoid/validatable_spec.rb +71 -103
  709. data/spec/mongoid/warnings_spec.rb +5 -9
  710. data/spec/mongoid_spec.rb +25 -41
  711. data/spec/rails/controller_extension/controller_runtime_spec.rb +45 -49
  712. data/spec/rails/mongoid_spec.rb +15 -15
  713. data/spec/shared/lib/mrss/cluster_config.rb +5 -40
  714. data/spec/shared/lib/mrss/constraints.rb +7 -46
  715. data/spec/shared/lib/mrss/docker_runner.rb +10 -21
  716. data/spec/shared/lib/mrss/eg_config_utils.rb +0 -31
  717. data/spec/shared/lib/mrss/release/candidate.rb +18 -12
  718. data/spec/shared/lib/mrss/server_version_registry.rb +1 -5
  719. data/spec/shared/share/Dockerfile.erb +6 -8
  720. data/spec/shared/shlib/server.sh +0 -50
  721. data/spec/shared/shlib/set_env.sh +4 -10
  722. data/spec/spec_helper.rb +54 -31
  723. data/spec/support/authorization.rb +0 -1
  724. data/spec/support/client_registry.rb +1 -2
  725. data/spec/support/constraints.rb +8 -25
  726. data/spec/support/crypt/models.rb +7 -8
  727. data/spec/support/crypt.rb +6 -9
  728. data/spec/support/expectations.rb +21 -7
  729. data/spec/support/feature_sandbox.rb +1 -4
  730. data/spec/support/helpers.rb +0 -1
  731. data/spec/support/immutable_ids.rb +20 -21
  732. data/spec/support/macros.rb +1 -3
  733. data/spec/support/models/account.rb +4 -5
  734. data/spec/support/models/acolyte.rb +5 -5
  735. data/spec/support/models/actor.rb +3 -3
  736. data/spec/support/models/actress.rb +0 -1
  737. data/spec/support/models/address.rb +11 -11
  738. data/spec/support/models/address_component.rb +1 -1
  739. data/spec/support/models/address_number.rb +1 -1
  740. data/spec/support/models/agency.rb +1 -1
  741. data/spec/support/models/agent.rb +1 -1
  742. data/spec/support/models/album.rb +1 -2
  743. data/spec/support/models/alert.rb +1 -1
  744. data/spec/support/models/animal.rb +4 -5
  745. data/spec/support/models/answer.rb +1 -1
  746. data/spec/support/models/appointment.rb +2 -2
  747. data/spec/support/models/armrest.rb +0 -1
  748. data/spec/support/models/array_field.rb +0 -1
  749. data/spec/support/models/article.rb +0 -1
  750. data/spec/support/models/artist.rb +16 -12
  751. data/spec/support/models/artwork.rb +1 -1
  752. data/spec/support/models/audible_sound.rb +0 -1
  753. data/spec/support/models/audio.rb +2 -2
  754. data/spec/support/models/augmentation.rb +1 -2
  755. data/spec/support/models/author.rb +1 -1
  756. data/spec/support/models/baby.rb +1 -1
  757. data/spec/support/models/band.rb +0 -1
  758. data/spec/support/models/bar.rb +2 -2
  759. data/spec/support/models/basic.rb +0 -1
  760. data/spec/support/models/bed.rb +0 -1
  761. data/spec/support/models/big_palette.rb +0 -1
  762. data/spec/support/models/birthday.rb +3 -5
  763. data/spec/support/models/bolt.rb +0 -1
  764. data/spec/support/models/bomb.rb +1 -1
  765. data/spec/support/models/book.rb +1 -1
  766. data/spec/support/models/breed.rb +1 -1
  767. data/spec/support/models/browser.rb +1 -2
  768. data/spec/support/models/building.rb +0 -1
  769. data/spec/support/models/building_address.rb +1 -1
  770. data/spec/support/models/bus.rb +1 -1
  771. data/spec/support/models/business.rb +2 -2
  772. data/spec/support/models/callback_test.rb +1 -1
  773. data/spec/support/models/canvas.rb +5 -6
  774. data/spec/support/models/car.rb +0 -1
  775. data/spec/support/models/cat.rb +0 -2
  776. data/spec/support/models/catalog.rb +0 -1
  777. data/spec/support/models/category.rb +1 -1
  778. data/spec/support/models/child.rb +1 -1
  779. data/spec/support/models/child_doc.rb +5 -6
  780. data/spec/support/models/church.rb +1 -1
  781. data/spec/support/models/circle.rb +0 -1
  782. data/spec/support/models/circuit.rb +2 -2
  783. data/spec/support/models/circus.rb +0 -1
  784. data/spec/support/models/code.rb +2 -1
  785. data/spec/support/models/coding/pull_request.rb +0 -1
  786. data/spec/support/models/coding.rb +0 -1
  787. data/spec/support/models/comment.rb +0 -1
  788. data/spec/support/models/company.rb +0 -1
  789. data/spec/support/models/consumption_period.rb +0 -1
  790. data/spec/support/models/contextable_item.rb +1 -1
  791. data/spec/support/models/contractor.rb +1 -1
  792. data/spec/support/models/cookie.rb +0 -1
  793. data/spec/support/models/country_code.rb +2 -3
  794. data/spec/support/models/courier_job.rb +2 -2
  795. data/spec/support/models/cover.rb +0 -1
  796. data/spec/support/models/crate.rb +0 -1
  797. data/spec/support/models/customer.rb +0 -1
  798. data/spec/support/models/customer_address.rb +0 -1
  799. data/spec/support/models/deed.rb +1 -1
  800. data/spec/support/models/definition.rb +1 -1
  801. data/spec/support/models/delegating_patient.rb +0 -1
  802. data/spec/support/models/description.rb +0 -1
  803. data/spec/support/models/dictionary.rb +1 -1
  804. data/spec/support/models/division.rb +2 -2
  805. data/spec/support/models/doctor.rb +0 -1
  806. data/spec/support/models/dog.rb +2 -2
  807. data/spec/support/models/dokument.rb +1 -1
  808. data/spec/support/models/draft.rb +0 -1
  809. data/spec/support/models/dragon.rb +1 -1
  810. data/spec/support/models/driver.rb +2 -2
  811. data/spec/support/models/drug.rb +1 -1
  812. data/spec/support/models/dungeon.rb +1 -1
  813. data/spec/support/models/edit.rb +1 -1
  814. data/spec/support/models/email.rb +1 -1
  815. data/spec/support/models/employer.rb +1 -2
  816. data/spec/support/models/entry.rb +1 -1
  817. data/spec/support/models/eraser.rb +0 -1
  818. data/spec/support/models/even.rb +1 -1
  819. data/spec/support/models/event.rb +3 -4
  820. data/spec/support/models/exhibition.rb +1 -1
  821. data/spec/support/models/exhibitor.rb +1 -1
  822. data/spec/support/models/explosion.rb +1 -1
  823. data/spec/support/models/eye.rb +0 -1
  824. data/spec/support/models/eye_bowl.rb +2 -3
  825. data/spec/support/models/face.rb +2 -3
  826. data/spec/support/models/fanatic.rb +1 -1
  827. data/spec/support/models/favorite.rb +1 -1
  828. data/spec/support/models/filesystem.rb +1 -1
  829. data/spec/support/models/fire_hydrant.rb +1 -1
  830. data/spec/support/models/firefox.rb +0 -1
  831. data/spec/support/models/fish.rb +0 -1
  832. data/spec/support/models/folder.rb +0 -2
  833. data/spec/support/models/folder_item.rb +1 -3
  834. data/spec/support/models/fruits.rb +9 -5
  835. data/spec/support/models/game.rb +3 -4
  836. data/spec/support/models/ghost.rb +0 -1
  837. data/spec/support/models/guitar.rb +0 -1
  838. data/spec/support/models/hole.rb +0 -1
  839. data/spec/support/models/home.rb +1 -1
  840. data/spec/support/models/house.rb +2 -2
  841. data/spec/support/models/html_writer.rb +0 -1
  842. data/spec/support/models/id_key.rb +3 -3
  843. data/spec/support/models/idnodef.rb +0 -1
  844. data/spec/support/models/image.rb +0 -1
  845. data/spec/support/models/implant.rb +1 -2
  846. data/spec/support/models/instrument.rb +2 -3
  847. data/spec/support/models/item.rb +2 -2
  848. data/spec/support/models/jar.rb +1 -2
  849. data/spec/support/models/kaleidoscope.rb +1 -1
  850. data/spec/support/models/kangaroo.rb +1 -1
  851. data/spec/support/models/label.rb +2 -2
  852. data/spec/support/models/language.rb +1 -1
  853. data/spec/support/models/lat_lng.rb +0 -1
  854. data/spec/support/models/league.rb +1 -1
  855. data/spec/support/models/learner.rb +0 -1
  856. data/spec/support/models/line_item.rb +1 -1
  857. data/spec/support/models/location.rb +1 -1
  858. data/spec/support/models/login.rb +1 -2
  859. data/spec/support/models/manufacturer.rb +0 -1
  860. data/spec/support/models/meat.rb +1 -1
  861. data/spec/support/models/membership.rb +1 -1
  862. data/spec/support/models/message.rb +1 -2
  863. data/spec/support/models/minim.rb +0 -1
  864. data/spec/support/models/mixed_drink.rb +1 -1
  865. data/spec/support/models/modifier_models.rb +25 -0
  866. data/spec/support/models/mop.rb +0 -1
  867. data/spec/support/models/movie.rb +1 -1
  868. data/spec/support/models/my_hash.rb +1 -2
  869. data/spec/support/models/name.rb +4 -5
  870. data/spec/support/models/name_only.rb +0 -1
  871. data/spec/support/models/node.rb +1 -1
  872. data/spec/support/models/note.rb +3 -3
  873. data/spec/support/models/nut.rb +0 -1
  874. data/spec/support/models/odd.rb +1 -1
  875. data/spec/support/models/order.rb +1 -1
  876. data/spec/support/models/ordered_post.rb +1 -1
  877. data/spec/support/models/ordered_preference.rb +1 -1
  878. data/spec/support/models/oscar.rb +1 -1
  879. data/spec/support/models/other_owner_object.rb +0 -1
  880. data/spec/support/models/override.rb +3 -11
  881. data/spec/support/models/ownable.rb +1 -1
  882. data/spec/support/models/owner.rb +1 -1
  883. data/spec/support/models/pack.rb +0 -1
  884. data/spec/support/models/page.rb +3 -3
  885. data/spec/support/models/page_question.rb +1 -1
  886. data/spec/support/models/palette.rb +2 -2
  887. data/spec/support/models/parent.rb +2 -2
  888. data/spec/support/models/parent_doc.rb +1 -1
  889. data/spec/support/models/passport.rb +0 -1
  890. data/spec/support/models/patient.rb +2 -2
  891. data/spec/support/models/pdf_writer.rb +0 -1
  892. data/spec/support/models/pencil.rb +0 -1
  893. data/spec/support/models/person.rb +32 -28
  894. data/spec/support/models/pet.rb +1 -1
  895. data/spec/support/models/pet_owner.rb +1 -1
  896. data/spec/support/models/phone.rb +1 -2
  897. data/spec/support/models/piano.rb +0 -1
  898. data/spec/support/models/pizza.rb +1 -1
  899. data/spec/support/models/player.rb +5 -5
  900. data/spec/support/models/post.rb +12 -12
  901. data/spec/support/models/post_genre.rb +1 -1
  902. data/spec/support/models/powerup.rb +1 -2
  903. data/spec/support/models/preference.rb +2 -2
  904. data/spec/support/models/princess.rb +1 -1
  905. data/spec/support/models/product.rb +3 -3
  906. data/spec/support/models/profile.rb +2 -1
  907. data/spec/support/models/pronunciation.rb +1 -1
  908. data/spec/support/models/pub.rb +2 -2
  909. data/spec/support/models/publication/encyclopedia.rb +0 -1
  910. data/spec/support/models/publication/review.rb +0 -1
  911. data/spec/support/models/publication.rb +0 -1
  912. data/spec/support/models/purchase.rb +1 -1
  913. data/spec/support/models/purchased_item.rb +1 -1
  914. data/spec/support/models/question.rb +2 -2
  915. data/spec/support/models/quiz.rb +1 -1
  916. data/spec/support/models/rating.rb +1 -1
  917. data/spec/support/models/record.rb +2 -3
  918. data/spec/support/models/registry.rb +1 -1
  919. data/spec/support/models/role.rb +1 -1
  920. data/spec/support/models/root_category.rb +1 -1
  921. data/spec/support/models/sandbox/app/models/app_models_message.rb +0 -1
  922. data/spec/support/models/sandbox/lib/models/lib_models_message.rb +0 -1
  923. data/spec/support/models/sandbox/sandbox_message.rb +0 -1
  924. data/spec/support/models/sandbox/sandbox_user.rb +0 -1
  925. data/spec/support/models/sandbox/subdir/sandbox_comment.rb +0 -1
  926. data/spec/support/models/sandwich.rb +1 -1
  927. data/spec/support/models/scheduler.rb +0 -1
  928. data/spec/support/models/school.rb +0 -1
  929. data/spec/support/models/scribe.rb +1 -1
  930. data/spec/support/models/sealer.rb +0 -1
  931. data/spec/support/models/seat.rb +0 -1
  932. data/spec/support/models/seo.rb +1 -1
  933. data/spec/support/models/series.rb +1 -1
  934. data/spec/support/models/server.rb +1 -1
  935. data/spec/support/models/service.rb +2 -2
  936. data/spec/support/models/shape.rb +3 -3
  937. data/spec/support/models/shelf.rb +1 -1
  938. data/spec/support/models/shield.rb +2 -2
  939. data/spec/support/models/shipment_address.rb +0 -1
  940. data/spec/support/models/shipping_container.rb +1 -1
  941. data/spec/support/models/shipping_pack.rb +0 -1
  942. data/spec/support/models/shirt.rb +0 -1
  943. data/spec/support/models/shop.rb +2 -2
  944. data/spec/support/models/short_agent.rb +0 -1
  945. data/spec/support/models/short_quiz.rb +1 -1
  946. data/spec/support/models/simple.rb +1 -1
  947. data/spec/support/models/slave.rb +1 -1
  948. data/spec/support/models/song.rb +1 -2
  949. data/spec/support/models/sound.rb +2 -2
  950. data/spec/support/models/spacer.rb +0 -1
  951. data/spec/support/models/square.rb +0 -1
  952. data/spec/support/models/staff.rb +0 -1
  953. data/spec/support/models/store_as_dup_test1.rb +2 -2
  954. data/spec/support/models/store_as_dup_test2.rb +1 -1
  955. data/spec/support/models/store_as_dup_test3.rb +2 -2
  956. data/spec/support/models/store_as_dup_test4.rb +1 -1
  957. data/spec/support/models/strategy.rb +0 -1
  958. data/spec/support/models/student.rb +1 -2
  959. data/spec/support/models/sub_item.rb +0 -1
  960. data/spec/support/models/subscription.rb +2 -2
  961. data/spec/support/models/survey.rb +2 -2
  962. data/spec/support/models/symptom.rb +2 -2
  963. data/spec/support/models/system_role.rb +2 -3
  964. data/spec/support/models/tag.rb +2 -2
  965. data/spec/support/models/target.rb +1 -1
  966. data/spec/support/models/template.rb +1 -1
  967. data/spec/support/models/thing.rb +1 -1
  968. data/spec/support/models/threadlocker.rb +0 -1
  969. data/spec/support/models/title.rb +0 -1
  970. data/spec/support/models/tool.rb +3 -3
  971. data/spec/support/models/topping.rb +1 -1
  972. data/spec/support/models/toy.rb +0 -1
  973. data/spec/support/models/track.rb +1 -1
  974. data/spec/support/models/translation.rb +1 -1
  975. data/spec/support/models/tree.rb +2 -3
  976. data/spec/support/models/truck.rb +0 -1
  977. data/spec/support/models/updatable.rb +0 -1
  978. data/spec/support/models/user.rb +3 -4
  979. data/spec/support/models/user_account.rb +3 -3
  980. data/spec/support/models/validation_callback.rb +4 -4
  981. data/spec/support/models/vehicle.rb +2 -3
  982. data/spec/support/models/version.rb +1 -1
  983. data/spec/support/models/vertex.rb +0 -1
  984. data/spec/support/models/vet_visit.rb +1 -1
  985. data/spec/support/models/video.rb +2 -2
  986. data/spec/support/models/video_game.rb +0 -1
  987. data/spec/support/models/washer.rb +0 -1
  988. data/spec/support/models/weapon.rb +1 -2
  989. data/spec/support/models/wiki_page.rb +2 -3
  990. data/spec/support/models/word.rb +2 -2
  991. data/spec/support/models/word_origin.rb +1 -2
  992. data/spec/support/models/writer.rb +3 -3
  993. data/spec/support/rails_mock.rb +7 -12
  994. data/spec/support/shared/time.rb +0 -1
  995. data/spec/support/sinatra_mock.rb +4 -2
  996. data/spec/support/spec_config.rb +19 -18
  997. metadata +14 -2
@@ -1,996 +1,909 @@
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::Optional do
7
-
8
6
  let(:query) do
9
7
  Mongoid::Query.new
10
8
  end
11
9
 
12
- shared_examples_for "a cloning option" do
13
-
14
- it "returns a cloned query" do
15
- expect(selection).to_not equal(query)
10
+ shared_examples_for 'a cloning option' do
11
+ it 'returns a cloned query' do
12
+ expect(selection).not_to equal(query)
16
13
  end
17
14
  end
18
15
 
19
- [ :asc, :ascending ].each do |method|
20
-
16
+ %i[asc ascending].each do |method|
21
17
  describe "##{method}" do
22
-
23
- context "when using the official mongodb driver syntax" do
24
-
25
- context "when the query is aggregating" do
26
-
18
+ context 'when using the official mongodb driver syntax' do
19
+ context 'when the query is aggregating' do
27
20
  let(:selection) do
28
21
  query.project(name: 1).send(method, :field_one, :field_two)
29
22
  end
30
23
 
31
- it "adds the sorting criteria" do
24
+ it 'adds the sorting criteria' do
32
25
  expect(selection.options).to eq(
33
- { sort: { "field_one" => 1, "field_two" => 1 }}
26
+ { sort: { 'field_one' => 1, 'field_two' => 1 } }
34
27
  )
35
28
  end
36
29
 
37
- it "adds the sort to the aggregation" do
30
+ it 'adds the sort to the aggregation' do
38
31
  expect(selection.pipeline).to include(
39
- { "$sort" => { "field_one" => 1, "field_two" => 1 }}
32
+ { '$sort' => { 'field_one' => 1, 'field_two' => 1 } }
40
33
  )
41
34
  end
42
35
 
43
- it "does not add multiple entries to the pipeline" do
44
- expect(selection.pipeline).to_not include(
45
- { "$sort" => { "field_one" => 1 }}
36
+ it 'does not add multiple entries to the pipeline' do
37
+ expect(selection.pipeline).not_to include(
38
+ { '$sort' => { 'field_one' => 1 } }
46
39
  )
47
40
  end
48
41
 
49
- it_behaves_like "a cloning option"
42
+ it_behaves_like 'a cloning option'
50
43
  end
51
44
 
52
- context "when provided symbols" do
53
-
45
+ context 'when provided symbols' do
54
46
  let(:selection) do
55
47
  query.send(method, :field_one, :field_two)
56
48
  end
57
49
 
58
- it "adds the sorting criteria" do
50
+ it 'adds the sorting criteria' do
59
51
  expect(selection.options).to eq(
60
- { sort: { "field_one" => 1, "field_two" => 1 }}
52
+ { sort: { 'field_one' => 1, 'field_two' => 1 } }
61
53
  )
62
54
  end
63
55
 
64
- it_behaves_like "a cloning option"
56
+ it_behaves_like 'a cloning option'
65
57
  end
66
58
 
67
- context "when provided an array of symbols" do
68
-
59
+ context 'when provided an array of symbols' do
69
60
  let(:selection) do
70
- query.send(method, [ :field_one, :field_two ])
61
+ query.send(method, %i[field_one field_two])
71
62
  end
72
63
 
73
- it "adds the sorting criteria" do
64
+ it 'adds the sorting criteria' do
74
65
  expect(selection.options).to eq(
75
- { sort: { "field_one" => 1, "field_two" => 1 }}
66
+ { sort: { 'field_one' => 1, 'field_two' => 1 } }
76
67
  )
77
68
  end
78
69
 
79
- it_behaves_like "a cloning option"
70
+ it_behaves_like 'a cloning option'
80
71
  end
81
72
 
82
- context "when provided strings" do
83
-
73
+ context 'when provided strings' do
84
74
  let(:selection) do
85
- query.send(method, "field_one", "field_two")
75
+ query.send(method, 'field_one', 'field_two')
86
76
  end
87
77
 
88
- it "adds the sorting criteria" do
78
+ it 'adds the sorting criteria' do
89
79
  expect(selection.options).to eq(
90
- { sort: { "field_one" => 1, "field_two" => 1 }}
80
+ { sort: { 'field_one' => 1, 'field_two' => 1 } }
91
81
  )
92
82
  end
93
83
 
94
- it_behaves_like "a cloning option"
84
+ it_behaves_like 'a cloning option'
95
85
  end
96
86
 
97
- context "when provided an array of strings" do
98
-
87
+ context 'when provided an array of strings' do
99
88
  let(:selection) do
100
- query.send(method, [ "field_one", "field_two" ])
89
+ query.send(method, %w[field_one field_two])
101
90
  end
102
91
 
103
- it "adds the sorting criteria" do
92
+ it 'adds the sorting criteria' do
104
93
  expect(selection.options).to eq(
105
- { sort: { "field_one" => 1, "field_two" => 1 }}
94
+ { sort: { 'field_one' => 1, 'field_two' => 1 } }
106
95
  )
107
96
  end
108
97
 
109
- it_behaves_like "a cloning option"
98
+ it_behaves_like 'a cloning option'
110
99
  end
111
100
 
112
- context "when provided no options" do
113
-
101
+ context 'when provided no options' do
114
102
  let(:selection) do
115
103
  query.send(method)
116
104
  end
117
105
 
118
- it "does not add any sorting criteria" do
106
+ it 'does not add any sorting criteria' do
119
107
  expect(selection.options).to be_empty
120
108
  end
121
109
 
122
- it "returns the query" do
110
+ it 'returns the query' do
123
111
  expect(selection).to eq(query)
124
112
  end
125
113
 
126
- it_behaves_like "a cloning option"
114
+ it_behaves_like 'a cloning option'
127
115
  end
128
116
 
129
- context "when provided nil" do
130
-
117
+ context 'when provided nil' do
131
118
  let(:selection) do
132
119
  query.send(method, nil)
133
120
  end
134
121
 
135
- it "does not add any sorting criteria" do
122
+ it 'does not add any sorting criteria' do
136
123
  expect(selection.options).to be_empty
137
124
  end
138
125
 
139
- it "returns the query" do
126
+ it 'returns the query' do
140
127
  expect(selection).to eq(query)
141
128
  end
142
129
 
143
- it_behaves_like "a cloning option"
130
+ it_behaves_like 'a cloning option'
144
131
  end
145
132
  end
146
133
  end
147
134
  end
148
135
 
149
- describe "#batch_size" do
150
-
151
- context "when provided no options" do
152
-
136
+ describe '#batch_size' do
137
+ context 'when provided no options' do
153
138
  let(:selection) do
154
139
  query.batch_size
155
140
  end
156
141
 
157
- it "does not add any options" do
142
+ it 'does not add any options' do
158
143
  expect(selection.options).to eq({})
159
144
  end
160
145
 
161
- it_behaves_like "a cloning option"
146
+ it_behaves_like 'a cloning option'
162
147
  end
163
148
 
164
- context "when provided nil" do
165
-
149
+ context 'when provided nil' do
166
150
  let(:selection) do
167
151
  query.batch_size(nil)
168
152
  end
169
153
 
170
- it "does not add any options" do
154
+ it 'does not add any options' do
171
155
  expect(selection.options).to eq({})
172
156
  end
173
157
 
174
- it_behaves_like "a cloning option"
158
+ it_behaves_like 'a cloning option'
175
159
  end
176
160
 
177
- context "when provided arguments" do
178
-
161
+ context 'when provided arguments' do
179
162
  let(:selection) do
180
163
  query.batch_size(500)
181
164
  end
182
165
 
183
- it "adds the field options" do
166
+ it 'adds the field options' do
184
167
  expect(selection.options).to eq({ batch_size: 500 })
185
168
  end
186
169
 
187
- it_behaves_like "a cloning option"
170
+ it_behaves_like 'a cloning option'
188
171
  end
189
172
  end
190
173
 
191
- [ :desc, :descending ].each do |method|
192
-
174
+ %i[desc descending].each do |method|
193
175
  describe "##{method}" do
194
-
195
- context "when using the official mongodb driver syntax" do
196
-
197
- context "when the query is aggregating" do
198
-
176
+ context 'when using the official mongodb driver syntax' do
177
+ context 'when the query is aggregating' do
199
178
  let(:selection) do
200
179
  query.project(name: 1).send(method, :field_one, :field_two)
201
180
  end
202
181
 
203
- it "adds the sorting criteria" do
182
+ it 'adds the sorting criteria' do
204
183
  expect(selection.options).to eq(
205
- { sort: { "field_one" => -1, "field_two" => -1 }}
184
+ { sort: { 'field_one' => -1, 'field_two' => -1 } }
206
185
  )
207
186
  end
208
187
 
209
- it "adds the sort to the aggregation" do
188
+ it 'adds the sort to the aggregation' do
210
189
  expect(selection.pipeline).to include(
211
- { "$sort" => { "field_one" => -1, "field_two" => -1 }}
190
+ { '$sort' => { 'field_one' => -1, 'field_two' => -1 } }
212
191
  )
213
192
  end
214
193
 
215
- it "does not add multiple entries to the pipeline" do
216
- expect(selection.pipeline).to_not include(
217
- { "$sort" => { "field_one" => -1 }}
194
+ it 'does not add multiple entries to the pipeline' do
195
+ expect(selection.pipeline).not_to include(
196
+ { '$sort' => { 'field_one' => -1 } }
218
197
  )
219
198
  end
220
199
 
221
- it_behaves_like "a cloning option"
200
+ it_behaves_like 'a cloning option'
222
201
  end
223
202
 
224
- context "when provided symbols" do
225
-
203
+ context 'when provided symbols' do
226
204
  let(:selection) do
227
205
  query.send(method, :field_one, :field_two)
228
206
  end
229
207
 
230
- it "adds the sorting criteria" do
208
+ it 'adds the sorting criteria' do
231
209
  expect(selection.options).to eq(
232
- { sort: { "field_one" => -1, "field_two" => -1 }}
210
+ { sort: { 'field_one' => -1, 'field_two' => -1 } }
233
211
  )
234
212
  end
235
213
 
236
- it_behaves_like "a cloning option"
214
+ it_behaves_like 'a cloning option'
237
215
  end
238
216
 
239
- context "when provided an array of symbols" do
240
-
217
+ context 'when provided an array of symbols' do
241
218
  let(:selection) do
242
- query.send(method, [ :field_one, :field_two ])
219
+ query.send(method, %i[field_one field_two])
243
220
  end
244
221
 
245
- it "adds the sorting criteria" do
222
+ it 'adds the sorting criteria' do
246
223
  expect(selection.options).to eq(
247
- { sort: { "field_one" => -1, "field_two" => -1 }}
224
+ { sort: { 'field_one' => -1, 'field_two' => -1 } }
248
225
  )
249
226
  end
250
227
 
251
- it_behaves_like "a cloning option"
228
+ it_behaves_like 'a cloning option'
252
229
  end
253
230
 
254
- context "when provided strings" do
255
-
231
+ context 'when provided strings' do
256
232
  let(:selection) do
257
- query.send(method, "field_one", "field_two")
233
+ query.send(method, 'field_one', 'field_two')
258
234
  end
259
235
 
260
- it "adds the sorting criteria" do
236
+ it 'adds the sorting criteria' do
261
237
  expect(selection.options).to eq(
262
- { sort: { "field_one" => -1, "field_two" => -1 }}
238
+ { sort: { 'field_one' => -1, 'field_two' => -1 } }
263
239
  )
264
240
  end
265
241
 
266
- it_behaves_like "a cloning option"
242
+ it_behaves_like 'a cloning option'
267
243
  end
268
244
 
269
- context "when provided an array of strings" do
270
-
245
+ context 'when provided an array of strings' do
271
246
  let(:selection) do
272
- query.send(method, [ "field_one", "field_two" ])
247
+ query.send(method, %w[field_one field_two])
273
248
  end
274
249
 
275
- it "adds the sorting criteria" do
250
+ it 'adds the sorting criteria' do
276
251
  expect(selection.options).to eq(
277
- { sort: { "field_one" => -1, "field_two" => -1 }}
252
+ { sort: { 'field_one' => -1, 'field_two' => -1 } }
278
253
  )
279
254
  end
280
255
 
281
- it_behaves_like "a cloning option"
256
+ it_behaves_like 'a cloning option'
282
257
  end
283
258
 
284
- context "when provided no options" do
285
-
259
+ context 'when provided no options' do
286
260
  let(:selection) do
287
261
  query.send(method)
288
262
  end
289
263
 
290
- it "does not add any sorting criteria" do
264
+ it 'does not add any sorting criteria' do
291
265
  expect(selection.options).to be_empty
292
266
  end
293
267
 
294
- it "returns the query" do
268
+ it 'returns the query' do
295
269
  expect(selection).to eq(query)
296
270
  end
297
271
 
298
- it_behaves_like "a cloning option"
272
+ it_behaves_like 'a cloning option'
299
273
  end
300
274
 
301
- context "when provided nil" do
302
-
275
+ context 'when provided nil' do
303
276
  let(:selection) do
304
277
  query.send(method, nil)
305
278
  end
306
279
 
307
- it "does not add any sorting criteria" do
280
+ it 'does not add any sorting criteria' do
308
281
  expect(selection.options).to be_empty
309
282
  end
310
283
 
311
- it "returns the query" do
284
+ it 'returns the query' do
312
285
  expect(selection).to eq(query)
313
286
  end
314
287
 
315
- it_behaves_like "a cloning option"
288
+ it_behaves_like 'a cloning option'
316
289
  end
317
290
  end
318
291
  end
319
292
  end
320
293
 
321
- describe "#hint" do
322
-
323
- context "when provided no options" do
324
-
294
+ describe '#hint' do
295
+ context 'when provided no options' do
325
296
  let(:selection) do
326
297
  query.hint
327
298
  end
328
299
 
329
- it "does not add any options" do
300
+ it 'does not add any options' do
330
301
  expect(selection.options).to eq({})
331
302
  end
332
303
 
333
- it "returns the query" do
304
+ it 'returns the query' do
334
305
  expect(selection).to eq(query)
335
306
  end
336
307
 
337
- it_behaves_like "a cloning option"
308
+ it_behaves_like 'a cloning option'
338
309
  end
339
310
 
340
- context "when provided nil" do
341
-
311
+ context 'when provided nil' do
342
312
  let(:selection) do
343
313
  query.hint(nil)
344
314
  end
345
315
 
346
- it "does not add any options" do
316
+ it 'does not add any options' do
347
317
  expect(selection.options).to eq({})
348
318
  end
349
319
 
350
- it "returns the query" do
320
+ it 'returns the query' do
351
321
  expect(selection).to eq(query)
352
322
  end
353
323
 
354
- it_behaves_like "a cloning option"
324
+ it_behaves_like 'a cloning option'
355
325
  end
356
326
 
357
- context "when provided arguments" do
358
-
359
- context "when the argument is a hash" do
360
-
327
+ context 'when provided arguments' do
328
+ context 'when the argument is a hash' do
361
329
  let(:selection) do
362
- query.hint("$natural" => 1)
330
+ query.hint('$natural' => 1)
363
331
  end
364
332
 
365
- it "adds the field options" do
366
- expect(selection.options).to eq({ hint: { "$natural" => 1 }})
333
+ it 'adds the field options' do
334
+ expect(selection.options).to eq({ hint: { '$natural' => 1 } })
367
335
  end
368
336
 
369
- it_behaves_like "a cloning option"
337
+ it_behaves_like 'a cloning option'
370
338
  end
371
339
  end
372
340
  end
373
341
 
374
- describe "#limit" do
375
-
376
- context "when provided no options" do
377
-
342
+ describe '#limit' do
343
+ context 'when provided no options' do
378
344
  let(:selection) do
379
345
  query.limit
380
346
  end
381
347
 
382
- it "does not add any options" do
348
+ it 'does not add any options' do
383
349
  expect(selection.options).to eq({})
384
350
  end
385
351
 
386
- it "returns the query" do
352
+ it 'returns the query' do
387
353
  expect(selection).to eq(query)
388
354
  end
389
355
 
390
- it_behaves_like "a cloning option"
356
+ it_behaves_like 'a cloning option'
391
357
  end
392
358
 
393
- context "when provided nil" do
394
-
359
+ context 'when provided nil' do
395
360
  let(:selection) do
396
361
  query.limit(nil)
397
362
  end
398
363
 
399
- it "does not add any options" do
364
+ it 'does not add any options' do
400
365
  expect(selection.options).to eq({})
401
366
  end
402
367
 
403
- it "returns the query" do
368
+ it 'returns the query' do
404
369
  expect(selection).to eq(query)
405
370
  end
406
371
 
407
- it_behaves_like "a cloning option"
372
+ it_behaves_like 'a cloning option'
408
373
  end
409
374
 
410
- context "when the query is aggregating" do
411
-
375
+ context 'when the query is aggregating' do
412
376
  let(:selection) do
413
377
  query.project(name: 1).limit(10)
414
378
  end
415
379
 
416
- it "adds the field options" do
380
+ it 'adds the field options' do
417
381
  expect(selection.options).to eq({ limit: 10 })
418
382
  end
419
383
 
420
- it "adds the limit to the aggregation" do
421
- expect(selection.pipeline).to include({ "$limit" => 10 })
384
+ it 'adds the limit to the aggregation' do
385
+ expect(selection.pipeline).to include({ '$limit' => 10 })
422
386
  end
423
387
 
424
- it_behaves_like "a cloning option"
388
+ it_behaves_like 'a cloning option'
425
389
  end
426
390
 
427
- context "when provided arguments" do
428
-
429
- context "when the argument is an integer" do
430
-
391
+ context 'when provided arguments' do
392
+ context 'when the argument is an integer' do
431
393
  let(:selection) do
432
394
  query.limit(10)
433
395
  end
434
396
 
435
- it "adds the field options" do
397
+ it 'adds the field options' do
436
398
  expect(selection.options).to eq({ limit: 10 })
437
399
  end
438
400
 
439
- it_behaves_like "a cloning option"
401
+ it_behaves_like 'a cloning option'
440
402
  end
441
403
 
442
- context "when the argument is a float" do
443
-
404
+ context 'when the argument is a float' do
444
405
  let(:selection) do
445
406
  query.limit(10.25)
446
407
  end
447
408
 
448
- it "adds the field options as an integer" do
409
+ it 'adds the field options as an integer' do
449
410
  expect(selection.options).to eq({ limit: 10 })
450
411
  end
451
412
 
452
- it_behaves_like "a cloning option"
413
+ it_behaves_like 'a cloning option'
453
414
  end
454
415
 
455
- context "when the argument is a string" do
456
-
416
+ context 'when the argument is a string' do
457
417
  let(:selection) do
458
- query.limit("10")
418
+ query.limit('10')
459
419
  end
460
420
 
461
- it "adds the field options as an integer" do
421
+ it 'adds the field options as an integer' do
462
422
  expect(selection.options).to eq({ limit: 10 })
463
423
  end
464
424
 
465
- it_behaves_like "a cloning option"
425
+ it_behaves_like 'a cloning option'
466
426
  end
467
427
  end
468
428
  end
469
429
 
470
- describe "#max_scan" do
471
-
472
- context "when provided no options" do
473
-
430
+ describe '#max_scan' do
431
+ context 'when provided no options' do
474
432
  let(:selection) do
475
433
  query.max_scan
476
434
  end
477
435
 
478
- it "does not add any options" do
436
+ it 'does not add any options' do
479
437
  expect(selection.options).to eq({})
480
438
  end
481
439
 
482
- it "returns the query" do
440
+ it 'returns the query' do
483
441
  expect(selection).to eq(query)
484
442
  end
485
443
 
486
- it_behaves_like "a cloning option"
444
+ it_behaves_like 'a cloning option'
487
445
  end
488
446
 
489
- context "when provided nil" do
490
-
447
+ context 'when provided nil' do
491
448
  let(:selection) do
492
449
  query.max_scan(nil)
493
450
  end
494
451
 
495
- it "does not add any options" do
452
+ it 'does not add any options' do
496
453
  expect(selection.options).to eq({})
497
454
  end
498
455
 
499
- it "returns the query" do
456
+ it 'returns the query' do
500
457
  expect(selection).to eq(query)
501
458
  end
502
459
 
503
- it_behaves_like "a cloning option"
460
+ it_behaves_like 'a cloning option'
504
461
  end
505
462
 
506
- context "when provided arguments" do
507
-
463
+ context 'when provided arguments' do
508
464
  let(:selection) do
509
465
  query.max_scan(500)
510
466
  end
511
467
 
512
- it "adds the field options" do
468
+ it 'adds the field options' do
513
469
  expect(selection.options).to eq({ max_scan: 500 })
514
470
  end
515
471
 
516
- it_behaves_like "a cloning option"
472
+ it_behaves_like 'a cloning option'
517
473
  end
518
474
  end
519
475
 
520
- describe "#max_time_ms" do
521
-
522
- context "when provided no options" do
523
-
476
+ describe '#max_time_ms' do
477
+ context 'when provided no options' do
524
478
  let(:selection) do
525
479
  query.max_time_ms
526
480
  end
527
481
 
528
- it "does not add any options" do
482
+ it 'does not add any options' do
529
483
  expect(selection.options).to eq({})
530
484
  end
531
485
 
532
- it "returns the query" do
486
+ it 'returns the query' do
533
487
  expect(selection).to eq(query)
534
488
  end
535
489
 
536
- it_behaves_like "a cloning option"
490
+ it_behaves_like 'a cloning option'
537
491
  end
538
492
 
539
- context "when provided nil" do
540
-
493
+ context 'when provided nil' do
541
494
  let(:selection) do
542
495
  query.max_time_ms(nil)
543
496
  end
544
497
 
545
- it "does not add any options" do
498
+ it 'does not add any options' do
546
499
  expect(selection.options).to eq({})
547
500
  end
548
501
 
549
- it "returns the query" do
502
+ it 'returns the query' do
550
503
  expect(selection).to eq(query)
551
504
  end
552
505
 
553
- it_behaves_like "a cloning option"
506
+ it_behaves_like 'a cloning option'
554
507
  end
555
508
 
556
- context "when provided arguments" do
557
-
509
+ context 'when provided arguments' do
558
510
  let(:selection) do
559
511
  query.max_time_ms(500)
560
512
  end
561
513
 
562
- it "adds the field options" do
514
+ it 'adds the field options' do
563
515
  expect(selection.options).to eq({ max_time_ms: 500 })
564
516
  end
565
517
 
566
- it_behaves_like "a cloning option"
518
+ it_behaves_like 'a cloning option'
567
519
  end
568
520
  end
569
521
 
570
- describe "#no_timeout" do
571
-
522
+ describe '#no_timeout' do
572
523
  let(:selection) do
573
524
  query.no_timeout
574
525
  end
575
526
 
576
- it "adds the timeout option" do
527
+ it 'adds the timeout option' do
577
528
  expect(selection.options).to eq({ timeout: false })
578
529
  end
579
530
 
580
- it_behaves_like "a cloning option"
531
+ it_behaves_like 'a cloning option'
581
532
  end
582
533
 
583
- describe "#only" do
584
-
585
- context "when provided no options" do
586
-
534
+ describe '#only' do
535
+ context 'when provided no options' do
587
536
  let(:selection) do
588
537
  query.only
589
538
  end
590
539
 
591
- it "does not add any options" do
540
+ it 'does not add any options' do
592
541
  expect(selection.options).to eq({})
593
542
  end
594
543
 
595
- it "returns the query" do
544
+ it 'returns the query' do
596
545
  expect(selection).to eq(query)
597
546
  end
598
547
 
599
- it_behaves_like "a cloning option"
548
+ it_behaves_like 'a cloning option'
600
549
  end
601
550
 
602
- context "when provided nil" do
603
-
551
+ context 'when provided nil' do
604
552
  let(:selection) do
605
553
  query.only(nil)
606
554
  end
607
555
 
608
- it "does not add any options" do
556
+ it 'does not add any options' do
609
557
  expect(selection.options).to eq({})
610
558
  end
611
559
 
612
- it "returns the query" do
560
+ it 'returns the query' do
613
561
  expect(selection).to eq(query)
614
562
  end
615
563
 
616
- it_behaves_like "a cloning option"
564
+ it_behaves_like 'a cloning option'
617
565
  end
618
566
 
619
- context "when provided fields" do
620
-
621
- context "as several arguments" do
622
-
567
+ context 'when provided fields' do
568
+ context 'as several arguments' do
623
569
  let(:selection) do
624
570
  query.only(:first, :second)
625
571
  end
626
572
 
627
- it "adds the field options" do
573
+ it 'adds the field options' do
628
574
  expect(selection.options).to eq(
629
- { fields: { "first" => 1, "second" => 1 }}
575
+ { fields: { 'first' => 1, 'second' => 1 } }
630
576
  )
631
577
  end
632
578
 
633
- it_behaves_like "a cloning option"
579
+ it_behaves_like 'a cloning option'
634
580
  end
635
581
 
636
- context "as one argument - array" do
637
-
582
+ context 'as one argument - array' do
638
583
  let(:selection) do
639
- query.only([:first, :second])
584
+ query.only(%i[first second])
640
585
  end
641
586
 
642
- it "adds the field options" do
587
+ it 'adds the field options' do
643
588
  expect(selection.options).to eq(
644
- { fields: { "first" => 1, "second" => 1 }}
589
+ { fields: { 'first' => 1, 'second' => 1 } }
645
590
  )
646
591
  end
647
592
 
648
- it_behaves_like "a cloning option"
593
+ it_behaves_like 'a cloning option'
649
594
  end
650
595
  end
651
596
 
652
- context "when #without was called first" do
653
-
597
+ context 'when #without was called first' do
654
598
  let(:selection) do
655
599
  query.without(:id).only(:first)
656
600
  end
657
601
 
658
- it "adds both fields to option" do
602
+ it 'adds both fields to option' do
659
603
  expect(selection.options).to eq(
660
- { fields: { "id" => 0, "first" => 1 } }
604
+ { fields: { 'id' => 0, 'first' => 1 } }
661
605
  )
662
606
  end
663
607
  end
664
608
  end
665
609
 
666
- [ :order, :order_by ].each do |method|
667
-
610
+ %i[order order_by].each do |method|
668
611
  describe "##{method}" do
669
-
670
- context "when using the official mongodb driver syntax" do
671
-
672
- context "when provided a hash" do
673
-
674
- context "when the query is aggregating" do
675
-
612
+ context 'when using the official mongodb driver syntax' do
613
+ context 'when provided a hash' do
614
+ context 'when the query is aggregating' do
676
615
  let(:selection) do
677
616
  query.project(name: 1).send("#{method}", field_one: 1, field_two: -1)
678
617
  end
679
618
 
680
- it "adds the sorting criteria" do
619
+ it 'adds the sorting criteria' do
681
620
  expect(selection.options).to eq(
682
- { sort: { "field_one" => 1, "field_two" => -1 }}
621
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
683
622
  )
684
623
  end
685
624
 
686
- it "adds the sort to the aggregation" do
625
+ it 'adds the sort to the aggregation' do
687
626
  expect(selection.pipeline).to include(
688
- { "$sort" => { "field_one" => 1, "field_two" => -1 }}
627
+ { '$sort' => { 'field_one' => 1, 'field_two' => -1 } }
689
628
  )
690
629
  end
691
630
 
692
- it "does not add multiple entries to the pipeline" do
693
- expect(selection.pipeline).to_not include(
694
- { "$sort" => { "field_one" => 1 }}
631
+ it 'does not add multiple entries to the pipeline' do
632
+ expect(selection.pipeline).not_to include(
633
+ { '$sort' => { 'field_one' => 1 } }
695
634
  )
696
635
  end
697
636
 
698
- it_behaves_like "a cloning option"
637
+ it_behaves_like 'a cloning option'
699
638
  end
700
639
 
701
- context "when the hash has integer values" do
702
-
640
+ context 'when the hash has integer values' do
703
641
  let(:selection) do
704
642
  query.send("#{method}", field_one: 1, field_two: -1)
705
643
  end
706
644
 
707
- it "adds the sorting criteria" do
645
+ it 'adds the sorting criteria' do
708
646
  expect(selection.options).to eq(
709
- { sort: { "field_one" => 1, "field_two" => -1 }}
647
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
710
648
  )
711
649
  end
712
650
 
713
- it_behaves_like "a cloning option"
651
+ it_behaves_like 'a cloning option'
714
652
  end
715
653
 
716
- context "when the hash has symbol values" do
717
-
654
+ context 'when the hash has symbol values' do
718
655
  let(:selection) do
719
656
  query.send("#{method}", field_one: :asc, field_two: :desc)
720
657
  end
721
658
 
722
- it "adds the sorting criteria" do
659
+ it 'adds the sorting criteria' do
723
660
  expect(selection.options).to eq(
724
- { sort: { "field_one" => 1, "field_two" => -1 }}
661
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
725
662
  )
726
663
  end
727
664
 
728
- it_behaves_like "a cloning option"
665
+ it_behaves_like 'a cloning option'
729
666
  end
730
667
 
731
- context "when the hash has string values" do
732
-
668
+ context 'when the hash has string values' do
733
669
  let(:selection) do
734
- query.send("#{method}", field_one: "asc", field_two: "desc")
670
+ query.send("#{method}", field_one: 'asc', field_two: 'desc')
735
671
  end
736
672
 
737
- it "adds the sorting criteria" do
673
+ it 'adds the sorting criteria' do
738
674
  expect(selection.options).to eq(
739
- { sort: { "field_one" => 1, "field_two" => -1 }}
675
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
740
676
  )
741
677
  end
742
678
 
743
- it_behaves_like "a cloning option"
679
+ it_behaves_like 'a cloning option'
744
680
  end
745
681
 
746
- context "when the hash has hash values" do
747
-
682
+ context 'when the hash has hash values' do
748
683
  let(:selection) do
749
- query.send("#{method}", score: { "$meta" => "textScore"})
684
+ query.send("#{method}", score: { '$meta' => 'textScore' })
750
685
  end
751
686
 
752
- it "adds the sorting criteria" do
687
+ it 'adds the sorting criteria' do
753
688
  expect(selection.options).to eq(
754
- { sort: { "score" => { "$meta" => "textScore" } }}
689
+ { sort: { 'score' => { '$meta' => 'textScore' } } }
755
690
  )
756
691
  end
757
692
 
758
- it_behaves_like "a cloning option"
693
+ it_behaves_like 'a cloning option'
759
694
  end
760
695
  end
761
696
 
762
- context "when provided an array" do
763
-
764
- context "when the array is multi-dimensional" do
765
-
766
- context "when the arrays have integer values" do
767
-
697
+ context 'when provided an array' do
698
+ context 'when the array is multi-dimensional' do
699
+ context 'when the arrays have integer values' do
768
700
  let(:selection) do
769
- query.send("#{method}", [[ :field_one, 1 ],[ :field_two, -1 ]])
701
+ query.send("#{method}", [ [ :field_one, 1 ], [ :field_two, -1 ] ])
770
702
  end
771
703
 
772
- it "adds the sorting criteria" do
704
+ it 'adds the sorting criteria' do
773
705
  expect(selection.options).to eq(
774
- { sort: { "field_one" => 1, "field_two" => -1 }}
706
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
775
707
  )
776
708
  end
777
709
 
778
- it_behaves_like "a cloning option"
710
+ it_behaves_like 'a cloning option'
779
711
  end
780
712
 
781
- context "when the arrays have symbol values" do
782
-
713
+ context 'when the arrays have symbol values' do
783
714
  let(:selection) do
784
- query.send("#{method}", [[ :field_one, :asc ],[ :field_two, :desc ]])
715
+ query.send("#{method}", [ %i[field_one asc], %i[field_two desc] ])
785
716
  end
786
717
 
787
- it "adds the sorting criteria" do
718
+ it 'adds the sorting criteria' do
788
719
  expect(selection.options).to eq(
789
- { sort: { "field_one" => 1, "field_two" => -1 }}
720
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
790
721
  )
791
722
  end
792
723
 
793
- it_behaves_like "a cloning option"
724
+ it_behaves_like 'a cloning option'
794
725
  end
795
726
 
796
- context "when the arrays have string values" do
797
-
727
+ context 'when the arrays have string values' do
798
728
  let(:selection) do
799
- query.send("#{method}", [[ :field_one, "asc" ],[ :field_two, "desc" ]])
729
+ query.send("#{method}", [ [ :field_one, 'asc' ], [ :field_two, 'desc' ] ])
800
730
  end
801
731
 
802
- it "adds the sorting criteria" do
732
+ it 'adds the sorting criteria' do
803
733
  expect(selection.options).to eq(
804
- { sort: { "field_one" => 1, "field_two" => -1 }}
734
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
805
735
  )
806
736
  end
807
737
 
808
- it_behaves_like "a cloning option"
738
+ it_behaves_like 'a cloning option'
809
739
  end
810
740
  end
811
741
 
812
- context "when the array is selectable keys" do
813
-
742
+ context 'when the array is selectable keys' do
814
743
  let(:selection) do
815
744
  query.send("#{method}", [ :field_one.asc, :field_two.desc ])
816
745
  end
817
746
 
818
- it "adds the sorting criteria" do
747
+ it 'adds the sorting criteria' do
819
748
  expect(selection.options).to eq(
820
- { sort: { "field_one" => 1, "field_two" => -1 }}
749
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
821
750
  )
822
751
  end
823
752
 
824
- it_behaves_like "a cloning option"
753
+ it_behaves_like 'a cloning option'
825
754
  end
826
755
  end
827
756
 
828
- context "when provided values" do
829
-
830
- context "when the values are arrays" do
831
-
832
- context "when the values have integer directions" do
833
-
757
+ context 'when provided values' do
758
+ context 'when the values are arrays' do
759
+ context 'when the values have integer directions' do
834
760
  let(:selection) do
835
- query.send("#{method}", [ :field_one, 1 ],[ :field_two, -1 ])
761
+ query.send("#{method}", [ :field_one, 1 ], [ :field_two, -1 ])
836
762
  end
837
763
 
838
- it "adds the sorting criteria" do
764
+ it 'adds the sorting criteria' do
839
765
  expect(selection.options).to eq(
840
- { sort: { "field_one" => 1, "field_two" => -1 }}
766
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
841
767
  )
842
768
  end
843
769
 
844
- it_behaves_like "a cloning option"
770
+ it_behaves_like 'a cloning option'
845
771
  end
846
772
 
847
- context "when the values have symbol directions" do
848
-
773
+ context 'when the values have symbol directions' do
849
774
  let(:selection) do
850
- query.send("#{method}", [ :field_one, :asc ],[ :field_two, :desc ])
775
+ query.send("#{method}", %i[field_one asc], %i[field_two desc])
851
776
  end
852
777
 
853
- it "adds the sorting criteria" do
778
+ it 'adds the sorting criteria' do
854
779
  expect(selection.options).to eq(
855
- { sort: { "field_one" => 1, "field_two" => -1 }}
780
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
856
781
  )
857
782
  end
858
783
 
859
- it_behaves_like "a cloning option"
784
+ it_behaves_like 'a cloning option'
860
785
  end
861
786
 
862
- context "when the values have string directions" do
863
-
787
+ context 'when the values have string directions' do
864
788
  let(:selection) do
865
- query.send("#{method}", [ :field_one, "asc" ],[ :field_two, "desc" ])
789
+ query.send("#{method}", [ :field_one, 'asc' ], [ :field_two, 'desc' ])
866
790
  end
867
791
 
868
- it "adds the sorting criteria" do
792
+ it 'adds the sorting criteria' do
869
793
  expect(selection.options).to eq(
870
- { sort: { "field_one" => 1, "field_two" => -1 }}
794
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
871
795
  )
872
796
  end
873
797
 
874
- it_behaves_like "a cloning option"
798
+ it_behaves_like 'a cloning option'
875
799
  end
876
800
  end
877
801
 
878
- context "when the values are selectable keys" do
879
-
802
+ context 'when the values are selectable keys' do
880
803
  let(:selection) do
881
804
  query.send("#{method}", :field_one.asc, :field_two.desc)
882
805
  end
883
806
 
884
- it "adds the sorting criteria" do
807
+ it 'adds the sorting criteria' do
885
808
  expect(selection.options).to eq(
886
- { sort: { "field_one" => 1, "field_two" => -1 }}
809
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
887
810
  )
888
811
  end
889
812
 
890
- it_behaves_like "a cloning option"
813
+ it_behaves_like 'a cloning option'
891
814
  end
892
815
  end
893
816
 
894
- context "when provided a string" do
895
-
896
- context "when the direction is lowercase" do
897
-
898
- context "when abbreviated" do
899
-
817
+ context 'when provided a string' do
818
+ context 'when the direction is lowercase' do
819
+ context 'when abbreviated' do
900
820
  let(:selection) do
901
- query.send("#{method}", "field_one asc, field_two desc")
821
+ query.send("#{method}", 'field_one asc, field_two desc')
902
822
  end
903
823
 
904
- it "adds the sorting criteria" do
824
+ it 'adds the sorting criteria' do
905
825
  expect(selection.options).to eq(
906
- { sort: { "field_one" => 1, "field_two" => -1 }}
826
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
907
827
  )
908
828
  end
909
829
 
910
- it_behaves_like "a cloning option"
830
+ it_behaves_like 'a cloning option'
911
831
  end
912
832
 
913
- context "when spelled out" do
914
-
833
+ context 'when spelled out' do
915
834
  let(:selection) do
916
- query.send("#{method}", "field_one ascending, field_two descending")
835
+ query.send("#{method}", 'field_one ascending, field_two descending')
917
836
  end
918
837
 
919
- it "adds the sorting criteria" do
838
+ it 'adds the sorting criteria' do
920
839
  expect(selection.options).to eq(
921
- { sort: { "field_one" => 1, "field_two" => -1 }}
840
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
922
841
  )
923
842
  end
924
843
 
925
- it_behaves_like "a cloning option"
844
+ it_behaves_like 'a cloning option'
926
845
  end
927
846
  end
928
847
 
929
- context "when the direction is uppercase" do
930
-
931
- context "when abbreviated" do
932
-
848
+ context 'when the direction is uppercase' do
849
+ context 'when abbreviated' do
933
850
  let(:selection) do
934
- query.send("#{method}", "field_one ASC, field_two DESC")
851
+ query.send("#{method}", 'field_one ASC, field_two DESC')
935
852
  end
936
853
 
937
- it "adds the sorting criteria" do
854
+ it 'adds the sorting criteria' do
938
855
  expect(selection.options).to eq(
939
- { sort: { "field_one" => 1, "field_two" => -1 }}
856
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
940
857
  )
941
858
  end
942
859
 
943
- it_behaves_like "a cloning option"
860
+ it_behaves_like 'a cloning option'
944
861
  end
945
862
 
946
- context "when spelled out" do
947
-
863
+ context 'when spelled out' do
948
864
  let(:selection) do
949
- query.send("#{method}", "field_one ASCENDING, field_two DESCENDING")
865
+ query.send("#{method}", 'field_one ASCENDING, field_two DESCENDING')
950
866
  end
951
867
 
952
- it "adds the sorting criteria" do
868
+ it 'adds the sorting criteria' do
953
869
  expect(selection.options).to eq(
954
- { sort: { "field_one" => 1, "field_two" => -1 }}
870
+ { sort: { 'field_one' => 1, 'field_two' => -1 } }
955
871
  )
956
872
  end
957
873
 
958
- it_behaves_like "a cloning option"
874
+ it_behaves_like 'a cloning option'
959
875
  end
960
876
  end
961
877
  end
962
878
 
963
- context "when provided no options" do
964
-
879
+ context 'when provided no options' do
965
880
  let(:selection) do
966
881
  query.order_by
967
882
  end
968
883
 
969
- it "returns the query" do
884
+ it 'returns the query' do
970
885
  expect(selection).to eq(query)
971
886
  end
972
887
 
973
- it_behaves_like "a cloning option"
888
+ it_behaves_like 'a cloning option'
974
889
  end
975
890
 
976
- context "when provided nil" do
977
-
891
+ context 'when provided nil' do
978
892
  let(:selection) do
979
893
  query.send("#{method}", nil)
980
894
  end
981
895
 
982
- it "returns the query" do
896
+ it 'returns the query' do
983
897
  expect(selection).to eq(query)
984
898
  end
985
899
 
986
- it_behaves_like "a cloning option"
900
+ it_behaves_like 'a cloning option'
987
901
  end
988
902
  end
989
903
  end
990
904
  end
991
905
 
992
- describe "#reoder" do
993
-
906
+ describe '#reoder' do
994
907
  let(:selection) do
995
908
  query.order_by(field_one: 1, field_two: -1)
996
909
  end
@@ -999,8 +912,8 @@ describe Mongoid::Criteria::Queryable::Optional do
999
912
  selection.reorder(field_three: 1)
1000
913
  end
1001
914
 
1002
- it "replaces all order options with the new options" do
1003
- expect(reordered.options).to eq(sort: { "field_three" => 1 })
915
+ it 'replaces all order options with the new options' do
916
+ expect(reordered.options).to eq(sort: { 'field_three' => 1 })
1004
917
  end
1005
918
 
1006
919
  it 'does not alter the original criteria object' do
@@ -1008,324 +921,298 @@ describe Mongoid::Criteria::Queryable::Optional do
1008
921
  end
1009
922
  end
1010
923
 
1011
- [ :skip, :offset ].each do |method|
1012
-
1013
- describe "\##{method}" do
1014
-
1015
- context "when provided no options" do
1016
-
924
+ %i[skip offset].each do |method|
925
+ describe "##{method}" do
926
+ context 'when provided no options' do
1017
927
  let(:selection) do
1018
928
  query.send(method)
1019
929
  end
1020
930
 
1021
- it "does not add any options" do
931
+ it 'does not add any options' do
1022
932
  expect(selection.options).to eq({})
1023
933
  end
1024
934
 
1025
- it "returns the query" do
935
+ it 'returns the query' do
1026
936
  expect(selection).to eq(query)
1027
937
  end
1028
938
 
1029
- it_behaves_like "a cloning option"
939
+ it_behaves_like 'a cloning option'
1030
940
  end
1031
941
 
1032
- context "when provided nil" do
1033
-
942
+ context 'when provided nil' do
1034
943
  let(:selection) do
1035
944
  query.send(method, nil)
1036
945
  end
1037
946
 
1038
- it "does not add any options" do
947
+ it 'does not add any options' do
1039
948
  expect(selection.options).to eq({})
1040
949
  end
1041
950
 
1042
- it "returns the query" do
951
+ it 'returns the query' do
1043
952
  expect(selection).to eq(query)
1044
953
  end
1045
954
 
1046
- it_behaves_like "a cloning option"
955
+ it_behaves_like 'a cloning option'
1047
956
  end
1048
957
 
1049
- context "when the query is aggregating" do
1050
-
958
+ context 'when the query is aggregating' do
1051
959
  let(:selection) do
1052
960
  query.project(name: 1).skip(10)
1053
961
  end
1054
962
 
1055
- it "adds the field options" do
963
+ it 'adds the field options' do
1056
964
  expect(selection.options).to eq({ skip: 10 })
1057
965
  end
1058
966
 
1059
- it "adds the skip to the aggregation" do
1060
- expect(selection.pipeline).to include({ "$skip" => 10 })
967
+ it 'adds the skip to the aggregation' do
968
+ expect(selection.pipeline).to include({ '$skip' => 10 })
1061
969
  end
1062
970
 
1063
- it_behaves_like "a cloning option"
971
+ it_behaves_like 'a cloning option'
1064
972
  end
1065
973
 
1066
- context "when provided arguments" do
1067
-
1068
- context "when provided an integer" do
1069
-
974
+ context 'when provided arguments' do
975
+ context 'when provided an integer' do
1070
976
  let(:selection) do
1071
977
  query.send(method, 10)
1072
978
  end
1073
979
 
1074
- it "adds the field options" do
980
+ it 'adds the field options' do
1075
981
  expect(selection.options).to eq({ skip: 10 })
1076
982
  end
1077
983
 
1078
- it_behaves_like "a cloning option"
984
+ it_behaves_like 'a cloning option'
1079
985
  end
1080
986
 
1081
- context "when provided a float" do
1082
-
987
+ context 'when provided a float' do
1083
988
  let(:selection) do
1084
989
  query.send(method, 10.25)
1085
990
  end
1086
991
 
1087
- it "adds the field options converted to an integer" do
992
+ it 'adds the field options converted to an integer' do
1088
993
  expect(selection.options).to eq({ skip: 10 })
1089
994
  end
1090
995
 
1091
- it_behaves_like "a cloning option"
996
+ it_behaves_like 'a cloning option'
1092
997
  end
1093
998
 
1094
- context "when provided a non number" do
1095
-
999
+ context 'when provided a non number' do
1096
1000
  let(:selection) do
1097
- query.send(method, "10")
1001
+ query.send(method, '10')
1098
1002
  end
1099
1003
 
1100
- it "adds the field options converted to an integer" do
1004
+ it 'adds the field options converted to an integer' do
1101
1005
  expect(selection.options).to eq({ skip: 10 })
1102
1006
  end
1103
1007
 
1104
- it_behaves_like "a cloning option"
1008
+ it_behaves_like 'a cloning option'
1105
1009
  end
1106
1010
  end
1107
1011
  end
1108
1012
  end
1109
1013
 
1110
- describe "#slice" do
1111
-
1112
- context "when provided no options" do
1113
-
1014
+ describe '#slice' do
1015
+ context 'when provided no options' do
1114
1016
  let(:selection) do
1115
1017
  query.slice
1116
1018
  end
1117
1019
 
1118
- it "does not add any options" do
1020
+ it 'does not add any options' do
1119
1021
  expect(selection.options).to eq({})
1120
1022
  end
1121
1023
 
1122
- it "returns the query" do
1024
+ it 'returns the query' do
1123
1025
  expect(selection).to eq(query)
1124
1026
  end
1125
1027
 
1126
- it_behaves_like "a cloning option"
1028
+ it_behaves_like 'a cloning option'
1127
1029
  end
1128
1030
 
1129
- context "when provided nil" do
1130
-
1031
+ context 'when provided nil' do
1131
1032
  let(:selection) do
1132
1033
  query.slice(nil)
1133
1034
  end
1134
1035
 
1135
- it "does not add any options" do
1036
+ it 'does not add any options' do
1136
1037
  expect(selection.options).to eq({})
1137
1038
  end
1138
1039
 
1139
- it "returns the query" do
1040
+ it 'returns the query' do
1140
1041
  expect(selection).to eq(query)
1141
1042
  end
1142
1043
 
1143
- it_behaves_like "a cloning option"
1044
+ it_behaves_like 'a cloning option'
1144
1045
  end
1145
1046
 
1146
- context "when provided a single argument" do
1147
-
1047
+ context 'when provided a single argument' do
1148
1048
  let(:selection) do
1149
- query.slice(:first => 5)
1049
+ query.slice(first: 5)
1150
1050
  end
1151
1051
 
1152
- it "adds the field options" do
1052
+ it 'adds the field options' do
1153
1053
  expect(selection.options).to eq(
1154
- { fields: { "first" => { "$slice" => 5 }}}
1054
+ { fields: { 'first' => { '$slice' => 5 } } }
1155
1055
  )
1156
1056
  end
1157
1057
 
1158
- it_behaves_like "a cloning option"
1058
+ it_behaves_like 'a cloning option'
1159
1059
  end
1160
1060
 
1161
- context "when provided a multiple arguments" do
1162
-
1061
+ context 'when provided a multiple arguments' do
1163
1062
  let(:selection) do
1164
- query.slice(:first => 5, :second => [ 0, 3 ])
1063
+ query.slice(first: 5, second: [ 0, 3 ])
1165
1064
  end
1166
1065
 
1167
- it "adds the field options" do
1066
+ it 'adds the field options' do
1168
1067
  expect(selection.options).to eq({ fields:
1169
- { "first" => { "$slice" => 5 }, "second" => { "$slice" => [ 0, 3 ] }}
1170
- })
1068
+ { 'first' => { '$slice' => 5 }, 'second' => { '$slice' => [ 0, 3 ] } } })
1171
1069
  end
1172
1070
 
1173
- it_behaves_like "a cloning option"
1071
+ it_behaves_like 'a cloning option'
1174
1072
  end
1175
1073
 
1176
- context "when existing field arguments exist" do
1177
-
1074
+ context 'when existing field arguments exist' do
1178
1075
  let(:limited) do
1179
1076
  query.only(:name)
1180
1077
  end
1181
1078
 
1182
1079
  let(:selection) do
1183
- limited.slice(:first => 5, :second => [ 0, 3 ])
1080
+ limited.slice(first: 5, second: [ 0, 3 ])
1184
1081
  end
1185
1082
 
1186
- it "adds the field options" do
1083
+ it 'adds the field options' do
1187
1084
  expect(selection.options).to eq({
1188
- fields: {
1189
- "name" => 1,
1190
- "first" => { "$slice" => 5 },
1191
- "second" => { "$slice" => [ 0, 3 ] }
1192
- }
1193
- })
1085
+ fields: {
1086
+ 'name' => 1,
1087
+ 'first' => { '$slice' => 5 },
1088
+ 'second' => { '$slice' => [ 0, 3 ] }
1089
+ }
1090
+ })
1194
1091
  end
1195
1092
 
1196
- it_behaves_like "a cloning option"
1093
+ it_behaves_like 'a cloning option'
1197
1094
  end
1198
1095
  end
1199
1096
 
1200
- describe "#snapshot" do
1201
-
1097
+ describe '#snapshot' do
1202
1098
  let(:selection) do
1203
1099
  query.snapshot
1204
1100
  end
1205
1101
 
1206
- it "adds the snapshot option" do
1102
+ it 'adds the snapshot option' do
1207
1103
  expect(selection.options).to eq({ snapshot: true })
1208
1104
  end
1209
1105
 
1210
- it_behaves_like "a cloning option"
1106
+ it_behaves_like 'a cloning option'
1211
1107
  end
1212
1108
 
1213
- describe "#comment" do
1214
-
1109
+ describe '#comment' do
1215
1110
  let(:selection) do
1216
1111
  query.comment('slow query')
1217
1112
  end
1218
1113
 
1219
- it "adds the comment option" do
1114
+ it 'adds the comment option' do
1220
1115
  expect(selection.options).to eq({ comment: 'slow query' })
1221
1116
  end
1222
1117
 
1223
- it_behaves_like "a cloning option"
1118
+ it_behaves_like 'a cloning option'
1224
1119
  end
1225
1120
 
1226
- describe "#cursor_type" do
1227
-
1121
+ describe '#cursor_type' do
1228
1122
  let(:selection) do
1229
1123
  query.cursor_type(:tailable)
1230
1124
  end
1231
1125
 
1232
- it "adds the cursor type option" do
1126
+ it 'adds the cursor type option' do
1233
1127
  expect(selection.options).to eq({ cursor_type: :tailable })
1234
1128
  end
1235
1129
 
1236
- it_behaves_like "a cloning option"
1130
+ it_behaves_like 'a cloning option'
1237
1131
  end
1238
1132
 
1239
- describe "#collation" do
1240
-
1133
+ describe '#collation' do
1241
1134
  let(:selection) do
1242
1135
  query.collation(locale: 'fr', strength: 2)
1243
1136
  end
1244
1137
 
1245
- it "adds the collation option" do
1246
- expect(selection.options).to eq(collation: {'locale' => 'fr', 'strength' => 2})
1138
+ it 'adds the collation option' do
1139
+ expect(selection.options).to eq(collation: { 'locale' => 'fr', 'strength' => 2 })
1247
1140
  end
1248
1141
 
1249
- it_behaves_like "a cloning option"
1142
+ it_behaves_like 'a cloning option'
1250
1143
  end
1251
1144
 
1252
- describe "#without" do
1253
-
1254
- context "when provided no options" do
1255
-
1145
+ describe '#without' do
1146
+ context 'when provided no options' do
1256
1147
  let(:selection) do
1257
1148
  query.without
1258
1149
  end
1259
1150
 
1260
- it "does not add any options" do
1151
+ it 'does not add any options' do
1261
1152
  expect(selection.options).to eq({})
1262
1153
  end
1263
1154
 
1264
- it "returns the query" do
1155
+ it 'returns the query' do
1265
1156
  expect(selection).to eq(query)
1266
1157
  end
1267
1158
 
1268
- it_behaves_like "a cloning option"
1159
+ it_behaves_like 'a cloning option'
1269
1160
  end
1270
1161
 
1271
- context "when provided nil" do
1272
-
1162
+ context 'when provided nil' do
1273
1163
  let(:selection) do
1274
1164
  query.without(nil)
1275
1165
  end
1276
1166
 
1277
- it "does not add any options" do
1167
+ it 'does not add any options' do
1278
1168
  expect(selection.options).to eq({})
1279
1169
  end
1280
1170
 
1281
- it "returns the query" do
1171
+ it 'returns the query' do
1282
1172
  expect(selection).to eq(query)
1283
1173
  end
1284
1174
 
1285
- it_behaves_like "a cloning option"
1175
+ it_behaves_like 'a cloning option'
1286
1176
  end
1287
1177
 
1288
- context "when provided fields" do
1289
-
1290
- context "as several arguments" do
1291
-
1178
+ context 'when provided fields' do
1179
+ context 'as several arguments' do
1292
1180
  let(:selection) do
1293
1181
  query.without(:first, :second)
1294
1182
  end
1295
1183
 
1296
- it "adds the field options" do
1184
+ it 'adds the field options' do
1297
1185
  expect(selection.options).to eq(
1298
- { fields: { "first" => 0, "second" => 0 }}
1186
+ { fields: { 'first' => 0, 'second' => 0 } }
1299
1187
  )
1300
1188
  end
1301
1189
 
1302
- it_behaves_like "a cloning option"
1190
+ it_behaves_like 'a cloning option'
1303
1191
  end
1304
1192
 
1305
- context "as one argument - array" do
1306
-
1193
+ context 'as one argument - array' do
1307
1194
  let(:selection) do
1308
- query.without([:first, :second])
1195
+ query.without(%i[first second])
1309
1196
  end
1310
1197
 
1311
- it "adds the field options" do
1198
+ it 'adds the field options' do
1312
1199
  expect(selection.options).to eq(
1313
- { fields: { "first" => 0, "second" => 0 }}
1200
+ { fields: { 'first' => 0, 'second' => 0 } }
1314
1201
  )
1315
1202
  end
1316
1203
 
1317
- it_behaves_like "a cloning option"
1204
+ it_behaves_like 'a cloning option'
1318
1205
  end
1319
1206
  end
1320
1207
 
1321
- context "when #only was called before" do
1208
+ context 'when #only was called before' do
1322
1209
  let(:selection) do
1323
1210
  query.only(:first).without(:id)
1324
1211
  end
1325
1212
 
1326
- it "adds both fields to options" do
1213
+ it 'adds both fields to options' do
1327
1214
  expect(selection.options).to eq(
1328
- { fields: { "first" => 1, "id" => 0 } }
1215
+ { fields: { 'first' => 1, 'id' => 0 } }
1329
1216
  )
1330
1217
  end
1331
1218
  end