mongoid 7.1.11 → 7.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (485) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +10 -3
  4. data/Rakefile +11 -30
  5. data/lib/config/locales/en.yml +37 -14
  6. data/lib/mongoid/association/depending.rb +1 -6
  7. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +1 -1
  8. data/lib/mongoid/association/many.rb +3 -3
  9. data/lib/mongoid/association/proxy.rb +1 -1
  10. data/lib/mongoid/association/referenced/belongs_to/buildable.rb +1 -1
  11. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +1 -1
  12. data/lib/mongoid/association/referenced/has_many/enumerable.rb +37 -2
  13. data/lib/mongoid/association/referenced/has_many/proxy.rb +9 -2
  14. data/lib/mongoid/association/referenced/has_one/buildable.rb +1 -1
  15. data/lib/mongoid/association/referenced/has_one/proxy.rb +1 -6
  16. data/lib/mongoid/atomic/modifiers.rb +1 -1
  17. data/lib/mongoid/attributes/dynamic.rb +1 -1
  18. data/lib/mongoid/attributes.rb +1 -8
  19. data/lib/mongoid/clients/factory.rb +17 -0
  20. data/lib/mongoid/composable.rb +1 -0
  21. data/lib/mongoid/config/environment.rb +1 -9
  22. data/lib/mongoid/config.rb +3 -0
  23. data/lib/mongoid/contextual/atomic.rb +2 -7
  24. data/lib/mongoid/contextual/mongo.rb +23 -4
  25. data/lib/mongoid/contextual/none.rb +0 -3
  26. data/lib/mongoid/copyable.rb +2 -2
  27. data/lib/mongoid/criteria/queryable/key.rb +1 -1
  28. data/lib/mongoid/criteria/queryable/mergeable.rb +2 -2
  29. data/lib/mongoid/criteria/queryable/selectable.rb +23 -8
  30. data/lib/mongoid/criteria/queryable/selector.rb +7 -3
  31. data/lib/mongoid/criteria/queryable/storable.rb +7 -7
  32. data/lib/mongoid/criteria.rb +58 -8
  33. data/lib/mongoid/document.rb +19 -9
  34. data/lib/mongoid/errors/invalid_discriminator_key_target.rb +25 -0
  35. data/lib/mongoid/errors/invalid_elem_match_operator.rb +33 -0
  36. data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +26 -0
  37. data/lib/mongoid/errors/invalid_expression_operator.rb +28 -0
  38. data/lib/mongoid/errors/invalid_field_operator.rb +33 -0
  39. data/lib/mongoid/errors/invalid_query.rb +41 -0
  40. data/lib/mongoid/errors/mongoid_error.rb +1 -1
  41. data/lib/mongoid/errors.rb +7 -2
  42. data/lib/mongoid/factory.rb +27 -10
  43. data/lib/mongoid/fields/validators/macro.rb +22 -9
  44. data/lib/mongoid/findable.rb +50 -14
  45. data/lib/mongoid/indexable.rb +2 -2
  46. data/lib/mongoid/interceptable.rb +2 -4
  47. data/lib/mongoid/matchable.rb +1 -149
  48. data/lib/mongoid/matcher/all.rb +22 -0
  49. data/lib/mongoid/matcher/and.rb +21 -0
  50. data/lib/mongoid/matcher/elem_match.rb +35 -0
  51. data/lib/mongoid/matcher/elem_match_expression.rb +20 -0
  52. data/lib/mongoid/matcher/eq.rb +11 -0
  53. data/lib/mongoid/matcher/eq_impl.rb +32 -0
  54. data/lib/mongoid/matcher/eq_impl_with_regexp.rb +21 -0
  55. data/lib/mongoid/matcher/exists.rb +15 -0
  56. data/lib/mongoid/matcher/expression.rb +40 -0
  57. data/lib/mongoid/matcher/expression_operator.rb +19 -0
  58. data/lib/mongoid/matcher/field_expression.rb +63 -0
  59. data/lib/mongoid/matcher/field_operator.rb +52 -0
  60. data/lib/mongoid/matcher/gt.rb +17 -0
  61. data/lib/mongoid/matcher/gte.rb +17 -0
  62. data/lib/mongoid/matcher/in.rb +25 -0
  63. data/lib/mongoid/matcher/lt.rb +17 -0
  64. data/lib/mongoid/matcher/lte.rb +17 -0
  65. data/lib/mongoid/matcher/ne.rb +16 -0
  66. data/lib/mongoid/matcher/nin.rb +11 -0
  67. data/lib/mongoid/matcher/nor.rb +25 -0
  68. data/lib/mongoid/matcher/not.rb +29 -0
  69. data/lib/mongoid/matcher/or.rb +21 -0
  70. data/lib/mongoid/matcher/regex.rb +41 -0
  71. data/lib/mongoid/matcher/size.rb +26 -0
  72. data/lib/mongoid/matcher.rb +127 -0
  73. data/lib/mongoid/persistable/deletable.rb +1 -1
  74. data/lib/mongoid/persistence_context.rb +1 -3
  75. data/lib/mongoid/query_cache.rb +64 -62
  76. data/lib/mongoid/reloadable.rb +2 -7
  77. data/lib/mongoid/serializable.rb +1 -1
  78. data/lib/mongoid/tasks/database.rb +1 -1
  79. data/lib/mongoid/traversable.rb +111 -4
  80. data/lib/mongoid/validatable/associated.rb +1 -1
  81. data/lib/mongoid/validatable/presence.rb +3 -3
  82. data/lib/mongoid/validatable/uniqueness.rb +1 -1
  83. data/lib/mongoid/version.rb +1 -1
  84. data/lib/mongoid.rb +23 -1
  85. data/lib/rails/generators/mongoid/config/config_generator.rb +1 -8
  86. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +1 -1
  87. data/spec/integration/app_spec.rb +88 -178
  88. data/spec/integration/associations/embedded_spec.rb +94 -0
  89. data/spec/integration/associations/has_many_spec.rb +39 -46
  90. data/spec/integration/associations/has_one_spec.rb +39 -46
  91. data/spec/integration/associations/nested_attributes_assignment_spec.rb +116 -0
  92. data/spec/integration/atomic/modifiers_spec.rb +117 -0
  93. data/spec/integration/discriminator_key_spec.rb +354 -0
  94. data/spec/integration/discriminator_value_spec.rb +207 -0
  95. data/spec/integration/document_spec.rb +0 -21
  96. data/spec/integration/{matchable_spec.rb → matcher_examples_spec.rb} +120 -41
  97. data/spec/integration/matcher_operator_data/all.yml +140 -0
  98. data/spec/integration/matcher_operator_data/and.yml +93 -0
  99. data/spec/integration/matcher_operator_data/elem_match.yml +363 -0
  100. data/spec/integration/matcher_operator_data/elem_match_expr.yml +213 -0
  101. data/spec/integration/matcher_operator_data/eq.yml +191 -0
  102. data/spec/integration/matcher_operator_data/exists.yml +213 -0
  103. data/spec/integration/matcher_operator_data/generic_op.yml +17 -0
  104. data/spec/integration/matcher_operator_data/gt.yml +132 -0
  105. data/spec/integration/matcher_operator_data/gte.yml +132 -0
  106. data/spec/integration/matcher_operator_data/implicit.yml +331 -0
  107. data/spec/integration/matcher_operator_data/implicit_traversal.yml +16 -0
  108. data/spec/integration/matcher_operator_data/in.yml +194 -0
  109. data/spec/integration/matcher_operator_data/invalid_op.yml +59 -0
  110. data/spec/integration/matcher_operator_data/invalid_syntax.yml +39 -0
  111. data/spec/integration/matcher_operator_data/lt.yml +132 -0
  112. data/spec/integration/matcher_operator_data/lte.yml +132 -0
  113. data/spec/integration/matcher_operator_data/multiple.yml +29 -0
  114. data/spec/integration/matcher_operator_data/ne.yml +150 -0
  115. data/spec/integration/matcher_operator_data/nin.yml +114 -0
  116. data/spec/integration/matcher_operator_data/nor.yml +126 -0
  117. data/spec/integration/matcher_operator_data/not.yml +196 -0
  118. data/spec/integration/matcher_operator_data/or.yml +137 -0
  119. data/spec/integration/matcher_operator_data/regex.yml +174 -0
  120. data/spec/integration/matcher_operator_data/regex_options.yml +72 -0
  121. data/spec/integration/matcher_operator_data/size.yml +174 -0
  122. data/spec/integration/matcher_operator_spec.rb +100 -0
  123. data/spec/integration/matcher_spec.rb +189 -0
  124. data/spec/integration/server_query_spec.rb +142 -0
  125. data/spec/lite_spec_helper.rb +7 -7
  126. data/spec/mongoid/association/depending_spec.rb +78 -26
  127. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +0 -50
  128. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +37 -17
  129. data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
  130. data/spec/mongoid/association/embedded/embeds_one_models.rb +1 -0
  131. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +0 -17
  132. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +460 -186
  133. data/spec/mongoid/association/referenced/has_many_models.rb +9 -0
  134. data/spec/mongoid/association/referenced/has_one_models.rb +9 -0
  135. data/spec/mongoid/atomic/modifiers_spec.rb +47 -0
  136. data/spec/mongoid/atomic/paths_spec.rb +0 -41
  137. data/spec/mongoid/atomic_spec.rb +23 -0
  138. data/spec/mongoid/attributes/nested_spec.rb +1 -1
  139. data/spec/mongoid/attributes_spec.rb +0 -241
  140. data/spec/mongoid/clients/factory_spec.rb +35 -9
  141. data/spec/mongoid/clients/options_spec.rb +3 -11
  142. data/spec/mongoid/clients/sessions_spec.rb +1 -6
  143. data/spec/mongoid/config/environment_spec.rb +8 -86
  144. data/spec/mongoid/config_spec.rb +28 -0
  145. data/spec/mongoid/contextual/atomic_spec.rb +29 -81
  146. data/spec/mongoid/contextual/geo_near_spec.rb +1 -1
  147. data/spec/mongoid/contextual/mongo_spec.rb +70 -16
  148. data/spec/mongoid/copyable_spec.rb +153 -1
  149. data/spec/mongoid/copyable_spec_models.rb +14 -0
  150. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +0 -36
  151. data/spec/mongoid/criteria/queryable/selectable_spec.rb +84 -82
  152. data/spec/mongoid/criteria_spec.rb +204 -43
  153. data/spec/mongoid/document_query_spec.rb +0 -51
  154. data/spec/mongoid/document_spec.rb +90 -36
  155. data/spec/mongoid/errors/delete_restriction_spec.rb +1 -1
  156. data/spec/mongoid/errors/mongoid_error_spec.rb +8 -20
  157. data/spec/mongoid/factory_spec.rb +261 -28
  158. data/spec/mongoid/fields_spec.rb +48 -2
  159. data/spec/mongoid/findable_spec.rb +32 -0
  160. data/spec/mongoid/indexable_spec.rb +28 -2
  161. data/spec/mongoid/inspectable_spec.rb +29 -2
  162. data/spec/mongoid/interceptable_spec.rb +2 -2
  163. data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +259 -0
  164. data/spec/mongoid/matcher/extract_attribute_spec.rb +47 -0
  165. data/spec/mongoid/persistable/creatable_spec.rb +108 -25
  166. data/spec/mongoid/persistable/deletable_spec.rb +86 -0
  167. data/spec/mongoid/persistable/savable_spec.rb +174 -16
  168. data/spec/mongoid/persistable/settable_spec.rb +0 -30
  169. data/spec/mongoid/persistable/updatable_spec.rb +0 -2
  170. data/spec/mongoid/persistable_spec.rb +2 -2
  171. data/spec/mongoid/query_cache_middleware_spec.rb +16 -3
  172. data/spec/mongoid/query_cache_spec.rb +442 -41
  173. data/spec/mongoid/reloadable_spec.rb +72 -0
  174. data/spec/mongoid/serializable_spec.rb +21 -3
  175. data/spec/mongoid/traversable_spec.rb +1100 -0
  176. data/spec/spec_helper.rb +3 -5
  177. data/spec/support/child_process_helper.rb +79 -0
  178. data/spec/support/constraints.rb +250 -0
  179. data/spec/support/helpers.rb +1 -1
  180. data/spec/support/lite_constraints.rb +22 -0
  181. data/spec/{app → support}/models/account.rb +0 -0
  182. data/spec/{app → support}/models/acolyte.rb +0 -0
  183. data/spec/{app → support}/models/actor.rb +1 -1
  184. data/spec/{app → support}/models/actress.rb +0 -0
  185. data/spec/{app → support}/models/address.rb +0 -4
  186. data/spec/{app → support}/models/address_component.rb +0 -0
  187. data/spec/{app → support}/models/address_number.rb +0 -0
  188. data/spec/{app → support}/models/agency.rb +0 -0
  189. data/spec/{app → support}/models/agent.rb +0 -0
  190. data/spec/{app → support}/models/album.rb +0 -0
  191. data/spec/{app → support}/models/alert.rb +0 -0
  192. data/spec/{app → support}/models/animal.rb +0 -0
  193. data/spec/{app → support}/models/answer.rb +0 -0
  194. data/spec/{app → support}/models/appointment.rb +0 -0
  195. data/spec/support/models/armrest.rb +10 -0
  196. data/spec/{app → support}/models/array_field.rb +0 -0
  197. data/spec/{app → support}/models/article.rb +0 -0
  198. data/spec/{app → support}/models/artist.rb +0 -0
  199. data/spec/{app → support}/models/artwork.rb +0 -0
  200. data/spec/{app → support}/models/audio.rb +0 -0
  201. data/spec/{app → support}/models/augmentation.rb +0 -0
  202. data/spec/{app → support}/models/author.rb +0 -0
  203. data/spec/{app → support}/models/baby.rb +0 -0
  204. data/spec/{app → support}/models/band.rb +0 -0
  205. data/spec/{app → support}/models/bar.rb +0 -0
  206. data/spec/{app → support}/models/basic.rb +0 -0
  207. data/spec/{app → support}/models/bed.rb +0 -0
  208. data/spec/{app → support}/models/big_palette.rb +0 -0
  209. data/spec/{app → support}/models/birthday.rb +0 -0
  210. data/spec/{app → support}/models/bomb.rb +0 -0
  211. data/spec/{app → support}/models/book.rb +0 -0
  212. data/spec/{app → support}/models/breed.rb +0 -0
  213. data/spec/{app → support}/models/browser.rb +1 -1
  214. data/spec/{app → support}/models/building.rb +0 -0
  215. data/spec/{app → support}/models/building_address.rb +0 -0
  216. data/spec/{app → support}/models/bus.rb +0 -0
  217. data/spec/{app → support}/models/business.rb +0 -0
  218. data/spec/{app → support}/models/callback_test.rb +0 -0
  219. data/spec/{app → support}/models/canvas.rb +1 -1
  220. data/spec/{app → support}/models/car.rb +0 -0
  221. data/spec/{app → support}/models/cat.rb +0 -0
  222. data/spec/{app → support}/models/category.rb +0 -0
  223. data/spec/{app → support}/models/child.rb +0 -0
  224. data/spec/{app → support}/models/child_doc.rb +0 -0
  225. data/spec/{app → support}/models/church.rb +0 -0
  226. data/spec/{app → support}/models/circle.rb +0 -0
  227. data/spec/{app → support}/models/circuit.rb +0 -0
  228. data/spec/{app → support}/models/circus.rb +0 -0
  229. data/spec/{app → support}/models/code.rb +0 -0
  230. data/spec/{app → support}/models/coding/pull_request.rb +0 -0
  231. data/spec/{app → support}/models/coding.rb +1 -1
  232. data/spec/{app → support}/models/comment.rb +0 -0
  233. data/spec/{app → support}/models/company.rb +0 -0
  234. data/spec/{app → support}/models/consumption_period.rb +0 -0
  235. data/spec/{app → support}/models/contextable_item.rb +0 -0
  236. data/spec/{app → support}/models/contractor.rb +0 -0
  237. data/spec/{app → support}/models/cookie.rb +0 -0
  238. data/spec/{app → support}/models/country_code.rb +0 -0
  239. data/spec/{app → support}/models/courier_job.rb +0 -0
  240. data/spec/support/models/crate.rb +13 -0
  241. data/spec/support/models/deed.rb +8 -0
  242. data/spec/{app → support}/models/definition.rb +0 -0
  243. data/spec/{app → support}/models/delegating_patient.rb +0 -0
  244. data/spec/{app → support}/models/description.rb +0 -0
  245. data/spec/{app → support}/models/dictionary.rb +0 -6
  246. data/spec/{app → support}/models/division.rb +0 -0
  247. data/spec/{app → support}/models/doctor.rb +0 -0
  248. data/spec/{app → support}/models/dog.rb +0 -0
  249. data/spec/{app → support}/models/dokument.rb +0 -0
  250. data/spec/{app → support}/models/draft.rb +0 -0
  251. data/spec/{app → support}/models/dragon.rb +0 -0
  252. data/spec/{app → support}/models/driver.rb +1 -1
  253. data/spec/{app → support}/models/drug.rb +0 -0
  254. data/spec/{app → support}/models/dungeon.rb +0 -0
  255. data/spec/{app → support}/models/edit.rb +0 -0
  256. data/spec/{app → support}/models/email.rb +0 -0
  257. data/spec/{app → support}/models/employer.rb +0 -0
  258. data/spec/{app → support}/models/entry.rb +0 -0
  259. data/spec/{app → support}/models/eraser.rb +0 -0
  260. data/spec/{app → support}/models/even.rb +0 -0
  261. data/spec/{app → support}/models/event.rb +0 -0
  262. data/spec/{app → support}/models/exhibition.rb +0 -0
  263. data/spec/{app → support}/models/exhibitor.rb +0 -0
  264. data/spec/{app → support}/models/explosion.rb +0 -0
  265. data/spec/{app → support}/models/eye.rb +0 -0
  266. data/spec/{app → support}/models/eye_bowl.rb +0 -0
  267. data/spec/{app → support}/models/face.rb +0 -0
  268. data/spec/{app → support}/models/favorite.rb +0 -0
  269. data/spec/{app → support}/models/filesystem.rb +0 -0
  270. data/spec/{app → support}/models/fire_hydrant.rb +0 -0
  271. data/spec/{app → support}/models/firefox.rb +0 -0
  272. data/spec/{app → support}/models/fish.rb +0 -0
  273. data/spec/{app → support}/models/folder.rb +0 -0
  274. data/spec/{app → support}/models/folder_item.rb +0 -0
  275. data/spec/{app → support}/models/fruits.rb +0 -0
  276. data/spec/{app → support}/models/game.rb +0 -0
  277. data/spec/{app → support}/models/ghost.rb +0 -0
  278. data/spec/support/models/guitar.rb +5 -0
  279. data/spec/{app → support}/models/home.rb +0 -0
  280. data/spec/{app → support}/models/house.rb +0 -0
  281. data/spec/{app → support}/models/html_writer.rb +0 -0
  282. data/spec/{app → support}/models/id_key.rb +0 -0
  283. data/spec/support/models/idnodef.rb +8 -0
  284. data/spec/{app → support}/models/image.rb +0 -0
  285. data/spec/{app → support}/models/implant.rb +0 -0
  286. data/spec/support/models/instrument.rb +9 -0
  287. data/spec/{app → support}/models/item.rb +1 -1
  288. data/spec/{app → support}/models/jar.rb +0 -0
  289. data/spec/{app → support}/models/kaleidoscope.rb +0 -0
  290. data/spec/{app → support}/models/kangaroo.rb +0 -0
  291. data/spec/{app → support}/models/label.rb +0 -0
  292. data/spec/{app → support}/models/language.rb +0 -0
  293. data/spec/{app → support}/models/lat_lng.rb +0 -0
  294. data/spec/{app → support}/models/league.rb +0 -0
  295. data/spec/{app → support}/models/learner.rb +0 -0
  296. data/spec/{app → support}/models/line_item.rb +0 -0
  297. data/spec/{app → support}/models/location.rb +0 -0
  298. data/spec/{app → support}/models/login.rb +0 -0
  299. data/spec/{app → support}/models/manufacturer.rb +0 -0
  300. data/spec/{app → support}/models/meat.rb +0 -0
  301. data/spec/{app → support}/models/membership.rb +0 -0
  302. data/spec/{app → support}/models/message.rb +0 -0
  303. data/spec/{app → support}/models/minim.rb +0 -0
  304. data/spec/{app → support}/models/mixed_drink.rb +0 -0
  305. data/spec/{app → support}/models/mop.rb +0 -10
  306. data/spec/{app → support}/models/movie.rb +0 -0
  307. data/spec/{app → support}/models/my_hash.rb +0 -0
  308. data/spec/{app → support}/models/name.rb +0 -0
  309. data/spec/{app → support}/models/name_only.rb +0 -0
  310. data/spec/{app → support}/models/node.rb +0 -0
  311. data/spec/{app → support}/models/note.rb +0 -0
  312. data/spec/{app → support}/models/odd.rb +0 -0
  313. data/spec/{app → support}/models/ordered_post.rb +0 -0
  314. data/spec/{app → support}/models/ordered_preference.rb +0 -0
  315. data/spec/{app → support}/models/oscar.rb +0 -0
  316. data/spec/{app → support}/models/other_owner_object.rb +0 -0
  317. data/spec/{app → support}/models/override.rb +0 -0
  318. data/spec/{app → support}/models/ownable.rb +0 -0
  319. data/spec/{app → support}/models/owner.rb +2 -0
  320. data/spec/{app → support}/models/pack.rb +0 -0
  321. data/spec/{app → support}/models/page.rb +0 -0
  322. data/spec/{app → support}/models/page_question.rb +0 -0
  323. data/spec/{app → support}/models/palette.rb +1 -1
  324. data/spec/{app → support}/models/parent.rb +0 -0
  325. data/spec/{app → support}/models/parent_doc.rb +0 -0
  326. data/spec/{app → support}/models/passport.rb +0 -0
  327. data/spec/{app → support}/models/patient.rb +0 -0
  328. data/spec/{app → support}/models/pdf_writer.rb +0 -0
  329. data/spec/{app → support}/models/pencil.rb +0 -0
  330. data/spec/{app → support}/models/person.rb +1 -12
  331. data/spec/{app → support}/models/pet.rb +0 -0
  332. data/spec/{app → support}/models/pet_owner.rb +0 -0
  333. data/spec/{app → support}/models/phone.rb +0 -0
  334. data/spec/support/models/piano.rb +5 -0
  335. data/spec/{app → support}/models/pizza.rb +0 -0
  336. data/spec/{app → support}/models/player.rb +0 -0
  337. data/spec/{app → support}/models/post.rb +0 -0
  338. data/spec/{app → support}/models/post_genre.rb +0 -0
  339. data/spec/{app → support}/models/powerup.rb +0 -0
  340. data/spec/{app → support}/models/preference.rb +0 -0
  341. data/spec/{app → support}/models/princess.rb +0 -0
  342. data/spec/{app → support}/models/product.rb +0 -0
  343. data/spec/support/models/profile.rb +18 -0
  344. data/spec/{app → support}/models/pronunciation.rb +0 -0
  345. data/spec/{app → support}/models/pub.rb +0 -0
  346. data/spec/{app → support}/models/publication/encyclopedia.rb +0 -0
  347. data/spec/{app → support}/models/publication/review.rb +0 -0
  348. data/spec/support/models/publication.rb +5 -0
  349. data/spec/{app → support}/models/purchase.rb +0 -0
  350. data/spec/{app → support}/models/question.rb +0 -0
  351. data/spec/{app → support}/models/quiz.rb +0 -0
  352. data/spec/{app → support}/models/rating.rb +0 -0
  353. data/spec/{app → support}/models/record.rb +0 -0
  354. data/spec/{app → support}/models/registry.rb +0 -0
  355. data/spec/{app → support}/models/role.rb +0 -0
  356. data/spec/{app → support}/models/root_category.rb +0 -0
  357. data/spec/{app → support}/models/sandwich.rb +0 -0
  358. data/spec/{app → support}/models/scheduler.rb +0 -0
  359. data/spec/{app/models/profile.rb → support/models/scribe.rb} +2 -2
  360. data/spec/support/models/seat.rb +25 -0
  361. data/spec/{app → support}/models/seo.rb +0 -0
  362. data/spec/{app → support}/models/series.rb +0 -1
  363. data/spec/{app → support}/models/server.rb +0 -0
  364. data/spec/{app → support}/models/service.rb +0 -0
  365. data/spec/{app → support}/models/shape.rb +2 -2
  366. data/spec/{app → support}/models/shelf.rb +0 -0
  367. data/spec/{app → support}/models/shipment_address.rb +0 -0
  368. data/spec/{app → support}/models/shipping_container.rb +0 -0
  369. data/spec/{app → support}/models/shipping_pack.rb +0 -0
  370. data/spec/{app → support}/models/shop.rb +0 -0
  371. data/spec/{app → support}/models/short_agent.rb +0 -0
  372. data/spec/{app → support}/models/short_quiz.rb +0 -0
  373. data/spec/{app → support}/models/simple.rb +0 -0
  374. data/spec/{app → support}/models/slave.rb +0 -0
  375. data/spec/{app → support}/models/song.rb +0 -0
  376. data/spec/{app → support}/models/sound.rb +0 -0
  377. data/spec/{app → support}/models/square.rb +0 -0
  378. data/spec/{app → support}/models/staff.rb +0 -0
  379. data/spec/{app → support}/models/store_as_dup_test1.rb +0 -0
  380. data/spec/{app → support}/models/store_as_dup_test2.rb +0 -0
  381. data/spec/{app → support}/models/store_as_dup_test3.rb +0 -0
  382. data/spec/{app → support}/models/store_as_dup_test4.rb +0 -0
  383. data/spec/{app → support}/models/strategy.rb +0 -0
  384. data/spec/{app → support}/models/sub_item.rb +0 -0
  385. data/spec/{app → support}/models/subscription.rb +0 -0
  386. data/spec/{app → support}/models/survey.rb +0 -0
  387. data/spec/{app → support}/models/symptom.rb +0 -0
  388. data/spec/support/models/system_role.rb +7 -0
  389. data/spec/{app → support}/models/tag.rb +0 -0
  390. data/spec/{app → support}/models/target.rb +0 -0
  391. data/spec/{app → support}/models/template.rb +0 -0
  392. data/spec/{app → support}/models/thing.rb +0 -0
  393. data/spec/{app → support}/models/title.rb +0 -0
  394. data/spec/{app → support}/models/tool.rb +2 -2
  395. data/spec/{app → support}/models/topping.rb +0 -0
  396. data/spec/support/models/toy.rb +10 -0
  397. data/spec/{app → support}/models/track.rb +0 -0
  398. data/spec/{app → support}/models/translation.rb +0 -0
  399. data/spec/{app → support}/models/tree.rb +0 -0
  400. data/spec/{app → support}/models/truck.rb +2 -0
  401. data/spec/{app → support}/models/updatable.rb +0 -0
  402. data/spec/{app → support}/models/user.rb +0 -0
  403. data/spec/{app → support}/models/user_account.rb +0 -0
  404. data/spec/{app → support}/models/validation_callback.rb +0 -0
  405. data/spec/{app → support}/models/vehicle.rb +7 -2
  406. data/spec/{app → support}/models/version.rb +0 -0
  407. data/spec/{app → support}/models/vertex.rb +0 -0
  408. data/spec/{app → support}/models/vet_visit.rb +0 -0
  409. data/spec/{app → support}/models/video.rb +0 -0
  410. data/spec/{app → support}/models/video_game.rb +0 -0
  411. data/spec/{app → support}/models/weapon.rb +0 -0
  412. data/spec/{app → support}/models/wiki_page.rb +0 -1
  413. data/spec/{app → support}/models/word.rb +0 -0
  414. data/spec/{app → support}/models/word_origin.rb +0 -0
  415. data/spec/{app → support}/models/writer.rb +2 -2
  416. data/spec/support/spec_config.rb +1 -9
  417. data/spec/support/spec_organizer.rb +130 -0
  418. data.tar.gz.sig +0 -0
  419. metadata +847 -844
  420. metadata.gz.sig +0 -0
  421. data/lib/mongoid/errors/empty_config_file.rb +0 -26
  422. data/lib/mongoid/errors/invalid_config_file.rb +0 -26
  423. data/lib/mongoid/matchable/all.rb +0 -30
  424. data/lib/mongoid/matchable/and.rb +0 -32
  425. data/lib/mongoid/matchable/default.rb +0 -121
  426. data/lib/mongoid/matchable/elem_match.rb +0 -36
  427. data/lib/mongoid/matchable/eq.rb +0 -23
  428. data/lib/mongoid/matchable/exists.rb +0 -25
  429. data/lib/mongoid/matchable/gt.rb +0 -25
  430. data/lib/mongoid/matchable/gte.rb +0 -25
  431. data/lib/mongoid/matchable/in.rb +0 -26
  432. data/lib/mongoid/matchable/lt.rb +0 -25
  433. data/lib/mongoid/matchable/lte.rb +0 -25
  434. data/lib/mongoid/matchable/ne.rb +0 -23
  435. data/lib/mongoid/matchable/nin.rb +0 -24
  436. data/lib/mongoid/matchable/nor.rb +0 -38
  437. data/lib/mongoid/matchable/or.rb +0 -35
  438. data/lib/mongoid/matchable/regexp.rb +0 -30
  439. data/lib/mongoid/matchable/size.rb +0 -23
  440. data/spec/app/models/customer.rb +0 -11
  441. data/spec/app/models/customer_address.rb +0 -12
  442. data/spec/app/models/publication.rb +0 -5
  443. data/spec/integration/associations/embeds_many_spec.rb +0 -24
  444. data/spec/integration/associations/embeds_one_spec.rb +0 -24
  445. data/spec/integration/callbacks_models.rb +0 -49
  446. data/spec/integration/callbacks_spec.rb +0 -216
  447. data/spec/integration/contextual/empty_spec.rb +0 -142
  448. data/spec/mongoid/errors/invalid_config_file_spec.rb +0 -32
  449. data/spec/mongoid/matchable/all_spec.rb +0 -34
  450. data/spec/mongoid/matchable/and_spec.rb +0 -190
  451. data/spec/mongoid/matchable/default_spec.rb +0 -140
  452. data/spec/mongoid/matchable/elem_match_spec.rb +0 -109
  453. data/spec/mongoid/matchable/eq_spec.rb +0 -49
  454. data/spec/mongoid/matchable/exists_spec.rb +0 -60
  455. data/spec/mongoid/matchable/gt_spec.rb +0 -89
  456. data/spec/mongoid/matchable/gte_spec.rb +0 -87
  457. data/spec/mongoid/matchable/in_spec.rb +0 -52
  458. data/spec/mongoid/matchable/lt_spec.rb +0 -88
  459. data/spec/mongoid/matchable/lte_spec.rb +0 -88
  460. data/spec/mongoid/matchable/ne_spec.rb +0 -49
  461. data/spec/mongoid/matchable/nin_spec.rb +0 -51
  462. data/spec/mongoid/matchable/nor_spec.rb +0 -210
  463. data/spec/mongoid/matchable/or_spec.rb +0 -134
  464. data/spec/mongoid/matchable/regexp_spec.rb +0 -62
  465. data/spec/mongoid/matchable/size_spec.rb +0 -28
  466. data/spec/mongoid/matchable_spec.rb +0 -856
  467. data/spec/shared/LICENSE +0 -20
  468. data/spec/shared/bin/get-mongodb-download-url +0 -17
  469. data/spec/shared/bin/s3-copy +0 -45
  470. data/spec/shared/bin/s3-upload +0 -69
  471. data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
  472. data/spec/shared/lib/mrss/cluster_config.rb +0 -226
  473. data/spec/shared/lib/mrss/constraints.rb +0 -385
  474. data/spec/shared/lib/mrss/docker_runner.rb +0 -271
  475. data/spec/shared/lib/mrss/event_subscriber.rb +0 -200
  476. data/spec/shared/lib/mrss/lite_constraints.rb +0 -191
  477. data/spec/shared/lib/mrss/server_version_registry.rb +0 -120
  478. data/spec/shared/lib/mrss/spec_organizer.rb +0 -179
  479. data/spec/shared/lib/mrss/utils.rb +0 -15
  480. data/spec/shared/share/Dockerfile.erb +0 -323
  481. data/spec/shared/share/haproxy-1.conf +0 -16
  482. data/spec/shared/share/haproxy-2.conf +0 -17
  483. data/spec/shared/shlib/distro.sh +0 -73
  484. data/spec/shared/shlib/server.sh +0 -367
  485. data/spec/shared/shlib/set_env.sh +0 -131
