mongoid 6.4.8 → 7.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (315) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +0 -26
  5. data/lib/config/locales/en.yml +17 -21
  6. data/lib/mongoid.rb +2 -2
  7. data/lib/mongoid/association.rb +150 -0
  8. data/lib/mongoid/association/accessors.rb +339 -0
  9. data/lib/mongoid/{relations/binding.rb → association/bindable.rb} +32 -52
  10. data/lib/mongoid/association/builders.rb +92 -0
  11. data/lib/mongoid/{relations/constraint.rb → association/constrainable.rb} +11 -22
  12. data/lib/mongoid/association/depending.rb +116 -0
  13. data/lib/mongoid/{relations/eager.rb → association/eager_loadable.rb} +11 -11
  14. data/lib/mongoid/association/embedded.rb +4 -0
  15. data/lib/mongoid/{relations → association}/embedded/batchable.rb +27 -53
  16. data/lib/mongoid/association/embedded/cyclic.rb +109 -0
  17. data/lib/mongoid/association/embedded/embedded_in.rb +154 -0
  18. data/lib/mongoid/association/embedded/embedded_in/binding.rb +56 -0
  19. data/lib/mongoid/{relations/builders/embedded/in.rb → association/embedded/embedded_in/buildable.rb} +12 -6
  20. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +121 -0
  21. data/lib/mongoid/association/embedded/embeds_many.rb +210 -0
  22. data/lib/mongoid/{relations/bindings/embedded/many.rb → association/embedded/embeds_many/binding.rb} +11 -9
  23. data/lib/mongoid/{relations/builders/embedded/many.rb → association/embedded/embeds_many/buildable.rb} +13 -7
  24. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +529 -0
  25. data/lib/mongoid/association/embedded/embeds_one.rb +173 -0
  26. data/lib/mongoid/{relations/bindings/embedded/one.rb → association/embedded/embeds_one/binding.rb} +12 -10
  27. data/lib/mongoid/{relations/builders/embedded/one.rb → association/embedded/embeds_one/buildable.rb} +13 -7
  28. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +130 -0
  29. data/lib/mongoid/association/macros.rb +204 -0
  30. data/lib/mongoid/{relations → association}/many.rb +18 -52
  31. data/lib/mongoid/{relations → association}/marshalable.rb +6 -4
  32. data/lib/mongoid/association/nested.rb +15 -0
  33. data/lib/mongoid/association/nested/many.rb +200 -0
  34. data/lib/mongoid/association/nested/nested_buildable.rb +72 -0
  35. data/lib/mongoid/association/nested/one.rb +127 -0
  36. data/lib/mongoid/{relations → association}/one.rb +6 -6
  37. data/lib/mongoid/association/options.rb +152 -0
  38. data/lib/mongoid/{relations → association}/proxy.rb +31 -58
  39. data/lib/mongoid/association/referenced.rb +7 -0
  40. data/lib/mongoid/association/referenced/auto_save.rb +79 -0
  41. data/lib/mongoid/association/referenced/belongs_to.rb +248 -0
  42. data/lib/mongoid/association/referenced/belongs_to/binding.rb +87 -0
  43. data/lib/mongoid/association/referenced/belongs_to/buildable.rb +46 -0
  44. data/lib/mongoid/association/referenced/belongs_to/eager.rb +36 -0
  45. data/lib/mongoid/association/referenced/belongs_to/proxy.rb +136 -0
  46. data/lib/mongoid/association/referenced/counter_cache.rb +163 -0
  47. data/lib/mongoid/association/referenced/eager.rb +159 -0
  48. data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +290 -0
  49. data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +71 -0
  50. data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +40 -0
  51. data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +52 -0
  52. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +310 -0
  53. data/lib/mongoid/association/referenced/has_many.rb +273 -0
  54. data/lib/mongoid/{relations/bindings/referenced/many.rb → association/referenced/has_many/binding.rb} +6 -5
  55. data/lib/mongoid/association/referenced/has_many/buildable.rb +38 -0
  56. data/lib/mongoid/association/referenced/has_many/eager.rb +43 -0
  57. data/lib/mongoid/association/referenced/has_many/enumerable.rb +479 -0
  58. data/lib/mongoid/association/referenced/has_many/proxy.rb +577 -0
  59. data/lib/mongoid/association/referenced/has_one.rb +204 -0
  60. data/lib/mongoid/{relations/bindings/referenced/one.rb → association/referenced/has_one/binding.rb} +11 -8
  61. data/lib/mongoid/association/referenced/has_one/buildable.rb +60 -0
  62. data/lib/mongoid/association/referenced/has_one/eager.rb +35 -0
  63. data/lib/mongoid/{relations/builders/nested_attributes/one.rb → association/referenced/has_one/nested_builder.rb} +9 -9
  64. data/lib/mongoid/association/referenced/has_one/proxy.rb +113 -0
  65. data/lib/mongoid/association/referenced/syncable.rb +170 -0
  66. data/lib/mongoid/{relations → association}/reflections.rb +21 -17
  67. data/lib/mongoid/association/relatable.rb +415 -0
  68. data/lib/mongoid/association/touchable.rb +97 -0
  69. data/lib/mongoid/atomic.rb +6 -6
  70. data/lib/mongoid/atomic/modifiers.rb +8 -12
  71. data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
  72. data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
  73. data/lib/mongoid/attributes.rb +2 -1
  74. data/lib/mongoid/attributes/nested.rb +10 -10
  75. data/lib/mongoid/attributes/processing.rb +2 -2
  76. data/lib/mongoid/attributes/readonly.rb +2 -4
  77. data/lib/mongoid/clients.rb +0 -2
  78. data/lib/mongoid/clients/options.rb +1 -1
  79. data/lib/mongoid/clients/storage_options.rb +0 -1
  80. data/lib/mongoid/composable.rb +3 -4
  81. data/lib/mongoid/config.rb +1 -0
  82. data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
  83. data/lib/mongoid/contextual/atomic.rb +3 -6
  84. data/lib/mongoid/contextual/map_reduce.rb +3 -7
  85. data/lib/mongoid/contextual/memory.rb +5 -10
  86. data/lib/mongoid/contextual/mongo.rb +10 -27
  87. data/lib/mongoid/copyable.rb +6 -6
  88. data/lib/mongoid/criteria.rb +1 -2
  89. data/lib/mongoid/criteria/includable.rb +14 -14
  90. data/lib/mongoid/criteria/modifiable.rb +8 -14
  91. data/lib/mongoid/criteria/queryable/mergeable.rb +1 -3
  92. data/lib/mongoid/criteria/queryable/pipeline.rb +10 -5
  93. data/lib/mongoid/criteria/queryable/selectable.rb +10 -34
  94. data/lib/mongoid/document.rb +6 -6
  95. data/lib/mongoid/errors.rb +3 -1
  96. data/lib/mongoid/errors/invalid_dependent_strategy.rb +32 -0
  97. data/lib/mongoid/errors/invalid_relation_option.rb +29 -0
  98. data/lib/mongoid/errors/unknown_model.rb +25 -0
  99. data/lib/mongoid/extensions/array.rb +5 -5
  100. data/lib/mongoid/extensions/big_decimal.rb +1 -1
  101. data/lib/mongoid/extensions/object.rb +4 -4
  102. data/lib/mongoid/extensions/range.rb +1 -0
  103. data/lib/mongoid/extensions/regexp.rb +0 -1
  104. data/lib/mongoid/extensions/string.rb +1 -3
  105. data/lib/mongoid/factory.rb +4 -3
  106. data/lib/mongoid/fields.rb +1 -1
  107. data/lib/mongoid/fields/foreign_key.rb +5 -5
  108. data/lib/mongoid/fields/standard.rb +2 -14
  109. data/lib/mongoid/fields/validators/macro.rb +1 -1
  110. data/lib/mongoid/indexable.rb +8 -5
  111. data/lib/mongoid/interceptable.rb +5 -5
  112. data/lib/mongoid/matchable.rb +0 -3
  113. data/lib/mongoid/persistable.rb +4 -5
  114. data/lib/mongoid/persistable/creatable.rb +2 -4
  115. data/lib/mongoid/persistable/deletable.rb +9 -10
  116. data/lib/mongoid/persistable/destroyable.rb +5 -1
  117. data/lib/mongoid/persistable/incrementable.rb +1 -1
  118. data/lib/mongoid/persistable/logical.rb +1 -1
  119. data/lib/mongoid/persistable/settable.rb +5 -5
  120. data/lib/mongoid/persistable/updatable.rb +2 -2
  121. data/lib/mongoid/persistable/upsertable.rb +1 -2
  122. data/lib/mongoid/persistence_context.rb +4 -9
  123. data/lib/mongoid/query_cache.rb +18 -65
  124. data/lib/mongoid/railtie.rb +0 -17
  125. data/lib/mongoid/reloadable.rb +1 -1
  126. data/lib/mongoid/scopable.rb +3 -3
  127. data/lib/mongoid/serializable.rb +3 -3
  128. data/lib/mongoid/tasks/database.rb +2 -3
  129. data/lib/mongoid/threaded.rb +0 -74
  130. data/lib/mongoid/traversable.rb +2 -2
  131. data/lib/mongoid/validatable.rb +8 -8
  132. data/lib/mongoid/validatable/presence.rb +2 -2
  133. data/lib/mongoid/validatable/uniqueness.rb +4 -4
  134. data/lib/mongoid/version.rb +1 -1
  135. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +3 -4
  136. data/spec/app/models/animal.rb +2 -1
  137. data/spec/app/models/band.rb +0 -1
  138. data/spec/app/models/bomb.rb +1 -1
  139. data/spec/app/models/message.rb +1 -1
  140. data/spec/app/models/person.rb +5 -2
  141. data/spec/app/models/vertex.rb +6 -0
  142. data/spec/app/models/wiki_page.rb +1 -1
  143. data/spec/config/mongoid.yml +1 -0
  144. data/spec/mongoid/{relations → association}/accessors_spec.rb +1 -1
  145. data/spec/mongoid/{relations → association}/auto_save_spec.rb +60 -12
  146. data/spec/mongoid/{relations → association}/builders_spec.rb +1 -1
  147. data/spec/mongoid/association/constrainable_spec.rb +115 -0
  148. data/spec/mongoid/{relations → association}/counter_cache_spec.rb +1 -1
  149. data/spec/mongoid/association/depending_spec.rb +613 -0
  150. data/spec/mongoid/{relations → association}/eager_spec.rb +12 -12
  151. data/spec/mongoid/{relations → association/embedded}/cyclic_spec.rb +1 -1
  152. data/spec/mongoid/{relations → association}/embedded/dirty_spec.rb +0 -0
  153. data/spec/mongoid/{relations/bindings/embedded/in_spec.rb → association/embedded/embedded_in/binding_spec.rb} +13 -13
  154. data/spec/mongoid/{relations/builders/embedded/in_spec.rb → association/embedded/embedded_in/buildable_spec.rb} +9 -9
  155. data/spec/mongoid/{relations/embedded/in_spec.rb → association/embedded/embedded_in/proxy_spec.rb} +5 -77
  156. data/spec/mongoid/association/embedded/embedded_in_spec.rb +843 -0
  157. data/spec/mongoid/{relations/bindings/embedded/many_spec.rb → association/embedded/embeds_many/binding_spec.rb} +3 -3
  158. data/spec/mongoid/{relations/builders/embedded/many_spec.rb → association/embedded/embeds_many/buildable_spec.rb} +17 -45
  159. data/spec/mongoid/{relations/embedded/many_spec.rb → association/embedded/embeds_many/proxy_spec.rb} +140 -428
  160. data/spec/mongoid/association/embedded/embeds_many_spec.rb +852 -0
  161. data/spec/mongoid/{relations/bindings/embedded/one_spec.rb → association/embedded/embeds_one/binding_spec.rb} +4 -4
  162. data/spec/mongoid/{relations/builders/embedded/one_spec.rb → association/embedded/embeds_one/buildable_spec.rb} +14 -34
  163. data/spec/mongoid/{relations/embedded/one_spec.rb → association/embedded/embeds_one/proxy_spec.rb} +39 -84
  164. data/spec/mongoid/association/embedded/embeds_one_spec.rb +908 -0
  165. data/spec/mongoid/{relations → association}/macros_spec.rb +148 -93
  166. data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/many_spec.rb +16 -19
  167. data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/one_spec.rb +17 -20
  168. data/spec/mongoid/association/options_spec.rb +1321 -0
  169. data/spec/mongoid/{relations → association}/polymorphic_spec.rb +7 -34
  170. data/spec/mongoid/{relations/bindings/referenced/in_spec.rb → association/referenced/belongs_to/binding_spec.rb} +7 -7
  171. data/spec/mongoid/{relations/builders/referenced/in_spec.rb → association/referenced/belongs_to/buildable_spec.rb} +46 -79
  172. data/spec/mongoid/{relations/eager/belongs_to_spec.rb → association/referenced/belongs_to/eager_spec.rb} +9 -9
  173. data/spec/mongoid/{relations/referenced/in_spec.rb → association/referenced/belongs_to/proxy_spec.rb} +57 -91
  174. data/spec/mongoid/association/referenced/belongs_to_spec.rb +1963 -0
  175. data/spec/mongoid/{relations/bindings/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/binding_spec.rb} +5 -5
  176. data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +121 -0
  177. data/spec/mongoid/{relations/eager/has_and_belongs_to_many_spec.rb → association/referenced/has_and_belongs_to_many/eager_spec.rb} +5 -5
  178. data/spec/mongoid/{relations/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/proxy_spec.rb} +107 -98
  179. data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +1027 -0
  180. data/spec/mongoid/{relations/bindings/referenced/many_spec.rb → association/referenced/has_many/binding_spec.rb} +5 -5
  181. data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +119 -0
  182. data/spec/mongoid/{relations/eager/has_many_spec.rb → association/referenced/has_many/eager_spec.rb} +11 -11
  183. data/spec/mongoid/{relations/targets → association/referenced/has_many}/enumerable_spec.rb +1 -109
  184. data/spec/mongoid/{relations/referenced/many_spec.rb → association/referenced/has_many/proxy_spec.rb} +28 -93
  185. data/spec/mongoid/association/referenced/has_many_spec.rb +1225 -0
  186. data/spec/mongoid/{relations/bindings/referenced/one_spec.rb → association/referenced/has_one/binding_spec.rb} +4 -4
  187. data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +113 -0
  188. data/spec/mongoid/{relations/eager/has_one_spec.rb → association/referenced/has_one/eager_spec.rb} +10 -10
  189. data/spec/mongoid/{relations/referenced/one_spec.rb → association/referenced/has_one/proxy_spec.rb} +9 -109
  190. data/spec/mongoid/association/referenced/has_one_spec.rb +1244 -0
  191. data/spec/mongoid/{relations → association}/reflections_spec.rb +1 -12
  192. data/spec/mongoid/{relations/synchronization_spec.rb → association/syncable_spec.rb} +4 -2
  193. data/spec/mongoid/{relations → association}/touchable_spec.rb +19 -1
  194. data/spec/mongoid/{relations_spec.rb → association_spec.rb} +1 -1
  195. data/spec/mongoid/atomic/modifiers_spec.rb +17 -17
  196. data/spec/mongoid/atomic_spec.rb +17 -17
  197. data/spec/mongoid/attributes/nested_spec.rb +14 -12
  198. data/spec/mongoid/attributes/readonly_spec.rb +80 -125
  199. data/spec/mongoid/clients/factory_spec.rb +28 -52
  200. data/spec/mongoid/clients/options_spec.rb +65 -69
  201. data/spec/mongoid/config_spec.rb +24 -0
  202. data/spec/mongoid/contextual/geo_near_spec.rb +0 -1
  203. data/spec/mongoid/contextual/mongo_spec.rb +4 -112
  204. data/spec/mongoid/criteria/modifiable_spec.rb +183 -60
  205. data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +3 -3
  206. data/spec/mongoid/criteria/queryable/pipeline_spec.rb +12 -0
  207. data/spec/mongoid/criteria/queryable/selectable_spec.rb +6 -74
  208. data/spec/mongoid/criteria/queryable/selector_spec.rb +2 -2
  209. data/spec/mongoid/criteria/scopable_spec.rb +0 -81
  210. data/spec/mongoid/criteria_spec.rb +16 -19
  211. data/spec/mongoid/document_spec.rb +2 -56
  212. data/spec/mongoid/extensions/array_spec.rb +11 -15
  213. data/spec/mongoid/extensions/big_decimal_spec.rb +9 -9
  214. data/spec/mongoid/extensions/object_spec.rb +7 -11
  215. data/spec/mongoid/extensions/range_spec.rb +7 -0
  216. data/spec/mongoid/extensions/regexp_spec.rb +0 -23
  217. data/spec/mongoid/extensions/string_spec.rb +7 -35
  218. data/spec/mongoid/factory_spec.rb +18 -11
  219. data/spec/mongoid/fields/foreign_key_spec.rb +24 -32
  220. data/spec/mongoid/fields_spec.rb +2 -2
  221. data/spec/mongoid/findable_spec.rb +1 -1
  222. data/spec/mongoid/indexable_spec.rb +18 -8
  223. data/spec/mongoid/interceptable_spec.rb +21 -2
  224. data/spec/mongoid/matchable_spec.rb +1 -26
  225. data/spec/mongoid/persistable/deletable_spec.rb +0 -19
  226. data/spec/mongoid/persistable/destroyable_spec.rb +0 -19
  227. data/spec/mongoid/persistable/incrementable_spec.rb +6 -6
  228. data/spec/mongoid/persistable/savable_spec.rb +3 -3
  229. data/spec/mongoid/persistable/settable_spec.rb +1 -35
  230. data/spec/mongoid/persistable/updatable_spec.rb +2 -2
  231. data/spec/mongoid/persistable_spec.rb +16 -16
  232. data/spec/mongoid/persistence_context_spec.rb +0 -14
  233. data/spec/mongoid/positional_spec.rb +10 -10
  234. data/spec/mongoid/query_cache_spec.rb +18 -87
  235. data/spec/mongoid/relations/proxy_spec.rb +124 -124
  236. data/spec/mongoid/scopable_spec.rb +0 -13
  237. data/spec/mongoid/threaded_spec.rb +0 -68
  238. data/spec/mongoid/validatable/associated_spec.rb +1 -1
  239. data/spec/mongoid/validatable/presence_spec.rb +7 -6
  240. data/spec/mongoid/validatable_spec.rb +1 -1
  241. data/spec/spec_helper.rb +7 -83
  242. metadata +586 -611
  243. metadata.gz.sig +2 -5
  244. data/lib/mongoid/clients/sessions.rb +0 -113
  245. data/lib/mongoid/errors/invalid_session_use.rb +0 -24
  246. data/lib/mongoid/matchable/nor.rb +0 -37
  247. data/lib/mongoid/railties/controller_runtime.rb +0 -86
  248. data/lib/mongoid/relations.rb +0 -148
  249. data/lib/mongoid/relations/accessors.rb +0 -267
  250. data/lib/mongoid/relations/auto_save.rb +0 -94
  251. data/lib/mongoid/relations/bindings.rb +0 -9
  252. data/lib/mongoid/relations/bindings/embedded/in.rb +0 -59
  253. data/lib/mongoid/relations/bindings/referenced/in.rb +0 -65
  254. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +0 -70
  255. data/lib/mongoid/relations/builder.rb +0 -57
  256. data/lib/mongoid/relations/builders.rb +0 -106
  257. data/lib/mongoid/relations/builders/nested_attributes/many.rb +0 -199
  258. data/lib/mongoid/relations/builders/referenced/in.rb +0 -26
  259. data/lib/mongoid/relations/builders/referenced/many.rb +0 -26
  260. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +0 -39
  261. data/lib/mongoid/relations/builders/referenced/one.rb +0 -26
  262. data/lib/mongoid/relations/cascading.rb +0 -56
  263. data/lib/mongoid/relations/cascading/delete.rb +0 -44
  264. data/lib/mongoid/relations/cascading/destroy.rb +0 -43
  265. data/lib/mongoid/relations/cascading/nullify.rb +0 -35
  266. data/lib/mongoid/relations/cascading/restrict.rb +0 -39
  267. data/lib/mongoid/relations/conversions.rb +0 -34
  268. data/lib/mongoid/relations/counter_cache.rb +0 -160
  269. data/lib/mongoid/relations/cyclic.rb +0 -107
  270. data/lib/mongoid/relations/eager/base.rb +0 -153
  271. data/lib/mongoid/relations/eager/belongs_to.rb +0 -31
  272. data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +0 -47
  273. data/lib/mongoid/relations/eager/has_many.rb +0 -38
  274. data/lib/mongoid/relations/eager/has_one.rb +0 -30
  275. data/lib/mongoid/relations/embedded/in.rb +0 -241
  276. data/lib/mongoid/relations/embedded/many.rb +0 -683
  277. data/lib/mongoid/relations/embedded/one.rb +0 -235
  278. data/lib/mongoid/relations/macros.rb +0 -367
  279. data/lib/mongoid/relations/metadata.rb +0 -1179
  280. data/lib/mongoid/relations/nested_builder.rb +0 -74
  281. data/lib/mongoid/relations/options.rb +0 -49
  282. data/lib/mongoid/relations/polymorphic.rb +0 -39
  283. data/lib/mongoid/relations/referenced/in.rb +0 -304
  284. data/lib/mongoid/relations/referenced/many.rb +0 -812
  285. data/lib/mongoid/relations/referenced/many_to_many.rb +0 -479
  286. data/lib/mongoid/relations/referenced/one.rb +0 -290
  287. data/lib/mongoid/relations/synchronization.rb +0 -169
  288. data/lib/mongoid/relations/targets.rb +0 -2
  289. data/lib/mongoid/relations/targets/enumerable.rb +0 -493
  290. data/lib/mongoid/relations/touchable.rb +0 -97
  291. data/spec/app/models/array_field.rb +0 -7
  292. data/spec/app/models/delegating_patient.rb +0 -16
  293. data/spec/integration/document_spec.rb +0 -22
  294. data/spec/mongoid/clients/sessions_spec.rb +0 -334
  295. data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +0 -184
  296. data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +0 -201
  297. data/spec/mongoid/matchable/nor_spec.rb +0 -209
  298. data/spec/mongoid/relations/builders/referenced/many_spec.rb +0 -137
  299. data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +0 -178
  300. data/spec/mongoid/relations/builders/referenced/one_spec.rb +0 -111
  301. data/spec/mongoid/relations/cascading/delete_spec.rb +0 -101
  302. data/spec/mongoid/relations/cascading/destroy_spec.rb +0 -47
  303. data/spec/mongoid/relations/cascading/nullify_spec.rb +0 -32
  304. data/spec/mongoid/relations/cascading/restrict_spec.rb +0 -68
  305. data/spec/mongoid/relations/cascading_spec.rb +0 -355
  306. data/spec/mongoid/relations/constraint_spec.rb +0 -75
  307. data/spec/mongoid/relations/conversions_spec.rb +0 -128
  308. data/spec/mongoid/relations/metadata_spec.rb +0 -1985
  309. data/spec/mongoid/relations/options_spec.rb +0 -35
  310. data/spec/rails/controller_extension/controller_runtime_spec.rb +0 -110
  311. data/spec/support/cluster_config.rb +0 -158
  312. data/spec/support/constraints.rb +0 -101
  313. data/spec/support/macros.rb +0 -20
  314. data/spec/support/session_registry.rb +0 -50
  315. data/spec/support/spec_config.rb +0 -42
