mongoid 3.1.5 → 8.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (1501) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +636 -33
  4. data/LICENSE +2 -1
  5. data/README.md +32 -24
  6. data/Rakefile +75 -5
  7. data/lib/config/locales/en.yml +301 -132
  8. data/lib/mongoid/association/accessors.rb +431 -0
  9. data/lib/mongoid/association/bindable.rb +227 -0
  10. data/lib/mongoid/association/builders.rb +86 -0
  11. data/lib/mongoid/association/constrainable.rb +42 -0
  12. data/lib/mongoid/association/depending.rb +128 -0
  13. data/lib/mongoid/association/eager_loadable.rb +57 -0
  14. data/lib/mongoid/association/embedded/batchable.rb +398 -0
  15. data/lib/mongoid/association/embedded/cyclic.rb +102 -0
  16. data/lib/mongoid/association/embedded/embedded_in/binding.rb +74 -0
  17. data/lib/mongoid/association/embedded/embedded_in/buildable.rb +38 -0
  18. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +111 -0
  19. data/lib/mongoid/association/embedded/embedded_in.rb +135 -0
  20. data/lib/mongoid/association/embedded/embeds_many/binding.rb +42 -0
  21. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +45 -0
  22. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +571 -0
  23. data/lib/mongoid/association/embedded/embeds_many.rb +183 -0
  24. data/lib/mongoid/association/embedded/embeds_one/binding.rb +43 -0
  25. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +53 -0
  26. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +164 -0
  27. data/lib/mongoid/association/embedded/embeds_one.rb +150 -0
  28. data/lib/mongoid/association/embedded.rb +6 -0
  29. data/lib/mongoid/association/macros.rb +228 -0
  30. data/lib/mongoid/association/many.rb +202 -0
  31. data/lib/mongoid/association/marshalable.rb +31 -0
  32. data/lib/mongoid/association/nested/many.rb +192 -0
  33. data/lib/mongoid/association/nested/nested_buildable.rb +66 -0
  34. data/lib/mongoid/association/nested/one.rb +116 -0
  35. data/lib/mongoid/association/nested.rb +15 -0
  36. data/lib/mongoid/association/one.rb +53 -0
  37. data/lib/mongoid/association/options.rb +122 -0
  38. data/lib/mongoid/association/proxy.rb +200 -0
  39. data/lib/mongoid/association/referenced/auto_save.rb +74 -0
  40. data/lib/mongoid/association/referenced/belongs_to/binding.rb +83 -0
  41. data/lib/mongoid/association/referenced/belongs_to/buildable.rb +48 -0
  42. data/lib/mongoid/association/referenced/belongs_to/eager.rb +73 -0
  43. data/lib/mongoid/association/referenced/belongs_to/proxy.rb +124 -0
  44. data/lib/mongoid/association/referenced/belongs_to.rb +226 -0
  45. data/lib/mongoid/association/referenced/counter_cache.rb +152 -0
  46. data/lib/mongoid/association/referenced/eager.rb +163 -0
  47. data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +72 -0
  48. data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +40 -0
  49. data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +53 -0
  50. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +345 -0
  51. data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +273 -0
  52. data/lib/mongoid/association/referenced/has_many/binding.rb +36 -0
  53. data/lib/mongoid/association/referenced/has_many/buildable.rb +38 -0
  54. data/lib/mongoid/association/referenced/has_many/eager.rb +44 -0
  55. data/lib/mongoid/association/referenced/has_many/enumerable.rb +494 -0
  56. data/lib/mongoid/association/referenced/has_many/proxy.rb +551 -0
  57. data/lib/mongoid/association/referenced/has_many.rb +251 -0
  58. data/lib/mongoid/association/referenced/has_one/binding.rb +42 -0
  59. data/lib/mongoid/association/referenced/has_one/buildable.rb +74 -0
  60. data/lib/mongoid/association/referenced/has_one/eager.rb +36 -0
  61. data/lib/mongoid/association/referenced/has_one/nested_builder.rb +113 -0
  62. data/lib/mongoid/association/referenced/has_one/proxy.rb +108 -0
  63. data/lib/mongoid/association/referenced/has_one.rb +184 -0
  64. data/lib/mongoid/association/referenced/syncable.rb +155 -0
  65. data/lib/mongoid/association/referenced.rb +9 -0
  66. data/lib/mongoid/association/reflections.rb +69 -0
  67. data/lib/mongoid/association/relatable.rb +489 -0
  68. data/lib/mongoid/association.rb +135 -0
  69. data/lib/mongoid/atomic/modifiers.rb +41 -61
  70. data/lib/mongoid/atomic/paths/embedded/many.rb +24 -8
  71. data/lib/mongoid/atomic/paths/embedded/one.rb +5 -8
  72. data/lib/mongoid/atomic/paths/embedded.rb +3 -34
  73. data/lib/mongoid/atomic/paths/root.rb +4 -20
  74. data/lib/mongoid/atomic/paths.rb +2 -1
  75. data/lib/mongoid/atomic.rb +52 -69
  76. data/lib/mongoid/attributes/dynamic.rb +141 -0
  77. data/lib/mongoid/attributes/nested.rb +93 -0
  78. data/lib/mongoid/attributes/processing.rb +35 -97
  79. data/lib/mongoid/attributes/projector.rb +119 -0
  80. data/lib/mongoid/attributes/readonly.rb +27 -10
  81. data/lib/mongoid/attributes.rb +159 -181
  82. data/lib/mongoid/cacheable.rb +33 -0
  83. data/lib/mongoid/changeable.rb +420 -0
  84. data/lib/mongoid/clients/factory.rb +105 -0
  85. data/lib/mongoid/clients/options.rb +111 -0
  86. data/lib/mongoid/clients/sessions.rb +113 -0
  87. data/lib/mongoid/clients/storage_options.rb +79 -0
  88. data/lib/mongoid/clients/validators/storage.rb +58 -0
  89. data/lib/mongoid/clients/validators.rb +3 -0
  90. data/lib/mongoid/clients.rb +79 -0
  91. data/lib/mongoid/composable.rb +128 -0
  92. data/lib/mongoid/config/environment.rb +51 -13
  93. data/lib/mongoid/config/options.rb +30 -18
  94. data/lib/mongoid/config/validators/client.rb +128 -0
  95. data/lib/mongoid/config/validators/option.rb +3 -4
  96. data/lib/mongoid/config/validators.rb +3 -2
  97. data/lib/mongoid/config.rb +170 -89
  98. data/lib/mongoid/contextual/aggregable/memory.rb +40 -27
  99. data/lib/mongoid/contextual/aggregable/mongo.rb +33 -36
  100. data/lib/mongoid/contextual/aggregable/none.rb +65 -0
  101. data/lib/mongoid/contextual/aggregable.rb +17 -0
  102. data/lib/mongoid/contextual/atomic.rb +80 -79
  103. data/lib/mongoid/contextual/command.rb +8 -11
  104. data/lib/mongoid/contextual/geo_near.rb +42 -44
  105. data/lib/mongoid/contextual/map_reduce.rb +33 -127
  106. data/lib/mongoid/contextual/memory.rb +226 -88
  107. data/lib/mongoid/contextual/mongo.rb +466 -293
  108. data/lib/mongoid/contextual/none.rb +193 -0
  109. data/lib/mongoid/contextual/queryable.rb +3 -4
  110. data/lib/mongoid/contextual.rb +11 -11
  111. data/lib/mongoid/copyable.rb +68 -20
  112. data/lib/mongoid/criteria/findable.rb +143 -0
  113. data/lib/mongoid/criteria/includable.rb +92 -0
  114. data/lib/mongoid/criteria/inspectable.rb +24 -0
  115. data/lib/mongoid/criteria/marshalable.rb +55 -0
  116. data/lib/mongoid/criteria/modifiable.rb +235 -0
  117. data/lib/mongoid/criteria/options.rb +24 -0
  118. data/lib/mongoid/criteria/permission.rb +71 -0
  119. data/lib/mongoid/criteria/queryable/aggregable.rb +109 -0
  120. data/lib/mongoid/criteria/queryable/expandable.rb +68 -0
  121. data/lib/mongoid/criteria/queryable/extensions/array.rb +151 -0
  122. data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +57 -0
  123. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +33 -0
  124. data/lib/mongoid/criteria/queryable/extensions/date.rb +63 -0
  125. data/lib/mongoid/criteria/queryable/extensions/date_time.rb +52 -0
  126. data/lib/mongoid/criteria/queryable/extensions/hash.rb +163 -0
  127. data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +75 -0
  128. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +81 -0
  129. data/lib/mongoid/criteria/queryable/extensions/object.rb +182 -0
  130. data/lib/mongoid/criteria/queryable/extensions/range.rb +102 -0
  131. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +72 -0
  132. data/lib/mongoid/criteria/queryable/extensions/set.rb +33 -0
  133. data/lib/mongoid/criteria/queryable/extensions/string.rb +122 -0
  134. data/lib/mongoid/criteria/queryable/extensions/symbol.rb +74 -0
  135. data/lib/mongoid/criteria/queryable/extensions/time.rb +60 -0
  136. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +66 -0
  137. data/lib/mongoid/criteria/queryable/extensions.rb +25 -0
  138. data/lib/mongoid/criteria/queryable/key.rb +177 -0
  139. data/lib/mongoid/criteria/queryable/macroable.rb +26 -0
  140. data/lib/mongoid/criteria/queryable/mergeable.rb +434 -0
  141. data/lib/mongoid/criteria/queryable/optional.rb +380 -0
  142. data/lib/mongoid/criteria/queryable/options.rb +136 -0
  143. data/lib/mongoid/criteria/queryable/pipeline.rb +106 -0
  144. data/lib/mongoid/criteria/queryable/selectable.rb +937 -0
  145. data/lib/mongoid/criteria/queryable/selector.rb +287 -0
  146. data/lib/mongoid/criteria/queryable/smash.rb +128 -0
  147. data/lib/mongoid/criteria/queryable/storable.rb +237 -0
  148. data/lib/mongoid/criteria/queryable.rb +90 -0
  149. data/lib/mongoid/criteria/scopable.rb +166 -0
  150. data/lib/mongoid/criteria.rb +177 -189
  151. data/lib/mongoid/deprecable.rb +36 -0
  152. data/lib/mongoid/deprecation.rb +25 -0
  153. data/lib/mongoid/document.rb +193 -139
  154. data/lib/mongoid/equality.rb +35 -18
  155. data/lib/mongoid/errors/ambiguous_relationship.rb +5 -6
  156. data/lib/mongoid/errors/callback.rb +2 -3
  157. data/lib/mongoid/errors/criteria_argument_required.rb +18 -0
  158. data/lib/mongoid/errors/delete_restriction.rb +10 -13
  159. data/lib/mongoid/errors/document_not_destroyed.rb +22 -0
  160. data/lib/mongoid/errors/document_not_found.rb +36 -21
  161. data/lib/mongoid/errors/empty_config_file.rb +25 -0
  162. data/lib/mongoid/errors/in_memory_collation_not_supported.rb +19 -0
  163. data/lib/mongoid/errors/invalid_collection.rb +2 -1
  164. data/lib/mongoid/errors/invalid_config_file.rb +25 -0
  165. data/lib/mongoid/errors/invalid_config_option.rb +3 -4
  166. data/lib/mongoid/errors/invalid_dependent_strategy.rb +31 -0
  167. data/lib/mongoid/errors/invalid_discriminator_key_target.rb +24 -0
  168. data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +23 -0
  169. data/lib/mongoid/errors/invalid_elem_match_operator.rb +32 -0
  170. data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +25 -0
  171. data/lib/mongoid/errors/invalid_expression_operator.rb +27 -0
  172. data/lib/mongoid/errors/invalid_field.rb +10 -9
  173. data/lib/mongoid/errors/invalid_field_operator.rb +32 -0
  174. data/lib/mongoid/errors/invalid_field_option.rb +2 -3
  175. data/lib/mongoid/errors/invalid_field_type.rb +26 -0
  176. data/lib/mongoid/errors/invalid_find.rb +2 -3
  177. data/lib/mongoid/errors/invalid_includes.rb +2 -3
  178. data/lib/mongoid/errors/invalid_index.rb +2 -3
  179. data/lib/mongoid/errors/invalid_options.rb +4 -5
  180. data/lib/mongoid/errors/invalid_path.rb +2 -3
  181. data/lib/mongoid/errors/invalid_persistence_option.rb +26 -0
  182. data/lib/mongoid/errors/invalid_query.rb +40 -0
  183. data/lib/mongoid/errors/invalid_relation.rb +61 -0
  184. data/lib/mongoid/errors/invalid_relation_option.rb +28 -0
  185. data/lib/mongoid/errors/invalid_scope.rb +2 -3
  186. data/lib/mongoid/errors/invalid_session_use.rb +21 -0
  187. data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +6 -5
  188. data/lib/mongoid/errors/invalid_storage_options.rb +4 -5
  189. data/lib/mongoid/errors/invalid_storage_parent.rb +25 -0
  190. data/lib/mongoid/errors/invalid_time.rb +2 -3
  191. data/lib/mongoid/errors/inverse_not_found.rb +4 -5
  192. data/lib/mongoid/errors/mixed_client_configuration.rb +27 -0
  193. data/lib/mongoid/errors/mixed_relations.rb +2 -3
  194. data/lib/mongoid/errors/mongoid_error.rb +22 -23
  195. data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +3 -4
  196. data/lib/mongoid/errors/no_client_config.rb +21 -0
  197. data/lib/mongoid/errors/no_client_database.rb +26 -0
  198. data/lib/mongoid/errors/no_client_hosts.rb +26 -0
  199. data/lib/mongoid/errors/no_clients_config.rb +19 -0
  200. data/lib/mongoid/errors/no_default_client.rb +22 -0
  201. data/lib/mongoid/errors/no_environment.rb +2 -3
  202. data/lib/mongoid/errors/no_map_reduce_output.rb +2 -3
  203. data/lib/mongoid/errors/no_metadata.rb +2 -3
  204. data/lib/mongoid/errors/no_parent.rb +2 -3
  205. data/lib/mongoid/errors/readonly_attribute.rb +3 -4
  206. data/lib/mongoid/errors/readonly_document.rb +21 -0
  207. data/lib/mongoid/errors/scope_overwrite.rb +2 -1
  208. data/lib/mongoid/errors/too_many_nested_attribute_records.rb +3 -1
  209. data/lib/mongoid/errors/unknown_attribute.rb +3 -4
  210. data/lib/mongoid/errors/unknown_model.rb +24 -0
  211. data/lib/mongoid/errors/unsaved_document.rb +3 -2
  212. data/lib/mongoid/errors/unsupported_javascript.rb +2 -3
  213. data/lib/mongoid/errors/validations.rb +2 -1
  214. data/lib/mongoid/errors.rb +30 -9
  215. data/lib/mongoid/evolvable.rb +4 -5
  216. data/lib/mongoid/extensions/array.rb +45 -52
  217. data/lib/mongoid/extensions/big_decimal.rb +41 -22
  218. data/lib/mongoid/extensions/binary.rb +42 -0
  219. data/lib/mongoid/extensions/boolean.rb +19 -17
  220. data/lib/mongoid/extensions/date.rb +33 -23
  221. data/lib/mongoid/extensions/date_time.rb +5 -13
  222. data/lib/mongoid/extensions/decimal128.rb +36 -0
  223. data/lib/mongoid/extensions/false_class.rb +5 -8
  224. data/lib/mongoid/extensions/float.rb +11 -16
  225. data/lib/mongoid/extensions/hash.rb +88 -49
  226. data/lib/mongoid/extensions/integer.rb +10 -18
  227. data/lib/mongoid/extensions/module.rb +3 -4
  228. data/lib/mongoid/extensions/nil_class.rb +2 -5
  229. data/lib/mongoid/extensions/object.rb +38 -62
  230. data/lib/mongoid/extensions/object_id.rb +7 -12
  231. data/lib/mongoid/extensions/range.rb +46 -17
  232. data/lib/mongoid/extensions/regexp.rb +15 -8
  233. data/lib/mongoid/extensions/set.rb +17 -15
  234. data/lib/mongoid/extensions/string.rb +40 -80
  235. data/lib/mongoid/extensions/symbol.rb +7 -23
  236. data/lib/mongoid/extensions/time.rb +42 -25
  237. data/lib/mongoid/extensions/time_with_zone.rb +27 -10
  238. data/lib/mongoid/extensions/true_class.rb +5 -8
  239. data/lib/mongoid/extensions.rb +31 -13
  240. data/lib/mongoid/factory.rb +99 -11
  241. data/lib/mongoid/fields/foreign_key.rb +26 -34
  242. data/lib/mongoid/fields/localized.rb +24 -13
  243. data/lib/mongoid/fields/standard.rb +19 -73
  244. data/lib/mongoid/fields/validators/macro.rb +56 -15
  245. data/lib/mongoid/fields/validators.rb +2 -1
  246. data/lib/mongoid/fields.rb +342 -87
  247. data/lib/mongoid/findable.rb +219 -0
  248. data/lib/mongoid/indexable/specification.rb +103 -0
  249. data/lib/mongoid/indexable/validators/options.rb +110 -0
  250. data/lib/mongoid/indexable.rb +148 -0
  251. data/lib/mongoid/inspectable.rb +52 -0
  252. data/lib/mongoid/interceptable.rb +312 -0
  253. data/lib/mongoid/loggable.rb +15 -18
  254. data/lib/mongoid/matchable.rb +23 -0
  255. data/lib/mongoid/matcher/all.rb +22 -0
  256. data/lib/mongoid/matcher/and.rb +21 -0
  257. data/lib/mongoid/matcher/bits.rb +41 -0
  258. data/lib/mongoid/matcher/bits_all_clear.rb +20 -0
  259. data/lib/mongoid/matcher/bits_all_set.rb +20 -0
  260. data/lib/mongoid/matcher/bits_any_clear.rb +20 -0
  261. data/lib/mongoid/matcher/bits_any_set.rb +20 -0
  262. data/lib/mongoid/matcher/elem_match.rb +36 -0
  263. data/lib/mongoid/matcher/elem_match_expression.rb +20 -0
  264. data/lib/mongoid/matcher/eq.rb +11 -0
  265. data/lib/mongoid/matcher/eq_impl.rb +67 -0
  266. data/lib/mongoid/matcher/eq_impl_with_regexp.rb +26 -0
  267. data/lib/mongoid/matcher/exists.rb +15 -0
  268. data/lib/mongoid/matcher/expression.rb +35 -0
  269. data/lib/mongoid/matcher/expression_operator.rb +19 -0
  270. data/lib/mongoid/matcher/field_expression.rb +62 -0
  271. data/lib/mongoid/matcher/field_operator.rb +54 -0
  272. data/lib/mongoid/matcher/gt.rb +17 -0
  273. data/lib/mongoid/matcher/gte.rb +17 -0
  274. data/lib/mongoid/matcher/in.rb +25 -0
  275. data/lib/mongoid/matcher/lt.rb +17 -0
  276. data/lib/mongoid/matcher/lte.rb +17 -0
  277. data/lib/mongoid/matcher/mod.rb +17 -0
  278. data/lib/mongoid/matcher/ne.rb +16 -0
  279. data/lib/mongoid/matcher/nin.rb +11 -0
  280. data/lib/mongoid/matcher/nor.rb +25 -0
  281. data/lib/mongoid/matcher/not.rb +29 -0
  282. data/lib/mongoid/matcher/or.rb +21 -0
  283. data/lib/mongoid/matcher/regex.rb +41 -0
  284. data/lib/mongoid/matcher/size.rb +26 -0
  285. data/lib/mongoid/matcher/type.rb +99 -0
  286. data/lib/mongoid/matcher.rb +115 -0
  287. data/lib/mongoid/persistable/creatable.rb +181 -0
  288. data/lib/mongoid/persistable/deletable.rb +132 -0
  289. data/lib/mongoid/persistable/destroyable.rb +57 -0
  290. data/lib/mongoid/persistable/incrementable.rb +35 -0
  291. data/lib/mongoid/persistable/logical.rb +36 -0
  292. data/lib/mongoid/persistable/poppable.rb +36 -0
  293. data/lib/mongoid/persistable/pullable.rb +50 -0
  294. data/lib/mongoid/persistable/pushable.rb +66 -0
  295. data/lib/mongoid/persistable/renamable.rb +37 -0
  296. data/lib/mongoid/persistable/savable.rb +47 -0
  297. data/lib/mongoid/persistable/settable.rb +93 -0
  298. data/lib/mongoid/persistable/unsettable.rb +36 -0
  299. data/lib/mongoid/persistable/updatable.rb +165 -0
  300. data/lib/mongoid/persistable/upsertable.rb +51 -0
  301. data/lib/mongoid/persistable.rb +305 -0
  302. data/lib/mongoid/persistence_context.rb +239 -0
  303. data/lib/mongoid/positional.rb +72 -0
  304. data/lib/mongoid/query_cache.rb +64 -0
  305. data/lib/mongoid/railtie.rb +35 -78
  306. data/lib/mongoid/railties/controller_runtime.rb +88 -0
  307. data/lib/mongoid/railties/database.rake +18 -25
  308. data/lib/mongoid/reloadable.rb +94 -0
  309. data/lib/mongoid/scopable.rb +324 -0
  310. data/lib/mongoid/selectable.rb +49 -0
  311. data/lib/mongoid/serializable.rb +170 -0
  312. data/lib/mongoid/shardable.rb +130 -0
  313. data/lib/mongoid/stateful.rb +134 -0
  314. data/lib/mongoid/stringified_symbol.rb +52 -0
  315. data/lib/mongoid/tasks/database.rake +38 -0
  316. data/lib/mongoid/tasks/database.rb +194 -0
  317. data/lib/mongoid/threaded/lifecycle.rb +28 -70
  318. data/lib/mongoid/threaded.rb +142 -219
  319. data/lib/mongoid/timestamps/created/short.rb +2 -1
  320. data/lib/mongoid/timestamps/created.rb +9 -5
  321. data/lib/mongoid/timestamps/short.rb +2 -1
  322. data/lib/mongoid/timestamps/timeless.rb +52 -16
  323. data/lib/mongoid/timestamps/updated/short.rb +4 -3
  324. data/lib/mongoid/timestamps/updated.rb +14 -9
  325. data/lib/mongoid/timestamps.rb +4 -3
  326. data/lib/mongoid/touchable.rb +131 -0
  327. data/lib/mongoid/traversable.rb +337 -0
  328. data/lib/mongoid/validatable/associated.rb +47 -0
  329. data/lib/mongoid/validatable/format.rb +21 -0
  330. data/lib/mongoid/validatable/length.rb +21 -0
  331. data/lib/mongoid/validatable/localizable.rb +29 -0
  332. data/lib/mongoid/validatable/macros.rb +89 -0
  333. data/lib/mongoid/validatable/presence.rb +81 -0
  334. data/lib/mongoid/validatable/queryable.rb +29 -0
  335. data/lib/mongoid/validatable/uniqueness.rb +304 -0
  336. data/lib/mongoid/validatable.rb +160 -0
  337. data/lib/mongoid/version.rb +3 -2
  338. data/lib/mongoid/warnings.rb +28 -0
  339. data/lib/mongoid.rb +68 -109
  340. data/lib/rails/generators/mongoid/config/config_generator.rb +10 -2
  341. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +150 -45
  342. data/lib/rails/generators/mongoid/model/model_generator.rb +3 -3
  343. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -4
  344. data/lib/rails/generators/mongoid_generator.rb +5 -41
  345. data/lib/rails/mongoid.rb +6 -129
  346. data/spec/README.md +33 -0
  347. data/spec/config/mongoid.yml +56 -25
  348. data/spec/config/mongoid_with_schema_map_uuid.yml +27 -0
  349. data/spec/integration/app_spec.rb +345 -0
  350. data/spec/integration/associations/belongs_to_spec.rb +33 -0
  351. data/spec/integration/associations/embedded_dirty_spec.rb +57 -0
  352. data/spec/integration/associations/embedded_spec.rb +283 -0
  353. data/spec/integration/associations/embeds_many_spec.rb +219 -0
  354. data/spec/integration/associations/embeds_one_spec.rb +41 -0
  355. data/spec/integration/associations/foreign_key_spec.rb +107 -0
  356. data/spec/integration/associations/foreign_key_spec_models.rb +64 -0
  357. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +21 -0
  358. data/spec/integration/associations/has_many_spec.rb +128 -0
  359. data/spec/integration/associations/has_one_spec.rb +272 -0
  360. data/spec/integration/associations/nested_attributes_assignment_spec.rb +115 -0
  361. data/spec/integration/associations/reverse_population_spec.rb +34 -0
  362. data/spec/integration/associations/reverse_population_spec_models.rb +36 -0
  363. data/spec/integration/associations/scope_option_spec.rb +101 -0
  364. data/spec/integration/atomic/modifiers_spec.rb +116 -0
  365. data/spec/integration/bson_regexp_raw_spec.rb +19 -0
  366. data/spec/integration/callbacks_models.rb +155 -0
  367. data/spec/integration/callbacks_spec.rb +450 -0
  368. data/spec/integration/contextual/empty_spec.rb +141 -0
  369. data/spec/integration/criteria/alias_query_spec.rb +161 -0
  370. data/spec/integration/criteria/date_field_spec.rb +40 -0
  371. data/spec/integration/criteria/default_scope_spec.rb +72 -0
  372. data/spec/integration/criteria/logical_spec.rb +124 -0
  373. data/spec/integration/criteria/range_spec.rb +359 -0
  374. data/spec/integration/criteria/time_with_zone_spec.rb +142 -0
  375. data/spec/integration/discriminator_key_spec.rb +392 -0
  376. data/spec/integration/discriminator_value_spec.rb +206 -0
  377. data/spec/integration/document_spec.rb +51 -0
  378. data/spec/integration/dots_and_dollars_spec.rb +277 -0
  379. data/spec/integration/i18n_fallbacks_spec.rb +89 -0
  380. data/spec/integration/matcher_examples_spec.rb +765 -0
  381. data/spec/integration/matcher_operator_data/all.yml +140 -0
  382. data/spec/integration/matcher_operator_data/and.yml +93 -0
  383. data/spec/integration/matcher_operator_data/bits_all_clear.yml +159 -0
  384. data/spec/integration/matcher_operator_data/bits_all_set.yml +159 -0
  385. data/spec/integration/matcher_operator_data/bits_any_clear.yml +159 -0
  386. data/spec/integration/matcher_operator_data/bits_any_set.yml +159 -0
  387. data/spec/integration/matcher_operator_data/comment.yml +22 -0
  388. data/spec/integration/matcher_operator_data/elem_match.yml +409 -0
  389. data/spec/integration/matcher_operator_data/elem_match_expr.yml +213 -0
  390. data/spec/integration/matcher_operator_data/eq.yml +191 -0
  391. data/spec/integration/matcher_operator_data/exists.yml +213 -0
  392. data/spec/integration/matcher_operator_data/generic_op.yml +17 -0
  393. data/spec/integration/matcher_operator_data/gt.yml +132 -0
  394. data/spec/integration/matcher_operator_data/gt_types.yml +63 -0
  395. data/spec/integration/matcher_operator_data/gte.yml +132 -0
  396. data/spec/integration/matcher_operator_data/gte_types.yml +15 -0
  397. data/spec/integration/matcher_operator_data/implicit.yml +331 -0
  398. data/spec/integration/matcher_operator_data/implicit_traversal.yml +112 -0
  399. data/spec/integration/matcher_operator_data/in.yml +210 -0
  400. data/spec/integration/matcher_operator_data/invalid_op.yml +59 -0
  401. data/spec/integration/matcher_operator_data/invalid_syntax.yml +39 -0
  402. data/spec/integration/matcher_operator_data/lt.yml +132 -0
  403. data/spec/integration/matcher_operator_data/lt_types.yml +15 -0
  404. data/spec/integration/matcher_operator_data/lte.yml +132 -0
  405. data/spec/integration/matcher_operator_data/lte_types.yml +15 -0
  406. data/spec/integration/matcher_operator_data/mod.yml +55 -0
  407. data/spec/integration/matcher_operator_data/multiple.yml +29 -0
  408. data/spec/integration/matcher_operator_data/ne.yml +150 -0
  409. data/spec/integration/matcher_operator_data/ne_types.yml +15 -0
  410. data/spec/integration/matcher_operator_data/nin.yml +114 -0
  411. data/spec/integration/matcher_operator_data/nor.yml +126 -0
  412. data/spec/integration/matcher_operator_data/not.yml +196 -0
  413. data/spec/integration/matcher_operator_data/or.yml +137 -0
  414. data/spec/integration/matcher_operator_data/regex.yml +174 -0
  415. data/spec/integration/matcher_operator_data/regex_options.yml +72 -0
  416. data/spec/integration/matcher_operator_data/size.yml +174 -0
  417. data/spec/integration/matcher_operator_data/type.yml +70 -0
  418. data/spec/integration/matcher_operator_data/type_array.yml +16 -0
  419. data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
  420. data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
  421. data/spec/integration/matcher_operator_data/type_code.yml +26 -0
  422. data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
  423. data/spec/integration/matcher_operator_data/type_date.yml +39 -0
  424. data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
  425. data/spec/integration/matcher_operator_data/type_decimal.yml +41 -0
  426. data/spec/integration/matcher_operator_data/type_double.yml +15 -0
  427. data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
  428. data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
  429. data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
  430. data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
  431. data/spec/integration/matcher_operator_data/type_null.yml +23 -0
  432. data/spec/integration/matcher_operator_data/type_object.yml +23 -0
  433. data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
  434. data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
  435. data/spec/integration/matcher_operator_data/type_string.yml +15 -0
  436. data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
  437. data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
  438. data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
  439. data/spec/integration/matcher_operator_spec.rb +122 -0
  440. data/spec/integration/matcher_spec.rb +283 -0
  441. data/spec/integration/persistence/range_field_spec.rb +350 -0
  442. data/spec/integration/server_query_spec.rb +141 -0
  443. data/spec/integration/shardable_spec.rb +148 -0
  444. data/spec/integration/stringified_symbol_field_spec.rb +203 -0
  445. data/spec/lite_spec_helper.rb +83 -0
  446. data/spec/mongoid/association/accessors_spec.rb +1067 -0
  447. data/spec/mongoid/association/auto_save_spec.rb +403 -0
  448. data/spec/mongoid/association/builders_spec.rb +255 -0
  449. data/spec/mongoid/association/constrainable_spec.rb +117 -0
  450. data/spec/mongoid/association/counter_cache_spec.rb +452 -0
  451. data/spec/mongoid/association/depending_spec.rb +959 -0
  452. data/spec/mongoid/association/eager_spec.rb +282 -0
  453. data/spec/mongoid/association/embedded/cyclic_spec.rb +180 -0
  454. data/spec/mongoid/association/embedded/dirty_spec.rb +67 -0
  455. data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +174 -0
  456. data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +90 -0
  457. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +619 -0
  458. data/spec/mongoid/association/embedded/embedded_in_spec.rb +903 -0
  459. data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +56 -0
  460. data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +218 -0
  461. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +4863 -0
  462. data/spec/mongoid/association/embedded/embeds_many_models.rb +226 -0
  463. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +63 -0
  464. data/spec/mongoid/association/embedded/embeds_many_spec.rb +932 -0
  465. data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +79 -0
  466. data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +106 -0
  467. data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +1025 -0
  468. data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +8 -0
  469. data/spec/mongoid/association/embedded/embeds_one_models.rb +73 -0
  470. data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +28 -0
  471. data/spec/mongoid/association/embedded/embeds_one_spec.rb +984 -0
  472. data/spec/mongoid/association/macros_spec.rb +1116 -0
  473. data/spec/mongoid/association/nested/many_spec.rb +232 -0
  474. data/spec/mongoid/association/nested/one_spec.rb +253 -0
  475. data/spec/mongoid/association/options_spec.rb +1323 -0
  476. data/spec/mongoid/association/polymorphic_spec.rb +162 -0
  477. data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +244 -0
  478. data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +292 -0
  479. data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +412 -0
  480. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +1388 -0
  481. data/spec/mongoid/association/referenced/belongs_to_models.rb +11 -0
  482. data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +57 -0
  483. data/spec/mongoid/association/referenced/belongs_to_spec.rb +2046 -0
  484. data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +180 -0
  485. data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +148 -0
  486. data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +196 -0
  487. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +76 -0
  488. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +3836 -0
  489. data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +92 -0
  490. data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +39 -0
  491. data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +1104 -0
  492. data/spec/mongoid/association/referenced/has_many/binding_spec.rb +155 -0
  493. data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +251 -0
  494. data/spec/mongoid/association/referenced/has_many/eager_spec.rb +290 -0
  495. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +2232 -0
  496. data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +23 -0
  497. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +4161 -0
  498. data/spec/mongoid/association/referenced/has_many_models.rb +97 -0
  499. data/spec/mongoid/association/referenced/has_many_query_spec.rb +37 -0
  500. data/spec/mongoid/association/referenced/has_many_spec.rb +1273 -0
  501. data/spec/mongoid/association/referenced/has_one/binding_spec.rb +133 -0
  502. data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +159 -0
  503. data/spec/mongoid/association/referenced/has_one/eager_spec.rb +193 -0
  504. data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +1248 -0
  505. data/spec/mongoid/association/referenced/has_one_models.rb +113 -0
  506. data/spec/mongoid/association/referenced/has_one_query_spec.rb +37 -0
  507. data/spec/mongoid/association/referenced/has_one_spec.rb +1383 -0
  508. data/spec/mongoid/association/reflections_spec.rb +92 -0
  509. data/spec/mongoid/association/syncable_spec.rb +513 -0
  510. data/spec/mongoid/association_spec.rb +191 -0
  511. data/spec/mongoid/atomic/modifiers_spec.rb +88 -39
  512. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +10 -49
  513. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +9 -49
  514. data/spec/mongoid/atomic/paths/root_spec.rb +5 -61
  515. data/spec/mongoid/atomic/paths_spec.rb +115 -35
  516. data/spec/mongoid/atomic_spec.rb +89 -42
  517. data/spec/mongoid/attributes/dynamic_spec.rb +152 -0
  518. data/spec/mongoid/attributes/nested_spec.rb +5000 -0
  519. data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
  520. data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
  521. data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
  522. data/spec/mongoid/attributes/projector_spec.rb +40 -0
  523. data/spec/mongoid/attributes/readonly_spec.rb +166 -64
  524. data/spec/mongoid/attributes_spec.rb +1418 -409
  525. data/spec/mongoid/cacheable_spec.rb +114 -0
  526. data/spec/mongoid/changeable_spec.rb +1914 -0
  527. data/spec/mongoid/clients/factory_spec.rb +426 -0
  528. data/spec/mongoid/clients/options_spec.rb +521 -0
  529. data/spec/mongoid/clients/sessions_spec.rb +297 -0
  530. data/spec/mongoid/clients/transactions_spec.rb +415 -0
  531. data/spec/mongoid/clients_spec.rb +1084 -0
  532. data/spec/mongoid/composable_spec.rb +33 -0
  533. data/spec/mongoid/config/environment_spec.rb +138 -17
  534. data/spec/mongoid/config/options_spec.rb +26 -7
  535. data/spec/mongoid/config_spec.rb +607 -93
  536. data/spec/mongoid/contextual/aggregable/memory_spec.rb +433 -153
  537. data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
  538. data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +62 -0
  539. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +221 -56
  540. data/spec/mongoid/contextual/aggregable/none_spec.rb +60 -0
  541. data/spec/mongoid/contextual/atomic_spec.rb +577 -162
  542. data/spec/mongoid/contextual/geo_near_spec.rb +104 -38
  543. data/spec/mongoid/contextual/map_reduce_spec.rb +137 -142
  544. data/spec/mongoid/contextual/memory_spec.rb +1880 -269
  545. data/spec/mongoid/contextual/mongo_spec.rb +2523 -601
  546. data/spec/mongoid/contextual/none_spec.rb +123 -0
  547. data/spec/mongoid/copyable_spec.rb +833 -76
  548. data/spec/mongoid/copyable_spec_models.rb +47 -0
  549. data/spec/mongoid/criteria/findable_spec.rb +1132 -0
  550. data/spec/mongoid/criteria/includable_spec.rb +1492 -0
  551. data/spec/mongoid/criteria/includable_spec_models.rb +54 -0
  552. data/spec/mongoid/criteria/inspectable_spec.rb +29 -0
  553. data/spec/mongoid/criteria/marshalable_spec.rb +47 -0
  554. data/spec/mongoid/criteria/modifiable_spec.rb +1812 -0
  555. data/spec/mongoid/criteria/options_spec.rb +31 -0
  556. data/spec/mongoid/criteria/queryable/aggregable_spec.rb +372 -0
  557. data/spec/mongoid/criteria/queryable/expandable_spec.rb +61 -0
  558. data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +513 -0
  559. data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +169 -0
  560. data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +60 -0
  561. data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +215 -0
  562. data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +343 -0
  563. data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +434 -0
  564. data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +60 -0
  565. data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +67 -0
  566. data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +314 -0
  567. data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +67 -0
  568. data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +79 -0
  569. data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +119 -0
  570. data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +110 -0
  571. data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +370 -0
  572. data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +91 -0
  573. data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +92 -0
  574. data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +41 -0
  575. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +347 -0
  576. data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +169 -0
  577. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +406 -0
  578. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +387 -0
  579. data/spec/mongoid/criteria/queryable/key_spec.rb +96 -0
  580. data/spec/mongoid/criteria/queryable/mergeable_spec.rb +182 -0
  581. data/spec/mongoid/criteria/queryable/optional_spec.rb +1317 -0
  582. data/spec/mongoid/criteria/queryable/options_spec.rb +362 -0
  583. data/spec/mongoid/criteria/queryable/pipeline_spec.rb +214 -0
  584. data/spec/mongoid/criteria/queryable/queryable_spec.rb +139 -0
  585. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +2119 -0
  586. data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +38 -0
  587. data/spec/mongoid/criteria/queryable/selectable_spec.rb +2462 -0
  588. data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +589 -0
  589. data/spec/mongoid/criteria/queryable/selector_spec.rb +895 -0
  590. data/spec/mongoid/criteria/queryable/smash_spec.rb +32 -0
  591. data/spec/mongoid/criteria/queryable/storable_spec.rb +226 -0
  592. data/spec/mongoid/criteria/scopable_spec.rb +601 -0
  593. data/spec/mongoid/criteria_projection_spec.rb +410 -0
  594. data/spec/mongoid/criteria_spec.rb +1828 -3572
  595. data/spec/mongoid/document_fields_spec.rb +262 -0
  596. data/spec/mongoid/document_persistence_context_spec.rb +32 -0
  597. data/spec/mongoid/document_query_spec.rb +89 -0
  598. data/spec/mongoid/document_spec.rb +452 -221
  599. data/spec/mongoid/equality_spec.rb +155 -52
  600. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +8 -6
  601. data/spec/mongoid/errors/callback_spec.rb +5 -3
  602. data/spec/mongoid/errors/delete_restriction_spec.rb +7 -5
  603. data/spec/mongoid/errors/document_not_destroyed_spec.rb +35 -0
  604. data/spec/mongoid/errors/document_not_found_spec.rb +89 -11
  605. data/spec/mongoid/errors/invalid_collection_spec.rb +5 -3
  606. data/spec/mongoid/errors/invalid_config_file_spec.rb +31 -0
  607. data/spec/mongoid/errors/invalid_config_option_spec.rb +5 -3
  608. data/spec/mongoid/errors/invalid_field_option_spec.rb +5 -3
  609. data/spec/mongoid/errors/invalid_field_spec.rb +6 -4
  610. data/spec/mongoid/errors/invalid_field_type_spec.rb +55 -0
  611. data/spec/mongoid/errors/invalid_find_spec.rb +5 -3
  612. data/spec/mongoid/errors/invalid_includes_spec.rb +5 -3
  613. data/spec/mongoid/errors/invalid_index_spec.rb +5 -3
  614. data/spec/mongoid/errors/invalid_options_spec.rb +7 -5
  615. data/spec/mongoid/errors/invalid_path_spec.rb +5 -3
  616. data/spec/mongoid/errors/invalid_relation_spec.rb +39 -0
  617. data/spec/mongoid/errors/invalid_scope_spec.rb +7 -5
  618. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +5 -3
  619. data/spec/mongoid/errors/invalid_storage_options_spec.rb +5 -3
  620. data/spec/mongoid/errors/invalid_time_spec.rb +5 -3
  621. data/spec/mongoid/errors/inverse_not_found_spec.rb +6 -4
  622. data/spec/mongoid/errors/mixed_client_configuration_spec.rb +31 -0
  623. data/spec/mongoid/errors/mixed_relations_spec.rb +5 -3
  624. data/spec/mongoid/errors/mongoid_error_spec.rb +45 -10
  625. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +8 -6
  626. data/spec/mongoid/errors/no_client_config_spec.rb +31 -0
  627. data/spec/mongoid/errors/no_client_database_spec.rb +31 -0
  628. data/spec/mongoid/errors/no_client_hosts_spec.rb +31 -0
  629. data/spec/mongoid/errors/no_clients_config_spec.rb +31 -0
  630. data/spec/mongoid/errors/no_environment_spec.rb +8 -6
  631. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +5 -3
  632. data/spec/mongoid/errors/no_metadata_spec.rb +5 -3
  633. data/spec/mongoid/errors/no_parent_spec.rb +6 -4
  634. data/spec/mongoid/errors/readonly_attribute_spec.rb +5 -3
  635. data/spec/mongoid/errors/readonly_document_spec.rb +31 -0
  636. data/spec/mongoid/errors/scope_overwrite_spec.rb +5 -3
  637. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +6 -4
  638. data/spec/mongoid/errors/unknown_attribute_spec.rb +7 -5
  639. data/spec/mongoid/errors/unsaved_document_spec.rb +6 -4
  640. data/spec/mongoid/errors/unsupported_javascript_spec.rb +5 -3
  641. data/spec/mongoid/errors/validations_spec.rb +9 -7
  642. data/spec/mongoid/extensions/array_spec.rb +108 -116
  643. data/spec/mongoid/extensions/big_decimal_spec.rb +838 -49
  644. data/spec/mongoid/extensions/binary_spec.rb +55 -18
  645. data/spec/mongoid/extensions/boolean_spec.rb +76 -74
  646. data/spec/mongoid/extensions/date_class_mongoize_spec.rb +339 -0
  647. data/spec/mongoid/extensions/date_spec.rb +59 -145
  648. data/spec/mongoid/extensions/date_time_spec.rb +35 -76
  649. data/spec/mongoid/extensions/decimal128_spec.rb +46 -0
  650. data/spec/mongoid/extensions/false_class_spec.rb +7 -5
  651. data/spec/mongoid/extensions/float_spec.rb +69 -62
  652. data/spec/mongoid/extensions/hash_spec.rb +197 -30
  653. data/spec/mongoid/extensions/integer_spec.rb +63 -65
  654. data/spec/mongoid/extensions/module_spec.rb +4 -2
  655. data/spec/mongoid/extensions/nil_class_spec.rb +3 -1
  656. data/spec/mongoid/extensions/object_id_spec.rb +136 -134
  657. data/spec/mongoid/extensions/object_spec.rb +53 -57
  658. data/spec/mongoid/extensions/range_spec.rb +287 -28
  659. data/spec/mongoid/extensions/regexp_spec.rb +71 -21
  660. data/spec/mongoid/extensions/set_spec.rb +112 -4
  661. data/spec/mongoid/extensions/string_spec.rb +188 -89
  662. data/spec/mongoid/extensions/stringified_symbol_spec.rb +84 -0
  663. data/spec/mongoid/extensions/symbol_spec.rb +25 -30
  664. data/spec/mongoid/extensions/time_spec.rb +703 -110
  665. data/spec/mongoid/extensions/time_with_zone_spec.rb +82 -67
  666. data/spec/mongoid/extensions/true_class_spec.rb +7 -5
  667. data/spec/mongoid/extensions_spec.rb +43 -0
  668. data/spec/mongoid/factory_spec.rb +374 -25
  669. data/spec/mongoid/fields/foreign_key_spec.rb +116 -92
  670. data/spec/mongoid/fields/localized_spec.rb +177 -35
  671. data/spec/mongoid/fields/standard_spec.rb +15 -13
  672. data/spec/mongoid/fields_spec.rb +952 -238
  673. data/spec/mongoid/findable_spec.rb +632 -0
  674. data/spec/mongoid/indexable/specification_spec.rb +129 -0
  675. data/spec/mongoid/indexable_spec.rb +643 -0
  676. data/spec/mongoid/inspectable_spec.rb +86 -0
  677. data/spec/mongoid/interceptable_spec.rb +2373 -0
  678. data/spec/mongoid/interceptable_spec_models.rb +307 -0
  679. data/spec/mongoid/loggable_spec.rb +3 -1
  680. data/spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml +104 -0
  681. data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +239 -0
  682. data/spec/mongoid/matcher/extract_attribute_spec.rb +36 -0
  683. data/spec/mongoid/mongoizable_spec.rb +285 -0
  684. data/spec/mongoid/persistable/creatable_spec.rb +662 -0
  685. data/spec/mongoid/persistable/deletable_spec.rb +514 -0
  686. data/spec/mongoid/persistable/destroyable_spec.rb +455 -0
  687. data/spec/mongoid/persistable/incrementable_spec.rb +241 -0
  688. data/spec/mongoid/persistable/logical_spec.rb +159 -0
  689. data/spec/mongoid/persistable/poppable_spec.rb +131 -0
  690. data/spec/mongoid/persistable/pullable_spec.rb +258 -0
  691. data/spec/mongoid/persistable/pushable_spec.rb +353 -0
  692. data/spec/mongoid/persistable/renamable_spec.rb +151 -0
  693. data/spec/mongoid/persistable/savable_spec.rb +684 -0
  694. data/spec/mongoid/persistable/settable_spec.rb +544 -0
  695. data/spec/mongoid/persistable/unsettable_spec.rb +171 -0
  696. data/spec/mongoid/persistable/updatable_spec.rb +760 -0
  697. data/spec/mongoid/persistable/upsertable_spec.rb +122 -0
  698. data/spec/mongoid/persistable_spec.rb +321 -0
  699. data/spec/mongoid/persistence_context_spec.rb +745 -0
  700. data/spec/mongoid/positional_spec.rb +223 -0
  701. data/spec/mongoid/query_cache_middleware_spec.rb +50 -0
  702. data/spec/mongoid/query_cache_spec.rb +870 -0
  703. data/spec/mongoid/relations/proxy_spec.rb +125 -47
  704. data/spec/mongoid/reloadable_spec.rb +665 -0
  705. data/spec/mongoid/scopable_spec.rb +1234 -0
  706. data/spec/mongoid/selectable_spec.rb +136 -0
  707. data/spec/mongoid/serializable_spec.rb +963 -0
  708. data/spec/mongoid/shardable_models.rb +61 -0
  709. data/spec/mongoid/shardable_spec.rb +204 -0
  710. data/spec/mongoid/stateful_spec.rb +157 -0
  711. data/spec/mongoid/tasks/database_rake_spec.rb +287 -0
  712. data/spec/mongoid/tasks/database_spec.rb +181 -0
  713. data/spec/mongoid/threaded_spec.rb +88 -78
  714. data/spec/mongoid/timestamps/created/short_spec.rb +9 -7
  715. data/spec/mongoid/timestamps/created_spec.rb +8 -6
  716. data/spec/mongoid/timestamps/timeless_spec.rb +29 -10
  717. data/spec/mongoid/timestamps/updated/short_spec.rb +16 -14
  718. data/spec/mongoid/timestamps/updated_spec.rb +14 -16
  719. data/spec/mongoid/timestamps_spec.rb +406 -18
  720. data/spec/mongoid/timestamps_spec_models.rb +67 -0
  721. data/spec/mongoid/touchable_spec.rb +704 -0
  722. data/spec/mongoid/touchable_spec_models.rb +57 -0
  723. data/spec/mongoid/traversable_spec.rb +1410 -0
  724. data/spec/mongoid/validatable/associated_spec.rb +208 -0
  725. data/spec/mongoid/validatable/format_spec.rb +85 -0
  726. data/spec/mongoid/validatable/length_spec.rb +225 -0
  727. data/spec/mongoid/validatable/numericality_spec.rb +32 -0
  728. data/spec/mongoid/validatable/presence_spec.rb +592 -0
  729. data/spec/mongoid/validatable/uniqueness_spec.rb +2504 -0
  730. data/spec/mongoid/validatable_spec.rb +327 -0
  731. data/spec/mongoid/warnings_spec.rb +35 -0
  732. data/spec/mongoid_spec.rb +20 -20
  733. data/spec/rails/controller_extension/controller_runtime_spec.rb +112 -0
  734. data/spec/rails/mongoid_spec.rb +37 -354
  735. data/spec/shared/LICENSE +20 -0
  736. data/spec/shared/bin/get-mongodb-download-url +17 -0
  737. data/spec/shared/bin/s3-copy +45 -0
  738. data/spec/shared/bin/s3-upload +69 -0
  739. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  740. data/spec/shared/lib/mrss/cluster_config.rb +231 -0
  741. data/spec/shared/lib/mrss/constraints.rb +378 -0
  742. data/spec/shared/lib/mrss/docker_runner.rb +291 -0
  743. data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
  744. data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
  745. data/spec/shared/lib/mrss/lite_constraints.rb +230 -0
  746. data/spec/shared/lib/mrss/server_version_registry.rb +120 -0
  747. data/spec/shared/lib/mrss/session_registry.rb +69 -0
  748. data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
  749. data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
  750. data/spec/shared/lib/mrss/utils.rb +15 -0
  751. data/spec/shared/share/Dockerfile.erb +325 -0
  752. data/spec/shared/share/haproxy-1.conf +16 -0
  753. data/spec/shared/share/haproxy-2.conf +17 -0
  754. data/spec/shared/shlib/config.sh +27 -0
  755. data/spec/shared/shlib/distro.sh +74 -0
  756. data/spec/shared/shlib/server.sh +392 -0
  757. data/spec/shared/shlib/set_env.sh +169 -0
  758. data/spec/spec_helper.rb +163 -42
  759. data/spec/support/authorization.rb +15 -0
  760. data/spec/support/client_registry.rb +9 -0
  761. data/spec/support/constraints.rb +77 -0
  762. data/spec/support/expectations.rb +32 -0
  763. data/spec/support/helpers.rb +11 -0
  764. data/spec/support/macros.rb +81 -0
  765. data/spec/support/models/account.rb +38 -0
  766. data/spec/support/models/acolyte.rb +19 -0
  767. data/spec/support/models/actor.rb +20 -0
  768. data/spec/support/models/actress.rb +4 -0
  769. data/spec/support/models/address.rb +85 -0
  770. data/spec/support/models/address_component.rb +7 -0
  771. data/spec/support/models/address_number.rb +8 -0
  772. data/spec/support/models/agency.rb +7 -0
  773. data/spec/support/models/agent.rb +18 -0
  774. data/spec/support/models/album.rb +20 -0
  775. data/spec/support/models/alert.rb +9 -0
  776. data/spec/support/models/animal.rb +28 -0
  777. data/spec/support/models/answer.rb +8 -0
  778. data/spec/support/models/appointment.rb +9 -0
  779. data/spec/support/models/armrest.rb +9 -0
  780. data/spec/support/models/array_field.rb +7 -0
  781. data/spec/support/models/article.rb +14 -0
  782. data/spec/support/models/artist.rb +91 -0
  783. data/spec/support/models/artwork.rb +6 -0
  784. data/spec/support/models/audible_sound.rb +3 -0
  785. data/spec/support/models/audio.rb +7 -0
  786. data/spec/support/models/augmentation.rb +25 -0
  787. data/spec/support/models/author.rb +8 -0
  788. data/spec/support/models/baby.rb +6 -0
  789. data/spec/support/models/band.rb +40 -0
  790. data/spec/support/models/bar.rb +12 -0
  791. data/spec/support/models/basic.rb +8 -0
  792. data/spec/support/models/bed.rb +3 -0
  793. data/spec/support/models/big_palette.rb +4 -0
  794. data/spec/support/models/birthday.rb +15 -0
  795. data/spec/support/models/bolt.rb +7 -0
  796. data/spec/support/models/bomb.rb +6 -0
  797. data/spec/support/models/book.rb +18 -0
  798. data/spec/support/models/breed.rb +6 -0
  799. data/spec/support/models/browser.rb +8 -0
  800. data/spec/support/models/building.rb +8 -0
  801. data/spec/support/models/building_address.rb +9 -0
  802. data/spec/support/models/bus.rb +9 -0
  803. data/spec/support/models/business.rb +7 -0
  804. data/spec/support/models/callback_test.rb +11 -0
  805. data/spec/support/models/canvas.rb +27 -0
  806. data/spec/support/models/car.rb +3 -0
  807. data/spec/support/models/cat.rb +10 -0
  808. data/spec/support/models/catalog.rb +24 -0
  809. data/spec/support/models/category.rb +10 -0
  810. data/spec/support/models/child.rb +6 -0
  811. data/spec/support/models/child_doc.rb +24 -0
  812. data/spec/support/models/church.rb +8 -0
  813. data/spec/support/models/circle.rb +5 -0
  814. data/spec/support/models/circuit.rb +6 -0
  815. data/spec/support/models/circus.rb +12 -0
  816. data/spec/support/models/code.rb +15 -0
  817. data/spec/support/models/coding/pull_request.rb +11 -0
  818. data/spec/support/models/coding.rb +3 -0
  819. data/spec/support/models/comment.rb +18 -0
  820. data/spec/support/models/company.rb +7 -0
  821. data/spec/support/models/consumption_period.rb +9 -0
  822. data/spec/support/models/contextable_item.rb +7 -0
  823. data/spec/support/models/contractor.rb +7 -0
  824. data/spec/support/models/cookie.rb +8 -0
  825. data/spec/support/models/country_code.rb +12 -0
  826. data/spec/support/models/courier_job.rb +6 -0
  827. data/spec/support/models/crate.rb +12 -0
  828. data/spec/support/models/customer.rb +10 -0
  829. data/spec/support/models/customer_address.rb +11 -0
  830. data/spec/support/models/deed.rb +7 -0
  831. data/spec/support/models/definition.rb +11 -0
  832. data/spec/support/models/delegating_patient.rb +15 -0
  833. data/spec/support/models/description.rb +13 -0
  834. data/spec/support/models/dictionary.rb +18 -0
  835. data/spec/support/models/division.rb +12 -0
  836. data/spec/support/models/doctor.rb +14 -0
  837. data/spec/support/models/dog.rb +9 -0
  838. data/spec/support/models/dokument.rb +8 -0
  839. data/spec/support/models/draft.rb +11 -0
  840. data/spec/support/models/dragon.rb +6 -0
  841. data/spec/support/models/driver.rb +9 -0
  842. data/spec/support/models/drug.rb +8 -0
  843. data/spec/support/models/dungeon.rb +6 -0
  844. data/spec/support/models/edit.rb +7 -0
  845. data/spec/support/models/email.rb +8 -0
  846. data/spec/support/models/employer.rb +7 -0
  847. data/spec/support/models/entry.rb +8 -0
  848. data/spec/support/models/eraser.rb +3 -0
  849. data/spec/support/models/even.rb +9 -0
  850. data/spec/support/models/event.rb +24 -0
  851. data/spec/support/models/exhibition.rb +6 -0
  852. data/spec/support/models/exhibitor.rb +8 -0
  853. data/spec/support/models/explosion.rb +6 -0
  854. data/spec/support/models/eye.rb +11 -0
  855. data/spec/support/models/eye_bowl.rb +11 -0
  856. data/spec/support/models/face.rb +10 -0
  857. data/spec/support/models/fanatic.rb +8 -0
  858. data/spec/support/models/favorite.rb +8 -0
  859. data/spec/support/models/filesystem.rb +7 -0
  860. data/spec/support/models/fire_hydrant.rb +8 -0
  861. data/spec/support/models/firefox.rb +6 -0
  862. data/spec/support/models/fish.rb +9 -0
  863. data/spec/support/models/folder.rb +9 -0
  864. data/spec/support/models/folder_item.rb +11 -0
  865. data/spec/support/models/fruits.rb +36 -0
  866. data/spec/support/models/game.rb +21 -0
  867. data/spec/support/models/ghost.rb +9 -0
  868. data/spec/support/models/guitar.rb +4 -0
  869. data/spec/support/models/hole.rb +12 -0
  870. data/spec/support/models/home.rb +6 -0
  871. data/spec/support/models/house.rb +8 -0
  872. data/spec/support/models/html_writer.rb +5 -0
  873. data/spec/support/models/id_key.rb +8 -0
  874. data/spec/support/models/idnodef.rb +7 -0
  875. data/spec/support/models/image.rb +24 -0
  876. data/spec/support/models/implant.rb +27 -0
  877. data/spec/support/models/instrument.rb +8 -0
  878. data/spec/support/models/item.rb +10 -0
  879. data/spec/support/models/jar.rb +9 -0
  880. data/spec/support/models/kaleidoscope.rb +8 -0
  881. data/spec/support/models/kangaroo.rb +6 -0
  882. data/spec/support/models/label.rb +52 -0
  883. data/spec/support/models/language.rb +7 -0
  884. data/spec/support/models/lat_lng.rb +17 -0
  885. data/spec/support/models/league.rb +13 -0
  886. data/spec/support/models/learner.rb +4 -0
  887. data/spec/support/models/line_item.rb +8 -0
  888. data/spec/support/models/location.rb +10 -0
  889. data/spec/support/models/login.rb +10 -0
  890. data/spec/support/models/manufacturer.rb +9 -0
  891. data/spec/support/models/meat.rb +6 -0
  892. data/spec/support/models/membership.rb +7 -0
  893. data/spec/support/models/message.rb +13 -0
  894. data/spec/support/models/minim.rb +6 -0
  895. data/spec/support/models/mixed_drink.rb +6 -0
  896. data/spec/support/models/mop.rb +24 -0
  897. data/spec/support/models/movie.rb +15 -0
  898. data/spec/support/models/my_hash.rb +4 -0
  899. data/spec/support/models/name.rb +26 -0
  900. data/spec/support/models/name_only.rb +8 -0
  901. data/spec/support/models/node.rb +7 -0
  902. data/spec/support/models/note.rb +19 -0
  903. data/spec/support/models/nut.rb +7 -0
  904. data/spec/support/models/odd.rb +9 -0
  905. data/spec/support/models/order.rb +12 -0
  906. data/spec/support/models/ordered_post.rb +13 -0
  907. data/spec/support/models/ordered_preference.rb +8 -0
  908. data/spec/support/models/oscar.rb +16 -0
  909. data/spec/support/models/other_owner_object.rb +4 -0
  910. data/spec/support/models/override.rb +18 -0
  911. data/spec/support/models/ownable.rb +8 -0
  912. data/spec/support/models/owner.rb +10 -0
  913. data/spec/support/models/pack.rb +5 -0
  914. data/spec/support/models/page.rb +18 -0
  915. data/spec/support/models/page_question.rb +6 -0
  916. data/spec/support/models/palette.rb +9 -0
  917. data/spec/support/models/parent.rb +7 -0
  918. data/spec/support/models/parent_doc.rb +8 -0
  919. data/spec/support/models/passport.rb +22 -0
  920. data/spec/support/models/patient.rb +11 -0
  921. data/spec/support/models/pdf_writer.rb +5 -0
  922. data/spec/support/models/pencil.rb +3 -0
  923. data/spec/support/models/person.rb +231 -0
  924. data/spec/support/models/pet.rb +25 -0
  925. data/spec/support/models/pet_owner.rb +8 -0
  926. data/spec/support/models/phone.rb +13 -0
  927. data/spec/support/models/piano.rb +4 -0
  928. data/spec/support/models/pizza.rb +9 -0
  929. data/spec/support/models/player.rb +39 -0
  930. data/spec/support/models/post.rb +52 -0
  931. data/spec/support/models/post_genre.rb +8 -0
  932. data/spec/support/models/powerup.rb +25 -0
  933. data/spec/support/models/preference.rb +11 -0
  934. data/spec/support/models/princess.rb +12 -0
  935. data/spec/support/models/product.rb +19 -0
  936. data/spec/support/models/profile.rb +17 -0
  937. data/spec/support/models/pronunciation.rb +7 -0
  938. data/spec/support/models/pub.rb +8 -0
  939. data/spec/support/models/publication/encyclopedia.rb +11 -0
  940. data/spec/support/models/publication/review.rb +13 -0
  941. data/spec/support/models/publication.rb +4 -0
  942. data/spec/support/models/purchase.rb +6 -0
  943. data/spec/support/models/purchased_item.rb +10 -0
  944. data/spec/support/models/question.rb +10 -0
  945. data/spec/support/models/quiz.rb +9 -0
  946. data/spec/support/models/rating.rb +10 -0
  947. data/spec/support/models/record.rb +54 -0
  948. data/spec/support/models/registry.rb +7 -0
  949. data/spec/support/models/role.rb +9 -0
  950. data/spec/support/models/root_category.rb +6 -0
  951. data/spec/support/models/sandwich.rb +11 -0
  952. data/spec/support/models/scheduler.rb +9 -0
  953. data/spec/support/models/school.rb +14 -0
  954. data/spec/support/models/scribe.rb +7 -0
  955. data/spec/support/models/sealer.rb +7 -0
  956. data/spec/support/models/seat.rb +24 -0
  957. data/spec/support/models/seo.rb +9 -0
  958. data/spec/support/models/series.rb +7 -0
  959. data/spec/support/models/server.rb +15 -0
  960. data/spec/support/models/service.rb +24 -0
  961. data/spec/support/models/shape.rb +14 -0
  962. data/spec/support/models/shelf.rb +7 -0
  963. data/spec/support/models/shield.rb +18 -0
  964. data/spec/support/models/shipment_address.rb +5 -0
  965. data/spec/support/models/shipping_container.rb +7 -0
  966. data/spec/support/models/shipping_pack.rb +5 -0
  967. data/spec/support/models/shirt.rb +11 -0
  968. data/spec/support/models/shop.rb +8 -0
  969. data/spec/support/models/short_agent.rb +6 -0
  970. data/spec/support/models/short_quiz.rb +7 -0
  971. data/spec/support/models/simple.rb +7 -0
  972. data/spec/support/models/slave.rb +8 -0
  973. data/spec/support/models/song.rb +10 -0
  974. data/spec/support/models/sound.rb +7 -0
  975. data/spec/support/models/spacer.rb +7 -0
  976. data/spec/support/models/square.rb +6 -0
  977. data/spec/support/models/staff.rb +9 -0
  978. data/spec/support/models/store_as_dup_test1.rb +7 -0
  979. data/spec/support/models/store_as_dup_test2.rb +7 -0
  980. data/spec/support/models/store_as_dup_test3.rb +7 -0
  981. data/spec/support/models/store_as_dup_test4.rb +7 -0
  982. data/spec/support/models/strategy.rb +5 -0
  983. data/spec/support/models/student.rb +14 -0
  984. data/spec/support/models/sub_item.rb +5 -0
  985. data/spec/support/models/subscription.rb +7 -0
  986. data/spec/support/models/survey.rb +7 -0
  987. data/spec/support/models/symptom.rb +8 -0
  988. data/spec/support/models/system_role.rb +7 -0
  989. data/spec/support/models/tag.rb +10 -0
  990. data/spec/support/models/target.rb +7 -0
  991. data/spec/support/models/template.rb +7 -0
  992. data/spec/support/models/thing.rb +11 -0
  993. data/spec/support/models/threadlocker.rb +7 -0
  994. data/spec/support/models/title.rb +5 -0
  995. data/spec/support/models/tool.rb +10 -0
  996. data/spec/support/models/topping.rb +7 -0
  997. data/spec/support/models/toy.rb +9 -0
  998. data/spec/support/models/track.rb +40 -0
  999. data/spec/support/models/translation.rb +7 -0
  1000. data/spec/support/models/tree.rb +11 -0
  1001. data/spec/support/models/truck.rb +7 -0
  1002. data/spec/support/models/updatable.rb +7 -0
  1003. data/spec/support/models/user.rb +23 -0
  1004. data/spec/support/models/user_account.rb +12 -0
  1005. data/spec/support/models/validation_callback.rb +12 -0
  1006. data/spec/support/models/vehicle.rb +18 -0
  1007. data/spec/support/models/version.rb +7 -0
  1008. data/spec/support/models/vertex.rb +8 -0
  1009. data/spec/support/models/vet_visit.rb +7 -0
  1010. data/spec/support/models/video.rb +15 -0
  1011. data/spec/support/models/video_game.rb +3 -0
  1012. data/spec/support/models/washer.rb +7 -0
  1013. data/spec/support/models/weapon.rb +25 -0
  1014. data/spec/support/models/wiki_page.rb +17 -0
  1015. data/spec/support/models/word.rb +17 -0
  1016. data/spec/support/models/word_origin.rb +13 -0
  1017. data/spec/support/models/writer.rb +13 -0
  1018. data/spec/support/schema_maps/schema_map_aws.json +17 -0
  1019. data/spec/support/schema_maps/schema_map_aws_key_alt_names.json +12 -0
  1020. data/spec/support/schema_maps/schema_map_azure.json +17 -0
  1021. data/spec/support/schema_maps/schema_map_azure_key_alt_names.json +12 -0
  1022. data/spec/support/schema_maps/schema_map_gcp.json +17 -0
  1023. data/spec/support/schema_maps/schema_map_gcp_key_alt_names.json +12 -0
  1024. data/spec/support/schema_maps/schema_map_kmip.json +17 -0
  1025. data/spec/support/schema_maps/schema_map_kmip_key_alt_names.json +12 -0
  1026. data/spec/support/schema_maps/schema_map_local.json +18 -0
  1027. data/spec/support/schema_maps/schema_map_local_key_alt_names.json +12 -0
  1028. data/spec/support/shared/time.rb +53 -0
  1029. data/spec/support/spec_config.rb +64 -0
  1030. data.tar.gz.sig +0 -0
  1031. metadata +1582 -912
  1032. metadata.gz.sig +0 -0
  1033. data/lib/mongoid/atomic/positionable.rb +0 -73
  1034. data/lib/mongoid/callbacks.rb +0 -314
  1035. data/lib/mongoid/components.rb +0 -93
  1036. data/lib/mongoid/config/inflections.rb +0 -6
  1037. data/lib/mongoid/config/validators/session.rb +0 -140
  1038. data/lib/mongoid/contextual/eager.rb +0 -158
  1039. data/lib/mongoid/contextual/find_and_modify.rb +0 -69
  1040. data/lib/mongoid/criterion/findable.rb +0 -179
  1041. data/lib/mongoid/criterion/inspection.rb +0 -25
  1042. data/lib/mongoid/criterion/marshalable.rb +0 -48
  1043. data/lib/mongoid/criterion/modifiable.rb +0 -189
  1044. data/lib/mongoid/criterion/scoping.rb +0 -158
  1045. data/lib/mongoid/dirty.rb +0 -376
  1046. data/lib/mongoid/errors/eager_load.rb +0 -22
  1047. data/lib/mongoid/errors/mixed_session_configuration.rb +0 -28
  1048. data/lib/mongoid/errors/no_default_session.rb +0 -23
  1049. data/lib/mongoid/errors/no_session_config.rb +0 -22
  1050. data/lib/mongoid/errors/no_session_database.rb +0 -27
  1051. data/lib/mongoid/errors/no_session_hosts.rb +0 -27
  1052. data/lib/mongoid/errors/no_sessions_config.rb +0 -20
  1053. data/lib/mongoid/errors/versioning_not_on_root.rb +0 -23
  1054. data/lib/mongoid/finders.rb +0 -130
  1055. data/lib/mongoid/hierarchy.rb +0 -188
  1056. data/lib/mongoid/identity_map.rb +0 -163
  1057. data/lib/mongoid/indexes/validators/options.rb +0 -102
  1058. data/lib/mongoid/indexes.rb +0 -154
  1059. data/lib/mongoid/inspection.rb +0 -55
  1060. data/lib/mongoid/json.rb +0 -16
  1061. data/lib/mongoid/matchers/all.rb +0 -27
  1062. data/lib/mongoid/matchers/and.rb +0 -30
  1063. data/lib/mongoid/matchers/default.rb +0 -72
  1064. data/lib/mongoid/matchers/exists.rb +0 -23
  1065. data/lib/mongoid/matchers/gt.rb +0 -21
  1066. data/lib/mongoid/matchers/gte.rb +0 -21
  1067. data/lib/mongoid/matchers/in.rb +0 -24
  1068. data/lib/mongoid/matchers/lt.rb +0 -21
  1069. data/lib/mongoid/matchers/lte.rb +0 -21
  1070. data/lib/mongoid/matchers/ne.rb +0 -21
  1071. data/lib/mongoid/matchers/nin.rb +0 -21
  1072. data/lib/mongoid/matchers/or.rb +0 -33
  1073. data/lib/mongoid/matchers/size.rb +0 -21
  1074. data/lib/mongoid/matchers/strategies.rb +0 -97
  1075. data/lib/mongoid/matchers.rb +0 -32
  1076. data/lib/mongoid/multi_parameter_attributes.rb +0 -105
  1077. data/lib/mongoid/nested_attributes.rb +0 -78
  1078. data/lib/mongoid/observer.rb +0 -192
  1079. data/lib/mongoid/paranoia.rb +0 -137
  1080. data/lib/mongoid/persistence/atomic/add_to_set.rb +0 -47
  1081. data/lib/mongoid/persistence/atomic/bit.rb +0 -35
  1082. data/lib/mongoid/persistence/atomic/inc.rb +0 -45
  1083. data/lib/mongoid/persistence/atomic/operation.rb +0 -154
  1084. data/lib/mongoid/persistence/atomic/pop.rb +0 -32
  1085. data/lib/mongoid/persistence/atomic/pull.rb +0 -32
  1086. data/lib/mongoid/persistence/atomic/pull_all.rb +0 -32
  1087. data/lib/mongoid/persistence/atomic/push.rb +0 -25
  1088. data/lib/mongoid/persistence/atomic/push_all.rb +0 -25
  1089. data/lib/mongoid/persistence/atomic/rename.rb +0 -30
  1090. data/lib/mongoid/persistence/atomic/sets.rb +0 -28
  1091. data/lib/mongoid/persistence/atomic/unset.rb +0 -27
  1092. data/lib/mongoid/persistence/atomic.rb +0 -231
  1093. data/lib/mongoid/persistence/deletion.rb +0 -32
  1094. data/lib/mongoid/persistence/insertion.rb +0 -38
  1095. data/lib/mongoid/persistence/modification.rb +0 -35
  1096. data/lib/mongoid/persistence/operations/embedded/insert.rb +0 -46
  1097. data/lib/mongoid/persistence/operations/embedded/remove.rb +0 -43
  1098. data/lib/mongoid/persistence/operations/insert.rb +0 -34
  1099. data/lib/mongoid/persistence/operations/remove.rb +0 -33
  1100. data/lib/mongoid/persistence/operations/update.rb +0 -59
  1101. data/lib/mongoid/persistence/operations/upsert.rb +0 -28
  1102. data/lib/mongoid/persistence/operations.rb +0 -214
  1103. data/lib/mongoid/persistence/upsertion.rb +0 -31
  1104. data/lib/mongoid/persistence.rb +0 -352
  1105. data/lib/mongoid/railties/document.rb +0 -12
  1106. data/lib/mongoid/relations/accessors.rb +0 -299
  1107. data/lib/mongoid/relations/auto_save.rb +0 -107
  1108. data/lib/mongoid/relations/binding.rb +0 -241
  1109. data/lib/mongoid/relations/bindings/embedded/in.rb +0 -63
  1110. data/lib/mongoid/relations/bindings/embedded/many.rb +0 -52
  1111. data/lib/mongoid/relations/bindings/embedded/one.rb +0 -55
  1112. data/lib/mongoid/relations/bindings/referenced/in.rb +0 -70
  1113. data/lib/mongoid/relations/bindings/referenced/many.rb +0 -42
  1114. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +0 -67
  1115. data/lib/mongoid/relations/bindings/referenced/one.rb +0 -44
  1116. data/lib/mongoid/relations/bindings.rb +0 -9
  1117. data/lib/mongoid/relations/builder.rb +0 -57
  1118. data/lib/mongoid/relations/builders/embedded/in.rb +0 -29
  1119. data/lib/mongoid/relations/builders/embedded/many.rb +0 -36
  1120. data/lib/mongoid/relations/builders/embedded/one.rb +0 -30
  1121. data/lib/mongoid/relations/builders/nested_attributes/many.rb +0 -177
  1122. data/lib/mongoid/relations/builders/nested_attributes/one.rb +0 -127
  1123. data/lib/mongoid/relations/builders/referenced/in.rb +0 -26
  1124. data/lib/mongoid/relations/builders/referenced/many.rb +0 -27
  1125. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +0 -40
  1126. data/lib/mongoid/relations/builders/referenced/one.rb +0 -26
  1127. data/lib/mongoid/relations/builders.rb +0 -104
  1128. data/lib/mongoid/relations/cascading/delete.rb +0 -44
  1129. data/lib/mongoid/relations/cascading/destroy.rb +0 -43
  1130. data/lib/mongoid/relations/cascading/nullify.rb +0 -35
  1131. data/lib/mongoid/relations/cascading/restrict.rb +0 -39
  1132. data/lib/mongoid/relations/cascading.rb +0 -58
  1133. data/lib/mongoid/relations/constraint.rb +0 -49
  1134. data/lib/mongoid/relations/conversions.rb +0 -34
  1135. data/lib/mongoid/relations/counter_cache.rb +0 -107
  1136. data/lib/mongoid/relations/cyclic.rb +0 -107
  1137. data/lib/mongoid/relations/embedded/batchable.rb +0 -356
  1138. data/lib/mongoid/relations/embedded/in.rb +0 -231
  1139. data/lib/mongoid/relations/embedded/many.rb +0 -659
  1140. data/lib/mongoid/relations/embedded/one.rb +0 -223
  1141. data/lib/mongoid/relations/macros.rb +0 -359
  1142. data/lib/mongoid/relations/many.rb +0 -217
  1143. data/lib/mongoid/relations/marshalable.rb +0 -32
  1144. data/lib/mongoid/relations/metadata.rb +0 -1227
  1145. data/lib/mongoid/relations/nested_builder.rb +0 -74
  1146. data/lib/mongoid/relations/one.rb +0 -60
  1147. data/lib/mongoid/relations/options.rb +0 -48
  1148. data/lib/mongoid/relations/polymorphic.rb +0 -40
  1149. data/lib/mongoid/relations/proxy.rb +0 -264
  1150. data/lib/mongoid/relations/referenced/in.rb +0 -314
  1151. data/lib/mongoid/relations/referenced/many.rb +0 -789
  1152. data/lib/mongoid/relations/referenced/many_to_many.rb +0 -495
  1153. data/lib/mongoid/relations/referenced/one.rb +0 -297
  1154. data/lib/mongoid/relations/reflections.rb +0 -62
  1155. data/lib/mongoid/relations/synchronization.rb +0 -169
  1156. data/lib/mongoid/relations/targets/enumerable.rb +0 -473
  1157. data/lib/mongoid/relations/targets.rb +0 -2
  1158. data/lib/mongoid/relations/touchable.rb +0 -61
  1159. data/lib/mongoid/relations.rb +0 -162
  1160. data/lib/mongoid/reloading.rb +0 -92
  1161. data/lib/mongoid/scoping.rb +0 -356
  1162. data/lib/mongoid/serialization.rb +0 -161
  1163. data/lib/mongoid/sessions/factory.rb +0 -129
  1164. data/lib/mongoid/sessions/mongo_uri.rb +0 -93
  1165. data/lib/mongoid/sessions/validators/storage.rb +0 -49
  1166. data/lib/mongoid/sessions/validators.rb +0 -2
  1167. data/lib/mongoid/sessions.rb +0 -433
  1168. data/lib/mongoid/sharding.rb +0 -61
  1169. data/lib/mongoid/state.rb +0 -97
  1170. data/lib/mongoid/unit_of_work.rb +0 -61
  1171. data/lib/mongoid/validations/associated.rb +0 -46
  1172. data/lib/mongoid/validations/format.rb +0 -20
  1173. data/lib/mongoid/validations/length.rb +0 -20
  1174. data/lib/mongoid/validations/localizable.rb +0 -30
  1175. data/lib/mongoid/validations/macros.rb +0 -93
  1176. data/lib/mongoid/validations/presence.rb +0 -86
  1177. data/lib/mongoid/validations/queryable.rb +0 -31
  1178. data/lib/mongoid/validations/uniqueness.rb +0 -330
  1179. data/lib/mongoid/validations.rb +0 -166
  1180. data/lib/mongoid/versioning.rb +0 -217
  1181. data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
  1182. data/lib/rack/mongoid.rb +0 -2
  1183. data/lib/rails/generators/mongoid/observer/observer_generator.rb +0 -17
  1184. data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +0 -4
  1185. data/lib/support/ruby_version.rb +0 -26
  1186. data/spec/app/models/account.rb +0 -32
  1187. data/spec/app/models/acolyte.rb +0 -16
  1188. data/spec/app/models/actor.rb +0 -19
  1189. data/spec/app/models/actor_observer.rb +0 -15
  1190. data/spec/app/models/actress.rb +0 -2
  1191. data/spec/app/models/address.rb +0 -72
  1192. data/spec/app/models/address_component.rb +0 -5
  1193. data/spec/app/models/address_number.rb +0 -6
  1194. data/spec/app/models/agency.rb +0 -5
  1195. data/spec/app/models/agent.rb +0 -12
  1196. data/spec/app/models/album.rb +0 -14
  1197. data/spec/app/models/alert.rb +0 -5
  1198. data/spec/app/models/animal.rb +0 -25
  1199. data/spec/app/models/answer.rb +0 -4
  1200. data/spec/app/models/appointment.rb +0 -7
  1201. data/spec/app/models/article.rb +0 -13
  1202. data/spec/app/models/artist.rb +0 -66
  1203. data/spec/app/models/artwork.rb +0 -4
  1204. data/spec/app/models/augmentation.rb +0 -11
  1205. data/spec/app/models/author.rb +0 -6
  1206. data/spec/app/models/band.rb +0 -25
  1207. data/spec/app/models/bar.rb +0 -9
  1208. data/spec/app/models/basic.rb +0 -6
  1209. data/spec/app/models/bed.rb +0 -1
  1210. data/spec/app/models/big_palette.rb +0 -2
  1211. data/spec/app/models/birthday.rb +0 -13
  1212. data/spec/app/models/book.rb +0 -12
  1213. data/spec/app/models/breed.rb +0 -4
  1214. data/spec/app/models/browser.rb +0 -6
  1215. data/spec/app/models/building.rb +0 -7
  1216. data/spec/app/models/building_address.rb +0 -7
  1217. data/spec/app/models/bus.rb +0 -7
  1218. data/spec/app/models/business.rb +0 -5
  1219. data/spec/app/models/callback_recorder.rb +0 -25
  1220. data/spec/app/models/callback_test.rb +0 -9
  1221. data/spec/app/models/canvas.rb +0 -25
  1222. data/spec/app/models/car.rb +0 -1
  1223. data/spec/app/models/cat.rb +0 -8
  1224. data/spec/app/models/category.rb +0 -8
  1225. data/spec/app/models/child.rb +0 -4
  1226. data/spec/app/models/child_doc.rb +0 -22
  1227. data/spec/app/models/church.rb +0 -4
  1228. data/spec/app/models/circle.rb +0 -3
  1229. data/spec/app/models/circuit.rb +0 -4
  1230. data/spec/app/models/circus.rb +0 -7
  1231. data/spec/app/models/code.rb +0 -5
  1232. data/spec/app/models/comment.rb +0 -16
  1233. data/spec/app/models/contractor.rb +0 -7
  1234. data/spec/app/models/cookie.rb +0 -6
  1235. data/spec/app/models/country_code.rb +0 -8
  1236. data/spec/app/models/definition.rb +0 -8
  1237. data/spec/app/models/description.rb +0 -11
  1238. data/spec/app/models/dictionary.rb +0 -10
  1239. data/spec/app/models/division.rb +0 -10
  1240. data/spec/app/models/doctor.rb +0 -12
  1241. data/spec/app/models/dog.rb +0 -7
  1242. data/spec/app/models/dokument.rb +0 -5
  1243. data/spec/app/models/driver.rb +0 -7
  1244. data/spec/app/models/drug.rb +0 -8
  1245. data/spec/app/models/email.rb +0 -6
  1246. data/spec/app/models/employer.rb +0 -5
  1247. data/spec/app/models/entry.rb +0 -6
  1248. data/spec/app/models/eraser.rb +0 -1
  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 -5
  1252. data/spec/app/models/eye.rb +0 -9
  1253. data/spec/app/models/eye_bowl.rb +0 -9
  1254. data/spec/app/models/face.rb +0 -8
  1255. data/spec/app/models/favorite.rb +0 -6
  1256. data/spec/app/models/filesystem.rb +0 -4
  1257. data/spec/app/models/fire_hydrant.rb +0 -6
  1258. data/spec/app/models/firefox.rb +0 -4
  1259. data/spec/app/models/fish.rb +0 -8
  1260. data/spec/app/models/folder.rb +0 -7
  1261. data/spec/app/models/folder_item.rb +0 -9
  1262. data/spec/app/models/fruits.rb +0 -28
  1263. data/spec/app/models/game.rb +0 -21
  1264. data/spec/app/models/ghost.rb +0 -7
  1265. data/spec/app/models/home.rb +0 -4
  1266. data/spec/app/models/house.rb +0 -8
  1267. data/spec/app/models/html_writer.rb +0 -3
  1268. data/spec/app/models/image.rb +0 -22
  1269. data/spec/app/models/implant.rb +0 -16
  1270. data/spec/app/models/item.rb +0 -12
  1271. data/spec/app/models/jar.rb +0 -7
  1272. data/spec/app/models/label.rb +0 -40
  1273. data/spec/app/models/language.rb +0 -5
  1274. data/spec/app/models/lat_lng.rb +0 -15
  1275. data/spec/app/models/league.rb +0 -11
  1276. data/spec/app/models/learner.rb +0 -2
  1277. data/spec/app/models/line_item.rb +0 -6
  1278. data/spec/app/models/location.rb +0 -8
  1279. data/spec/app/models/login.rb +0 -8
  1280. data/spec/app/models/manufacturer.rb +0 -7
  1281. data/spec/app/models/meat.rb +0 -4
  1282. data/spec/app/models/membership.rb +0 -4
  1283. data/spec/app/models/mixed_drink.rb +0 -4
  1284. data/spec/app/models/movie.rb +0 -12
  1285. data/spec/app/models/my_hash.rb +0 -2
  1286. data/spec/app/models/name.rb +0 -23
  1287. data/spec/app/models/node.rb +0 -5
  1288. data/spec/app/models/note.rb +0 -12
  1289. data/spec/app/models/ordered_post.rb +0 -6
  1290. data/spec/app/models/ordered_preference.rb +0 -6
  1291. data/spec/app/models/oscar.rb +0 -15
  1292. data/spec/app/models/override.rb +0 -16
  1293. data/spec/app/models/ownable.rb +0 -6
  1294. data/spec/app/models/owner.rb +0 -6
  1295. data/spec/app/models/pack.rb +0 -3
  1296. data/spec/app/models/page.rb +0 -5
  1297. data/spec/app/models/page_question.rb +0 -4
  1298. data/spec/app/models/palette.rb +0 -7
  1299. data/spec/app/models/paranoid_phone.rb +0 -25
  1300. data/spec/app/models/paranoid_post.rb +0 -36
  1301. data/spec/app/models/parent.rb +0 -5
  1302. data/spec/app/models/parent_doc.rb +0 -6
  1303. data/spec/app/models/passport.rb +0 -5
  1304. data/spec/app/models/patient.rb +0 -9
  1305. data/spec/app/models/pdf_writer.rb +0 -3
  1306. data/spec/app/models/pencil.rb +0 -1
  1307. data/spec/app/models/person.rb +0 -201
  1308. data/spec/app/models/pet.rb +0 -23
  1309. data/spec/app/models/pet_owner.rb +0 -6
  1310. data/spec/app/models/phone.rb +0 -11
  1311. data/spec/app/models/phone_observer.rb +0 -6
  1312. data/spec/app/models/pizza.rb +0 -7
  1313. data/spec/app/models/player.rb +0 -35
  1314. data/spec/app/models/post.rb +0 -43
  1315. data/spec/app/models/powerup.rb +0 -11
  1316. data/spec/app/models/preference.rb +0 -9
  1317. data/spec/app/models/princess.rb +0 -8
  1318. data/spec/app/models/product.rb +0 -17
  1319. data/spec/app/models/profile.rb +0 -5
  1320. data/spec/app/models/pronunciation.rb +0 -5
  1321. data/spec/app/models/purchase.rb +0 -4
  1322. data/spec/app/models/question.rb +0 -8
  1323. data/spec/app/models/quiz.rb +0 -10
  1324. data/spec/app/models/rating.rb +0 -8
  1325. data/spec/app/models/record.rb +0 -46
  1326. data/spec/app/models/registry.rb +0 -4
  1327. data/spec/app/models/role.rb +0 -7
  1328. data/spec/app/models/root_category.rb +0 -4
  1329. data/spec/app/models/sandwich.rb +0 -4
  1330. data/spec/app/models/scheduler.rb +0 -7
  1331. data/spec/app/models/seo.rb +0 -7
  1332. data/spec/app/models/series.rb +0 -4
  1333. data/spec/app/models/server.rb +0 -13
  1334. data/spec/app/models/service.rb +0 -22
  1335. data/spec/app/models/shape.rb +0 -12
  1336. data/spec/app/models/shelf.rb +0 -5
  1337. data/spec/app/models/shipping_container.rb +0 -5
  1338. data/spec/app/models/shipping_pack.rb +0 -3
  1339. data/spec/app/models/shop.rb +0 -6
  1340. data/spec/app/models/short_agent.rb +0 -4
  1341. data/spec/app/models/short_quiz.rb +0 -5
  1342. data/spec/app/models/slave.rb +0 -6
  1343. data/spec/app/models/song.rb +0 -8
  1344. data/spec/app/models/square.rb +0 -4
  1345. data/spec/app/models/strategy.rb +0 -3
  1346. data/spec/app/models/sub_item.rb +0 -3
  1347. data/spec/app/models/subscription.rb +0 -4
  1348. data/spec/app/models/survey.rb +0 -5
  1349. data/spec/app/models/symptom.rb +0 -6
  1350. data/spec/app/models/tag.rb +0 -8
  1351. data/spec/app/models/target.rb +0 -5
  1352. data/spec/app/models/template.rb +0 -5
  1353. data/spec/app/models/thing.rb +0 -9
  1354. data/spec/app/models/title.rb +0 -4
  1355. data/spec/app/models/tool.rb +0 -8
  1356. data/spec/app/models/topping.rb +0 -5
  1357. data/spec/app/models/track.rb +0 -38
  1358. data/spec/app/models/translation.rb +0 -5
  1359. data/spec/app/models/tree.rb +0 -9
  1360. data/spec/app/models/truck.rb +0 -3
  1361. data/spec/app/models/user.rb +0 -21
  1362. data/spec/app/models/user_account.rb +0 -10
  1363. data/spec/app/models/validation_callback.rb +0 -10
  1364. data/spec/app/models/vehicle.rb +0 -11
  1365. data/spec/app/models/version.rb +0 -5
  1366. data/spec/app/models/vet_visit.rb +0 -5
  1367. data/spec/app/models/video.rb +0 -17
  1368. data/spec/app/models/video_game.rb +0 -1
  1369. data/spec/app/models/weapon.rb +0 -11
  1370. data/spec/app/models/wiki_page.rb +0 -17
  1371. data/spec/app/models/word.rb +0 -12
  1372. data/spec/app/models/word_origin.rb +0 -11
  1373. data/spec/app/models/writer.rb +0 -11
  1374. data/spec/mongoid/atomic/positionable_spec.rb +0 -227
  1375. data/spec/mongoid/attributes/processing_spec.rb +0 -149
  1376. data/spec/mongoid/callbacks_spec.rb +0 -1564
  1377. data/spec/mongoid/components_spec.rb +0 -24
  1378. data/spec/mongoid/contextual/find_and_modify_spec.rb +0 -220
  1379. data/spec/mongoid/criterion/destructive_spec.rb +0 -101
  1380. data/spec/mongoid/criterion/inspection_spec.rb +0 -27
  1381. data/spec/mongoid/criterion/marshalable_spec.rb +0 -28
  1382. data/spec/mongoid/criterion/modifiable_spec.rb +0 -409
  1383. data/spec/mongoid/criterion/modification_spec.rb +0 -402
  1384. data/spec/mongoid/criterion/scoping_spec.rb +0 -391
  1385. data/spec/mongoid/dirty_spec.rb +0 -1508
  1386. data/spec/mongoid/errors/eager_load_spec.rb +0 -29
  1387. data/spec/mongoid/errors/mixed_session_configuration_spec.rb +0 -29
  1388. data/spec/mongoid/errors/no_session_config_spec.rb +0 -29
  1389. data/spec/mongoid/errors/no_session_database_spec.rb +0 -29
  1390. data/spec/mongoid/errors/no_session_hosts_spec.rb +0 -29
  1391. data/spec/mongoid/errors/no_sessions_config_spec.rb +0 -29
  1392. data/spec/mongoid/errors/versioning_not_on_root_spec.rb +0 -29
  1393. data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +0 -184
  1394. data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +0 -201
  1395. data/spec/mongoid/finders_spec.rb +0 -321
  1396. data/spec/mongoid/hierarchy_spec.rb +0 -244
  1397. data/spec/mongoid/identity_map_spec.rb +0 -564
  1398. data/spec/mongoid/indexes_spec.rb +0 -404
  1399. data/spec/mongoid/inspection_spec.rb +0 -57
  1400. data/spec/mongoid/json_spec.rb +0 -33
  1401. data/spec/mongoid/matchers/all_spec.rb +0 -31
  1402. data/spec/mongoid/matchers/and_spec.rb +0 -162
  1403. data/spec/mongoid/matchers/default_spec.rb +0 -130
  1404. data/spec/mongoid/matchers/exists_spec.rb +0 -57
  1405. data/spec/mongoid/matchers/gt_spec.rb +0 -74
  1406. data/spec/mongoid/matchers/gte_spec.rb +0 -74
  1407. data/spec/mongoid/matchers/in_spec.rb +0 -25
  1408. data/spec/mongoid/matchers/lt_spec.rb +0 -74
  1409. data/spec/mongoid/matchers/lte_spec.rb +0 -74
  1410. data/spec/mongoid/matchers/ne_spec.rb +0 -25
  1411. data/spec/mongoid/matchers/nin_spec.rb +0 -25
  1412. data/spec/mongoid/matchers/or_spec.rb +0 -106
  1413. data/spec/mongoid/matchers/size_spec.rb +0 -25
  1414. data/spec/mongoid/matchers_spec.rb +0 -532
  1415. data/spec/mongoid/multi_parameter_attributes_spec.rb +0 -128
  1416. data/spec/mongoid/nested_attributes_spec.rb +0 -4945
  1417. data/spec/mongoid/observer_spec.rb +0 -290
  1418. data/spec/mongoid/paranoia_spec.rb +0 -759
  1419. data/spec/mongoid/persistence/atomic/add_to_set_spec.rb +0 -262
  1420. data/spec/mongoid/persistence/atomic/bit_spec.rb +0 -88
  1421. data/spec/mongoid/persistence/atomic/inc_spec.rb +0 -133
  1422. data/spec/mongoid/persistence/atomic/pop_spec.rb +0 -111
  1423. data/spec/mongoid/persistence/atomic/pull_all_spec.rb +0 -77
  1424. data/spec/mongoid/persistence/atomic/pull_spec.rb +0 -80
  1425. data/spec/mongoid/persistence/atomic/push_all_spec.rb +0 -77
  1426. data/spec/mongoid/persistence/atomic/push_spec.rb +0 -77
  1427. data/spec/mongoid/persistence/atomic/rename_spec.rb +0 -42
  1428. data/spec/mongoid/persistence/atomic/sets_spec.rb +0 -154
  1429. data/spec/mongoid/persistence/atomic/unset_spec.rb +0 -65
  1430. data/spec/mongoid/persistence/atomic_spec.rb +0 -216
  1431. data/spec/mongoid/persistence/operations/embedded/insert_spec.rb +0 -191
  1432. data/spec/mongoid/persistence/operations/embedded/remove_spec.rb +0 -8
  1433. data/spec/mongoid/persistence/operations/insert_spec.rb +0 -149
  1434. data/spec/mongoid/persistence/operations/remove_spec.rb +0 -113
  1435. data/spec/mongoid/persistence/operations/update_spec.rb +0 -141
  1436. data/spec/mongoid/persistence/operations/upsert_spec.rb +0 -59
  1437. data/spec/mongoid/persistence/operations_spec.rb +0 -313
  1438. data/spec/mongoid/persistence_spec.rb +0 -2279
  1439. data/spec/mongoid/railties/document_spec.rb +0 -24
  1440. data/spec/mongoid/relations/accessors_spec.rb +0 -844
  1441. data/spec/mongoid/relations/auto_save_spec.rb +0 -261
  1442. data/spec/mongoid/relations/bindings/embedded/in_spec.rb +0 -171
  1443. data/spec/mongoid/relations/bindings/embedded/many_spec.rb +0 -54
  1444. data/spec/mongoid/relations/bindings/embedded/one_spec.rb +0 -77
  1445. data/spec/mongoid/relations/bindings/referenced/in_spec.rb +0 -241
  1446. data/spec/mongoid/relations/bindings/referenced/many_spec.rb +0 -153
  1447. data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +0 -178
  1448. data/spec/mongoid/relations/bindings/referenced/one_spec.rb +0 -131
  1449. data/spec/mongoid/relations/builders/embedded/in_spec.rb +0 -34
  1450. data/spec/mongoid/relations/builders/embedded/many_spec.rb +0 -132
  1451. data/spec/mongoid/relations/builders/embedded/one_spec.rb +0 -99
  1452. data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +0 -234
  1453. data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +0 -250
  1454. data/spec/mongoid/relations/builders/referenced/in_spec.rb +0 -241
  1455. data/spec/mongoid/relations/builders/referenced/many_spec.rb +0 -137
  1456. data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +0 -178
  1457. data/spec/mongoid/relations/builders/referenced/one_spec.rb +0 -124
  1458. data/spec/mongoid/relations/builders_spec.rb +0 -226
  1459. data/spec/mongoid/relations/cascading/delete_spec.rb +0 -101
  1460. data/spec/mongoid/relations/cascading/destroy_spec.rb +0 -47
  1461. data/spec/mongoid/relations/cascading/nullify_spec.rb +0 -32
  1462. data/spec/mongoid/relations/cascading/restrict_spec.rb +0 -68
  1463. data/spec/mongoid/relations/cascading_spec.rb +0 -355
  1464. data/spec/mongoid/relations/constraint_spec.rb +0 -74
  1465. data/spec/mongoid/relations/conversions_spec.rb +0 -126
  1466. data/spec/mongoid/relations/counter_cache_spec.rb +0 -205
  1467. data/spec/mongoid/relations/cyclic_spec.rb +0 -156
  1468. data/spec/mongoid/relations/embedded/dirty_spec.rb +0 -65
  1469. data/spec/mongoid/relations/embedded/in_spec.rb +0 -580
  1470. data/spec/mongoid/relations/embedded/many_spec.rb +0 -3841
  1471. data/spec/mongoid/relations/embedded/one_spec.rb +0 -1055
  1472. data/spec/mongoid/relations/macros_spec.rb +0 -625
  1473. data/spec/mongoid/relations/metadata_spec.rb +0 -2030
  1474. data/spec/mongoid/relations/options_spec.rb +0 -35
  1475. data/spec/mongoid/relations/polymorphic_spec.rb +0 -132
  1476. data/spec/mongoid/relations/referenced/in_spec.rb +0 -1501
  1477. data/spec/mongoid/relations/referenced/many_spec.rb +0 -3632
  1478. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +0 -3561
  1479. data/spec/mongoid/relations/referenced/one_spec.rb +0 -1331
  1480. data/spec/mongoid/relations/reflections_spec.rb +0 -101
  1481. data/spec/mongoid/relations/synchronization_spec.rb +0 -453
  1482. data/spec/mongoid/relations/targets/enumerable_spec.rb +0 -1710
  1483. data/spec/mongoid/relations_spec.rb +0 -188
  1484. data/spec/mongoid/reloading_spec.rb +0 -305
  1485. data/spec/mongoid/scoping_spec.rb +0 -978
  1486. data/spec/mongoid/serialization_spec.rb +0 -833
  1487. data/spec/mongoid/sessions/factory_spec.rb +0 -312
  1488. data/spec/mongoid/sessions/mongo_uri_spec.rb +0 -103
  1489. data/spec/mongoid/sessions_spec.rb +0 -1111
  1490. data/spec/mongoid/sharding_spec.rb +0 -61
  1491. data/spec/mongoid/state_spec.rb +0 -102
  1492. data/spec/mongoid/unit_of_work_spec.rb +0 -196
  1493. data/spec/mongoid/validations/associated_spec.rb +0 -183
  1494. data/spec/mongoid/validations/format_spec.rb +0 -83
  1495. data/spec/mongoid/validations/length_spec.rb +0 -223
  1496. data/spec/mongoid/validations/numericality_spec.rb +0 -30
  1497. data/spec/mongoid/validations/presence_spec.rb +0 -592
  1498. data/spec/mongoid/validations/uniqueness_spec.rb +0 -2399
  1499. data/spec/mongoid/validations_spec.rb +0 -309
  1500. data/spec/mongoid/versioning_spec.rb +0 -540
  1501. data/spec/rack/mongoid/middleware/identity_map_spec.rb +0 -72