@@ -31,16 +31,16 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
31
31
  person.posts.send(method, Post.new(person: person))
32
32
  end
33
33
 
34
- it "only adds the relation once" do
34
+ it "only adds the association once" do
35
35
  expect(person.posts.size).to eq(1)
36
36
  end
37
37
 
38
- it "only persists the relation once" do
38
+ it "only persists the association once" do
39
39
  expect(person.reload.posts.size).to eq(1)
40
40
  end
41
41
  end
42
42
 
43
- context "when the relations are not polymorphic" do
43
+ context "when the associations are not polymorphic" do
44
44
 
45
45
  context "when the parent is a new record" do
46
46
 
@@ -58,15 +58,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
58
58
  person.posts.send(method, post)
59
59
  end
60
60
 
61
- it "sets the foreign key on the relation" do
61
+ it "sets the foreign key on the association" do
62
62
  expect(post.person_id).to eq(person.id)
63
63
  end
64
64
 
65
- it "sets the base on the inverse relation" do
65
+ it "sets the base on the inverse association" do
66
66
  expect(post.person).to eq(person)
67
67
  end
68
68
 
69
- it "sets the same instance on the inverse relation" do
69
+ it "sets the same instance on the inverse association" do
70
70
  expect(post.person).to eql(person)
71
71
  end
