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
@@ -0,0 +1,852 @@
1
+ require "spec_helper"
2
+
3
+ describe Mongoid::Association::Embedded::EmbedsMany do
4
+
5
+ before do
6
+ class Container; include Mongoid::Document; end
7
+ class EmbeddedObject; include Mongoid::Document; end
8
+ end
9
+
10
+ after do
11
+ Container.relations.clear
12
+ EmbeddedObject.relations.clear
13
+ end
14
+
15
+ let(:embeds_many_class) do
16
+ Container
17
+ end
18
+
19
+ let(:name) do
20
+ :embedded_objects
21
+ end
22
+
23
+ let(:association) do
24
+ embeds_many_class.embeds_many name, options
25
+ end
26
+
27
+ let(:options) do
28
+ { }
29
+ end
30
+
31
+ describe '#relation_complements' do
32
+
33
+ let(:expected_complements) do
34
+ [
35
+ Mongoid::Association::Embedded::EmbeddedIn,
36
+ ]
37
+ end
38
+
39
+ it 'returns the relation complements' do
40
+ expect(association.send(:relation_complements)).to eq(expected_complements)
41
+ end
42
+ end
43
+
44
+ describe '#setup!' do
45
+
46
+ it 'sets up a getter for the relation' do
47
+ expect(Mongoid::Association::Accessors).to receive(:define_getter!).with(association)
48
+ association.setup!
49
+ end
50
+
51
+ it 'sets up a setter for the relation' do
52
+ expect(Mongoid::Association::Accessors).to receive(:define_setter!).with(association)
53
+ association.setup!
54
+ end
55
+
56
+ it 'sets up an existence check for the relation' do
57
+ expect(Mongoid::Association::Accessors).to receive(:define_existence_check!).with(association)
58
+ association.setup!
59
+ end
60
+
61
+ it 'sets up the builder for the relation' do
62
+ expect(Mongoid::Association::Builders).to receive(:define_builder!).with(association)
63
+ association.setup!
64
+ end
65
+
66
+ it 'sets up the creator for the relation' do
67
+ expect(Mongoid::Association::Builders).to receive(:define_creator!).with(association)
68
+ association.setup!
69
+ end
70
+
71
+ context 'when the :validate option is true' do
72
+
73
+ let(:options) do
74
+ {
75
+ validate: true
76
+ }
77
+ end
78
+
79
+ let(:association) do
80
+ # Note that it is necessary to create the association directly, otherwise the
81
+ # setup! method will be called by the :embeds_many macro
82
+ described_class.new(embeds_many_class, name, options)
83
+ end
84
+
85
+ it 'sets up validation' do
86
+ expect(embeds_many_class).to receive(:validates_associated).with(name).and_call_original
87
+ association.setup!
88
+ end
89
+ end
90
+
91
+ context 'when the :validate option is false' do
92
+
93
+ let(:options) do
94
+ {
95
+ validate: false
96
+ }
97
+ end
98
+
99
+ it 'does not set up validation' do
100
+ expect(embeds_many_class).not_to receive(:validates_associated)
101
+ association.setup!
102
+ end
103
+ end
104
+
105
+ context 'when the :validate option is not provided' do
106
+
107
+ let(:association) do
108
+ # Note that it is necessary to create the association directly, otherwise the
109
+ # setup! method will be called by the :embeds_many macro
110
+ described_class.new(embeds_many_class, name, options)
111
+ end
112
+
113
+ it 'sets up the validation because it uses the validation default (true)' do
114
+ expect(embeds_many_class).to receive(:validates_associated).with(name).and_call_original
115
+ association.setup!
116
+ end
117
+ end
118
+ end
119
+
120
+ describe '#type' do
121
+
122
+ context 'when polymorphic' do
123
+
124
+ let(:options) do
125
+ { as: :containable }
126
+ end
127
+
128
+ it 'returns the as attribute followed by "_type"' do
129
+ expect(association.type).to eq("#{options[:as]}_type")
130
+ end
131
+ end
132
+
133
+ context 'when not polymorphic' do
134
+
135
+ it 'returns nil' do
136
+ expect(association.type).to be_nil
137
+ end
138
+ end
139
+ end
140
+
141
+ describe '#inverse_type' do
142
+
143
+ context 'when polymorphic' do
144
+
145
+ let(:options) do
146
+ { as: :containable }
147
+ end
148
+
149
+ it 'returns nil' do
150
+ expect(association.inverse_type).to be_nil
151
+ end
152
+ end
153
+
154
+ context 'when not polymorphic' do
155
+
156
+ it 'returns nil' do
157
+ expect(association.inverse_type).to be_nil
158
+ end
159
+ end
160
+ end
161
+
162
+ describe '#inverse_type_setter' do
163
+
164
+ context 'when polymorphic' do
165
+
166
+ let(:options) do
167
+ { as: :containable }
168
+ end
169
+
170
+ it 'returns nil' do
171
+ expect(association.inverse_type).to be_nil
172
+ end
173
+ end
174
+
175
+ context 'when not polymorphic' do
176
+
177
+ it 'returns nil' do
178
+ expect(association.inverse_type).to be_nil
179
+ end
180
+ end
181
+ end
182
+
183
+ describe '#embedded?' do
184
+
185
+ it 'returns true' do
186
+ expect(association.embedded?).to be(true)
187
+ end
188
+ end
189
+
190
+ describe '#primary_key' do
191
+
192
+ it 'returns nil' do
193
+ expect(association.primary_key).to be_nil
194
+ end
195
+ end
196
+
197
+ describe '#indexed?' do
198
+
199
+ it 'returns false' do
200
+ expect(association.indexed?).to be(false)
201
+ end
202
+ end
203
+
204
+ describe '#relation' do
205
+
206
+ it 'returns Mongoid::Association::Embedded::EmbedsMany::Proxy' do
207
+ expect(association.relation).to be(Mongoid::Association::Embedded::EmbedsMany::Proxy)
208
+ end
209
+ end
210
+
211
+ describe '#validation_default' do
212
+
213
+ it 'returns true' do
214
+ expect(association.validation_default).to be(true)
215
+ end
216
+ end
217
+
218
+ describe '#name' do
219
+
220
+ it 'returns the name of the relation' do
221
+ expect(association.name).to be(name)
222
+ end
223
+ end
224
+
225
+ describe '#options' do
226
+
227
+ it 'returns the options' do
228
+ expect(association.options).to be(options)
229
+ end
230
+ end
231
+
232
+ describe '#cyclic?' do
233
+
234
+ context 'when :cyclic is specified in the options' do
235
+
236
+ let(:options) do
237
+ { cyclic: true }
238
+ end
239
+
240
+ it 'returns true' do
241
+ expect(association.cyclic?).to be(true)
242
+ end
243
+ end
244
+
245
+ context 'when :cyclic is not specified in the options' do
246
+
247
+ it 'returns false' do
248
+ expect(association.cyclic?).to be(false)
249
+ end
250
+ end
251
+ end
252
+
253
+ describe '#merge!' do
254
+
255
+ end
256
+
257
+ describe '#store_as' do
258
+
259
+ context 'when :store_as is specified in the options' do
260
+
261
+ let(:options) do
262
+ {
263
+ store_as: :baby_kangaroos
264
+ }
265
+ end
266
+
267
+ it 'returns the :store_as option as a String' do
268
+ expect(association.store_as).to eq(options[:store_as].to_s)
269
+ end
270
+ end
271
+
272
+ context 'when :store_as is not specified in the options' do
273
+
274
+ it 'returns name as a String' do
275
+ expect(association.store_as).to eq(name.to_s)
276
+ end
277
+ end
278
+ end
279
+
280
+ describe '#touchable?' do
281
+
282
+ it 'return false' do
283
+ expect(association.send(:touchable?)).to be(false)
284
+ end
285
+ end
286
+
287
+ describe '#order' do
288
+
289
+ context 'when order is specified in the options' do
290
+
291
+ let(:options) do
292
+ {
293
+ order: :rating.desc
294
+ }
295
+ end
296
+
297
+ it 'returns a Criteria Queryable Key' do
298
+ expect(association.order).to be_a(Mongoid::Criteria::Queryable::Key)
299
+ end
300
+ end
301
+
302
+ context 'when order is not specified in the options' do
303
+
304
+ it 'returns nil' do
305
+ expect(association.order).to be_nil
306
+ end
307
+ end
308
+ end
309
+
310
+ describe '#as' do
311
+
312
+ context 'when :as is specified in the options' do
313
+
314
+ let(:options) do
315
+ {
316
+ as: :containable
317
+ }
318
+ end
319
+
320
+ it 'returns the :as option' do
321
+ expect(association.as).to eq(options[:as])
322
+ end
323
+ end
324
+
325
+ context 'when :as is not specified in the options' do
326
+
327
+ it 'returns nil' do
328
+ expect(association.as).to be_nil
329
+ end
330
+ end
331
+ end
332
+
333
+ describe '#polymorphic?' do
334
+
335
+ context 'when :as is specified in the options' do
336
+
337
+ let(:options) do
338
+ {
339
+ as: :containable
340
+ }
341
+ end
342
+
343
+ it 'returns true' do
344
+ expect(association.polymorphic?).to be(true)
345
+ end
346
+
347
+ end
348
+
349
+ context 'when :as is not specified in the options' do
350
+
351
+ it 'returns false' do
352
+ expect(association.polymorphic?).to be(false)
353
+ end
354
+ end
355
+ end
356
+
357
+ describe '#type_setter' do
358
+
359
+ context 'when polymorphic' do
360
+
361
+ let(:options) do
362
+ { as: :containable }
363
+ end
364
+
365
+ it 'returns the type followed by = as a String' do
366
+ expect(association.type_setter).to eq("containable_type=")
367
+ end
368
+ end
369
+
370
+ context 'when not polymorphic' do
371
+
372
+ it 'returns nil' do
373
+ expect(association.type).to be_nil
374
+ end
375
+ end
376
+ end
377
+
378
+ describe '#dependent' do
379
+
380
+ it 'returns nil' do
381
+ expect(association.dependent).to be_nil
382
+ end
383
+ end
384
+
385
+ describe '#inverse_type' do
386
+
387
+ it 'returns nil' do
388
+ expect(association.inverse_type).to be_nil
389
+ end
390
+ end
391
+
392
+ describe '#bindable?' do
393
+
394
+ it 'returns false' do
395
+ expect(association.bindable?(Person.new)).to be(false)
396
+ end
397
+ end
398
+
399
+ describe '#inverses' do
400
+
401
+ context 'when polymorphic' do
402
+
403
+ before do
404
+ EmbeddedObject.embedded_in :containable, polymorphic: true
405
+ end
406
+
407
+ let(:options) do
408
+ {
409
+ as: :containable
410
+ }
411
+ end
412
+
413
+ context 'when another object is passed to the method' do
414
+
415
+ let(:instance_of_other_class) do
416
+ EmbeddedObject.new
417
+ end
418
+
419
+ context 'when the relation class has only one relation whose class matches the owning class' do
420
+
421
+ it 'returns the :as attribute of this association' do
422
+ expect(association.inverses(instance_of_other_class)).to match_array([ :containable ])
423
+ end
424
+ end
425
+
426
+ context 'when :inverse_of is specified' do
427
+
428
+ before do
429
+ options.merge!(inverse_of: :inverse_name)
430
+ end
431
+
432
+ it 'returns the :inverse_of value' do
433
+ expect(association.inverses(instance_of_other_class)).to eq([ :inverse_name ])
434
+ end
435
+ end
436
+
437
+ context 'when inverse_of is not specified' do
438
+
439
+ it 'returns the :as attribute of this association' do
440
+ expect(association.inverses(instance_of_other_class)).to match_array([ :containable ])
441
+ end
442
+ end
443
+ end
444
+
445
+ context 'when another object is not passed to the method' do
446
+
447
+ context 'when inverse_of is specified' do
448
+
449
+ before do
450
+ options.merge!(inverse_of: :inverse_name)
451
+ end
452
+
453
+ it 'returns the :inverse_of value' do
454
+ expect(association.inverses).to eq([ :inverse_name ])
455
+ end
456
+ end
457
+
458
+ context 'when inverse_of is not specified' do
459
+
460
+ it 'returns the :as attribute' do
461
+ expect(association.inverses).to eq([ :containable ])
462
+ end
463
+ end
464
+ end
465
+ end
466
+
467
+ context 'when not polymorphic' do
468
+
469
+ before do
470
+ EmbeddedObject.embedded_in :container
471
+ end
472
+
473
+ context 'when inverse_of is specified' do
474
+
475
+ before do
476
+ options.merge!(inverse_of: :inverse_name)
477
+ end
478
+
479
+ it 'returns the :inverse_of value' do
480
+ expect(association.inverses).to eq([ :inverse_name ])
481
+ end
482
+ end
483
+
484
+ context 'when inverse_of is not specified' do
485
+
486
+ it 'uses the inverse class to find the inverse name' do
487
+ expect(association.inverses).to eq([ :container ])
488
+ end
489
+ end
490
+
491
+ context 'when :cyclic is specified' do
492
+
493
+ it 'returns the cyclic inverse name' do
494
+
495
+ end
496
+ end
497
+ end
498
+ end
499
+
500
+ describe '##inverse' do
501
+
502
+ context 'when polymorphic' do
503
+
504
+ before do
505
+ EmbeddedObject.embedded_in :containable, polymorphic: true
506
+ end
507
+
508
+ let(:options) do
509
+ {
510
+ as: :containable
511
+ }
512
+ end
513
+
514
+ context 'when another object is passed to the method' do
515
+
516
+ let(:instance_of_other_class) do
517
+ EmbeddedObject.new
518
+ end
519
+
520
+ context 'when the relation class has only one relation whose class matches the owning class' do
521
+
522
+ it 'returns the :as attribute of this association' do
523
+ expect(association.inverse(instance_of_other_class)).to eq(:containable)
524
+ end
525
+ end
526
+
527
+ context 'when :inverse_of is specified' do
528
+
529
+ before do
530
+ options.merge!(inverse_of: :inverse_name)
531
+ end
532
+
533
+ it 'returns the :inverse_of value' do
534
+ expect(association.inverse(instance_of_other_class)).to eq(:inverse_name)
535
+ end
536
+ end
537
+
538
+ context 'when inverse_of is not specified' do
539
+
540
+ it 'returns the :as attribute of this association' do
541
+ expect(association.inverse(instance_of_other_class)).to eq(:containable)
542
+ end
543
+ end
544
+ end
545
+
546
+ context 'when another object is not passed to the method' do
547
+
548
+ context 'when inverse_of is specified' do
549
+
550
+ before do
551
+ options.merge!(inverse_of: :inverse_name)
552
+ end
553
+
554
+ it 'returns the :inverse_of value' do
555
+ expect(association.inverse).to eq(:inverse_name)
556
+ end
557
+ end
558
+
559
+ context 'when inverse_of is not specified' do
560
+
561
+ it 'returns the :as attribute' do
562
+ expect(association.inverse).to eq(:containable)
563
+ end
564
+ end
565
+ end
566
+ end
567
+
568
+ context 'when not polymorphic' do
569
+
570
+ before do
571
+ EmbeddedObject.embedded_in :container
572
+ end
573
+
574
+ context 'when inverse_of is specified' do
575
+
576
+ before do
577
+ options.merge!(inverse_of: :inverse_name)
578
+ end
579
+
580
+ it 'returns the :inverse_of value' do
581
+ expect(association.inverse).to eq(:inverse_name)
582
+ end
583
+ end
584
+
585
+ context 'when inverse_of is not specified' do
586
+
587
+ it 'uses the inverse class to find the inverse name' do
588
+ expect(association.inverse).to eq(:container)
589
+ end
590
+ end
591
+
592
+ context 'when :cyclic is specified' do
593
+
594
+ it 'returns the cyclic inverse name' do
595
+
596
+ end
597
+ end
598
+ end
599
+ end
600
+
601
+ describe '#inverse_association' do
602
+
603
+ end
604
+
605
+ describe '#autosave' do
606
+
607
+ it 'returns false' do
608
+ expect(association.autosave).to be(false)
609
+ end
610
+ end
611
+
612
+ describe '#relation_class_name' do
613
+
614
+ context 'when the :class_name option is specified' do
615
+
616
+ let(:options) do
617
+ { class_name: 'OtherEmbeddedObject' }
618
+ end
619
+
620
+ it 'returns the class name option' do
621
+ expect(association.relation_class_name).to eq('OtherEmbeddedObject')
622
+ end
623
+ end
624
+
625
+ context 'when the class_name option is not specified' do
626
+
627
+ it 'uses the name of the relation to deduce the class name' do
628
+ expect(association.relation_class_name).to eq('EmbeddedObject')
629
+ end
630
+ end
631
+ end
632
+
633
+ describe '#klass' do
634
+
635
+ context 'when the :class_name option is specified' do
636
+
637
+ let!(:_class) do
638
+ class OtherEmbeddedObject; end
639
+ OtherEmbeddedObject
640
+ end
641
+
642
+ let(:options) do
643
+ { class_name: 'OtherEmbeddedObject' }
644
+ end
645
+
646
+ it 'returns the class name option' do
647
+ expect(association.klass).to eq(_class)
648
+ end
649
+ end
650
+
651
+ context 'when the class_name option is not specified' do
652
+
653
+ it 'uses the name of the relation to deduce the class name' do
654
+ expect(association.klass).to eq(EmbeddedObject)
655
+ end
656
+ end
657
+ end
658
+
659
+ describe '#inverse_class_name' do
660
+
661
+ it 'returns the name of the owner class' do
662
+ expect(association.inverse_class_name).to eq(Container.name)
663
+ end
664
+ end
665
+
666
+ describe '#inverse_class' do
667
+
668
+ it 'returns the owner class' do
669
+ expect(association.inverse_class).to be(Container)
670
+ end
671
+ end
672
+
673
+ describe '#inverse_of' do
674
+
675
+ context 'when :inverse_of is specified in the options' do
676
+
677
+ let(:options) do
678
+ { inverse_of: :objects_list }
679
+ end
680
+
681
+ it 'returns the inverse_of value' do
682
+ expect(association.inverse_of).to eq(options[:inverse_of])
683
+ end
684
+ end
685
+
686
+ context 'when :inverse_of is not specified in the options' do
687
+
688
+ it 'returns nil' do
689
+ expect(association.inverse_of).to be_nil
690
+ end
691
+ end
692
+ end
693
+
694
+ describe '#key' do
695
+
696
+ it 'returns the name of the relation as a string' do
697
+ expect(association.key).to eq(name.to_s)
698
+ end
699
+ end
700
+
701
+ describe '#setter' do
702
+
703
+ it 'returns a string of the name followed by =' do
704
+ expect(association.setter).to eq("#{name}=")
705
+ end
706
+ end
707
+
708
+ describe '#validate?' do
709
+
710
+ context 'when :validate is specified in the options' do
711
+
712
+ context 'when validate is true' do
713
+
714
+ let(:options) do
715
+ { validate: true }
716
+ end
717
+
718
+ it 'returns true' do
719
+ expect(association.send(:validate?)).to be(true)
720
+ end
721
+ end
722
+
723
+ context 'when validate is false' do
724
+
725
+ let(:options) do
726
+ { validate: false }
727
+ end
728
+
729
+ it 'returns false' do
730
+ expect(association.send(:validate?)).to be(false)
731
+ end
732
+ end
733
+ end
734
+
735
+ context 'when :validate is not specified in the options' do
736
+
737
+ it 'returns the validation_default' do
738
+ expect(association.send(:validate?)).to eq(association.validation_default)
739
+ end
740
+ end
741
+ end
742
+
743
+ describe '#forced_nil_inverse?' do
744
+
745
+ it 'returns false' do
746
+ expect(association.forced_nil_inverse?).to be(false)
747
+ end
748
+ end
749
+
750
+ describe '#inverse_setter' do
751
+
752
+ context 'when an inverse can be determined' do
753
+
754
+ before do
755
+ EmbeddedObject.embedded_in :container
756
+ end
757
+
758
+ it 'returns the name of the inverse followed by =' do
759
+ expect(association.inverse_setter).to eq('container=')
760
+ end
761
+ end
762
+
763
+ context 'when an inverse cannot be determined' do
764
+
765
+ it 'returns nil' do
766
+ expect(association.inverse_setter).to be_nil
767
+ end
768
+ end
769
+ end
770
+
771
+ describe '#extension' do
772
+
773
+ context 'when a block is passed' do
774
+
775
+ let(:association) do
776
+ embeds_many_class.embeds_one name, options do; end
777
+ end
778
+
779
+ it 'defines an extension module' do
780
+ expect(association.extension).to be_a(Module)
781
+ end
782
+
783
+ it 'returns the extension' do
784
+ expect(association.extension).to eq(
785
+ "#{embeds_many_class.name}::#{embeds_many_class.name}#{name.to_s.camelize}RelationExtension".constantize)
786
+ end
787
+ end
788
+
789
+ context 'when an :extension is not specified in the options' do
790
+
791
+ it 'returns false' do
792
+ expect(association.extension).to be_nil
793
+ end
794
+ end
795
+ end
796
+
797
+ describe '#destructive?' do
798
+
799
+ it 'returns false' do
800
+ expect(association.destructive?).to be(false)
801
+ end
802
+ end
803
+
804
+ describe '#nested_builder' do
805
+
806
+ it 'returns an instance of Association::Nested::One' do
807
+ expect(association.nested_builder({}, {})).to be_a(Mongoid::Association::Nested::Many)
808
+ end
809
+ end
810
+
811
+ describe '#cascading_callbacks?' do
812
+
813
+ context 'when cascade_callbacks is specified in the options' do
814
+
815
+ context 'when :cascade_callbacks is true' do
816
+
817
+ let(:options) do
818
+ { cascade_callbacks: true }
819
+ end
820
+
821
+ it 'returns true' do
822
+ expect(association.cascading_callbacks?).to be(true)
823
+ end
824
+ end
825
+
826
+ context 'when :cascade_callbacks is false' do
827
+
828
+ let(:options) do
829
+ { cascade_callbacks: false }
830
+ end
831
+
832
+ it 'returns false' do
833
+ expect(association.cascading_callbacks?).to be(false)
834
+ end
835
+ end
836
+ end
837
+
838
+ context 'when cascade_callbacks is not specified in the options' do
839
+
840
+ it 'returns false' do
841
+ expect(association.cascading_callbacks?).to be(false)
842
+ end
843
+ end
844
+ end
845
+
846
+ describe '#path' do
847
+
848
+ it 'returns an instance of Mongoid::Atomic::Paths::Root' do
849
+ expect(association.path(double( :_parent => true))).to be_a(Mongoid::Atomic::Paths::Embedded::Many)
850
+ end
851
+ end
852
+ end