@@ -1,9 +1,13 @@
1
- # encoding: utf-8
2
- require "mongoid/criterion/inspection"
3
- require "mongoid/criterion/findable"
4
- require "mongoid/criterion/marshalable"
5
- require "mongoid/criterion/modifiable"
6
- require "mongoid/criterion/scoping"
1
+ # frozen_string_literal: true
2
+
3
+ require "mongoid/criteria/findable"
4
+ require "mongoid/criteria/includable"
5
+ require "mongoid/criteria/inspectable"
6
+ require "mongoid/criteria/marshalable"
7
+ require "mongoid/criteria/modifiable"
8
+ require "mongoid/criteria/queryable"
9
+ require "mongoid/criteria/scopable"
10
+ require "mongoid/criteria/options"
7
11
 
8
12
  module Mongoid
9
13
 
@@ -15,21 +19,31 @@ module Mongoid
15
19
  # against the database.
16
20
  class Criteria
17
21
  include Enumerable
22
+
23
+ # @api private
24
+ alias :_enumerable_find :find
25
+
18
26
  include Contextual
19
- include Origin::Queryable
20
- include Criterion::Inspection
21
- include Criterion::Findable
22
- include Criterion::Marshalable
23
- include Criterion::Modifiable
24
- include Criterion::Scoping
27
+ include Queryable
28
+ include Findable
29
+
30
+ # @api private
31
+ alias :_findable_find :find
32
+
33
+ include Inspectable
34
+ include Includable
35
+ include Marshalable
36
+ include Modifiable
37
+ include Scopable
38
+ include Clients::Options
39
+ include Clients::Sessions
40
+ include Options
25
41
 