72
72
 
@@ -78,7 +78,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
78
78
  expect(person.posts.size).to eq(1)
79
79
  end
80
80
 
81
- it "returns the relation" do
81
+ it "returns the association" do
82
82
  expect(added).to eq(person.posts)
83
83
  end
84
84
  end
@@ -93,15 +93,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
93
93
  person.posts.send(method, post)
94
94
  end
95
95
 
96
- it "sets the foreign key on the relation" do
96
+ it "sets the foreign key on the association" do
97
97
  expect(post.person_id).to eq(person.id)
98
98
  end
99
99
 
100
- it "sets the base on the inverse relation" do
100
+ it "sets the base on the inverse association" do
101
101
  expect(post.person).to eq(person)
102
102
  end
103
103
 
104
- it "sets the same instance on the inverse relation" do
104
+ it "sets the same instance on the inverse association" do
105
105
  expect(post.person).to eql(person)
106
106
  end
107
107
 
@@ -120,7 +120,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
120
120
  post.save
121
121
  end
122
122
 
123
- it "returns the correct count of the relation" do
123
+ it "returns the correct count of the association" do
124
124
  expect(person.posts.count).to eq(1)
125
125
  end
126
126
  end
@@ -139,11 +139,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
139
139
  end
140
140
  end
141
141
 