@@ -7,7 +7,7 @@ describe BigDecimal do
7
7
  context "when provided a big decimal" do
8
8
 
9
9
  let(:big_decimal) do
10
- BigDecimal("123456.789")
10
+ BigDecimal.new("123456.789")
11
11
  end
12
12
 
13
13
  it "returns the decimal as a string" do
@@ -25,11 +25,11 @@ describe BigDecimal do
25
25
  context "when provided an array of big decimals" do
26
26
 
27
27
  let(:bd_one) do
28
- BigDecimal("123456.789")
28
+ BigDecimal.new("123456.789")
29
29
  end
30
30
 
31
31
  let(:bd_two) do
32
- BigDecimal("123333.789")
32
+ BigDecimal.new("123333.789")
33
33
  end
34
34
 
35
35
  let(:array) do
@@ -196,5 +196,17 @@ describe Mongoid::Criteria::Queryable::Pipeline do
196
196
  end
197
197
  end
198
198
  end
199
+
200
+ context "when provided a hash" do
201
+ before do
202
+ pipeline.unwind(path: "$author", "includeArrayIndex" => "author_index", preserveNullAndEmptyArrays: true)
203
+ end
204
+
205
+ it "sets the hash" do
206
+ expect(pipeline).to eq([
207
+ { "$unwind" => { path: "$author", "includeArrayIndex" => "author_index", preserveNullAndEmptyArrays: true } }
208
+ ])
209
+ end
210
+ end
199
211
  end