26
42
  # Static array used to check with method missing - we only need to ever
27
43
  # instantiate once.
28
- #
29
- # @since 4.0.0
30
44
  CHECK = []
31
45
 
32
- attr_accessor :embedded, :klass
46
+ attr_accessor :embedded, :klass, :parent_document, :association
33
47
 
34
48
  # Returns true if the supplied +Enumerable+ or +Criteria+ is equal to the results
35
49
  # of this +Criteria+ or the criteria itself.
@@ -38,14 +52,60 @@ module Mongoid
38
52
  #
39
53
  # @param [ Object ] other The other +Enumerable+ or +Criteria+ to compare to.
40
54
  #
41
- # @return [ true, false ] If the objects are equal.
42
- #
43
- # @since 1.0.0
55
+ # @return [ true | false ] If the objects are equal.
44
56
  def ==(other)
45
57
  return super if other.respond_to?(:selector)
46
58
  entries == other
47
59
  end
48
60
 
61
+ # Finds one or many documents given the provided _id values, or filters
62
+ # the documents in the current scope in the application process space
63
+ # after loading them if needed.
64
+ #
65
+ # If this method is not given a block, it delegates to +Findable#find+
66
+ # and finds one or many documents for the provided _id values.
67
+ #
68
+ # If this method is given a block, it delegates to +Enumerable#find+ and
69
+ # returns the first document of those found by the current Crieria object
70
+ # for which the block returns a truthy value.
71
+ #
72
+ # Note that the "default proc" argument of Enumerable is not specially
73
+ # treated by Mongoid - the decision between delegating to +Findable+ vs
74
+ # +Enumerable+ is made solely based on whether +find+ is passed a block.
75
+ #
76
+ # @note Each argument can be an individual id, an array of ids or
77
+ # a nested array. Each array will be flattened.
78
+ #
79
+ # @example Finds a document by its _id, invokes Findable#find.
80
+ # critera.find("1234")
81
+ #
82
+ # @example Finds the first matching document using a block, invokes Enumerable#find.
83
+ # criteria.find { |item| item.name == "Depeche Mode" }
84
+ #
85
+ # @example Finds the first matching document using a block using the default Proc, invokes Enumerable#find.
86
+ # criteria.find(-> { "Default Band" }) { |item| item.name == "Milwaukee Mode" }
87
+ #
88
+ # @example Tries to find a document whose _id is the stringification of the provided Proc, typically failing.
89
+ # enumerator = criteria.find(-> { "Default Band" })
90
+ #
91
+ # @param [ Object | Array<Object> ] *args The ids.
92
+ # @param [ Proc ] block Optional block to pass.
93
+ #
94
+ # @return [ Document | Array<Document> | nil ] A document or matching documents.
95
+ #
96
+ # @raise Errors::DocumentNotFound If the parameters were _id values and
97
+ # not all documents are found and the +raise_not_found_error+
98
+ # Mongoid configuration option is truthy.
99
+ #
100
+ # @see https://ruby-doc.org/core/Enumerable.html#method-i-find
101
+ def find(*args, &block)
102
+ if block_given?
103
+ _enumerable_find(*args, &block)
104
+ else
105
+ _findable_find(*args)
106
+ end
107
+ end
108
+
49
109
  # Needed to properly get a criteria back as json