142
- it "adds the documents to the relation" do
142
+ it "adds the documents to the association" do
143
143
  expect(person.posts).to eq([ post ])
144
144
  end
145
145
 
146
- it "sets the foreign key on the inverse relation" do
146
+ it "sets the foreign key on the inverse association" do
147
147
  expect(post.person_id).to eq(person.id)
148
148
  end
149
149
 
@@ -174,15 +174,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
174
174
  person.posts.send(method, post)
175
175
  end
176
176
 
177
- it "sets the foreign key on the relation" do
177
+ it "sets the foreign key on the association" do
178
178
  expect(post.person_id).to eq(person.id)
179
179
  end
180
180
 
181
- it "sets the base on the inverse relation" do
181
+ it "sets the base on the inverse association" do
182
182
  expect(post.person).to eq(person)
183
183
  end
184
184
 
185
- it "sets the same instance on the inverse relation" do
185
+ it "sets the same instance on the inverse association" do
186
186
  expect(post.person).to eql(person)
187
187
  end
188
188
 
@@ -203,7 +203,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
203
203
  expect(person.changed).to eq([])
204
204
  end
205
205
 
206
- context "when the related item has embedded relations" do
206
+ context "when the related item has embedded associations" do
207
207
 
208
208
  let!(:user) do
209
209
  User.create
@@ -232,7 +232,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
232
232
  end
233
233
  end
234
234
 
235
- context "when documents already exist on the relation" do
235
+ context "when documents already exist on the association" do
236
236
 
237
237
  let(:post_two) do
238
238
  Post.new(title: "Test")
@@ -242,15 +242,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
242
242
  person.posts.send(method, post_two)
243
243
  end
244
244
 
245
- it "sets the foreign key on the relation" do
245
+ it "sets the foreign key on the association" do
246
246
  expect(post_two.person_id).to eq(person.id)
247
247
  end
248
248
 
249
- it "sets the base on the inverse relation" do
249
+ it "sets the base on the inverse association" do
250
250
  expect(post_two.person).to eq(person)
251
251
  end
252
252
 
253
- it "sets the same instance on the inverse relation" do
253
+ it "sets the same instance on the inverse association" do
254
254
  expect(post_two.person).to eql(person)
255
255
  end
256
256
 
@@ -277,7 +277,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
277
277
  end
278
278
  end
279
279
 
280
- context "when.adding to the relation" do
280
+ context "when.adding to the association" do
281
281
 
282
282
  let(:person) do
283
283
  Person.create
@@ -293,7 +293,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
293
293
  person.posts.send(method, post)
294
294
  end
295
295
 
296
- it "adds the document to the relation" do
296
+ it "adds the document to the association" do
297
297
  expect(person.posts).to eq([ post ])
298
298
  end
299
299
  end
@@ -318,7 +318,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
318
318
  end
319
319
  end
320
320
 
321
- context "when the relations are polymorphic" do
321
+ context "when the associations are polymorphic" do
322
322
 
323
323
  context "when the parent is a new record" do
324
324
 
@@ -334,11 +334,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
334
334
  movie.ratings.send(method, rating)
335
335
  end
336
336
 
337
- it "sets the foreign key on the relation" do
337
+ it "sets the foreign key on the association" do
338
338
  expect(rating.ratable_id).to eq(movie.id)
339
339
  end
340
340
 
341
- it "sets the base on the inverse relation" do
341
+ it "sets the base on the inverse association" do
342
342
  expect(rating.ratable).to eq(movie)
343
343
  end
344
344
 
@@ -365,11 +365,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
365
365
  movie.ratings.send(method, rating)
366
366
  end
367
367
 
368
- it "sets the foreign key on the relation" do
368
+ it "sets the foreign key on the association" do
369
369
  expect(rating.ratable_id).to eq(movie.id)
370
370
  end
371
371
 
372
- it "sets the base on the inverse relation" do
372
+ it "sets the base on the inverse association" do
373
373
  expect(rating.ratable).to eq(movie)
374
374
  end
375
375
 
@@ -387,7 +387,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
387
387
 
388
388
  describe "#=" do
389
389
 
390
- context "when the relation is not polymorphic" do
390
+ context "when the association is not polymorphic" do
391
391
 
392
392
  context "when the parent is a new record" do
393
393
 
@@ -403,15 +403,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
403
403
  person.posts = [ post ]
404
404
  end
405
405
 
406
- it "sets the target of the relation" do
406
+ it "sets the target of the association" do
407
407
  expect(person.posts._target).to eq([ post ])
408
408
  end
409
409
 
410
- it "sets the foreign key on the relation" do
410
+ it "sets the foreign key on the association" do
411
411
  expect(post.person_id).to eq(person.id)
412
412
  end
413
413
 
414
- it "sets the base on the inverse relation" do
414
+ it "sets the base on the inverse association" do
415
415
  expect(post.person).to eq(person)
416
416
  end
417
417
 
@@ -434,15 +434,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
434
434
  person.posts = [ post ]
435
435
  end
436
436
 
437
- it "sets the target of the relation" do
437
+ it "sets the target of the association" do
438
438
  expect(person.posts._target).to eq([ post ])
439
439
  end
440
440
 
441
- it "sets the foreign key of the relation" do
441
+ it "sets the foreign key of the association" do
442
442
  expect(post.person_id).to eq(person.id)
443
443
  end
444
444
 
445
- it "sets the base on the inverse relation" do
445
+ it "sets the base on the inverse association" do
446
446
  expect(post.person).to eq(person)
447
447
  end
448
448
 
@@ -450,7 +450,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
450
450
  expect(post).to be_persisted
451
451
  end
452
452
 
453
- context "when replacing the relation with the same documents" do
453
+ context "when replacing the association with the same documents" do
454
454
 
455
455
  context "when using the same in memory instance" do
456
456
 
@@ -458,11 +458,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
458
458
  person.posts = [ post ]
459
459
  end
460
460
 
461
- it "keeps the relation intact" do
461
+ it "keeps the association intact" do
462
462
  expect(person.posts).to eq([ post ])
463
463
  end
464
464
 
465
- it "does not delete the relation" do
465
+ it "does not delete the association" do
466
466
  expect(person.reload.posts).to eq([ post ])
467
467
  end
468
468
  end
@@ -477,11 +477,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
477
477
  from_db.posts = [ post ]
478
478
  end
479
479
 
480
- it "keeps the relation intact" do
480
+ it "keeps the association intact" do
481
481
  expect(from_db.posts).to eq([ post ])
482
482
  end
483
483
 
484
- it "does not delete the relation" do
484
+ it "does not delete the association" do
485
485
  expect(from_db.reload.posts).to eq([ post ])
486
486
  end
487
487
  end
@@ -499,7 +499,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
499
499
  person.posts = [ post, new_post ]
500
500
  end
501
501
 
502
- it "keeps the relation intact" do
502
+ it "keeps the association intact" do
503
503
  expect(person.posts.size).to eq(2)
504
504
  end
505
505
 
@@ -511,7 +511,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
511
511
  expect(person.posts).to include(new_post)
512
512
  end
513
513
 
514
- it "does not delete the relation" do
514
+ it "does not delete the association" do
515
515
  expect(person.reload.posts).to eq([ post, new_post ])
516
516
  end
517
517
  end
@@ -526,11 +526,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
526
526
  from_db.posts = [ post, new_post ]
527
527
  end
528
528
 
529
- it "keeps the relation intact" do
529
+ it "keeps the association intact" do
530
530
  expect(from_db.posts).to eq([ post, new_post ])
531
531
  end
532
532
 
533
- it "does not delete the relation" do
533
+ it "does not delete the association" do
534
534
  expect(from_db.reload.posts).to eq([ post, new_post ])
535
535
  end
536
536
  end
@@ -548,11 +548,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
548
548
  person.posts = [ new_post ]
549
549
  end
550
550
 
551
- it "keeps the relation intact" do
551
+ it "keeps the association intact" do
552
552
  expect(person.posts).to eq([ new_post ])
553
553
  end
554
554
 
555
- it "does not delete the relation" do
555
+ it "does not delete the association" do
556
556
  expect(person.reload.posts).to eq([ new_post ])
557
557
  end
558
558
  end
@@ -567,11 +567,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
567
567
  from_db.posts = [ new_post ]
568
568
  end
569
569
 
570
- it "keeps the relation intact" do
570
+ it "keeps the association intact" do
571
571
  expect(from_db.posts).to eq([ new_post ])
572
572
  end
573
573
 
574
- it "does not delete the relation" do
574
+ it "does not delete the association" do
575
575
  expect(from_db.reload.posts).to eq([ new_post ])
576
576
  end
577
577
  end
@@ -579,7 +579,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
579
579
  end
580
580
  end
581
581
 
582
- context "when the relation is polymorphic" do
582
+ context "when the association is polymorphic" do
583
583
 
584
584
  context "when the parent is a new record" do
585
585
 
@@ -595,15 +595,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
595
595
  movie.ratings = [ rating ]
596
596
  end
597
597
 
598
- it "sets the target of the relation" do
598
+ it "sets the target of the association" do
599
599
  expect(movie.ratings._target).to eq([ rating ])