200
212
  end
@@ -1073,26 +1073,6 @@ describe Mongoid::Criteria::Queryable::Selectable do
1073
1073
  })
1074
1074
  end
1075
1075
 
1076
- context "when used with the $box operator ($geoWithin query) " do
1077
- let(:selection) do
1078
- query.geo_spacial(
1079
- :location.within_box => [[ 1, 10 ], [ 2, 10 ]]
1080
- )
1081
- end
1082
-
1083
- it "adds the $geoIntersects expression" do
1084
- expect(selection.selector).to eq({
1085
- "location" => {
1086
- "$geoWithin" => {
1087
- "$box" => [
1088
- [ 1, 10 ], [ 2, 10 ]
1089
- ]
1090
- }
1091
- }
1092
- })
1093
- end
1094
- end
1095
-
1096
1076
  it_behaves_like "a cloning selection"
1097
1077
  end
1098
1078
  end
@@ -1469,7 +1449,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
1469
1449
 
1470
1450
  context "when the criterion are on the same field" do
1471
1451
 
1472
- context "when the strategy is the default (intersection)" do
1452
+ context "when the stretegy is the default (intersection)" do
1473
1453
 
1474
1454
  let(:selection) do
1475
1455
  query.in(first: [ 1, 2 ].freeze).in(first: [ 2, 3 ])