50
110
  #
51
111
  # @example Get the criteria as json.
@@ -58,39 +118,12 @@ module Mongoid
58
118
  entries.as_json(options)
59
119
  end
60
120
 
61
- # Tells the criteria that the cursor that gets returned needs to be
62
- # cached. This is so multiple iterations don't hit the database multiple
63
- # times, however this is not advisable when working with large data sets
64
- # as the entire results will get stored in memory.
65
- #
66
- # @example Flag the criteria as cached.
67
- # criteria.cache
68
- #
69
- # @return [ Criteria ] The cloned criteria.
70
- def cache
71
- crit = clone
72
- crit.options.merge!(cache: true)
73
- crit
74
- end
75
-
76
- # Will return true if the cache option has been set.
77
- #
78
- # @example Is the criteria cached?
79
- # criteria.cached?
80
- #
81
- # @return [ true, false ] If the criteria is flagged as cached.
82
- def cached?
83
- options[:cache] == true
84
- end
85
-
86
121
  # Get the documents from the embedded criteria.
87
122
  #
88
123
  # @example Get the documents.
89
124
  # criteria.documents
90
125
  #
91
126
  # @return [ Array<Document> ] The documents.
92
- #
93
- # @since 3.0.0
94
127
  def documents
95
128
  @documents ||= []