600
600
  end
601
601
 
602
- it "sets the foreign key on the relation" do
602
+ it "sets the foreign key on the association" do
603
603
  expect(rating.ratable_id).to eq(movie.id)
604
604
  end
605
605
 
606
- it "sets the base on the inverse relation" do
606
+ it "sets the base on the inverse association" do
607
607
  expect(rating.ratable).to eq(movie)
608
608
  end
609
609
 
@@ -626,15 +626,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
626
626
  movie.ratings = [ rating ]
627
627
  end
628
628
 
629
- it "sets the target of the relation" do
629
+ it "sets the target of the association" do
630
630
  expect(movie.ratings._target).to eq([ rating ])
631
631
  end
632
632
 
633
- it "sets the foreign key of the relation" do
633
+ it "sets the foreign key of the association" do
634
634
  expect(rating.ratable_id).to eq(movie.id)
635
635
  end
636
636
 
637
- it "sets the base on the inverse relation" do
637
+ it "sets the base on the inverse association" do
638
638
  expect(rating.ratable).to eq(movie)
639
639
  end
640
640
 
@@ -676,7 +676,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
676
676
 
677
677
  describe "#= nil" do
678
678
 
679
- context "when the relation is not polymorphic" do
679
+ context "when the association is not polymorphic" do
680
680
 
681
681
  context "when the parent is a new record" do
682
682
 
@@ -693,11 +693,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
693
693
  person.posts = nil
694
694
  end
695
695
 
696
- it "sets the relation to an empty array" do
696
+ it "sets the association to an empty array" do
697
697
  expect(person.posts).to be_empty
698
698
  end
699
699
 
700
- it "removed the inverse relation" do
700
+ it "removed the inverse association" do
701
701
  expect(post.person).to be_nil
702
702
  end
703
703
 
@@ -723,11 +723,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
723
723
  person.posts = nil
724
724
  end
725
725
 
726
- it "sets the relation to empty" do
726
+ it "sets the association to empty" do
727
727
  expect(person.posts).to be_empty
728
728
  end
729
729
 
730
- it "removed the inverse relation" do
730
+ it "removed the inverse association" do
731
731
  expect(post.person).to be_nil
732
732
  end
733
733
 
@@ -751,11 +751,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
751
751
  person.drugs = nil
752
752
  end
753
753
 
754
- it "sets the relation to empty" do
754
+ it "sets the association to empty" do
755
755
  expect(person.drugs).to be_empty
756
756
  end
757
757
 
758
- it "removed the inverse relation" do
758
+ it "removed the inverse association" do
759
759
  expect(drug.person).to be_nil
760
760
  end
761
761
 
@@ -763,14 +763,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
763
763
  expect(drug.person_id).to be_nil
764
764
  end
765
765
 
766
- it "nullifies the relation" do
766
+ it "nullifies the association" do
767
767
  expect(drug).to_not be_destroyed
768
768
  end
769
769
  end
770
770
  end
771
771
  end
772
772
 
773
- context "when the relation is polymorphic" do
773
+ context "when the association is polymorphic" do
774
774
 
775
775
  context "when the parent is a new record" do
776
776
 
@@ -787,11 +787,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
787
787
  movie.ratings = nil
788
788
  end
789
789
 
790
- it "sets the relation to an empty array" do
790
+ it "sets the association to an empty array" do
791
791
  expect(movie.ratings).to be_empty
792
792
  end
793
793
 
794
- it "removed the inverse relation" do
794
+ it "removed the inverse association" do
795
795
  expect(rating.ratable).to be_nil
796
796
  end
797
797
 
@@ -815,11 +815,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
815
815
  movie.ratings = nil
816
816
  end
817
817
 
818
- it "sets the relation to empty" do
818
+ it "sets the association to empty" do
819
819
  expect(movie.ratings).to be_empty
820
820
  end
821
821
 
822
- it "removed the inverse relation" do
822
+ it "removed the inverse association" do
823
823
  expect(rating.ratable).to be_nil
824
824
  end
825
825
 
@@ -870,7 +870,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
870
870
  Person.create(posts: posts)
871
871
  end
872
872
 
873
- it "returns ids of documents that are in the relation" do
873
+ it "returns ids of documents that are in the association" do
874
874
  expect(person.post_ids).to eq(posts.map(&:id))
875
875
  end
876
876
  end
@@ -879,7 +879,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
879
879
 
880
880
  describe "##{method}" do
881
881
 
882
- context "when the relation is not polymorphic" do
882
+ context "when the association is not polymorphic" do
883
883
 
884
884
  context "when the parent is a new record" do
885
885
 
@@ -891,11 +891,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
891
891
  person.posts.send(method, title: "$$$")
892
892
  end
893
893
 
894
- it "sets the foreign key on the relation" do
894
+ it "sets the foreign key on the association" do
895
895
  expect(post.person_id).to eq(person.id)
896
896
  end
897
897
 
898
- it "sets the base on the inverse relation" do
898
+ it "sets the base on the inverse association" do
899
899
  expect(post.person).to eq(person)
900
900
  end
901
901
 
@@ -930,11 +930,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
930
930
  person.posts.send(method, text: "Testing")
931
931
  end
932
932
 
933
- it "sets the foreign key on the relation" do
933
+ it "sets the foreign key on the association" do
934
934
  expect(post.person_id).to eq(person.id)
935
935
  end
936
936
 
937
- it "sets the base on the inverse relation" do
937
+ it "sets the base on the inverse association" do
938
938
  expect(post.person).to eq(person)
939
939
  end
940
940
 
@@ -952,7 +952,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
952
952
  end
953
953
  end
954
954
 
955
- context "when the relation is polymorphic" do
955
+ context "when the association is polymorphic" do
956
956
 
957
957
  context "when the parent is a subclass" do
958
958
 
@@ -983,11 +983,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
983
983
  movie.ratings.send(method, value: 3)
984
984
  end
985
985
 
986
- it "sets the foreign key on the relation" do
986
+ it "sets the foreign key on the association" do
987
987
  expect(rating.ratable_id).to eq(movie.id)
988
988
  end
989
989
 
990
- it "sets the base on the inverse relation" do
990
+ it "sets the base on the inverse association" do
991
991
  expect(rating.ratable).to eq(movie)
992
992
  end
993
993
 
@@ -1018,11 +1018,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1018
1018
  movie.ratings.send(method, value: 4)
1019
1019
  end
1020
1020
 
1021
- it "sets the foreign key on the relation" do
1021
+ it "sets the foreign key on the association" do
1022
1022
  expect(rating.ratable_id).to eq(movie.id)
1023
1023
  end
1024
1024
 
1025
- it "sets the base on the inverse relation" do
1025
+ it "sets the base on the inverse association" do
1026
1026
  expect(rating.ratable).to eq(movie)
1027
1027
  end
1028
1028
 
@@ -1044,7 +1044,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1044
1044
 
1045
1045
  describe "#clear" do
1046
1046
 
1047
- context "when the relation is not polymorphic" do
1047
+ context "when the association is not polymorphic" do
1048
1048
 
1049
1049
  context "when the parent has been persisted" do
1050
1050
 
@@ -1058,11 +1058,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1058
1058
  person.posts.create(title: "Testing")
1059
1059
  end
1060
1060
 
1061
- let!(:relation) do
1061
+ let!(:association) do
1062
1062
  person.posts.clear
1063
1063
  end
1064
1064
 
1065
- it "clears out the relation" do
1065
+ it "clears out the association" do
1066
1066
  expect(person.posts).to be_empty
1067
1067
  end
1068
1068
 
@@ -1074,8 +1074,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1074
1074
  expect(person.reload.posts).to be_empty
1075
1075
  end
1076
1076
 
1077
- it "returns the relation" do
1078
- expect(relation).to be_empty
1077
+ it "returns the association" do
1078
+ expect(association).to be_empty
1079
1079
  end
1080
1080
  end
1081
1081
 
@@ -1085,11 +1085,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1085
1085
  person.posts.build(title: "Testing")
1086
1086
  end
1087
1087
 
1088
- let!(:relation) do
1088
+ let!(:association) do
1089
1089
  person.posts.clear
1090
1090
  end
1091
1091
 
1092
- it "clears out the relation" do
1092
+ it "clears out the association" do
1093
1093
  expect(person.posts).to be_empty
1094
1094
  end
1095
1095
  end
@@ -1105,17 +1105,17 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1105
1105
  person.posts.build(title: "Testing")
1106
1106
  end
1107
1107
 
1108
- let!(:relation) do
1108
+ let!(:association) do
1109
1109
  person.posts.clear
1110
1110
  end
1111
1111
 
1112
- it "clears out the relation" do
1112
+ it "clears out the association" do
1113
1113
  expect(person.posts).to be_empty
1114
1114
  end
1115
1115
  end
1116
1116
  end
1117
1117
 
1118
- context "when the relation is polymorphic" do
1118
+ context "when the association is polymorphic" do
1119
1119
 
1120
1120
  context "when the parent has been persisted" do
1121
1121
 
@@ -1129,11 +1129,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1129
1129
  movie.ratings.create(value: 1)
1130
1130
  end
1131
1131
 
1132
- let!(:relation) do
1132
+ let!(:association) do
1133
1133
  movie.ratings.clear
1134
1134
  end
1135
1135
 
1136
- it "clears out the relation" do
1136
+ it "clears out the association" do
1137
1137
  expect(movie.ratings).to be_empty
1138
1138
  end
1139
1139
 
@@ -1145,8 +1145,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1145
1145
  expect(movie.reload.ratings).to be_empty
1146
1146
  end
1147
1147
 
1148
- it "returns the relation" do
1149
- expect(relation).to be_empty
1148
+ it "returns the association" do
1149
+ expect(association).to be_empty
1150
1150
  end
1151
1151
  end
1152
1152
 
@@ -1156,11 +1156,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1156
1156
  movie.ratings.build(value: 3)
1157
1157
  end
1158
1158
 
1159
- let!(:relation) do
1159
+ let!(:association) do
1160
1160
  movie.ratings.clear
1161
1161
  end
1162
1162
 
1163
- it "clears out the relation" do
1163
+ it "clears out the association" do
1164
1164
  expect(movie.ratings).to be_empty
1165
1165
  end
1166
1166
  end
@@ -1176,11 +1176,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1176
1176
  movie.ratings.build(value: 2)
1177
1177
  end
1178
1178
 
1179
- let!(:relation) do
1179
+ let!(:association) do
1180
1180
  movie.ratings.clear
1181
1181
  end
1182
1182
 
1183
- it "clears out the relation" do
1183
+ it "clears out the association" do
1184
1184
  expect(movie.ratings).to be_empty
1185
1185
  end
1186
1186
  end
@@ -1189,7 +1189,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1189
1189
 
1190
1190
  describe "#concat" do
1191
1191
 
1192
- context "when the relations are not polymorphic" do
1192
+ context "when the associations are not polymorphic" do
1193
1193
 
1194
1194
  context "when the parent is a new record" do
1195
1195
 
@@ -1205,15 +1205,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1205
1205
  person.posts.concat([ post ])
1206
1206
  end
1207
1207
 