@@ -1486,35 +1466,6 @@ describe Mongoid::Criteria::Queryable::Selectable do
1486
1466
  end
1487
1467
  end
1488
1468
 
1489
- context 'when the field is aliased' do
1490
-
1491
- before(:all) do
1492
- class TestModel
1493
- include Mongoid::Document
1494
- end
1495
- end
1496
-
1497
- after(:all) do
1498
- Object.send(:remove_const, :TestModel)
1499
- end
1500
-
1501
- let(:bson_object_id) do
1502
- BSON::ObjectId.new
1503
- end
1504
-
1505
- let(:selection) do
1506
- TestModel.in(id: [bson_object_id.to_s]).in(id: [bson_object_id.to_s])
1507
- end
1508
-
1509
- it "intersects the $in selectors" do
1510
- expect(selection.selector).to eq("_id" => { "$in" => [ bson_object_id ] })
1511
- end
1512
-
1513
- it "returns a cloned query" do
1514
- expect(selection).to_not equal(query)
1515
- end
1516
- end
1517
-
1518
1469
  context "when the stretegy is intersect" do
1519
1470
 
1520
1471
  let(:selection) do
@@ -1532,7 +1483,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
1532
1483
  end
1533
1484
  end
1534
1485
 
1535
- context "when the strategy is override" do
1486
+ context "when the stretegy is override" do
1536
1487
 