96
129
  end
@@ -102,8 +135,6 @@ module Mongoid
102
135
  # @param [ Array<Document> ] docs The embedded documents.
103
136
  #
104
137
  # @return [ Array<Document> ] The embedded documents.
105
- #
106
- # @since 3.0.0
107
138
  def documents=(docs)
108
139
  @documents = docs
109
140
  end
@@ -113,9 +144,7 @@ module Mongoid
113
144
  # @example Is the criteria for embedded documents?
114
145
  # criteria.embedded?
115
146
  #
116
- # @return [ true, false ] If the criteria is embedded.
117
- #
118
- # @since 3.0.0
147
+ # @return [ true | false ] If the criteria is embedded.
119
148
  def embedded?
120
149
  !!@embedded
121
150
  end
@@ -127,8 +156,6 @@ module Mongoid
127
156
  # criteria.extract_id
128
157
  #
129
158
  # @return [ Object ] The id.
130
- #
131
- # @since 2.3.0
132
159
  def extract_id
133
160
  selector.extract_id
134
161
  end
@@ -142,8 +169,6 @@ module Mongoid
142
169
  # @param [ Hash ] extras The extra driver options.
143
170
  #
144
171
  # @return [ Criteria ] The cloned criteria.
145
- #
146
- # @since 2.0.0
147
172
  def extras(extras)