1208
- it "sets the foreign key on the relation" do
1208
+ it "sets the foreign key on the association" do
1209
1209
  expect(post.person_id).to eq(person.id)
1210
1210
  end
1211
1211
 
1212
- it "sets the base on the inverse relation" do
1212
+ it "sets the base on the inverse association" do
1213
1213
  expect(post.person).to eq(person)
1214
1214
  end
1215
1215
 
1216
- it "sets the same instance on the inverse relation" do
1216
+ it "sets the same instance on the inverse association" do
1217
1217
  expect(post.person).to eql(person)
1218
1218
  end
1219
1219
 
@@ -1238,11 +1238,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1238
1238
  end
1239
1239
  end
1240
1240
 
1241
- it "adds the documents to the relation" do
1241
+ it "adds the documents to the association" do
1242
1242
  expect(person.posts).to eq([ post ])
1243
1243
  end
1244
1244
 
1245
- it "sets the foreign key on the inverse relation" do
1245
+ it "sets the foreign key on the inverse association" do
1246
1246
  expect(post.person_id).to eq(person.id)
1247
1247
  end
1248
1248
 
@@ -1277,15 +1277,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1277
1277
  person.posts.concat([ post, post_three ])
1278
1278
  end
1279
1279
 
1280
- it "sets the foreign key on the relation" do
1280
+ it "sets the foreign key on the association" do
1281
1281
  expect(post.person_id).to eq(person.id)
1282
1282
  end
1283
1283
 
1284
- it "sets the base on the inverse relation" do
1284
+ it "sets the base on the inverse association" do
1285
1285
  expect(post.person).to eq(person)
1286
1286
  end
1287
1287
 
1288
- it "sets the same instance on the inverse relation" do
1288
+ it "sets the same instance on the inverse association" do
1289
1289
  expect(post.person).to eql(person)
1290
1290
  end
1291
1291
 
@@ -1297,7 +1297,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1297
1297
  expect(person.posts.count).to eq(2)
1298
1298
  end
1299
1299
 
1300
- context "when documents already exist on the relation" do
1300
+ context "when documents already exist on the association" do
1301
1301
 
1302
1302
  let(:post_two) do
1303
1303
  Post.new(title: "Test")
@@ -1307,15 +1307,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1307
1307
  person.posts.concat([ post_two ])
1308
1308
  end
1309
1309
 
1310
- it "sets the foreign key on the relation" do
1310
+ it "sets the foreign key on the association" do
1311
1311
  expect(post_two.person_id).to eq(person.id)
1312
1312
  end
1313
1313
 
1314
- it "sets the base on the inverse relation" do
1314
+ it "sets the base on the inverse association" do
1315
1315
  expect(post_two.person).to eq(person)
1316
1316
  end
1317
1317
 
1318
- it "sets the same instance on the inverse relation" do
1318
+ it "sets the same instance on the inverse association" do
1319
1319
  expect(post_two.person).to eql(person)
1320
1320
  end
1321
1321
 
@@ -1339,7 +1339,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1339
1339
  end
1340
1340
  end
1341
1341
 
1342
- context "when the relations are polymorphic" do
1342
+ context "when the associations are polymorphic" do
1343
1343
 
1344
1344
  context "when the parent is a new record" do
1345
1345
 
@@ -1355,11 +1355,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1355
1355
  movie.ratings.concat([ rating ])
1356
1356
  end
1357
1357
 
1358
- it "sets the foreign key on the relation" do
1358
+ it "sets the foreign key on the association" do
1359
1359
  expect(rating.ratable_id).to eq(movie.id)
1360
1360
  end
1361
1361
 
1362
- it "sets the base on the inverse relation" do
1362
+ it "sets the base on the inverse association" do
1363
1363
  expect(rating.ratable).to eq(movie)
1364
1364
  end
1365
1365
 
@@ -1386,11 +1386,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1386
1386
  movie.ratings.concat([ rating ])
1387
1387
  end
1388
1388
 
1389
- it "sets the foreign key on the relation" do
1389
+ it "sets the foreign key on the association" do
1390
1390
  expect(rating.ratable_id).to eq(movie.id)
1391
1391
  end
1392
1392
 
1393
- it "sets the base on the inverse relation" do
1393
+ it "sets the base on the inverse association" do
1394
1394
  expect(rating.ratable).to eq(movie)
1395
1395
  end
1396
1396
 
@@ -1432,9 +1432,16 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1432
1432
  end
1433
1433
  end
1434
1434
 
1435
+ context "when no document is added" do
1436
+
1437
+ it "returns false" do
1438
+ expect(movie.ratings.any?).to be false
1439
+ end
1440
+ end
1441
+
1435
1442
  context "when new documents exist in the database" do
1436
1443
 
1437
- context "when the documents are part of the relation" do
1444
+ context "when the documents are part of the association" do
1438
1445
 
1439
1446
  before do
1440
1447
  Rating.create(ratable: movie)
@@ -1445,7 +1452,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1445
1452
  end
1446
1453
  end
1447
1454
 
1448
- context "when the documents are not part of the relation" do
1455
+ context "when the documents are not part of the association" do
1449
1456
 
1450
1457
  before do
1451
1458
  Rating.create
@@ -1458,6 +1465,188 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1458
1465
  end
1459
1466
  end
1460
1467
 
1468
+ describe "#any?" do
1469
+
1470
+ shared_examples 'does not query database when association is loaded' do
1471
+
1472
+ let(:fresh_movie) { Movie.find(movie.id) }
1473
+
1474
+ context 'when association is not loaded' do
1475
+ it 'queries database on each call' do
1476
+ fresh_movie
1477
+
1478
+ expect_query(1) do
1479
+ fresh_movie.ratings.any?.should be expected_result
1480
+ end
1481
+
1482
+ expect_query(1) do
1483
+ fresh_movie.ratings.any?.should be expected_result
1484
+ end
1485
+ end
1486
+
1487
+ context 'when using a block' do
1488
+ it 'queries database on first call only' do
1489
+ fresh_movie
1490
+
1491
+ expect_query(1) do
1492
+ fresh_movie.ratings.any? { false }.should be false
1493
+ end
1494
+
1495
+ expect_no_queries do
1496
+ fresh_movie.ratings.any? { false }.should be false
1497
+ end
1498
+ end
1499
+ end
1500
+ end
1501
+
1502
+ context 'when association is loaded' do
1503
+ it 'does not query database' do
1504
+ fresh_movie
1505
+
1506
+ expect_query(1) do
1507
+ fresh_movie.ratings.any?.should be expected_result
1508
+ end
1509
+
1510
+ fresh_movie.ratings.to_a
1511
+
1512
+ expect_no_queries do
1513
+ fresh_movie.ratings.any?.should be expected_result
1514
+ end
1515
+ end
1516
+ end
1517
+ end
1518
+
1519
+ let(:movie) do
1520
+ Movie.create
1521
+ end
1522
+
1523
+ context "when nothing exists on the association" do
1524
+
1525
+ context "when no document is added" do
1526
+
1527
+ let!(:movie) do
1528
+ Movie.create!
1529
+ end
1530
+
1531
+ it "returns false" do
1532
+ expect(movie.ratings.any?).to be false
1533
+ end
1534
+
1535
+ let(:expected_result) { false }
1536
+ include_examples 'does not query database when association is loaded'
1537
+ end
1538
+
1539
+ context "when the document is destroyed" do
1540
+
1541
+ before do
1542
+ Rating.create!
1543
+ end
1544
+
1545
+ let!(:movie) do
1546
+ Movie.create!
1547
+ end
1548
+
1549
+ it "returns false" do
1550
+ movie.destroy
1551
+ expect(movie.ratings.any?).to be false
1552
+ end
1553
+ end
1554
+ end
1555
+
1556
+ context "when appending to a association and _loaded/_unloaded are empty" do
1557
+
1558
+ let!(:movie) do
1559
+ Movie.create!
1560
+ end
1561
+
1562
+ before do
1563
+ movie.ratings << Rating.new
1564
+ end
1565
+
1566
+ it "returns true" do
1567
+ expect(movie.ratings.any?).to be true
1568
+ end
1569
+
1570
+ context 'when association is not loaded' do
1571
+ it 'queries database on each call' do
1572
+ expect_query(1) do
1573
+ movie.ratings.any?.should be true
1574
+ end
1575
+
1576
+ expect_query(1) do
1577
+ movie.ratings.any?.should be true
1578
+ end
1579
+ end
1580
+ end
1581
+
1582
+ context 'when association is loaded' do
1583
+ it 'does not query database' do
1584
+ expect_query(1) do
1585
+ movie.ratings.any?.should be true
1586
+ end
1587
+
1588
+ movie.ratings.to_a
1589
+
1590
+ expect_no_queries do
1591
+ movie.ratings.any?.should be true
1592
+ end
1593
+ end
1594
+ end
1595
+ end
1596
+
1597
+ context "when appending to a association in a transaction" do
1598
+ require_transaction_support
1599
+
1600
+ let!(:movie) do
1601
+ Movie.create!
1602
+ end
1603
+
1604
+ it "returns true" do
1605
+ movie.with_session do |session|
1606
+ session.with_transaction do
1607
+ expect{ movie.ratings << Rating.new }.to_not raise_error
1608
+ expect(movie.ratings.any?).to be true
1609
+ end
1610
+ end
1611
+ end
1612
+ end
1613
+
1614
+ context "when documents have been persisted" do
1615
+
1616
+ let!(:rating) do
1617
+ movie.ratings.create(value: 1)
1618
+ end
1619
+
1620
+ it "returns true" do
1621
+ expect(movie.ratings.any?).to be true
1622
+ end
1623
+
1624
+ let(:expected_result) { true }
1625
+ include_examples 'does not query database when association is loaded'
1626
+ end
1627
+
1628
+ context "when documents have not been persisted" do
1629
+
1630
+ let!(:rating) do
1631
+ movie.ratings.build(value: 1)
1632
+ end
1633
+
1634
+ it "returns false" do
1635
+ expect(movie.ratings.any?).to be true
1636
+ end
1637
+ end
1638
+
1639
+ context "when new documents exist in the database" do
1640
+ before do
1641
+ Rating.create(ratable: movie)
1642
+ end
1643
+
1644
+ it "returns true" do
1645
+ expect(movie.ratings.any?).to be true
1646
+ end
1647
+ end
1648
+ end
1649
+
1461
1650
  describe "#create" do
1462
1651
 
1463
1652
  context "when providing multiple attributes" do
@@ -1487,7 +1676,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1487
1676
  end
1488
1677
  end
1489
1678
 
1490
- context "when the relation is not polymorphic" do
1679
+ context "when the association is not polymorphic" do
1491
1680
 
1492
1681
  context "when the parent is a new record" do
1493
1682
 
@@ -1553,11 +1742,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1553
1742
  end
1554
1743
  end
1555
1744
 
1556
- it "sets the foreign key on the relation" do
1745
+ it "sets the foreign key on the association" do
1557
1746
  expect(post.person_id).to eq(person.id)
1558
1747
  end
1559
1748
 
1560
- it "sets the base on the inverse relation" do
1749
+ it "sets the base on the inverse association" do
1561
1750
  expect(post.person).to eq(person)
1562
1751
  end
1563
1752
 
