mongoid 7.0.13 → 9.1.1

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