148
173
  crit = clone
149
174
  crit.options.merge!(extras)
@@ -156,11 +181,9 @@ module Mongoid
156
181
  # criteria.field_list
157
182
  #
158
183
  # @return [ Array<String> ] The fields.
159
- #
160
- # @since 2.0.0
161
184
  def field_list
162
185
  if options[:fields]
163
- options[:fields].keys.reject{ |key| key == "_type" }
186
+ options[:fields].keys.reject{ |key| key == klass.discriminator_key }
164
187
  else
165
188
  []
166
189
  end
@@ -174,8 +197,6 @@ module Mongoid
174
197
  # criteria.freeze
175
198
  #
176
199
  # @return [ Criteria ] The frozen criteria.
177
- #
178
- # @since 2.0.0
179
200
  def freeze
180
201
  context and inclusions and super
181
202
  end
@@ -186,70 +207,11 @@ module Mongoid
186
207
  # Criteria.new(Band)
187
208
  #
188
209
  # @param [ Class ] klass The model class.
189
- #
190
- # @since 1.0.0
191
210
  def initialize(klass)
192
211
  @klass = klass
193
- klass ? super(klass.aliased_fields, klass.fields) : super({}, {})
194
- end
195
-
196
- # Eager loads all the provided relations. Will load all the documents
197
- # into the identity map who's ids match based on the extra query for the
198
- # ids.
199
- #
200
- # @note This will only work if Mongoid's identity map is enabled. To do
201
- # so set identity_map_enabled: true in your mongoid.yml
202
- #
203
- # @note This will work for embedded relations that reference another
204
- # collection via belongs_to as well.
205
- #
206
- # @note Eager loading brings all the documents into memory, so there is a
207
- # sweet spot on the performance gains. Internal benchmarks show that
208
- # eager loading becomes slower around 100k documents, but this will
209
- # naturally depend on the specific application.
210
- #
211
- # @example Eager load the provided relations.
212
- # Person.includes(:posts, :game)
213
- #
214
- # @param [ Array<Symbol> ] relations The names of the relations to eager
215
- # load.
216
- #
217
- # @return [ Criteria ] The cloned criteria.
218
- #
219
- # @since 2.2.0
220
- def includes(*relations)
221
- relations.flatten.each do |name|
222
- metadata = klass.reflect_on_association(name)
223
- raise Errors::InvalidIncludes.new(klass, relations) unless metadata
224
- inclusions.push(metadata) unless inclusions.include?(metadata)
225
- end
226
- clone
227
- end
228
-
229
- # Get a list of criteria that are to be executed for eager loading.
230
- #
231
- # @example Get the eager loading inclusions.
232
- # Person.includes(:game).inclusions
233
- #
234
- # @return [ Array<Metadata> ] The inclusions.
235
- #
236
- # @since 2.2.0
237
- def inclusions
238
- @inclusions ||= []
239
- end
240
-
241
- # Set the inclusions for the criteria.
242
- #
243
- # @example Set the inclusions.
244
- # criteria.inclusions = [ meta ]
245
- #
246
- # @param [ Array<Metadata> ] The inclusions.
247
- #
248
- # @return [ Array<Metadata> ] The new inclusions.
249
- #
250
- # @since 3.0.0
251
- def inclusions=(value)
252
- @inclusions = value
212
+ @embedded = nil
213
+ @none = nil
214
+ klass ? super(klass.aliased_fields, klass.fields, klass.relations, klass.aliased_associations) : super({}, {}, {}, {})
253
215
  end