@@ -1606,7 +1795,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1606
1795
  end
1607
1796
  end
1608
1797
 
1609
- context "when the relation is polymorphic" do
1798
+ context "when the association is polymorphic" do
1610
1799
 
1611
1800
  context "when the parent is a new record" do
1612
1801
 
@@ -1633,11 +1822,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1633
1822
  movie.ratings.create(value: 3)
1634
1823
  end
1635
1824
 
1636
- it "sets the foreign key on the relation" do
1825
+ it "sets the foreign key on the association" do
1637
1826
  expect(rating.ratable_id).to eq(movie.id)
1638
1827
  end
1639
1828
 
1640
- it "sets the base on the inverse relation" do
1829
+ it "sets the base on the inverse association" do
1641
1830
  expect(rating.ratable).to eq(movie)
1642
1831
  end
1643
1832
 
@@ -1700,7 +1889,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1700
1889
  end
1701
1890
  end
1702
1891
 
1703
- context "when the relation is not polymorphic" do
1892
+ context "when the association is not polymorphic" do
1704
1893
 
1705
1894
  context "when the parent is a new record" do
1706
1895
 
@@ -1727,11 +1916,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1727
1916
  person.posts.create!(title: "Testing")
1728
1917
  end
1729
1918
 
1730
- it "sets the foreign key on the relation" do
1919
+ it "sets the foreign key on the association" do
1731
1920
  expect(post.person_id).to eq(person.id)
1732
1921
  end
1733
1922
 
1734
- it "sets the base on the inverse relation" do
1923
+ it "sets the base on the inverse association" do
1735
1924
  expect(post.person).to eq(person)
1736
1925
  end
1737
1926
 
@@ -1758,7 +1947,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1758
1947
  end
1759
1948
  end
1760
1949
 
1761
- context "when the relation is polymorphic" do
1950
+ context "when the association is polymorphic" do
1762
1951
 
1763
1952
  context "when the parent is a new record" do
1764
1953
 
@@ -1785,11 +1974,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1785
1974
  movie.ratings.create!(value: 4)
1786
1975
  end
1787
1976
 
1788
- it "sets the foreign key on the relation" do
1977
+ it "sets the foreign key on the association" do
1789
1978
  expect(rating.ratable_id).to eq(movie.id)
1790
1979
  end
1791
1980
 
1792
- it "sets the base on the inverse relation" do
1981
+ it "sets the base on the inverse association" do
1793
1982
  expect(rating.ratable).to eq(movie)
1794
1983
  end
1795
1984
 
@@ -1823,7 +2012,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1823
2012
  Movie.new
1824
2013
  end
1825
2014
 
1826
- context "when the relation is polymorphic" do
2015
+ context "when the association is polymorphic" do
1827
2016
 
1828
2017
  let(:association) do
1829
2018
  Movie.relations["ratings"]
@@ -1843,7 +2032,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1843
2032
  end
1844
2033
  end
1845
2034
 
1846
- context "when the relation is not polymorphic" do
2035
+ context "when the association is not polymorphic" do
1847
2036
 
1848
2037
  let(:association) do
1849
2038
  Person.relations["posts"]
@@ -1914,7 +2103,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1914
2103
  expect(drug.person_id).to be_nil
1915
2104
  end
1916
2105
 
1917
- it "removes the document from the relation" do
2106
+ it "removes the document from the association" do
1918
2107
  expect(person.drugs).to_not include(drug)
1919
2108
  end
1920
2109
  end
@@ -1937,7 +2126,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1937
2126
  expect(drug.person_id).to be_nil
1938
2127
  end
1939
2128
 
1940
- it "removes the document from the relation" do
2129
+ it "removes the document from the association" do
1941
2130
  expect(person.drugs).to_not include(drug)
1942
2131
  end
1943
2132
  end
@@ -1963,7 +2152,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1963
2152
  expect(post).to be_destroyed
1964
2153
  end
1965
2154
 
1966
- it "removes the document from the relation" do
2155
+ it "removes the document from the association" do
1967
2156
  expect(person.posts).to_not include(post)
1968
2157
  end
1969
2158
  end
@@ -1986,7 +2175,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
1986
2175
  expect(post).to be_destroyed
1987
2176
  end
1988
2177
 
1989
- it "removes the document from the relation" do
2178
+ it "removes the document from the association" do
1990
2179
  expect(person.posts).to_not include(post)
1991
2180
  end
1992
2181
  end
@@ -2017,7 +2206,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2017
2206
 
2018
2207
  describe "##{method}" do
2019
2208
 
2020
- context "when the relation is not polymorphic" do
2209
+ context "when the association is not polymorphic" do
2021
2210
 
2022
2211
  context "when conditions are provided" do
2023
2212
 
@@ -2073,7 +2262,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2073
2262
  end
2074
2263
  end
2075
2264
 
2076
- context "when the relation is polymorphic" do
2265
+ context "when the association is polymorphic" do
2077
2266
 
2078
2267
  context "when conditions are provided" do
2079
2268
 
@@ -2152,9 +2341,35 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2152
2341
  it "returns true" do
2153
2342
  expect(person.posts.exists?).to be true
2154
2343
  end
2344
+
2345
+ context 'when association is not loaded' do
2346
+ it 'queries database on each call' do
2347
+ expect_query(1) do
2348
+ person.posts.exists?.should be true
2349
+ end
2350
+
2351
+ expect_query(1) do
2352
+ person.posts.exists?.should be true
2353
+ end
2354
+ end
2355
+ end
2356
+
2357
+ context 'when association is loaded' do
2358
+ it 'queries database on each call' do
2359
+ expect_query(1) do
2360
+ person.posts.exists?.should be true
2361
+ end
2362
+
2363
+ person.posts.to_a
2364
+
2365
+ expect_query(1) do
2366
+ person.posts.exists?.should be true
2367
+ end
2368
+ end
2369
+ end
2155
2370
  end
2156
2371
 
2157
- context "when no documents exist in the database" do
2372
+ context "when documents exist in application but not in database" do
2158
2373
 
2159
2374
  before do
2160
2375
  person.posts.build
@@ -2163,6 +2378,65 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2163
2378
  it "returns false" do
2164
2379
  expect(person.posts.exists?).to be false
2165
2380
  end
2381
+
2382
+ context 'when association is not loaded' do
2383
+ it 'queries database on each call' do
2384
+ expect_query(1) do
2385
+ person.posts.exists?.should be false
2386
+ end
2387
+
2388
+ expect_query(1) do
2389
+ person.posts.exists?.should be false
2390
+ end
2391
+ end
2392
+ end
2393
+
2394
+ context 'when association is loaded' do
2395
+ it 'queries database on each call' do
2396
+ expect_query(1) do
2397
+ person.posts.exists?.should be false
2398
+ end
2399
+
2400
+ person.posts.to_a
2401
+
2402
+ expect_query(1) do
2403
+ person.posts.exists?.should be false
2404
+ end
2405
+ end
2406
+ end
2407
+ end
2408
+
2409
+ context "when no documents exist" do
2410
+
2411
+ it "returns false" do
2412
+ expect(person.posts.exists?).to be false
2413
+ end
2414
+
2415
+ context 'when association is not loaded' do
2416
+ it 'queries database on each call' do
2417
+ expect_query(1) do
2418
+ person.posts.exists?.should be false
2419
+ end
2420
+
2421
+ expect_query(1) do
2422
+ person.posts.exists?.should be false
2423
+ end
2424
+ end
2425
+ end
2426
+
2427
+ context 'when association is loaded' do
2428
+ it 'queries database on each call' do
2429
+ expect_query(1) do
2430
+ person.posts.exists?.should be false
2431
+ end
2432
+
2433
+ person.posts.to_a
2434
+
2435
+ expect_query(1) do
2436
+ person.posts.exists?.should be false
2437
+ end
2438
+ end
2439
+ end
2166
2440
  end
2167
2441
  end
2168
2442
 
@@ -2189,7 +2463,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2189
2463
  end
2190
2464
  end
2191
2465
 
2192
- context "when the relation is not polymorphic" do
2466
+ context "when the association is not polymorphic" do
2193
2467
 
2194
2468
  let(:person) do
2195
2469
  Person.create
@@ -2200,7 +2474,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2200
2474
  end
2201
2475
 
2202
2476
  let!(:post_two) do
2203
- person.posts.create(title: "OMG I has relations")
2477
+ person.posts.create(title: "OMG I has associations")
2204
2478
  end
2205
2479
 
2206
2480
  context "when providing an id" do
@@ -2216,7 +2490,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2216
2490
  end
2217
2491
  end
2218
2492
 
2219
- context "when the id matches but is not scoped to the relation" do
2493
+ context "when the id matches but is not scoped to the association" do
2220
2494
 
2221
2495
  let(:post) do
2222
2496
  Post.create(title: "Unscoped")
@@ -2315,7 +2589,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2315
2589
  end
2316
2590
  end
2317
2591
 
2318
- context "when the relation is polymorphic" do
2592
+ context "when the association is polymorphic" do
2319
2593
 
2320
2594
  let(:movie) do
2321
2595
  Movie.create
@@ -2439,7 +2713,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2439
2713
 
2440
2714
  describe "#find_or_create_by" do
2441
2715
 
2442
- context "when the relation is not polymorphic" do
2716
+ context "when the association is not polymorphic" do
2443
2717
 
2444
2718
  let(:person) do
2445
2719
  Person.create
@@ -2459,7 +2733,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2459
2733
  expect(found).to eq(post)
2460
2734
  end
2461
2735
 
2462
- it "keeps the document in the relation" do
2736
+ it "keeps the document in the association" do
2463
2737
  expect(found.person).to eq(person)
2464
2738
  end
2465
2739
  end
@@ -2486,7 +2760,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2486
2760
  expect(found.content).to eq("The Content")
2487
2761
  end
2488
2762
 
2489
- it "keeps the document in the relation" do
2763
+ it "keeps the document in the association" do
2490
2764
  expect(found.person).to eq(person)
2491
2765
  end
2492
2766
  end
@@ -2505,14 +2779,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2505
2779
  expect(found).to be_persisted
2506
2780
  end
2507
2781
 
2508
- it "keeps the document in the relation" do
2782
+ it "keeps the document in the association" do
2509
2783
  expect(found.person).to eq(person)
2510
2784
  end
2511
2785
  end
2512
2786
  end
2513
2787
  end
2514
2788
 
2515
- context "when the relation is polymorphic" do
2789
+ context "when the association is polymorphic" do
2516
2790
 
2517
2791
  let(:movie) do
2518
2792
  Movie.create
@@ -2532,7 +2806,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2532
2806
  expect(found).to eq(rating)
2533
2807
  end
2534
2808
 
2535
- it "keeps the document in the relation" do
2809
+ it "keeps the document in the association" do
2536
2810
  expect(found.ratable).to eq(movie)
2537
2811
  end
2538
2812
  end
@@ -2551,7 +2825,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2551
2825
  expect(found).to be_persisted
2552
2826
  end
2553
2827
 
2554
- it "keeps the document in the relation" do
2828
+ it "keeps the document in the association" do
2555
2829
  expect(found.ratable).to eq(movie)
2556
2830
  end
2557
2831
  end