1537
1488
  let(:selection) do
1538
1489
  query.in(first: [ 1, 2 ]).override.in(first: [ 3, 4 ])
@@ -1549,7 +1500,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
1549
1500
  end
1550
1501
  end
1551
1502
 
1552
- context "when the strategy is union" do
1503
+ context "when the stretegy is union" do
1553
1504
 
1554
1505
  let(:selection) do
1555
1506
  query.in(first: [ 1, 2 ]).union.in(first: [ 3, 4 ])
@@ -3389,7 +3340,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
3389
3340
  end
3390
3341
 
3391
3342
  it "constructs a text search document" do
3392
- expect(selection.selector).to eq({ '$text' => { '$search' => "testing" }})
3343
+ expect(selection.selector).to eq({ :$text => { :$search => "testing" }})
3393
3344
  end
3394
3345
 
3395
3346
  it "returns the cloned selectable" do
@@ -3403,35 +3354,16 @@ describe Mongoid::Criteria::Queryable::Selectable do
3403
3354
  end
3404
3355
 
3405
3356
  it "constructs a text search document" do
3406
- expect(selection.selector['$text']['$search']).to eq("essais")
3357
+ expect(selection.selector[:$text][:$search]).to eq("essais")
3407
3358
  end
3408
3359
 
3409
3360
  it "add the options to the text search document" do