254
216
 
255
217
  # Merges another object with this +Criteria+ and returns a new criteria.
@@ -262,7 +224,7 @@ module Mongoid
262
224
  #
263
225
  # @example Merge the criteria with a hash. The hash must contain a klass
264
226
  # key and the key/value pairs correspond to method names/args.
265
-
227
+ #
266
228
  # criteria.merge({
267
229
  # klass: Band,
268
230
  # where: { name: "Depeche Mode" },
@@ -286,18 +248,37 @@ module Mongoid
286
248
  # @param [ Criteria ] other The criteria to merge in.
287
249
  #
288
250
  # @return [ Criteria ] The merged criteria.
289
- #
290
- # @since 3.0.0
291
251
  def merge!(other)
292
252
  criteria = other.to_criteria
293
253
  selector.merge!(criteria.selector)
294
254
  options.merge!(criteria.options)
295
255
  self.documents = criteria.documents.dup unless criteria.documents.empty?
296
256
  self.scoping_options = criteria.scoping_options
297
- self.inclusions = (inclusions + criteria.inclusions.dup).uniq
257
+ self.inclusions = (inclusions + criteria.inclusions).uniq
298
258
  self
299
259
  end
300
260
 
261
+ # Returns a criteria that will always contain zero results and never hits
262
+ # the database.
263
+ #
264
+ # @example Return a none criteria.
265
+ # criteria.none
266
+ #
267
+ # @return [ Criteria ] The none criteria.
268
+ def none
269
+ @none = true and self
270
+ end
271
+
272
+ # Is the criteria an empty but chainable criteria?
273
+ #
274
+ # @example Is the criteria a none criteria?
275
+ # criteria.empty_and_chainable?
276
+ #
277
+ # @return [ true | false ] If the criteria is a none.
278
+ def empty_and_chainable?
279
+ !!@none
280
+ end
281
+
301
282
  # Overriden to include _type in the fields.