@@ -2560,7 +2834,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2560
2834
 
2561
2835
  describe "#find_or_create_by!" do
2562
2836
 
2563
- context "when the relation is not polymorphic" do
2837
+ context "when the association is not polymorphic" do
2564
2838
 
2565
2839
  let(:person) do
2566
2840
  Person.create
@@ -2580,7 +2854,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2580
2854
  expect(found).to eq(post)
2581
2855
  end
2582
2856
 
2583
- it "keeps the document in the relation" do
2857
+ it "keeps the document in the association" do
2584
2858
  expect(found.person).to eq(person)
2585
2859
  end
2586
2860
  end
@@ -2607,7 +2881,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2607
2881
  expect(found.content).to eq("The Content")
2608
2882
  end
2609
2883
 
2610
- it "keeps the document in the relation" do
2884
+ it "keeps the document in the association" do
2611
2885
  expect(found.person).to eq(person)
2612
2886
  end
2613
2887
  end
@@ -2626,14 +2900,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2626
2900
  expect(found).to be_persisted
2627
2901
  end
2628
2902
 
2629
- it "keeps the document in the relation" do
2903
+ it "keeps the document in the association" do
2630
2904
  expect(found.person).to eq(person)
2631
2905
  end
2632
2906
  end
2633
2907
  end
2634
2908
  end
2635
2909
 
2636
- context "when the relation is polymorphic" do
2910
+ context "when the association is polymorphic" do
2637
2911
 
2638
2912
  let(:movie) do
2639
2913
  Movie.create
@@ -2653,7 +2927,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2653
2927
  expect(found).to eq(rating)
2654
2928
  end
2655
2929
 
2656
- it "keeps the document in the relation" do
2930
+ it "keeps the document in the association" do
2657
2931
  expect(found.ratable).to eq(movie)
2658
2932
  end
2659
2933
  end
@@ -2672,7 +2946,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2672
2946
  expect(found).to be_persisted
2673
2947
  end
2674
2948
 
2675
- it "keeps the document in the relation" do
2949
+ it "keeps the document in the association" do
2676
2950
  expect(found.ratable).to eq(movie)
2677
2951
  end
2678
2952
 
@@ -2690,7 +2964,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2690
2964
 
2691
2965
  describe "#find_or_initialize_by" do
2692
2966
 
2693
- context "when the relation is not polymorphic" do
2967
+ context "when the association is not polymorphic" do
2694
2968
 
2695
2969
  let(:person) do
2696
2970
  Person.create
@@ -2733,7 +3007,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2733
3007
  end
2734
3008
  end
2735
3009
 
2736
- context "when the relation is polymorphic" do
3010
+ context "when the association is polymorphic" do
2737
3011
 
2738
3012
  let(:movie) do
2739
3013
  Movie.create
@@ -2773,7 +3047,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2773
3047
 
2774
3048
  describe "#initialize" do
2775
3049
 
2776
- context "when an illegal mixed relation exists" do
3050
+ context "when an illegal mixed association exists" do
2777
3051
 
2778
3052
  let(:post) do
2779
3053
  Post.new
@@ -2786,7 +3060,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2786
3060
  end
2787
3061
  end
2788
3062
 
2789
- context "when a cyclic relation exists" do
3063
+ context "when a cyclic association exists" do
2790
3064
 
2791
3065
  let(:post) do
2792
3066
  Post.new
@@ -3053,7 +3327,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3053
3327
  end
3054
3328
  end
3055
3329
 
3056
- context "when the relation is not polymorphic" do
3330
+ context "when the association is not polymorphic" do
3057
3331
 
3058
3332
  let(:person) do
3059
3333
  Person.create
@@ -3087,19 +3361,19 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3087
3361
  expect(post_one.reload.person).to be_nil
3088
3362
  end
3089
3363
 
3090
- context "when adding a nullified document back to the relation" do
3364
+ context "when adding a nullified document back to the association" do
3091
3365
 
3092
3366
  before do
3093
3367
  person.posts.push(post_one)
3094
3368
  end
3095
3369
 
3096
- it "persists the relation" do
3370
+ it "persists the association" do
3097
3371
  expect(person.posts(true)).to eq([ post_one ])
3098
3372
  end
3099
3373
  end
3100
3374
  end
3101
3375
 
3102
- context "when the relation is polymorphic" do
3376
+ context "when the association is polymorphic" do
3103
3377
 
3104
3378
  let(:movie) do
3105
3379
  Movie.create(title: "Oldboy")
@@ -3182,7 +3456,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3182
3456
  person.posts.scoped
3183
3457
  end
3184
3458
 
3185
- it "returns the relation criteria" do
3459
+ it "returns the association criteria" do
3186
3460
  expect(scoped).to be_a(Mongoid::Criteria)
3187
3461
  end
3188
3462
 
@@ -3226,7 +3500,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3226
3500
 
3227
3501
  describe "#unscoped" do
3228
3502
 
3229
- context "when the relation has no default scope" do
3503
+ context "when the association has no default scope" do
3230
3504
 
3231
3505
  let!(:person) do
3232
3506
  Person.create
@@ -3249,7 +3523,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3249
3523
  end
3250
3524
  end
3251
3525
 
3252
- context "when the relation has a default scope" do
3526
+ context "when the association has a default scope" do
3253
3527
 
3254
3528
  let!(:church) do
3255
3529
  Church.create
@@ -3313,7 +3587,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3313
3587
  end
3314
3588
  end
3315
3589
 
3316
- context "when reloading the relation" do
3590
+ context "when reloading the association" do
3317
3591
 
3318
3592
  let!(:person) do
3319
3593
  Person.create
@@ -3331,7 +3605,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3331
3605
  person.posts << post_one
3332
3606
  end
3333
3607
 
3334
- context "when the relation references the same documents" do
3608
+ context "when the association references the same documents" do
3335
3609
 
3336
3610
  before do
3337
3611
  Post.collection.find({ _id: post_one.id }).
@@ -3347,7 +3621,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3347
3621
  end
3348
3622
  end
3349
3623
 
3350
- context "when the relation references different documents" do
3624
+ context "when the association references different documents" do
3351
3625
 
3352
3626
  before do
3353
3627
  person.posts << post_two
@@ -3434,7 +3708,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3434
3708
  expect(album.before_add_called).to be true
3435
3709
  end
3436
3710
 
3437
- it "adds the document to the relation" do
3711
+ it "adds the document to the association" do
3438
3712
  expect(artist.albums).to eq([ album ])
3439
3713
  end
3440
3714
  end
@@ -3446,7 +3720,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3446
3720
  begin; artist.albums << album; rescue; end
3447
3721
  end
3448
3722
 
3449
- it "does not add the document to the relation" do
3723
+ it "does not add the document to the association" do
3450
3724
  expect(artist.albums).to be_empty
3451
3725
  end
3452
3726
  end
@@ -3474,12 +3748,12 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3474
3748
  begin; artist.albums << album; rescue; end
3475
3749
  end
3476
3750
 
3477
- it "adds the document to the relation" do
3751
+ it "adds the document to the association" do
3478
3752
  expect(artist.albums).to eq([ album ])
3479
3753
  end
3480
3754
  end
3481
3755
 
3482
- context 'when the relation already exists' do
3756
+ context 'when the association already exists' do
3483
3757
 
3484
3758
  before do
3485
3759
  artist.albums << album
@@ -3492,7 +3766,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3492
3766
  Album.where(artist_id: artist.id).first
3493
3767
  end
3494
3768
 
3495
- it 'does not execute the callback when the relation is accessed' do
3769
+ it 'does not execute the callback when the association is accessed' do
3496
3770
  expect(reloaded_album.artist.after_add_referenced_called).to be(nil)
3497
3771
  end
3498
3772
  end
@@ -3524,7 +3798,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3524
3798
  expect(artist.before_remove_referenced_called).to be true
3525
3799
  end
3526
3800
 
3527
- it "removes the document from the relation" do
3801
+ it "removes the document from the association" do
3528
3802
  expect(artist.albums).to be_empty
3529
3803
  end
3530
3804
  end
@@ -3539,7 +3813,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3539
3813
  expect(artist.before_remove_referenced_called).to be true
3540
3814
  end
3541
3815
 
3542
- it "clears the relation" do
3816
+ it "clears the association" do
3543
3817
  expect(artist.albums).to be_empty
3544
3818
  end
3545
3819
  end
@@ -3556,7 +3830,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3556
3830
  begin; artist.albums.delete(album); rescue; end
3557
3831
  end
3558
3832
 
3559
- it "does not remove the document from the relation" do
3833
+ it "does not remove the document from the association" do
3560
3834
  expect(artist.albums).to eq([ album ])
3561
3835
  end
3562
3836
  end
@@ -3567,7 +3841,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3567
3841
  begin; artist.albums.clear; rescue; end
3568
3842
  end
3569
3843
 
3570
- it "does not clear the relation" do
3844
+ it "does not clear the association" do
3571
3845
  expect(artist.albums).to eq([ album ])
3572
3846
  end
3573
3847
  end
@@ -3627,7 +3901,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3627
3901
  begin; artist.albums.delete(album); rescue; end
3628
3902
  end
3629
3903
 
3630
- it "removes the documents from the relation" do
3904
+ it "removes the documents from the association" do
3631
3905
  expect(artist.albums).to be_empty
3632
3906
  end
3633
3907
  end
@@ -3638,14 +3912,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3638
3912
  begin; artist.albums.clear; rescue; end
3639
3913
  end
3640
3914
 
3641
- it "removes the documents from the relation" do
3915
+ it "removes the documents from the association" do
3642
3916
  expect(artist.albums).to be_empty
3643
3917
  end
3644
3918
  end
3645
3919
  end
3646
3920
  end
3647
3921
 
3648
- context "when executing a criteria call on an ordered relation" do
3922
+ context "when executing a criteria call on an ordered association" do
3649
3923
 
3650
3924
  let(:person) do
3651
3925
  Person.create
@@ -3683,7 +3957,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3683
3957
  end
3684
3958
  end
3685
3959
 
3686
- context "when accessing a relation named parent" do
3960
+ context "when accessing a association named parent" do
3687
3961
 
3688
3962
  let!(:parent) do
3689
3963
  Odd.create(name: "odd parent")
@@ -3694,7 +3968,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3694
3968
  end
3695
3969
 
3696
3970
  it "updates the child after accessing the parent" do
3697
- # Access parent relation on the child to make sure it is loaded
3971
+ # Access parent association on the child to make sure it is loaded
3698
3972
  child.parent
3699
3973
 
3700
3974
  new_child_name = "updated even child"
@@ -3707,7 +3981,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3707
3981
  end
3708
3982
  end
3709
3983
 
3710
- context 'when a document has referenced and embedded relations' do
3984
+ context 'when a document has referenced and embedded associations' do
3711
3985
 
3712
3986
  let(:agent) do
3713
3987
  Agent.new
@@ -3731,7 +4005,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
3731
4005
  end
3732
4006
  end
3733
4007
 
3734
- context 'when the two models use the same name to refer to the relation' do
4008
+ context 'when the two models use the same name to refer to the association' do
3735
4009
 
3736
4010
  let(:agent) do
3737
4011
  Agent.new