3410
- expect(selection.selector['$text'][:$language]).to eq("fr")
3361
+ expect(selection.selector[:$text][:$language]).to eq("fr")
3411
3362
  end
3412
3363
 
3413
3364
  it_behaves_like "a cloning selection"
3414
3365
  end
3415
3366
  end
3416
-
3417
- context 'when given more than once' do
3418
- let(:selection) do
3419
- query.text_search("one").text_search('two')
3420
- end
3421
-
3422
- # MongoDB server can only handle one text expression at a time,
3423
- # per https://docs.mongodb.com/manual/reference/operator/query/text/.
3424
- # Nonetheless we test that the query is built correctly when
3425
- # a user supplies more than one text condition.
3426
- it 'merges conditions' do
3427
- expect(Mongoid.logger).to receive(:warn)
3428
- expect(selection.selector).to eq('$and' => [
3429
- {'$text' => {'$search' => 'one'}}
3430
- ],
3431
- '$text' => {'$search' => 'two'},
3432
- )
3433
- end
3434
- end
3435
3367
  end
3436
3368
 
3437
3369
  describe "#where" do
@@ -370,11 +370,11 @@ describe Mongoid::Criteria::Queryable::Selector do
370
370
  context "when providing an array" do
371
371
 
372
372
  let(:big_one) do
373
- BigDecimal("1.2321")
373
+ BigDecimal.new("1.2321")
374
374
  end
375
375
 
376
376
  let(:big_two) do
377
- BigDecimal("4.2222")
377
+ BigDecimal.new("4.2222")
378
378
  end