302
283
  #
303
284
  # @example Limit the fields returned from the database.
@@ -306,16 +287,43 @@ module Mongoid
306
287
  # @param [ Array<Symbol> ] args The names of the fields.
307
288
  #
308
289
  # @return [ Criteria ] The cloned criteria.
309
- #
310
- # @since 1.0.0
311
290
  def only(*args)
312
- return clone if args.flatten.empty?
313
291
  args = args.flatten
292
+ return clone if args.empty?
293
+ if (args & Fields::IDS).empty?
294
+ args.unshift(:_id)
295
+ end
314
296
  if klass.hereditary?
315
- super(*args.push(:_type))
316
- else
317
- super(*args)
297
+ args.push(klass.discriminator_key.to_sym)
318
298
  end
299
+ super(*args)
300
+ end
301
+
302
+ # Set the read preference for the criteria.
303
+ #
304
+ # @example Set the read preference.
305
+ # criteria.read(mode: :primary_preferred)
306
+ #
307
+ # @param [ Hash ] value The mode preference.
308
+ #
309
+ # @return [ Criteria ] The cloned criteria.
310
+ def read(value = nil)
311
+ clone.tap do |criteria|
312
+ criteria.options.merge!(read: value)
313
+ end
314
+ end
315
+
316
+ # Overriden to exclude _id from the fields.
317
+ #
318
+ # @example Exclude fields returned from the database.
319
+ # Band.without(:name)
320
+ #
321
+ # @param [ Array<Symbol> ] args The names of the fields.
322
+ #
323
+ # @return [ Criteria ] The cloned criteria.
324
+ def without(*args)
325
+ args -= id_fields
326
+ super(*args)
319
327
  end
320
328
 
321
329
  # Returns true if criteria responds to the given method.
@@ -324,9 +332,9 @@ module Mongoid
324
332
  # crtiteria.respond_to?(:each)
325
333
  #
326
334
  # @param [ Symbol ] name The name of the class method on the +Document+.
327
- # @param [ true, false ] include_private Whether to include privates.
335
+ # @param [ true | false ] include_private Whether to include privates.
328
336
  #
329
- # @return [ true, false ] If the criteria responds to the method.
337
+ # @return [ true | false ] If the criteria responds to the method.
330
338
  def respond_to?(name, include_private = false)
331
339
  super || klass.respond_to?(name) || CHECK.respond_to?(name, include_private)
332
340
  end
@@ -339,8 +347,6 @@ module Mongoid
339
347
  # criteria.to_criteria
340
348
  #
341
349
  # @return [ Criteria ] self.
342
- #
343
- # @since 3.0.0
344
350
  def to_criteria
345
351
  self
346
352
  end
@@ -351,8 +357,6 @@ module Mongoid
351
357
  # criteria.to_proc
352
358
  #
353
359
  # @return [ Proc ] The wrapped criteria.
354
- #
355
- # @since 3.0.0
356
360
  def to_proc
357
361
  ->{ self }
358
362
  end
@@ -368,7 +372,7 @@ module Mongoid
368
372
  #
369
373
  # @return [ Criteria ] The cloned criteria.
370
374
  def type(types)
371
- any_in(_type: Array(types))
375
+ any_in(self.discriminator_key.to_sym => Array(types))
372
376
  end
373
377
 
374
378
  # This is the general entry point for most MongoDB queries. This either
@@ -381,49 +385,38 @@ module Mongoid
381
385
  # @example Add a javascript selection.
382
386
  # criteria.where("this.name == 'syd'")
383
387
  #
384
- # @param [ String, Hash ] criterion The javascript or standard selection.
388
+ # @param [ String | Hash ] expression The javascript or standard selection.
385
389
  #
386
390
  # @raise [ UnsupportedJavascript ] If provided a string and the criteria
387
391
  # is embedded.
388
392
  #
389
393
  # @return [ Criteria ] The cloned selectable.
390
- #
391
- # @since 1.0.0
392
- def where(expression)
393
- if expression.is_a?(::String) && embedded?
394
- raise Errors::UnsupportedJavascript.new(klass, expression)
394
+ def where(*args)
395
+ # Historically this method required exactly one argument.
396
+ # As of https://jira.mongodb.org/browse/MONGOID-4804 it also accepts
397
+ # zero arguments.
398
+ # The underlying where implemetation that super invokes supports
399
+ # any number of arguments, but we don't presently allow mutiple
400
+ # arguments through this method. This API can be reconsidered in the
401
+ # future.
402
+ if args.length > 1
403
+ raise ArgumentError, "Criteria#where requires zero or one arguments (given #{args.length})"
404
+ end
405
+ if args.length == 1
406
+ expression = args.first
407
+ if expression.is_a?(::String) && embedded?
408
+ raise Errors::UnsupportedJavascript.new(klass, expression)
409
+ end
395
410
  end
396
411
  super
397
412
  end
398
413
 
399
- # Tell the next persistance operation to query from a specific collection,
400
- # database or session.
401
- #
402
- # @example Send the criteria to another collection.
403
- # Band.where(name: "Depeche Mode").with(collection: "artists")
404
- #
405
- # @param [ Hash ] options The storage options.
406
- #
407
- # @option options [ String, Symbol ] :collection The collection name.
408
- # @option options [ String, Symbol ] :database The database name.
409
- # @option options [ String, Symbol ] :session The session name.
410
- #
411
- # @return [ Criteria ] The criteria.
412
- #
413
- # @since 3.0.0
414
- def with(options)
415
- Threaded.set_persistence_options(klass, options)
416
- self
417
- end
418
-
419
414
  # Get a version of this criteria without the options.
420
415
  #
421
416
  # @example Get the criteria without options.
422
417
  # criteria.without_options
423
418
  #
424
419
  # @return [ Criteria ] The cloned criteria.
425
- #
426
- # @since 3.0.4
427
420
  def without_options
428
421
  crit = clone
429
422
  crit.options.clear
@@ -442,10 +435,14 @@ module Mongoid
442
435
  # @param [ Hash ] scope The scope for the code.
443
436
  #
444
437
  # @return [ Criteria ] The criteria.
445
- #
446
- # @since 3.1.0
447
438
  def for_js(javascript, scope = {})
448
- js_query(Moped::BSON::Code.new(javascript, scope))
439
+ code = if scope.empty?
440
+ # CodeWithScope is not supported for $where as of MongoDB 4.4
441
+ BSON::Code.new(javascript)
442
+ else
443
+ BSON::CodeWithScope.new(javascript, scope)
444
+ end
445
+ js_query(code)
449
446
  end
450
447
 
451
448
  private
@@ -463,8 +460,6 @@ module Mongoid
463
460
  #
464
461
  # @raise [ Errors::DocumentNotFound ] If none are found and raising an
465
462
  # error.
466
- #
467
- # @since 3.0.0
468
463
  def check_for_missing_documents!(result, ids)
469
464
  if (result.size < ids.size) && Mongoid.raise_not_found_error
470
465
  raise Errors::DocumentNotFound.new(klass, ids, ids - result.map(&:_id))
@@ -485,8 +480,6 @@ module Mongoid
485
480
  # @param [ Criteria ] other The criteria getting cloned.
486
481
  #
487
482
  # @return [ nil ] nil.
488
- #
489
- # @since 1.0.0
490
483
  def initialize_copy(other)
491
484
  @inclusions = other.inclusions.dup
492
485
  @scoping_options = other.scoping_options
@@ -505,9 +498,7 @@ module Mongoid
505
498
  # @param [ Array ] args The arguments.
506
499
  #
507
500
  # @return [ Object ] The result of the method call.
508
- #
509
- # @since 1.0.0
510
- def method_missing(name, *args, &block)
501
+ ruby2_keywords def method_missing(name, *args, &block)
511
502
  if klass.respond_to?(name)
512
503
  klass.send(:with_scope, self) do
513
504
  klass.send(name, *args, &block)
@@ -525,9 +516,7 @@ module Mongoid
525
516
  # @example Add the type selection.
526
517
  # criteria.merge_type_selection
527
518
  #
528
- # @return [ true, false ] If type selection was added.
529
- #
530
- # @since 3.0.3
519
+ # @return [ true | false ] If type selection was added.
531
520
  def merge_type_selection
532
521
  selector.merge!(type_selection) if type_selectable?
533
522
  end
@@ -539,13 +528,11 @@ module Mongoid
539
528
  # @example If the criteria type selectable?
540
529
  # criteria.type_selectable?
541
530
  #
542
- # @return [ true, false ] If type selection should be added.
543
- #
544
- # @since 3.0.3
531
+ # @return [ true | false ] If type selection should be added.
545
532
  def type_selectable?
546
533
  klass.hereditary? &&
547
- !selector.keys.include?("_type") &&
548
- !selector.keys.include?(:_type)
534
+ !selector.keys.include?(self.discriminator_key) &&
535
+ !selector.keys.include?(self.discriminator_key.to_sym)
549
536
  end
550
537
 
551
538
  # Get the selector for type selection.
@@ -556,10 +543,13 @@ module Mongoid
556
543
  # criteria.type_selection
557
544
  #
558
545
  # @return [ Hash ] The type selection.
559
- #
560
- # @since 3.0.3
561
546
  def type_selection
562
- { _type: { "$in" => klass._types }}
547
+ klasses = klass._types
548
+ if klasses.size > 1
549
+ { klass.discriminator_key.to_sym => { "$in" => klass._types }}
550
+ else
551
+ { klass.discriminator_key.to_sym => klass._types[0] }
552
+ end
563
553
  end
564
554
 
565
555
  # Get a new selector with type selection in it.
@@ -570,8 +560,6 @@ module Mongoid
570
560
  # criteria.selector_with_type_selection
571
561
  #
572
562
  # @return [ Hash ] The selector.
573
- #
574
- # @since 3.0.3
575
563
  def selector_with_type_selection
576
564
  type_selectable? ? selector.merge(type_selection) : selector
577
565
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mongoid/deprecation"
4
+
5
+ module Mongoid
6
+
7
+ # Adds ability to declare Mongoid-specific deprecations.
8
+ #
9
+ # @api private
10
+ module Deprecable
11
+
12
+ # Declares method(s) as deprecated.
13
+ #
14
+ # @example Deprecate a method.
15
+ # Mongoid.deprecate(Cat, :meow); Cat.new.meow
16
+ # #=> Mongoid.logger.warn("meow is deprecated and will be removed from Mongoid 8.0")
17
+ #
18
+ # @example Deprecate a method and declare the replacement method.
19
+ # Mongoid.deprecate(Cat, meow: :speak); Cat.new.meow
20
+ # #=> Mongoid.logger.warn("meow is deprecated and will be removed from Mongoid 8.0 (use speak instead)")
21
+ #
22
+ # @example Deprecate a method and give replacement instructions.
23
+ # Mongoid.deprecate(Cat, meow: 'eat :catnip instead'); Cat.new.meow
24
+ # #=> Mongoid.logger.warn("meow is deprecated and will be removed from Mongoid 8.0 (eat :catnip instead)")
25
+ #
26
+ # @param [ Module ] target_module The parent which contains the method.
27
+ # @param [ Symbol | Hash<Symbol, [ Symbol | String ]> ] method_descriptors
28
+ # The methods to deprecate, with optional replacement instructions.
29
+ def deprecate(target_module, *method_descriptors)
30
+ Mongoid::Deprecation.deprecate_methods(target_module, *method_descriptors)
31
+ end
32
+ end
33
+ end
34
+
35
+ # Ensure Mongoid.deprecate can be used during initialization
36
+ Mongoid.extend(Mongoid::Deprecable)
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mongoid
4
+
5
+ # Utility class for logging deprecation warnings.
6
+ class Deprecation < ::ActiveSupport::Deprecation
7
+
8
+ @gem_name = 'Mongoid'
9
+
10
+ # Per change policy, deprecations will be removed in the next major version.
11
+ @deprecation_horizon = "#{Mongoid::VERSION.split('.').first.to_i + 1}.0".freeze
12
+
13
+ # Overrides default ActiveSupport::Deprecation behavior
14
+ # to use Mongoid's logger.
15
+ #
16
+ # @return Array<Proc> The deprecation behavior.
17
+ def behavior
18
+ @behavior ||= Array(->(message, callstack, _deprecation_horizon, _gem_name) {
19
+ logger = Mongoid.logger
20
+ logger.warn(message)
21
+ logger.debug(callstack.join("\n ")) if debug
22
+ })
23
+ end
24
+ end
25
+ end