379
379
 
380
380
  let(:array) do
@@ -388,85 +388,4 @@ describe Mongoid::Criteria::Scopable do
388
388
  end
389
389
  end
390
390
  end
391
-
392
- describe 'scope and where' do
393
- class ScopeWhereModel
394
- include Mongoid::Document
395
-
396
- scope :foo, -> { where(foo: true) }
397
- end
398
-
399
- shared_examples_for 'restricts to both' do
400
- it 'restricts to both' do
401
- expect(result.selector['foo']).to eq(true)
402
- expect(result.selector['hello']).to eq('world')
403
- end
404
- end
405
-
406
- context 'scope is given first' do
407
- let(:result) { ScopeWhereModel.foo.where(hello: 'world') }
408
-
409
- it_behaves_like 'restricts to both'
410
- end
411
-
412
- context 'where is given first' do
413
- let(:result) { ScopeWhereModel.where(hello: 'world').foo }
414
-
415
- it_behaves_like 'restricts to both'
416
- end
417
- end
418
-
419
- describe 'scope with argument and where' do
420
- class ArgumentScopeWhereModel
421
- include Mongoid::Document
422
-
423
- scope :my_text_search, ->(search) { where('$text' => {'$search' => search}) }
424
- end
425
-
426
- shared_examples_for 'restricts to both' do
427
- it 'restricts to both' do
428
- expect(result.selector['$text']).to eq({'$search' => 'bar'})
429
- expect(result.selector['hello']).to eq('world')
430
- end
431
- end
432
-
433
- context 'scope is given first' do
434
- let(:result) { ArgumentScopeWhereModel.my_text_search('bar').where(hello: 'world') }
435
-
436
- it_behaves_like 'restricts to both'
437
- end
438
-
439
- context 'where is given first' do
440
- let(:result) { ArgumentScopeWhereModel.where(hello: 'world').my_text_search('bar') }
441
-
442
- it_behaves_like 'restricts to both'
443
- end
444
- end
445
-
446
- describe 'built in text search scope and where' do
447
- class TextSearchScopeWhereModel
448
- include Mongoid::Document
449
-
450
- # using the default text_search scope
451
- end
452
-
453
- shared_examples_for 'restricts to both' do
454
- it 'restricts to both' do
455
- expect(result.selector['$text']).to eq({'$search' => 'bar'})
456
- expect(result.selector['hello']).to eq('world')
457
- end
458
- end
459
-
460
- context 'scope is given first' do
461
- let(:result) { TextSearchScopeWhereModel.text_search('bar').where(hello: 'world') }
462
-
463
- it_behaves_like 'restricts to both'
464
- end
465
-
466
- context 'where is given first' do
467
- let(:result) { TextSearchScopeWhereModel.where(hello: 'world').text_search('bar') }
468
-
469
- it_behaves_like 'restricts to both'
470
- end
471
- end
472
391
  end
@@ -975,7 +975,6 @@ describe Mongoid::Criteria do
975
975
  end
976
976
 
977
977
  describe "#geo_near" do
978
- max_server_version '4.0'
979
978
 
980
979
  before do
981
980
  Bar.create_indexes
@@ -1445,18 +1444,18 @@ describe Mongoid::Criteria do
1445
1444
  end
1446
1445
  end
1447
1446
 
1448
- context "when including the same metadata multiple times" do
1447
+ context "when including the same association multiple times" do
1449
1448
 
1450
1449
  let(:criteria) do
1451
1450
  Person.all.includes(:posts, :posts).includes(:posts)
1452
1451
  end
1453
1452
 
1454
- let(:metadata) do
1453
+ let(:association) do
1455
1454
  Person.reflect_on_association(:posts)
1456
1455
  end
1457
1456
 
1458
- it "does not duplicate the metadata in the inclusions" do
1459
- expect(criteria.inclusions).to eq([ metadata ])
1457
+ it "does not duplicate the association in the inclusions" do
1458
+ expect(criteria.inclusions).to eq([ association ])
1460
1459
  end
1461
1460
  end
1462
1461
 
@@ -2218,12 +2217,12 @@ describe Mongoid::Criteria do
2218
2217
  Band.includes(:records)
2219
2218
  end
2220
2219
 
2221
- let(:metadata) do
2220
+ let(:association) do
2222
2221
  Band.relations["records"]
2223
2222
  end
2224
2223
 
2225
2224
  it "returns the inclusions" do
2226
- expect(criteria.inclusions).to eq([ metadata ])
2225
+ expect(criteria.inclusions).to eq([ association ])
2227
2226
  end
2228
2227
  end
2229
2228
 
@@ -2233,16 +2232,16 @@ describe Mongoid::Criteria do
2233
2232
  Band.all
2234
2233
  end
2235
2234
 
2236
- let(:metadata) do
2235
+ let(:association) do
2237
2236
  Band.relations["records"]
2238
2237
  end
2239
2238
 
2240
2239
  before do
2241
- criteria.inclusions = [ metadata ]
2240
+ criteria.inclusions = [ association ]
2242
2241
  end
2243
2242
 
2244
2243
  it "sets the inclusions" do
2245
- expect(criteria.inclusions).to eq([ metadata ])
2244
+ expect(criteria.inclusions).to eq([ association ])
2246
2245
  end
2247
2246
  end
2248
2247
 
@@ -2410,7 +2409,7 @@ describe Mongoid::Criteria do
2410
2409
  end
2411
2410
  end
2412
2411
 
2413
- let(:metadata) do
2412
+ let(:association) do
2414
2413
  Band.relations["records"]
2415
2414
  end
2416
2415
 
@@ -2435,7 +2434,7 @@ describe Mongoid::Criteria do
2435
2434
  end
2436
2435
 
2437
2436
  it "merges the inclusions" do
2438
- expect(merged.inclusions).to eq([ metadata ])
2437
+ expect(merged.inclusions).to eq([ association ])
2439
2438
  end
2440
2439
 
2441
2440
  it "returns a new criteria" do
@@ -2449,7 +2448,7 @@ describe Mongoid::Criteria do
2449
2448
  { klass: Band, includes: [ :records ] }
2450
2449
  end
2451
2450
 
2452
- let(:metadata) do
2451
+ let(:association) do
2453
2452
  Band.relations["records"]
2454
2453
  end
2455
2454
 
@@ -2470,7 +2469,7 @@ describe Mongoid::Criteria do
2470
2469
  end
2471
2470
 
2472
2471
  it "merges the inclusions" do
2473
- expect(merged.inclusions).to eq([ metadata ])
2472
+ expect(merged.inclusions).to eq([ association ])
2474
2473
  end
2475
2474
 
2476
2475
  it "returns a new criteria" do
@@ -2495,7 +2494,7 @@ describe Mongoid::Criteria do
2495
2494
  end
2496
2495
  end
2497
2496
 
2498
- let(:metadata) do
2497
+ let(:association) do
2499
2498
  Band.relations["records"]
2500
2499
  end
2501
2500
 
@@ -2520,7 +2519,7 @@ describe Mongoid::Criteria do
2520
2519
  end
2521
2520
 
2522
2521
  it "merges the inclusions" do
2523
- expect(merged.inclusions).to eq([ metadata ])
2522
+ expect(merged.inclusions).to eq([ association ])
2524
2523
  end
2525
2524
 
2526
2525
  it "returns the same criteria" do
@@ -3322,8 +3321,6 @@ describe Mongoid::Criteria do
3322
3321
  end
3323
3322
 
3324
3323
  describe "#max_scan" do
3325
- max_server_version '4.0'
3326
-
3327
3324
  let!(:band) do
3328
3325
  Band.create(name: "Depeche Mode")
3329
3326
  end
@@ -3468,7 +3465,7 @@ describe Mongoid::Criteria do
3468
3465
  context "when querying on a big decimal" do
3469
3466
 
3470
3467
  let(:sales) do
3471
- BigDecimal('0.1')
3468
+ BigDecimal.new('0.1')
3472
3469
  end
3473
3470
 
3474
3471
  let!(:band) do
@@ -94,11 +94,11 @@ describe Mongoid::Document do
94
94
  context "when the document is not subclassed" do
95
95
 
96
96
  let(:types) do
97
- Address._types
97
+ Kangaroo._types
98
98
  end
99
99
 
100
100
  it "returns the document" do
101
- expect(types).to eq([ "Address" ])
101
+ expect(types).to eq([ "Kangaroo" ])
102
102
  end
103
103
  end
104
104
 
@@ -433,60 +433,6 @@ describe Mongoid::Document do
433
433
  end
434
434
  end
435
435
  end
436
-
437
- context ':compact option' do
438
-
439
- before do
440
- # These tests require a specific set of defined attributes
441
- # on the model
442
- expect(church.as_json.keys.sort).to eq(%w(_id location name))
443
- end
444
-
445
- context 'there is a nil valued attribute' do
446
- let(:church) do
447
- Church.create!(name: 'St. Basil')
448
- end
449
-
450
- it 'returns non-nil fields and _id only' do
451
- actual = church.as_json(compact: true)
452
- expect(actual).to eq('_id' => church.id, 'name' => 'St. Basil')
453
- end
454
- end
455
-
456
- context 'all attrbutes are nil valued' do
457
- let(:church) do
458
- Church.create!
459
- end
460
-
461
- it 'returns a hash with _id only' do
462
- actual = church.as_json(compact: true)
463
- expect(actual).to eq('_id' => church.id)
464
- end
465
- end
466
-
467
- context 'there are no nil valued attributes' do
468
- let(:church) do
469
- Church.create!(name: 'St. Basil', location: {})
470
- end
471
-
472
- it 'returns all fields and _id' do
473
- actual = church.as_json(compact: true)
474
- expect(actual).to eq('_id' => church.id, 'name' => 'St. Basil',
475
- 'location' => {})
476
- end
477
- end
478
-
479
- context 'when option is specified as a truthy value' do
480
- let(:church) do
481
- Church.create!(name: 'St. Basil')
482
- end
483
-
484
- it 'returns non-nil fields and _id only' do
485
- actual = church.as_json(compact: 1)
486
- expect(actual).to eq('_id' => church.id, 'name' => 'St. Basil')
487
- end
488
- end
489
- end
490
436
  end
491
437
 
492
438
  describe "#as_document" do