mongoid 3.1.6 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (571) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +479 -8
  3. data/README.md +10 -7
  4. data/lib/config/locales/en.yml +34 -20
  5. data/lib/mongoid.rb +10 -76
  6. data/lib/mongoid/atomic.rb +3 -14
  7. data/lib/mongoid/atomic/paths/embedded.rb +0 -30
  8. data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
  9. data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
  10. data/lib/mongoid/atomic/paths/root.rb +0 -13
  11. data/lib/mongoid/attributes.rb +65 -101
  12. data/lib/mongoid/attributes/dynamic.rb +154 -0
  13. data/lib/mongoid/attributes/nested.rb +82 -0
  14. data/lib/mongoid/attributes/processing.rb +13 -66
  15. data/lib/mongoid/{dirty.rb → changeable.rb} +32 -2
  16. data/lib/mongoid/composable.rb +105 -0
  17. data/lib/mongoid/config.rb +3 -9
  18. data/lib/mongoid/config/options.rb +1 -1
  19. data/lib/mongoid/contextual.rb +2 -0
  20. data/lib/mongoid/contextual/aggregable/memory.rb +2 -2
  21. data/lib/mongoid/contextual/aggregable/mongo.rb +7 -9
  22. data/lib/mongoid/contextual/atomic.rb +53 -53
  23. data/lib/mongoid/contextual/geo_near.rb +1 -1
  24. data/lib/mongoid/contextual/map_reduce.rb +4 -2
  25. data/lib/mongoid/contextual/memory.rb +23 -11
  26. data/lib/mongoid/contextual/mongo.rb +75 -57
  27. data/lib/mongoid/contextual/none.rb +90 -0
  28. data/lib/mongoid/contextual/text_search.rb +178 -0
  29. data/lib/mongoid/copyable.rb +2 -3
  30. data/lib/mongoid/criteria.rb +39 -34
  31. data/lib/mongoid/criteria/#findable.rb# +141 -0
  32. data/lib/mongoid/{criterion → criteria}/findable.rb +7 -47
  33. data/lib/mongoid/{criterion/inspection.rb → criteria/inspectable.rb} +2 -2
  34. data/lib/mongoid/{criterion → criteria}/marshalable.rb +3 -1
  35. data/lib/mongoid/{criterion → criteria}/modifiable.rb +28 -8
  36. data/lib/mongoid/criteria/permission.rb +70 -0
  37. data/lib/mongoid/{criterion/scoping.rb → criteria/scopable.rb} +2 -2
  38. data/lib/mongoid/document.rb +39 -24
  39. data/lib/mongoid/errors.rb +4 -1
  40. data/lib/mongoid/errors/document_not_destroyed.rb +25 -0
  41. data/lib/mongoid/errors/document_not_found.rb +2 -1
  42. data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
  43. data/lib/mongoid/errors/invalid_storage_parent.rb +26 -0
  44. data/lib/mongoid/errors/invalid_value.rb +16 -0
  45. data/lib/mongoid/errors/mongoid_error.rb +1 -1
  46. data/lib/mongoid/errors/readonly_document.rb +24 -0
  47. data/lib/mongoid/extensions.rb +15 -7
  48. data/lib/mongoid/extensions/array.rb +3 -3
  49. data/lib/mongoid/extensions/big_decimal.rb +1 -1
  50. data/lib/mongoid/extensions/boolean.rb +15 -17
  51. data/lib/mongoid/extensions/date.rb +1 -1
  52. data/lib/mongoid/extensions/date_time.rb +3 -3
  53. data/lib/mongoid/extensions/float.rb +2 -1
  54. data/lib/mongoid/extensions/hash.rb +3 -3
  55. data/lib/mongoid/extensions/integer.rb +1 -1
  56. data/lib/mongoid/extensions/object.rb +7 -7
  57. data/lib/mongoid/extensions/object_id.rb +5 -5
  58. data/lib/mongoid/extensions/range.rb +9 -3
  59. data/lib/mongoid/extensions/regexp.rb +1 -1
  60. data/lib/mongoid/extensions/set.rb +1 -1
  61. data/lib/mongoid/extensions/string.rb +6 -18
  62. data/lib/mongoid/extensions/symbol.rb +1 -1
  63. data/lib/mongoid/extensions/time.rb +3 -3
  64. data/lib/mongoid/extensions/time_with_zone.rb +1 -1
  65. data/lib/mongoid/factory.rb +8 -6
  66. data/lib/mongoid/fields.rb +41 -8
  67. data/lib/mongoid/fields/foreign_key.rb +3 -3
  68. data/lib/mongoid/fields/localized.rb +1 -1
  69. data/lib/mongoid/fields/standard.rb +5 -17
  70. data/lib/mongoid/fields/validators/macro.rb +15 -5
  71. data/lib/mongoid/{finders.rb → findable.rb} +35 -7
  72. data/lib/mongoid/{indexes.rb → indexable.rb} +50 -55
  73. data/lib/mongoid/indexable/specification.rb +104 -0
  74. data/lib/mongoid/{indexes → indexable}/validators/options.rb +2 -1
  75. data/lib/mongoid/{inspection.rb → inspectable.rb} +15 -11
  76. data/lib/mongoid/{callbacks.rb → interceptable.rb} +30 -62
  77. data/lib/mongoid/log_subscriber.rb +55 -0
  78. data/lib/mongoid/matchable.rb +152 -0
  79. data/lib/mongoid/{matchers → matchable}/all.rb +1 -1
  80. data/lib/mongoid/{matchers → matchable}/and.rb +2 -2
  81. data/lib/mongoid/{matchers → matchable}/default.rb +1 -1
  82. data/lib/mongoid/{matchers → matchable}/exists.rb +1 -1
  83. data/lib/mongoid/{matchers → matchable}/gt.rb +1 -1
  84. data/lib/mongoid/{matchers → matchable}/gte.rb +1 -1
  85. data/lib/mongoid/{matchers → matchable}/in.rb +2 -2
  86. data/lib/mongoid/{matchers → matchable}/lt.rb +1 -1
  87. data/lib/mongoid/{matchers → matchable}/lte.rb +1 -1
  88. data/lib/mongoid/{matchers → matchable}/ne.rb +2 -2
  89. data/lib/mongoid/{matchers → matchable}/nin.rb +3 -2
  90. data/lib/mongoid/{matchers → matchable}/or.rb +2 -2
  91. data/lib/mongoid/{matchers → matchable}/size.rb +1 -1
  92. data/lib/mongoid/persistable.rb +216 -0
  93. data/lib/mongoid/persistable/creatable.rb +189 -0
  94. data/lib/mongoid/persistable/deletable.rb +149 -0
  95. data/lib/mongoid/persistable/destroyable.rb +60 -0
  96. data/lib/mongoid/persistable/incrementable.rb +36 -0
  97. data/lib/mongoid/persistable/logical.rb +38 -0
  98. data/lib/mongoid/persistable/poppable.rb +39 -0
  99. data/lib/mongoid/persistable/pullable.rb +55 -0
  100. data/lib/mongoid/persistable/pushable.rb +62 -0
  101. data/lib/mongoid/persistable/renamable.rb +35 -0
  102. data/lib/mongoid/persistable/savable.rb +52 -0
  103. data/lib/mongoid/persistable/settable.rb +33 -0
  104. data/lib/mongoid/persistable/unsettable.rb +36 -0
  105. data/lib/mongoid/persistable/updatable.rb +153 -0
  106. data/lib/mongoid/persistable/upsertable.rb +55 -0
  107. data/lib/mongoid/positional.rb +71 -0
  108. data/lib/mongoid/query_cache.rb +255 -0
  109. data/lib/mongoid/railtie.rb +34 -60
  110. data/lib/mongoid/railties/database.rake +9 -25
  111. data/lib/mongoid/relations.rb +11 -25
  112. data/lib/mongoid/relations/accessors.rb +15 -51
  113. data/lib/mongoid/relations/auto_save.rb +15 -36
  114. data/lib/mongoid/relations/binding.rb +2 -25
  115. data/lib/mongoid/relations/bindings/embedded/in.rb +1 -1
  116. data/lib/mongoid/relations/bindings/embedded/many.rb +1 -3
  117. data/lib/mongoid/relations/bindings/referenced/in.rb +3 -8
  118. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -2
  119. data/lib/mongoid/relations/builder.rb +1 -1
  120. data/lib/mongoid/relations/builders.rb +2 -2
  121. data/lib/mongoid/relations/builders/embedded/one.rb +1 -1
  122. data/lib/mongoid/relations/builders/nested_attributes/many.rb +10 -13
  123. data/lib/mongoid/relations/builders/nested_attributes/one.rb +5 -6
  124. data/lib/mongoid/relations/builders/referenced/in.rb +1 -1
  125. data/lib/mongoid/relations/builders/referenced/many.rb +1 -2
  126. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +1 -2
  127. data/lib/mongoid/relations/builders/referenced/one.rb +1 -1
  128. data/lib/mongoid/relations/cascading.rb +3 -5
  129. data/lib/mongoid/relations/constraint.rb +1 -1
  130. data/lib/mongoid/relations/conversions.rb +1 -1
  131. data/lib/mongoid/relations/counter_cache.rb +39 -15
  132. data/lib/mongoid/relations/eager.rb +46 -0
  133. data/lib/mongoid/relations/eager/base.rb +149 -0
  134. data/lib/mongoid/relations/eager/belongs_to.rb +31 -0
  135. data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +47 -0
  136. data/lib/mongoid/relations/eager/has_many.rb +38 -0
  137. data/lib/mongoid/relations/eager/has_one.rb +30 -0
  138. data/lib/mongoid/relations/embedded/batchable.rb +4 -5
  139. data/lib/mongoid/relations/embedded/in.rb +4 -4
  140. data/lib/mongoid/relations/embedded/many.rb +14 -32
  141. data/lib/mongoid/relations/embedded/one.rb +1 -1
  142. data/lib/mongoid/relations/macros.rb +3 -4
  143. data/lib/mongoid/relations/many.rb +51 -31
  144. data/lib/mongoid/relations/marshalable.rb +3 -3
  145. data/lib/mongoid/relations/metadata.rb +14 -79
  146. data/lib/mongoid/relations/nested_builder.rb +2 -2
  147. data/lib/mongoid/relations/one.rb +1 -1
  148. data/lib/mongoid/relations/options.rb +1 -0
  149. data/lib/mongoid/relations/polymorphic.rb +0 -1
  150. data/lib/mongoid/relations/proxy.rb +21 -41
  151. data/lib/mongoid/relations/referenced/in.rb +4 -20
  152. data/lib/mongoid/relations/referenced/many.rb +22 -35
  153. data/lib/mongoid/relations/referenced/many_to_many.rb +19 -42
  154. data/lib/mongoid/relations/referenced/one.rb +6 -25
  155. data/lib/mongoid/relations/synchronization.rb +4 -4
  156. data/lib/mongoid/relations/targets/enumerable.rb +10 -10
  157. data/lib/mongoid/relations/touchable.rb +34 -1
  158. data/lib/mongoid/{reloading.rb → reloadable.rb} +7 -5
  159. data/lib/mongoid/{scoping.rb → scopable.rb} +36 -36
  160. data/lib/mongoid/selectable.rb +59 -0
  161. data/lib/mongoid/{serialization.rb → serializable.rb} +11 -2
  162. data/lib/mongoid/sessions.rb +37 -345
  163. data/lib/mongoid/sessions/factory.rb +2 -0
  164. data/lib/mongoid/sessions/options.rb +185 -0
  165. data/lib/mongoid/sessions/storage_options.rb +140 -0
  166. data/lib/mongoid/sessions/thread_options.rb +19 -0
  167. data/lib/mongoid/sessions/validators/storage.rb +16 -3
  168. data/lib/mongoid/{sharding.rb → shardable.rb} +5 -1
  169. data/lib/mongoid/{state.rb → stateful.rb} +13 -1
  170. data/lib/mongoid/support/query_counter.rb +23 -0
  171. data/lib/mongoid/tasks/database.rake +31 -0
  172. data/lib/mongoid/tasks/database.rb +107 -0
  173. data/lib/mongoid/threaded.rb +26 -172
  174. data/lib/mongoid/threaded/lifecycle.rb +0 -28
  175. data/lib/mongoid/timestamps/updated/short.rb +2 -2
  176. data/lib/mongoid/{hierarchy.rb → traversable.rb} +15 -7
  177. data/lib/mongoid/{validations.rb → validatable.rb} +23 -10
  178. data/lib/mongoid/{validations → validatable}/associated.rb +4 -2
  179. data/lib/mongoid/{validations → validatable}/format.rb +1 -1
  180. data/lib/mongoid/{validations → validatable}/length.rb +1 -1
  181. data/lib/mongoid/{validations → validatable}/localizable.rb +1 -1
  182. data/lib/mongoid/{validations → validatable}/macros.rb +4 -3
  183. data/lib/mongoid/{validations → validatable}/presence.rb +1 -1
  184. data/lib/mongoid/{validations → validatable}/queryable.rb +1 -2
  185. data/lib/mongoid/{validations → validatable}/uniqueness.rb +25 -21
  186. data/lib/mongoid/version.rb +1 -1
  187. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +46 -25
  188. data/lib/rails/generators/mongoid/model/model_generator.rb +0 -1
  189. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +0 -3
  190. data/lib/rails/generators/mongoid_generator.rb +3 -40
  191. data/lib/rails/mongoid.rb +0 -122
  192. data/lib/support/ruby_version.rb +1 -1
  193. data/spec/app/models/account.rb +2 -6
  194. data/spec/app/models/acolyte.rb +2 -1
  195. data/spec/app/models/actor.rb +0 -1
  196. data/spec/app/models/address.rb +8 -3
  197. data/spec/app/models/animal.rb +1 -1
  198. data/spec/app/models/appointment.rb +3 -3
  199. data/spec/app/models/article.rb +1 -4
  200. data/spec/app/models/audio.rb +5 -0
  201. data/spec/app/models/author.rb +0 -2
  202. data/spec/app/models/band.rb +3 -2
  203. data/spec/app/models/bar.rb +1 -0
  204. data/spec/app/models/book.rb +1 -0
  205. data/spec/app/models/building.rb +0 -2
  206. data/spec/app/models/building_address.rb +0 -2
  207. data/spec/app/models/bus.rb +1 -1
  208. data/spec/app/models/canvas.rb +1 -1
  209. data/spec/app/models/contextable_item.rb +5 -0
  210. data/spec/app/models/contractor.rb +0 -2
  211. data/spec/app/models/country_code.rb +1 -1
  212. data/spec/app/models/definition.rb +2 -2
  213. data/spec/app/models/dog.rb +1 -1
  214. data/spec/app/models/draft.rb +9 -0
  215. data/spec/app/models/dragon.rb +4 -0
  216. data/spec/app/models/drug.rb +1 -3
  217. data/spec/app/models/dungeon.rb +4 -0
  218. data/spec/app/models/edit.rb +5 -0
  219. data/spec/app/models/even.rb +7 -0
  220. data/spec/app/models/event.rb +1 -1
  221. data/spec/app/models/filesystem.rb +1 -0
  222. data/spec/app/models/fish.rb +0 -1
  223. data/spec/app/models/fruits.rb +6 -0
  224. data/spec/app/models/game.rb +0 -2
  225. data/spec/app/models/house.rb +1 -3
  226. data/spec/app/models/id_key.rb +6 -0
  227. data/spec/app/models/item.rb +1 -5
  228. data/spec/app/models/jar.rb +1 -1
  229. data/spec/app/models/label.rb +4 -4
  230. data/spec/app/models/line_item.rb +1 -1
  231. data/spec/app/models/login.rb +1 -1
  232. data/spec/app/models/message.rb +8 -0
  233. data/spec/app/models/movie.rb +1 -0
  234. data/spec/app/models/name.rb +3 -3
  235. data/spec/app/models/note.rb +3 -1
  236. data/spec/app/models/odd.rb +7 -0
  237. data/spec/app/models/oscar.rb +1 -1
  238. data/spec/app/models/parent_doc.rb +1 -1
  239. data/spec/app/models/person.rb +16 -10
  240. data/spec/app/models/phone.rb +1 -3
  241. data/spec/app/models/player.rb +3 -3
  242. data/spec/app/models/post.rb +5 -3
  243. data/spec/app/models/preference.rb +1 -1
  244. data/spec/app/models/quiz.rb +0 -3
  245. data/spec/app/models/record.rb +10 -5
  246. data/spec/app/models/registry.rb +1 -1
  247. data/spec/app/models/server.rb +1 -1
  248. data/spec/app/models/service.rb +3 -3
  249. data/spec/app/models/sound.rb +5 -0
  250. data/spec/app/models/symptom.rb +1 -1
  251. data/spec/app/models/template.rb +1 -1
  252. data/spec/app/models/title.rb +0 -1
  253. data/spec/app/models/track.rb +5 -5
  254. data/spec/app/models/tree.rb +3 -3
  255. data/spec/app/models/video.rb +1 -5
  256. data/spec/app/models/wiki_page.rb +2 -5
  257. data/spec/app/models/word.rb +3 -0
  258. data/spec/app/models/word_origin.rb +1 -1
  259. data/spec/config/mongoid.yml +7 -8
  260. data/spec/helpers.rb +18 -0
  261. data/spec/mongoid/#atomic_spec.rb# +365 -0
  262. data/spec/mongoid/atomic/modifiers_spec.rb +22 -22
  263. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +8 -49
  264. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +7 -49
  265. data/spec/mongoid/atomic/paths/root_spec.rb +3 -61
  266. data/spec/mongoid/atomic/paths_spec.rb +19 -19
  267. data/spec/mongoid/atomic_spec.rb +19 -19
  268. data/spec/mongoid/{nested_attributes_spec.rb → attributes/nested_spec.rb} +474 -592
  269. data/spec/mongoid/attributes/readonly_spec.rb +58 -18
  270. data/spec/mongoid/attributes_spec.rb +349 -434
  271. data/spec/mongoid/{dirty_spec.rb → changeable_spec.rb} +203 -153
  272. data/spec/mongoid/{components_spec.rb → composable_spec.rb} +3 -3
  273. data/spec/mongoid/config/environment_spec.rb +3 -3
  274. data/spec/mongoid/config/options_spec.rb +6 -6
  275. data/spec/mongoid/config_spec.rb +24 -48
  276. data/spec/mongoid/contextual/aggregable/memory_spec.rb +12 -12
  277. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +78 -38
  278. data/spec/mongoid/contextual/atomic_spec.rb +60 -56
  279. data/spec/mongoid/contextual/find_and_modify_spec.rb +14 -14
  280. data/spec/mongoid/contextual/geo_near_spec.rb +22 -22
  281. data/spec/mongoid/contextual/map_reduce_spec.rb +27 -27
  282. data/spec/mongoid/contextual/memory_spec.rb +156 -94
  283. data/spec/mongoid/contextual/mongo_spec.rb +238 -150
  284. data/spec/mongoid/contextual/none_spec.rb +127 -0
  285. data/spec/mongoid/contextual/text_search_spec.rb +209 -0
  286. data/spec/mongoid/copyable_spec.rb +56 -68
  287. data/spec/mongoid/criteria/findable_spec.rb +991 -0
  288. data/spec/mongoid/{criterion/inspection_spec.rb → criteria/inspectable_spec.rb} +5 -5
  289. data/spec/mongoid/{criterion → criteria}/marshalable_spec.rb +2 -2
  290. data/spec/mongoid/criteria/modifiable_spec.rb +1252 -0
  291. data/spec/mongoid/{criterion/scoping_spec.rb → criteria/scopable_spec.rb} +37 -37
  292. data/spec/mongoid/criteria_spec.rb +715 -2421
  293. data/spec/mongoid/document_spec.rb +171 -121
  294. data/spec/mongoid/equality_spec.rb +22 -22
  295. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +3 -3
  296. data/spec/mongoid/errors/callback_spec.rb +3 -3
  297. data/spec/mongoid/errors/delete_restriction_spec.rb +3 -3
  298. data/spec/mongoid/errors/document_not_destroyed_spec.rb +33 -0
  299. data/spec/mongoid/errors/document_not_found_spec.rb +11 -11
  300. data/spec/mongoid/errors/eager_load_spec.rb +3 -3
  301. data/spec/mongoid/errors/invalid_collection_spec.rb +3 -3
  302. data/spec/mongoid/errors/invalid_config_option_spec.rb +3 -3
  303. data/spec/mongoid/errors/invalid_field_option_spec.rb +3 -3
  304. data/spec/mongoid/errors/invalid_field_spec.rb +3 -3
  305. data/spec/mongoid/errors/invalid_find_spec.rb +3 -3
  306. data/spec/mongoid/errors/invalid_includes_spec.rb +3 -3
  307. data/spec/mongoid/errors/invalid_index_spec.rb +3 -3
  308. data/spec/mongoid/errors/invalid_options_spec.rb +3 -3
  309. data/spec/mongoid/errors/invalid_path_spec.rb +3 -3
  310. data/spec/mongoid/errors/invalid_scope_spec.rb +5 -5
  311. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -3
  312. data/spec/mongoid/errors/invalid_storage_options_spec.rb +3 -3
  313. data/spec/mongoid/errors/invalid_time_spec.rb +3 -3
  314. data/spec/mongoid/errors/inverse_not_found_spec.rb +3 -3
  315. data/spec/mongoid/errors/mixed_relations_spec.rb +3 -3
  316. data/spec/mongoid/errors/mixed_session_configuration_spec.rb +3 -3
  317. data/spec/mongoid/errors/mongoid_error_spec.rb +8 -8
  318. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +3 -3
  319. data/spec/mongoid/errors/no_environment_spec.rb +3 -3
  320. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +3 -3
  321. data/spec/mongoid/errors/no_metadata_spec.rb +3 -3
  322. data/spec/mongoid/errors/no_parent_spec.rb +3 -3
  323. data/spec/mongoid/errors/no_session_config_spec.rb +3 -3
  324. data/spec/mongoid/errors/no_session_database_spec.rb +3 -3
  325. data/spec/mongoid/errors/no_session_hosts_spec.rb +3 -3
  326. data/spec/mongoid/errors/no_sessions_config_spec.rb +3 -3
  327. data/spec/mongoid/errors/readonly_attribute_spec.rb +3 -3
  328. data/spec/mongoid/errors/readonly_document_spec.rb +29 -0
  329. data/spec/mongoid/errors/scope_overwrite_spec.rb +3 -3
  330. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +3 -3
  331. data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -5
  332. data/spec/mongoid/errors/unsaved_document_spec.rb +3 -3
  333. data/spec/mongoid/errors/unsupported_javascript_spec.rb +3 -3
  334. data/spec/mongoid/errors/validations_spec.rb +7 -7
  335. data/spec/mongoid/extensions/array_spec.rb +61 -61
  336. data/spec/mongoid/extensions/big_decimal_spec.rb +11 -11
  337. data/spec/mongoid/extensions/binary_spec.rb +12 -12
  338. data/spec/mongoid/extensions/boolean_spec.rb +18 -18
  339. data/spec/mongoid/extensions/date_spec.rb +13 -13
  340. data/spec/mongoid/extensions/date_time_spec.rb +8 -8
  341. data/spec/mongoid/extensions/false_class_spec.rb +5 -5
  342. data/spec/mongoid/extensions/float_spec.rb +29 -15
  343. data/spec/mongoid/extensions/hash_spec.rb +29 -29
  344. data/spec/mongoid/extensions/integer_spec.rb +15 -15
  345. data/spec/mongoid/extensions/module_spec.rb +2 -2
  346. data/spec/mongoid/extensions/nil_class_spec.rb +1 -1
  347. data/spec/mongoid/extensions/object_id_spec.rb +134 -134
  348. data/spec/mongoid/extensions/object_spec.rb +26 -26
  349. data/spec/mongoid/extensions/range_spec.rb +61 -12
  350. data/spec/mongoid/extensions/regexp_spec.rb +4 -4
  351. data/spec/mongoid/extensions/set_spec.rb +4 -4
  352. data/spec/mongoid/extensions/string_spec.rb +35 -46
  353. data/spec/mongoid/extensions/symbol_spec.rb +9 -9
  354. data/spec/mongoid/extensions/time_spec.rb +49 -49
  355. data/spec/mongoid/extensions/time_with_zone_spec.rb +34 -34
  356. data/spec/mongoid/extensions/true_class_spec.rb +5 -5
  357. data/spec/mongoid/extensions_spec.rb +29 -0
  358. data/spec/mongoid/factory_spec.rb +15 -15
  359. data/spec/mongoid/fields/foreign_key_spec.rb +73 -66
  360. data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +15 -15
  361. data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +22 -22
  362. data/spec/mongoid/fields/localized_spec.rb +38 -23
  363. data/spec/mongoid/fields/standard_spec.rb +12 -12
  364. data/spec/mongoid/fields_spec.rb +263 -217
  365. data/spec/mongoid/findable_spec.rb +509 -0
  366. data/spec/mongoid/indexable/specification_spec.rb +102 -0
  367. data/spec/mongoid/{indexes_spec.rb → indexable_spec.rb} +171 -51
  368. data/spec/mongoid/{inspection_spec.rb → inspectable_spec.rb} +6 -14
  369. data/spec/mongoid/{callbacks_spec.rb → interceptable_spec.rb} +117 -116
  370. data/spec/mongoid/log_subscriber_spec.rb +75 -0
  371. data/spec/mongoid/loggable_spec.rb +1 -1
  372. data/spec/mongoid/{matchers → matchable}/all_spec.rb +4 -4
  373. data/spec/mongoid/{matchers → matchable}/and_spec.rb +11 -11
  374. data/spec/mongoid/{matchers → matchable}/default_spec.rb +15 -15
  375. data/spec/mongoid/{matchers → matchable}/exists_spec.rb +5 -5
  376. data/spec/mongoid/{matchers → matchable}/gt_spec.rb +9 -8
  377. data/spec/mongoid/{matchers → matchable}/gte_spec.rb +7 -7
  378. data/spec/mongoid/matchable/in_spec.rb +49 -0
  379. data/spec/mongoid/{matchers → matchable}/lt_spec.rb +7 -7
  380. data/spec/mongoid/{matchers → matchable}/lte_spec.rb +7 -7
  381. data/spec/mongoid/matchable/ne_spec.rb +46 -0
  382. data/spec/mongoid/matchable/nin_spec.rb +48 -0
  383. data/spec/mongoid/{matchers → matchable}/or_spec.rb +6 -6
  384. data/spec/mongoid/{matchers → matchable}/size_spec.rb +3 -3
  385. data/spec/mongoid/{matchers_spec.rb → matchable_spec.rb} +41 -41
  386. data/spec/mongoid/persistable/creatable_spec.rb +553 -0
  387. data/spec/mongoid/persistable/deletable_spec.rb +218 -0
  388. data/spec/mongoid/persistable/destroyable_spec.rb +192 -0
  389. data/spec/mongoid/persistable/incrementable_spec.rb +173 -0
  390. data/spec/mongoid/persistable/logical_spec.rb +143 -0
  391. data/spec/mongoid/persistable/poppable_spec.rb +115 -0
  392. data/spec/mongoid/persistable/pullable_spec.rb +228 -0
  393. data/spec/mongoid/persistable/pushable_spec.rb +258 -0
  394. data/spec/mongoid/persistable/renamable_spec.rb +135 -0
  395. data/spec/mongoid/persistable/savable_spec.rb +498 -0
  396. data/spec/mongoid/persistable/settable_spec.rb +162 -0
  397. data/spec/mongoid/persistable/unsettable_spec.rb +155 -0
  398. data/spec/mongoid/persistable/updatable_spec.rb +558 -0
  399. data/spec/mongoid/persistable/upsertable_spec.rb +106 -0
  400. data/spec/mongoid/persistable_spec.rb +206 -0
  401. data/spec/mongoid/{atomic/positionable_spec.rb → positional_spec.rb} +14 -19
  402. data/spec/mongoid/query_cache_spec.rb +263 -0
  403. data/spec/mongoid/railties/document_spec.rb +2 -2
  404. data/spec/mongoid/relations/accessors_spec.rb +53 -145
  405. data/spec/mongoid/relations/auto_save_spec.rb +37 -17
  406. data/spec/mongoid/relations/bindings/embedded/in_spec.rb +12 -12
  407. data/spec/mongoid/relations/bindings/embedded/many_spec.rb +3 -3
  408. data/spec/mongoid/relations/bindings/embedded/one_spec.rb +5 -5
  409. data/spec/mongoid/relations/bindings/referenced/in_spec.rb +26 -26
  410. data/spec/mongoid/relations/bindings/referenced/many_spec.rb +10 -10
  411. data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +19 -19
  412. data/spec/mongoid/relations/bindings/referenced/one_spec.rb +12 -12
  413. data/spec/mongoid/relations/builders/embedded/in_spec.rb +4 -4
  414. data/spec/mongoid/relations/builders/embedded/many_spec.rb +18 -18
  415. data/spec/mongoid/relations/builders/embedded/one_spec.rb +11 -11
  416. data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +12 -13
  417. data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +14 -14
  418. data/spec/mongoid/relations/builders/referenced/in_spec.rb +24 -35
  419. data/spec/mongoid/relations/builders/referenced/many_spec.rb +15 -15
  420. data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +18 -18
  421. data/spec/mongoid/relations/builders/referenced/one_spec.rb +12 -25
  422. data/spec/mongoid/relations/builders_spec.rb +21 -21
  423. data/spec/mongoid/relations/cascading/delete_spec.rb +9 -9
  424. data/spec/mongoid/relations/cascading/destroy_spec.rb +6 -6
  425. data/spec/mongoid/relations/cascading/nullify_spec.rb +4 -4
  426. data/spec/mongoid/relations/cascading/restrict_spec.rb +7 -7
  427. data/spec/mongoid/relations/cascading_spec.rb +16 -16
  428. data/spec/mongoid/relations/constraint_spec.rb +8 -7
  429. data/spec/mongoid/relations/conversions_spec.rb +16 -14
  430. data/spec/mongoid/relations/counter_cache_spec.rb +85 -0
  431. data/spec/mongoid/relations/cyclic_spec.rb +18 -18
  432. data/spec/mongoid/relations/eager/belongs_to_spec.rb +154 -0
  433. data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +117 -0
  434. data/spec/mongoid/relations/eager/has_many_spec.rb +207 -0
  435. data/spec/mongoid/relations/eager/has_one_spec.rb +163 -0
  436. data/spec/mongoid/relations/eager_spec.rb +228 -0
  437. data/spec/mongoid/relations/embedded/dirty_spec.rb +8 -8
  438. data/spec/mongoid/relations/embedded/in_spec.rb +56 -57
  439. data/spec/mongoid/relations/embedded/many_spec.rb +467 -372
  440. data/spec/mongoid/relations/embedded/one_spec.rb +108 -141
  441. data/spec/mongoid/relations/macros_spec.rb +108 -102
  442. data/spec/mongoid/relations/metadata_spec.rb +180 -255
  443. data/spec/mongoid/relations/options_spec.rb +1 -1
  444. data/spec/mongoid/relations/polymorphic_spec.rb +13 -17
  445. data/spec/mongoid/relations/proxy_spec.rb +2 -2
  446. data/spec/mongoid/relations/referenced/in_spec.rb +128 -303
  447. data/spec/mongoid/relations/referenced/many_spec.rb +587 -527
  448. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +401 -424
  449. data/spec/mongoid/relations/referenced/one_spec.rb +149 -264
  450. data/spec/mongoid/relations/reflections_spec.rb +6 -6
  451. data/spec/mongoid/relations/synchronization_spec.rb +46 -50
  452. data/spec/mongoid/relations/targets/enumerable_spec.rb +118 -118
  453. data/spec/mongoid/relations/touchable_spec.rb +333 -0
  454. data/spec/mongoid/relations_spec.rb +16 -15
  455. data/spec/mongoid/{reloading_spec.rb → reloadable_spec.rb} +38 -55
  456. data/spec/mongoid/{scoping_spec.rb → scopable_spec.rb} +89 -164
  457. data/spec/mongoid/selectable_spec.rb +134 -0
  458. data/spec/mongoid/{serialization_spec.rb → serializable_spec.rb} +129 -82
  459. data/spec/mongoid/sessions/factory_spec.rb +49 -28
  460. data/spec/mongoid/sessions/mongo_uri_spec.rb +7 -7
  461. data/spec/mongoid/sessions/options_spec.rb +108 -0
  462. data/spec/mongoid/sessions_spec.rb +319 -178
  463. data/spec/mongoid/{sharding_spec.rb → shardable_spec.rb} +8 -8
  464. data/spec/mongoid/{state_spec.rb → stateful_spec.rb} +36 -11
  465. data/spec/mongoid/tasks/database_rake_spec.rb +285 -0
  466. data/spec/mongoid/tasks/database_spec.rb +160 -0
  467. data/spec/mongoid/threaded_spec.rb +17 -70
  468. data/spec/mongoid/timestamps/created/short_spec.rb +6 -6
  469. data/spec/mongoid/timestamps/created_spec.rb +5 -5
  470. data/spec/mongoid/timestamps/timeless_spec.rb +6 -6
  471. data/spec/mongoid/timestamps/updated/short_spec.rb +11 -11
  472. data/spec/mongoid/timestamps/updated_spec.rb +9 -13
  473. data/spec/mongoid/timestamps_spec.rb +9 -13
  474. data/spec/mongoid/{hierarchy_spec.rb → traversable_spec.rb} +19 -19
  475. data/spec/mongoid/{validations → validatable}/associated_spec.rb +45 -22
  476. data/spec/mongoid/{validations → validatable}/format_spec.rb +6 -6
  477. data/spec/mongoid/{validations → validatable}/length_spec.rb +14 -14
  478. data/spec/mongoid/{validations → validatable}/numericality_spec.rb +1 -1
  479. data/spec/mongoid/{validations → validatable}/presence_spec.rb +37 -44
  480. data/spec/mongoid/{validations → validatable}/uniqueness_spec.rb +184 -192
  481. data/spec/mongoid/{validations_spec.rb → validatable_spec.rb} +28 -28
  482. data/spec/mongoid_spec.rb +8 -8
  483. data/spec/rails/mongoid_spec.rb +19 -335
  484. data/spec/spec_helper.rb +31 -13
  485. metadata +303 -283
  486. data/lib/mongoid/atomic/positionable.rb +0 -73
  487. data/lib/mongoid/components.rb +0 -92
  488. data/lib/mongoid/config/inflections.rb +0 -6
  489. data/lib/mongoid/contextual/eager.rb +0 -158
  490. data/lib/mongoid/errors/versioning_not_on_root.rb +0 -23
  491. data/lib/mongoid/identity_map.rb +0 -163
  492. data/lib/mongoid/json.rb +0 -16
  493. data/lib/mongoid/matchers.rb +0 -32
  494. data/lib/mongoid/matchers/strategies.rb +0 -97
  495. data/lib/mongoid/multi_parameter_attributes.rb +0 -105
  496. data/lib/mongoid/nested_attributes.rb +0 -78
  497. data/lib/mongoid/observer.rb +0 -192
  498. data/lib/mongoid/paranoia.rb +0 -136
  499. data/lib/mongoid/persistence.rb +0 -357
  500. data/lib/mongoid/persistence/atomic.rb +0 -231
  501. data/lib/mongoid/persistence/atomic/add_to_set.rb +0 -47
  502. data/lib/mongoid/persistence/atomic/bit.rb +0 -35
  503. data/lib/mongoid/persistence/atomic/inc.rb +0 -45
  504. data/lib/mongoid/persistence/atomic/operation.rb +0 -154
  505. data/lib/mongoid/persistence/atomic/pop.rb +0 -32
  506. data/lib/mongoid/persistence/atomic/pull.rb +0 -32
  507. data/lib/mongoid/persistence/atomic/pull_all.rb +0 -32
  508. data/lib/mongoid/persistence/atomic/push.rb +0 -25
  509. data/lib/mongoid/persistence/atomic/push_all.rb +0 -25
  510. data/lib/mongoid/persistence/atomic/rename.rb +0 -30
  511. data/lib/mongoid/persistence/atomic/sets.rb +0 -28
  512. data/lib/mongoid/persistence/atomic/unset.rb +0 -27
  513. data/lib/mongoid/persistence/deletion.rb +0 -31
  514. data/lib/mongoid/persistence/insertion.rb +0 -38
  515. data/lib/mongoid/persistence/modification.rb +0 -35
  516. data/lib/mongoid/persistence/operations.rb +0 -214
  517. data/lib/mongoid/persistence/operations/embedded/insert.rb +0 -46
  518. data/lib/mongoid/persistence/operations/embedded/remove.rb +0 -43
  519. data/lib/mongoid/persistence/operations/insert.rb +0 -34
  520. data/lib/mongoid/persistence/operations/remove.rb +0 -33
  521. data/lib/mongoid/persistence/operations/update.rb +0 -59
  522. data/lib/mongoid/persistence/operations/upsert.rb +0 -28
  523. data/lib/mongoid/persistence/upsertion.rb +0 -31
  524. data/lib/mongoid/unit_of_work.rb +0 -61
  525. data/lib/mongoid/versioning.rb +0 -217
  526. data/lib/rack/mongoid.rb +0 -2
  527. data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
  528. data/lib/rails/generators/mongoid/observer/observer_generator.rb +0 -17
  529. data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +0 -4
  530. data/spec/app/models/actor_observer.rb +0 -15
  531. data/spec/app/models/callback_recorder.rb +0 -25
  532. data/spec/app/models/paranoid_phone.rb +0 -25
  533. data/spec/app/models/paranoid_post.rb +0 -36
  534. data/spec/app/models/phone_observer.rb +0 -6
  535. data/spec/mongoid/attributes/processing_spec.rb +0 -149
  536. data/spec/mongoid/criterion/destructive_spec.rb +0 -101
  537. data/spec/mongoid/criterion/modifiable_spec.rb +0 -409
  538. data/spec/mongoid/criterion/modification_spec.rb +0 -402
  539. data/spec/mongoid/errors/versioning_not_on_root_spec.rb +0 -29
  540. data/spec/mongoid/finders_spec.rb +0 -321
  541. data/spec/mongoid/identity_map_spec.rb +0 -564
  542. data/spec/mongoid/json_spec.rb +0 -33
  543. data/spec/mongoid/matchers/in_spec.rb +0 -25
  544. data/spec/mongoid/matchers/ne_spec.rb +0 -25
  545. data/spec/mongoid/matchers/nin_spec.rb +0 -25
  546. data/spec/mongoid/multi_parameter_attributes_spec.rb +0 -128
  547. data/spec/mongoid/observer_spec.rb +0 -290
  548. data/spec/mongoid/paranoia_spec.rb +0 -759
  549. data/spec/mongoid/persistence/atomic/add_to_set_spec.rb +0 -262
  550. data/spec/mongoid/persistence/atomic/bit_spec.rb +0 -88
  551. data/spec/mongoid/persistence/atomic/inc_spec.rb +0 -133
  552. data/spec/mongoid/persistence/atomic/pop_spec.rb +0 -111
  553. data/spec/mongoid/persistence/atomic/pull_all_spec.rb +0 -77
  554. data/spec/mongoid/persistence/atomic/pull_spec.rb +0 -80
  555. data/spec/mongoid/persistence/atomic/push_all_spec.rb +0 -77
  556. data/spec/mongoid/persistence/atomic/push_spec.rb +0 -77
  557. data/spec/mongoid/persistence/atomic/rename_spec.rb +0 -42
  558. data/spec/mongoid/persistence/atomic/sets_spec.rb +0 -154
  559. data/spec/mongoid/persistence/atomic/unset_spec.rb +0 -65
  560. data/spec/mongoid/persistence/atomic_spec.rb +0 -216
  561. data/spec/mongoid/persistence/operations/embedded/insert_spec.rb +0 -191
  562. data/spec/mongoid/persistence/operations/embedded/remove_spec.rb +0 -8
  563. data/spec/mongoid/persistence/operations/insert_spec.rb +0 -149
  564. data/spec/mongoid/persistence/operations/remove_spec.rb +0 -113
  565. data/spec/mongoid/persistence/operations/update_spec.rb +0 -141
  566. data/spec/mongoid/persistence/operations/upsert_spec.rb +0 -59
  567. data/spec/mongoid/persistence/operations_spec.rb +0 -313
  568. data/spec/mongoid/persistence_spec.rb +0 -2279
  569. data/spec/mongoid/unit_of_work_spec.rb +0 -196
  570. data/spec/mongoid/versioning_spec.rb +0 -540
  571. data/spec/rack/mongoid/middleware/identity_map_spec.rb +0 -72
@@ -56,27 +56,27 @@ describe Mongoid::Relations::Referenced::Many do
56
56
  end
57
57
 
58
58
  it "sets the foreign key on the relation" do
59
- post.person_id.should eq(person.id)
59
+ expect(post.person_id).to eq(person.id)
60
60
  end
61
61
 
62
62
  it "sets the base on the inverse relation" do
63
- post.person.should eq(person)
63
+ expect(post.person).to eq(person)
64
64
  end
65
65
 
66
66
  it "sets the same instance on the inverse relation" do
67
- post.person.should eql(person)
67
+ expect(post.person).to eql(person)
68
68
  end
69
69
 
70
70
  it "does not save the target" do
71
- post.should be_new_record
71
+ expect(post).to be_new_record
72
72
  end
73
73
 
74
74
  it "adds the document to the target" do
75
- person.posts.size.should eq(1)
75
+ expect(person.posts.size).to eq(1)
76
76
  end
77
77
 
78
78
  it "returns the relation" do
79
- added.should eq(person.posts)
79
+ expect(added).to eq(person.posts)
80
80
  end
81
81
  end
82
82
 
@@ -91,23 +91,23 @@ describe Mongoid::Relations::Referenced::Many do
91
91
  end
92
92
 
93
93
  it "sets the foreign key on the relation" do
94
- post.person_id.should eq(person.id)
94
+ expect(post.person_id).to eq(person.id)
95
95
  end
96
96
 
97
97
  it "sets the base on the inverse relation" do
98
- post.person.should eq(person)
98
+ expect(post.person).to eq(person)
99
99
  end
100
100
 
101
101
  it "sets the same instance on the inverse relation" do
102
- post.person.should eql(person)
102
+ expect(post.person).to eql(person)
103
103
  end
104
104
 
105
105
  it "does not save the parent" do
106
- person.should be_new_record
106
+ expect(person).to be_new_record
107
107
  end
108
108
 
109
109
  it "adds the document to the target" do
110
- person.posts.size.should eq(1)
110
+ expect(person.posts.size).to eq(1)
111
111
  end
112
112
 
113
113
  context "when subsequently saving the parent" do
@@ -118,7 +118,7 @@ describe Mongoid::Relations::Referenced::Many do
118
118
  end
119
119
 
120
120
  it "returns the correct count of the relation" do
121
- person.posts.count.should eq(1)
121
+ expect(person.posts.count).to eq(1)
122
122
  end
123
123
  end
124
124
  end
@@ -137,23 +137,23 @@ describe Mongoid::Relations::Referenced::Many do
137
137
  end
138
138
 
139
139
  it "adds the documents to the relation" do
140
- person.posts.should eq([ post ])
140
+ expect(person.posts).to eq([ post ])
141
141
  end
142
142
 
143
143
  it "sets the foreign key on the inverse relation" do
144
- post.person_id.should eq(person.id)
144
+ expect(post.person_id).to eq(person.id)
145
145
  end
146
146
 
147
147
  it "saves the target" do
148
- post.should be_persisted
148
+ expect(post).to be_persisted
149
149
  end
150
150
 
151
151
  it "adds the correct number of documents" do
152
- person.posts.size.should eq(1)
152
+ expect(person.posts.size).to eq(1)
153
153
  end
154
154
 
155
155
  it "persists the link" do
156
- person.reload.posts.should eq([ post ])
156
+ expect(person.reload.posts).to eq([ post ])
157
157
  end
158
158
  end
159
159
 
@@ -172,27 +172,43 @@ describe Mongoid::Relations::Referenced::Many do
172
172
  end
173
173
 
174
174
  it "sets the foreign key on the relation" do
175
- post.person_id.should eq(person.id)
175
+ expect(post.person_id).to eq(person.id)
176
176
  end
177
177
 
178
178
  it "sets the base on the inverse relation" do
179
- post.person.should eq(person)
179
+ expect(post.person).to eq(person)
180
180
  end
181
181
 
182
182
  it "sets the same instance on the inverse relation" do
183
- post.person.should eql(person)
183
+ expect(post.person).to eql(person)
184
184
  end
185
185
 
186
186
  it "saves the target" do
187
- post.should be_persisted
187
+ expect(post).to be_persisted
188
188
  end
189
189
 
190
190
  it "adds the document to the target" do
191
- person.posts.count.should eq(1)
191
+ expect(person.posts.count).to eq(1)
192
192
  end
193
193
 
194
194
  it "increments the counter cache" do
195
- person.reload.posts_count.should eq(1)
195
+ expect(person[:posts_count]).to eq(1)
196
+ expect(person.posts_count).to eq(1)
197
+ end
198
+
199
+ it "doesnt change the list of changes" do
200
+ expect(person.changed).to eq([])
201
+ end
202
+
203
+ context "when saving another post" do
204
+
205
+ before do
206
+ person.posts.send(method, Post.new)
207
+ end
208
+
209
+ it "increments the counter cache" do
210
+ expect(person.posts_count).to eq(2)
211
+ end
196
212
  end
197
213
 
198
214
  context "when documents already exist on the relation" do
@@ -206,41 +222,41 @@ describe Mongoid::Relations::Referenced::Many do
206
222
  end
207
223
 
208
224
  it "sets the foreign key on the relation" do
209
- post_two.person_id.should eq(person.id)
225
+ expect(post_two.person_id).to eq(person.id)
210
226
  end
211
227
 
212
228
  it "sets the base on the inverse relation" do
213
- post_two.person.should eq(person)
229
+ expect(post_two.person).to eq(person)
214
230
  end
215
231
 
216
232
  it "sets the same instance on the inverse relation" do
217
- post_two.person.should eql(person)
233
+ expect(post_two.person).to eql(person)
218
234
  end
219
235
 
220
236
  it "saves the target" do
221
- post_two.should be_persisted
237
+ expect(post_two).to be_persisted
222
238
  end
223
239
 
224
240
  it "adds the document to the target" do
225
- person.posts.count.should eq(2)
241
+ expect(person.posts.count).to eq(2)
226
242
  end
227
243
 
228
244
  it "increments the counter cache" do
229
- person.reload.posts_count.should eq(2)
245
+ expect(person.reload.posts_count).to eq(2)
230
246
  end
231
247
 
232
248
  it "contains the initial document in the target" do
233
- person.posts.should include(post)
249
+ expect(person.posts).to include(post)
234
250
  end
235
251
 
236
252
  it "contains the added document in the target" do
237
- person.posts.should include(post_two)
253
+ expect(person.posts).to include(post_two)
238
254
  end
239
255
  end
240
256
  end
241
257
  end
242
258
 
243
- context "when.with(safe: true).adding to the relation" do
259
+ context "when.adding to the relation" do
244
260
 
245
261
  let(:person) do
246
262
  Person.create
@@ -253,11 +269,11 @@ describe Mongoid::Relations::Referenced::Many do
253
269
  end
254
270
 
255
271
  before do
256
- person.posts.with(safe: true).send(method, post)
272
+ person.posts.send(method, post)
257
273
  end
258
274
 
259
275
  it "adds the document to the relation" do
260
- person.posts.should eq([ post ])
276
+ expect(person.posts).to eq([ post ])
261
277
  end
262
278
  end
263
279
 
@@ -275,7 +291,7 @@ describe Mongoid::Relations::Referenced::Many do
275
291
 
276
292
  it "raises an error" do
277
293
  expect {
278
- person.posts.with(safe: true).send(method, post)
294
+ person.posts.send(method, post)
279
295
  }.to raise_error(Moped::Errors::OperationFailure)
280
296
  end
281
297
  end
@@ -298,23 +314,19 @@ describe Mongoid::Relations::Referenced::Many do
298
314
  end
299
315
 
300
316
  it "sets the foreign key on the relation" do
301
- rating.ratable_id.should eq(movie.id)
302
- end
303
-
304
- it "does not set the inverse field on the relation" do
305
- rating.ratable_field.should be_nil
317
+ expect(rating.ratable_id).to eq(movie.id)
306
318
  end
307
319
 
308
320
  it "sets the base on the inverse relation" do
309
- rating.ratable.should eq(movie)
321
+ expect(rating.ratable).to eq(movie)
310
322
  end
311
323
 
312
324
  it "does not save the target" do
313
- rating.should be_new_record
325
+ expect(rating).to be_new_record
314
326
  end
315
327
 
316
328
  it "adds the document to the target" do
317
- movie.ratings.size.should eq(1)
329
+ expect(movie.ratings.size).to eq(1)
318
330
  end
319
331
  end
320
332
 
@@ -333,23 +345,19 @@ describe Mongoid::Relations::Referenced::Many do
333
345
  end
334
346
 
335
347
  it "sets the foreign key on the relation" do
336
- rating.ratable_id.should eq(movie.id)
337
- end
338
-
339
- it "does not set the inverse field on the relation" do
340
- rating.ratable_field.should be_nil
348
+ expect(rating.ratable_id).to eq(movie.id)
341
349
  end
342
350
 
343
351
  it "sets the base on the inverse relation" do
344
- rating.ratable.should eq(movie)
352
+ expect(rating.ratable).to eq(movie)
345
353
  end
346
354
 
347
355
  it "saves the target" do
348
- rating.should be_persisted
356
+ expect(rating).to be_persisted
349
357
  end
350
358
 
351
359
  it "adds the document to the target" do
352
- movie.ratings.count.should eq(1)
360
+ expect(movie.ratings.count).to eq(1)
353
361
  end
354
362
  end
355
363
  end
@@ -375,19 +383,19 @@ describe Mongoid::Relations::Referenced::Many do
375
383
  end
376
384
 
377
385
  it "sets the target of the relation" do
378
- person.posts.target.should eq([ post ])
386
+ expect(person.posts.target).to eq([ post ])
379
387
  end
380
388
 
381
389
  it "sets the foreign key on the relation" do
382
- post.person_id.should eq(person.id)
390
+ expect(post.person_id).to eq(person.id)
383
391
  end
384
392
 
385
393
  it "sets the base on the inverse relation" do
386
- post.person.should eq(person)
394
+ expect(post.person).to eq(person)
387
395
  end
388
396
 
389
397
  it "does not save the target" do
390
- post.should_not be_persisted
398
+ expect(post).to_not be_persisted
391
399
  end
392
400
  end
393
401
 
@@ -406,19 +414,19 @@ describe Mongoid::Relations::Referenced::Many do
406
414
  end
407
415
 
408
416
  it "sets the target of the relation" do
409
- person.posts.target.should eq([ post ])
417
+ expect(person.posts.target).to eq([ post ])
410
418
  end
411
419
 
412
420
  it "sets the foreign key of the relation" do
413
- post.person_id.should eq(person.id)
421
+ expect(post.person_id).to eq(person.id)
414
422
  end
415
423
 
416
424
  it "sets the base on the inverse relation" do
417
- post.person.should eq(person)
425
+ expect(post.person).to eq(person)
418
426
  end
419
427
 
420
428
  it "saves the target" do
421
- post.should be_persisted
429
+ expect(post).to be_persisted
422
430
  end
423
431
 
424
432
  context "when replacing the relation with the same documents" do
@@ -430,11 +438,11 @@ describe Mongoid::Relations::Referenced::Many do
430
438
  end
431
439
 
432
440
  it "keeps the relation intact" do
433
- person.posts.should eq([ post ])
441
+ expect(person.posts).to eq([ post ])
434
442
  end
435
443
 
436
444
  it "does not delete the relation" do
437
- person.reload.posts.should eq([ post ])
445
+ expect(person.reload.posts).to eq([ post ])
438
446
  end
439
447
  end
440
448
 
@@ -449,11 +457,11 @@ describe Mongoid::Relations::Referenced::Many do
449
457
  end
450
458
 
451
459
  it "keeps the relation intact" do
452
- from_db.posts.should eq([ post ])
460
+ expect(from_db.posts).to eq([ post ])
453
461
  end
454
462
 
455
463
  it "does not delete the relation" do
456
- from_db.reload.posts.should eq([ post ])
464
+ expect(from_db.reload.posts).to eq([ post ])
457
465
  end
458
466
  end
459
467
  end
@@ -471,19 +479,19 @@ describe Mongoid::Relations::Referenced::Many do
471
479
  end
472
480
 
473
481
  it "keeps the relation intact" do
474
- person.posts.size.should eq(2)
482
+ expect(person.posts.size).to eq(2)
475
483
  end
476
484
 
477
485
  it "keeps the first post" do
478
- person.posts.should include(post)
486
+ expect(person.posts).to include(post)
479
487
  end
480
488
 
481
489
  it "keeps the second post" do
482
- person.posts.should include(new_post)
490
+ expect(person.posts).to include(new_post)
483
491
  end
484
492
 
485
493
  it "does not delete the relation" do
486
- person.reload.posts.should eq([ post, new_post ])
494
+ expect(person.reload.posts).to eq([ post, new_post ])
487
495
  end
488
496
  end
489
497
 
@@ -498,11 +506,11 @@ describe Mongoid::Relations::Referenced::Many do
498
506
  end
499
507
 
500
508
  it "keeps the relation intact" do
501
- from_db.posts.should eq([ post, new_post ])
509
+ expect(from_db.posts).to eq([ post, new_post ])
502
510
  end
503
511
 
504
512
  it "does not delete the relation" do
505
- from_db.reload.posts.should eq([ post, new_post ])
513
+ expect(from_db.reload.posts).to eq([ post, new_post ])
506
514
  end
507
515
  end
508
516
  end
@@ -520,11 +528,11 @@ describe Mongoid::Relations::Referenced::Many do
520
528
  end
521
529
 
522
530
  it "keeps the relation intact" do
523
- person.posts.should eq([ new_post ])
531
+ expect(person.posts).to eq([ new_post ])
524
532
  end
525
533
 
526
534
  it "does not delete the relation" do
527
- person.reload.posts.should eq([ new_post ])
535
+ expect(person.reload.posts).to eq([ new_post ])
528
536
  end
529
537
  end
530
538
 
@@ -539,11 +547,11 @@ describe Mongoid::Relations::Referenced::Many do
539
547
  end
540
548
 
541
549
  it "keeps the relation intact" do
542
- from_db.posts.should eq([ new_post ])
550
+ expect(from_db.posts).to eq([ new_post ])
543
551
  end
544
552
 
545
553
  it "does not delete the relation" do
546
- from_db.reload.posts.should eq([ new_post ])
554
+ expect(from_db.reload.posts).to eq([ new_post ])
547
555
  end
548
556
  end
549
557
  end
@@ -567,19 +575,19 @@ describe Mongoid::Relations::Referenced::Many do
567
575
  end
568
576
 
569
577
  it "sets the target of the relation" do
570
- movie.ratings.target.should eq([ rating ])
578
+ expect(movie.ratings.target).to eq([ rating ])
571
579
  end
572
580
 
573
581
  it "sets the foreign key on the relation" do
574
- rating.ratable_id.should eq(movie.id)
582
+ expect(rating.ratable_id).to eq(movie.id)
575
583
  end
576
584
 
577
585
  it "sets the base on the inverse relation" do
578
- rating.ratable.should eq(movie)
586
+ expect(rating.ratable).to eq(movie)
579
587
  end
580
588
 
581
589
  it "does not save the target" do
582
- rating.should_not be_persisted
590
+ expect(rating).to_not be_persisted
583
591
  end
584
592
  end
585
593
 
@@ -598,19 +606,19 @@ describe Mongoid::Relations::Referenced::Many do
598
606
  end
599
607
 
600
608
  it "sets the target of the relation" do
601
- movie.ratings.target.should eq([ rating ])
609
+ expect(movie.ratings.target).to eq([ rating ])
602
610
  end
603
611
 
604
612
  it "sets the foreign key of the relation" do
605
- rating.ratable_id.should eq(movie.id)
613
+ expect(rating.ratable_id).to eq(movie.id)
606
614
  end
607
615
 
608
616
  it "sets the base on the inverse relation" do
609
- rating.ratable.should eq(movie)
617
+ expect(rating.ratable).to eq(movie)
610
618
  end
611
619
 
612
620
  it "saves the target" do
613
- rating.should be_persisted
621
+ expect(rating).to be_persisted
614
622
  end
615
623
  end
616
624
  end
@@ -635,11 +643,11 @@ describe Mongoid::Relations::Referenced::Many do
635
643
  end
636
644
 
637
645
  it "removes all the children" do
638
- person.posts.should be_empty
646
+ expect(person.posts).to be_empty
639
647
  end
640
648
 
641
649
  it "persists the changes" do
642
- person.posts(true).should be_empty
650
+ expect(person.posts(true)).to be_empty
643
651
  end
644
652
  end
645
653
  end
@@ -665,15 +673,15 @@ describe Mongoid::Relations::Referenced::Many do
665
673
  end
666
674
 
667
675
  it "sets the relation to an empty array" do
668
- person.posts.should be_empty
676
+ expect(person.posts).to be_empty
669
677
  end
670
678
 
671
679
  it "removed the inverse relation" do
672
- post.person.should be_nil
680
+ expect(post.person).to be_nil
673
681
  end
674
682
 
675
683
  it "removes the foreign key value" do
676
- post.person_id.should be_nil
684
+ expect(post.person_id).to be_nil
677
685
  end
678
686
  end
679
687
 
@@ -695,19 +703,19 @@ describe Mongoid::Relations::Referenced::Many do
695
703
  end
696
704
 
697
705
  it "sets the relation to empty" do
698
- person.posts.should be_empty
706
+ expect(person.posts).to be_empty
699
707
  end
700
708
 
701
709
  it "removed the inverse relation" do
702
- post.person.should be_nil
710
+ expect(post.person).to be_nil
703
711
  end
704
712
 
705
713
  it "removes the foreign key value" do
706
- post.person_id.should be_nil
714
+ expect(post.person_id).to be_nil
707
715
  end
708
716
 
709
717
  it "deletes the target from the database" do
710
- post.should be_destroyed
718
+ expect(post).to be_destroyed
711
719
  end
712
720
  end
713
721
 
@@ -723,19 +731,19 @@ describe Mongoid::Relations::Referenced::Many do
723
731
  end
724
732
 
725
733
  it "sets the relation to empty" do
726
- person.drugs.should be_empty
734
+ expect(person.drugs).to be_empty
727
735
  end
728
736
 
729
737
  it "removed the inverse relation" do
730
- drug.person.should be_nil
738
+ expect(drug.person).to be_nil
731
739
  end
732
740
 
733
741
  it "removes the foreign key value" do
734
- drug.person_id.should be_nil
742
+ expect(drug.person_id).to be_nil
735
743
  end
736
744
 
737
745
  it "nullifies the relation" do
738
- drug.should_not be_destroyed
746
+ expect(drug).to_not be_destroyed
739
747
  end
740
748
  end
741
749
  end
@@ -759,15 +767,15 @@ describe Mongoid::Relations::Referenced::Many do
759
767
  end
760
768
 
761
769
  it "sets the relation to an empty array" do
762
- movie.ratings.should be_empty
770
+ expect(movie.ratings).to be_empty
763
771
  end
764
772
 
765
773
  it "removed the inverse relation" do
766
- rating.ratable.should be_nil
774
+ expect(rating.ratable).to be_nil
767
775
  end
768
776
 
769
777
  it "removes the foreign key value" do
770
- rating.ratable_id.should be_nil
778
+ expect(rating.ratable_id).to be_nil
771
779
  end
772
780
  end
773
781
 
@@ -787,21 +795,21 @@ describe Mongoid::Relations::Referenced::Many do
787
795
  end
788
796
 
789
797
  it "sets the relation to empty" do
790
- movie.ratings.should be_empty
798
+ expect(movie.ratings).to be_empty
791
799
  end
792
800
 
793
801
  it "removed the inverse relation" do
794
- rating.ratable.should be_nil
802
+ expect(rating.ratable).to be_nil
795
803
  end
796
804
 
797
805
  it "removes the foreign key value" do
798
- rating.ratable_id.should be_nil
806
+ expect(rating.ratable_id).to be_nil
799
807
  end
800
808
 
801
809
  context "when dependent is nullify" do
802
810
 
803
811
  it "does not delete the target from the database" do
804
- rating.should_not be_destroyed
812
+ expect(rating).to_not be_destroyed
805
813
  end
806
814
  end
807
815
  end
@@ -827,7 +835,7 @@ describe Mongoid::Relations::Referenced::Many do
827
835
  end
828
836
 
829
837
  it "calls setter with documents find by given ids" do
830
- person.posts.should eq([ post_one, post_two ])
838
+ expect(person.posts).to eq([ post_one, post_two ])
831
839
  end
832
840
  end
833
841
 
@@ -842,7 +850,7 @@ describe Mongoid::Relations::Referenced::Many do
842
850
  end
843
851
 
844
852
  it "returns ids of documents that are in the relation" do
845
- person.post_ids.should eq(posts.map(&:id))
853
+ expect(person.post_ids).to eq(posts.map(&:id))
846
854
  end
847
855
  end
848
856
 
@@ -850,28 +858,6 @@ describe Mongoid::Relations::Referenced::Many do
850
858
 
851
859
  describe "##{method}" do
852
860
 
853
- context "when providing scoped mass assignment" do
854
-
855
- let(:person) do
856
- Person.new
857
- end
858
-
859
- let(:drug) do
860
- person.drugs.send(
861
- method,
862
- { name: "Oxycontin", generic: false }, as: :admin
863
- )
864
- end
865
-
866
- it "sets the attributes for the provided role" do
867
- drug.name.should eq("Oxycontin")
868
- end
869
-
870
- it "does not set the attributes for other roles" do
871
- drug.generic.should be_nil
872
- end
873
- end
874
-
875
861
  context "when the relation is not polymorphic" do
876
862
 
877
863
  context "when the parent is a new record" do
@@ -885,31 +871,31 @@ describe Mongoid::Relations::Referenced::Many do
885
871
  end
886
872
 
887
873
  it "sets the foreign key on the relation" do
888
- post.person_id.should eq(person.id)
874
+ expect(post.person_id).to eq(person.id)
889
875
  end
890
876
 
891
877
  it "sets the base on the inverse relation" do
892
- post.person.should eq(person)
878
+ expect(post.person).to eq(person)
893
879
  end
894
880
 
895
881
  it "sets the attributes" do
896
- post.title.should eq("$$$")
882
+ expect(post.title).to eq("$$$")
897
883
  end
898
884
 
899
885
  it "sets the post processed defaults" do
900
- post.person_title.should eq(person.title)
886
+ expect(post.person_title).to eq(person.title)
901
887
  end
902
888
 
903
889
  it "does not save the target" do
904
- post.should be_new_record
890
+ expect(post).to be_new_record
905
891
  end
906
892
 
907
893
  it "adds the document to the target" do
908
- person.posts.size.should eq(1)
894
+ expect(person.posts.size).to eq(1)
909
895
  end
910
896
 
911
897
  it "does not perform validation" do
912
- post.errors.should be_empty
898
+ expect(post.errors).to be_empty
913
899
  end
914
900
  end
915
901
 
@@ -924,23 +910,23 @@ describe Mongoid::Relations::Referenced::Many do
924
910
  end
925
911
 
926
912
  it "sets the foreign key on the relation" do
927
- post.person_id.should eq(person.id)
913
+ expect(post.person_id).to eq(person.id)
928
914
  end
929
915
 
930
916
  it "sets the base on the inverse relation" do
931
- post.person.should eq(person)
917
+ expect(post.person).to eq(person)
932
918
  end
933
919
 
934
920
  it "sets the attributes" do
935
- post.text.should eq("Testing")
921
+ expect(post.text).to eq("Testing")
936
922
  end
937
923
 
938
924
  it "does not save the target" do
939
- post.should be_new_record
925
+ expect(post).to be_new_record
940
926
  end
941
927
 
942
928
  it "adds the document to the target" do
943
- person.posts.size.should eq(1)
929
+ expect(person.posts.size).to eq(1)
944
930
  end
945
931
  end
946
932
  end
@@ -977,27 +963,27 @@ describe Mongoid::Relations::Referenced::Many do
977
963
  end
978
964
 
979
965
  it "sets the foreign key on the relation" do
980
- rating.ratable_id.should eq(movie.id)
966
+ expect(rating.ratable_id).to eq(movie.id)
981
967
  end
982
968
 
983
969
  it "sets the base on the inverse relation" do
984
- rating.ratable.should eq(movie)
970
+ expect(rating.ratable).to eq(movie)
985
971
  end
986
972
 
987
973
  it "sets the attributes" do
988
- rating.value.should eq(3)
974
+ expect(rating.value).to eq(3)
989
975
  end
990
976
 
991
977
  it "does not save the target" do
992
- rating.should be_new_record
978
+ expect(rating).to be_new_record
993
979
  end
994
980
 
995
981
  it "adds the document to the target" do
996
- movie.ratings.size.should eq(1)
982
+ expect(movie.ratings.size).to eq(1)
997
983
  end
998
984
 
999
985
  it "does not perform validation" do
1000
- rating.errors.should be_empty
986
+ expect(rating.errors).to be_empty
1001
987
  end
1002
988
  end
1003
989
 
@@ -1012,23 +998,23 @@ describe Mongoid::Relations::Referenced::Many do
1012
998
  end
1013
999
 
1014
1000
  it "sets the foreign key on the relation" do
1015
- rating.ratable_id.should eq(movie.id)
1001
+ expect(rating.ratable_id).to eq(movie.id)
1016
1002
  end
1017
1003
 
1018
1004
  it "sets the base on the inverse relation" do
1019
- rating.ratable.should eq(movie)
1005
+ expect(rating.ratable).to eq(movie)
1020
1006
  end
1021
1007
 
1022
1008
  it "sets the attributes" do
1023
- rating.value.should eq(4)
1009
+ expect(rating.value).to eq(4)
1024
1010
  end
1025
1011
 
1026
1012
  it "does not save the target" do
1027
- rating.should be_new_record
1013
+ expect(rating).to be_new_record
1028
1014
  end
1029
1015
 
1030
1016
  it "adds the document to the target" do
1031
- movie.ratings.size.should eq(1)
1017
+ expect(movie.ratings.size).to eq(1)
1032
1018
  end
1033
1019
  end
1034
1020
  end
@@ -1042,16 +1028,17 @@ describe Mongoid::Relations::Referenced::Many do
1042
1028
  end
1043
1029
 
1044
1030
  let(:document) do
1045
- stub
1031
+ double
1046
1032
  end
1047
1033
 
1048
1034
  let(:metadata) do
1049
- stub(extension?: false)
1035
+ double(extension?: false)
1050
1036
  end
1051
1037
 
1052
1038
  it "returns the embedded in builder" do
1053
- described_class.builder(nil, metadata, document).should
1054
- be_a_kind_of(builder_klass)
1039
+ expect(
1040
+ described_class.builder(nil, metadata, document)
1041
+ ).to be_a_kind_of(builder_klass)
1055
1042
  end
1056
1043
  end
1057
1044
 
@@ -1076,19 +1063,19 @@ describe Mongoid::Relations::Referenced::Many do
1076
1063
  end
1077
1064
 
1078
1065
  it "clears out the relation" do
1079
- person.posts.should be_empty
1066
+ expect(person.posts).to be_empty
1080
1067
  end
1081
1068
 
1082
1069
  it "marks the documents as deleted" do
1083
- post.should be_destroyed
1070
+ expect(post).to be_destroyed
1084
1071
  end
1085
1072
 
1086
1073
  it "deletes the documents from the db" do
1087
- person.reload.posts.should be_empty
1074
+ expect(person.reload.posts).to be_empty
1088
1075
  end
1089
1076
 
1090
1077
  it "returns the relation" do
1091
- relation.should be_empty
1078
+ expect(relation).to be_empty
1092
1079
  end
1093
1080
  end
1094
1081
 
@@ -1103,7 +1090,7 @@ describe Mongoid::Relations::Referenced::Many do
1103
1090
  end
1104
1091
 
1105
1092
  it "clears out the relation" do
1106
- person.posts.should be_empty
1093
+ expect(person.posts).to be_empty
1107
1094
  end
1108
1095
  end
1109
1096
  end
@@ -1123,7 +1110,7 @@ describe Mongoid::Relations::Referenced::Many do
1123
1110
  end
1124
1111
 
1125
1112
  it "clears out the relation" do
1126
- person.posts.should be_empty
1113
+ expect(person.posts).to be_empty
1127
1114
  end
1128
1115
  end
1129
1116
  end
@@ -1147,19 +1134,19 @@ describe Mongoid::Relations::Referenced::Many do
1147
1134
  end
1148
1135
 
1149
1136
  it "clears out the relation" do
1150
- movie.ratings.should be_empty
1137
+ expect(movie.ratings).to be_empty
1151
1138
  end
1152
1139
 
1153
1140
  it "handles the proper dependent strategy" do
1154
- rating.should_not be_destroyed
1141
+ expect(rating).to_not be_destroyed
1155
1142
  end
1156
1143
 
1157
1144
  it "deletes the documents from the db" do
1158
- movie.reload.ratings.should be_empty
1145
+ expect(movie.reload.ratings).to be_empty
1159
1146
  end
1160
1147
 
1161
1148
  it "returns the relation" do
1162
- relation.should be_empty
1149
+ expect(relation).to be_empty
1163
1150
  end
1164
1151
  end
1165
1152
 
@@ -1174,7 +1161,7 @@ describe Mongoid::Relations::Referenced::Many do
1174
1161
  end
1175
1162
 
1176
1163
  it "clears out the relation" do
1177
- movie.ratings.should be_empty
1164
+ expect(movie.ratings).to be_empty
1178
1165
  end
1179
1166
  end
1180
1167
  end
@@ -1194,7 +1181,7 @@ describe Mongoid::Relations::Referenced::Many do
1194
1181
  end
1195
1182
 
1196
1183
  it "clears out the relation" do
1197
- movie.ratings.should be_empty
1184
+ expect(movie.ratings).to be_empty
1198
1185
  end
1199
1186
  end
1200
1187
  end
@@ -1219,23 +1206,23 @@ describe Mongoid::Relations::Referenced::Many do
1219
1206
  end
1220
1207
 
1221
1208
  it "sets the foreign key on the relation" do
1222
- post.person_id.should eq(person.id)
1209
+ expect(post.person_id).to eq(person.id)
1223
1210
  end
1224
1211
 
1225
1212
  it "sets the base on the inverse relation" do
1226
- post.person.should eq(person)
1213
+ expect(post.person).to eq(person)
1227
1214
  end
1228
1215
 
1229
1216
  it "sets the same instance on the inverse relation" do
1230
- post.person.should eql(person)
1217
+ expect(post.person).to eql(person)
1231
1218
  end
1232
1219
 
1233
1220
  it "does not save the target" do
1234
- post.should be_new_record
1221
+ expect(post).to be_new_record
1235
1222
  end
1236
1223
 
1237
1224
  it "adds the document to the target" do
1238
- person.posts.size.should eq(1)
1225
+ expect(person.posts.size).to eq(1)
1239
1226
  end
1240
1227
  end
1241
1228
 
@@ -1252,23 +1239,23 @@ describe Mongoid::Relations::Referenced::Many do
1252
1239
  end
1253
1240
 
1254
1241
  it "adds the documents to the relation" do
1255
- person.posts.should eq([ post ])
1242
+ expect(person.posts).to eq([ post ])
1256
1243
  end
1257
1244
 
1258
1245
  it "sets the foreign key on the inverse relation" do
1259
- post.person_id.should eq(person.id)
1246
+ expect(post.person_id).to eq(person.id)
1260
1247
  end
1261
1248
 
1262
1249
  it "saves the target" do
1263
- post.should be_persisted
1250
+ expect(post).to be_persisted
1264
1251
  end
1265
1252
 
1266
1253
  it "adds the correct number of documents" do
1267
- person.posts.size.should eq(1)
1254
+ expect(person.posts.size).to eq(1)
1268
1255
  end
1269
1256
 
1270
1257
  it "persists the link" do
1271
- person.reload.posts.should eq([ post ])
1258
+ expect(person.reload.posts).to eq([ post ])
1272
1259
  end
1273
1260
  end
1274
1261
 
@@ -1291,23 +1278,23 @@ describe Mongoid::Relations::Referenced::Many do
1291
1278
  end
1292
1279
 
1293
1280
  it "sets the foreign key on the relation" do
1294
- post.person_id.should eq(person.id)
1281
+ expect(post.person_id).to eq(person.id)
1295
1282
  end
1296
1283
 
1297
1284
  it "sets the base on the inverse relation" do
1298
- post.person.should eq(person)
1285
+ expect(post.person).to eq(person)
1299
1286
  end
1300
1287
 
1301
1288
  it "sets the same instance on the inverse relation" do
1302
- post.person.should eql(person)
1289
+ expect(post.person).to eql(person)
1303
1290
  end
1304
1291
 
1305
1292
  it "saves the target" do
1306
- post.should be_persisted
1293
+ expect(post).to be_persisted
1307
1294
  end
1308
1295
 
1309
1296
  it "adds the document to the target" do
1310
- person.posts.count.should eq(2)
1297
+ expect(person.posts.count).to eq(2)
1311
1298
  end
1312
1299
 
1313
1300
  context "when documents already exist on the relation" do
@@ -1321,31 +1308,31 @@ describe Mongoid::Relations::Referenced::Many do
1321
1308
  end
1322
1309
 
1323
1310
  it "sets the foreign key on the relation" do
1324
- post_two.person_id.should eq(person.id)
1311
+ expect(post_two.person_id).to eq(person.id)
1325
1312
  end
1326
1313
 
1327
1314
  it "sets the base on the inverse relation" do
1328
- post_two.person.should eq(person)
1315
+ expect(post_two.person).to eq(person)
1329
1316
  end
1330
1317
 
1331
1318
  it "sets the same instance on the inverse relation" do
1332
- post_two.person.should eql(person)
1319
+ expect(post_two.person).to eql(person)
1333
1320
  end
1334
1321
 
1335
1322
  it "saves the target" do
1336
- post_two.should be_persisted
1323
+ expect(post_two).to be_persisted
1337
1324
  end
1338
1325
 
1339
1326
  it "adds the document to the target" do
1340
- person.posts.count.should eq(3)
1327
+ expect(person.posts.count).to eq(3)
1341
1328
  end
1342
1329
 
1343
1330
  it "contains the initial document in the target" do
1344
- person.posts.should include(post)
1331
+ expect(person.posts).to include(post)
1345
1332
  end
1346
1333
 
1347
1334
  it "contains the added document in the target" do
1348
- person.posts.should include(post_two)
1335
+ expect(person.posts).to include(post_two)
1349
1336
  end
1350
1337
  end
1351
1338
  end
@@ -1369,19 +1356,19 @@ describe Mongoid::Relations::Referenced::Many do
1369
1356
  end
1370
1357
 
1371
1358
  it "sets the foreign key on the relation" do
1372
- rating.ratable_id.should eq(movie.id)
1359
+ expect(rating.ratable_id).to eq(movie.id)
1373
1360
  end
1374
1361
 
1375
1362
  it "sets the base on the inverse relation" do
1376
- rating.ratable.should eq(movie)
1363
+ expect(rating.ratable).to eq(movie)
1377
1364
  end
1378
1365
 
1379
1366
  it "does not save the target" do
1380
- rating.should be_new_record
1367
+ expect(rating).to be_new_record
1381
1368
  end
1382
1369
 
1383
1370
  it "adds the document to the target" do
1384
- movie.ratings.size.should eq(1)
1371
+ expect(movie.ratings.size).to eq(1)
1385
1372
  end
1386
1373
  end
1387
1374
 
@@ -1400,19 +1387,19 @@ describe Mongoid::Relations::Referenced::Many do
1400
1387
  end
1401
1388
 
1402
1389
  it "sets the foreign key on the relation" do
1403
- rating.ratable_id.should eq(movie.id)
1390
+ expect(rating.ratable_id).to eq(movie.id)
1404
1391
  end
1405
1392
 
1406
1393
  it "sets the base on the inverse relation" do
1407
- rating.ratable.should eq(movie)
1394
+ expect(rating.ratable).to eq(movie)
1408
1395
  end
1409
1396
 
1410
1397
  it "saves the target" do
1411
- rating.should be_persisted
1398
+ expect(rating).to be_persisted
1412
1399
  end
1413
1400
 
1414
1401
  it "adds the document to the target" do
1415
- movie.ratings.count.should eq(1)
1402
+ expect(movie.ratings.count).to eq(1)
1416
1403
  end
1417
1404
  end
1418
1405
  end
@@ -1430,7 +1417,7 @@ describe Mongoid::Relations::Referenced::Many do
1430
1417
  end
1431
1418
 
1432
1419
  it "returns the number of persisted documents" do
1433
- movie.ratings.count.should eq(1)
1420
+ expect(movie.ratings.count).to eq(1)
1434
1421
  end
1435
1422
  end
1436
1423
 
@@ -1441,7 +1428,7 @@ describe Mongoid::Relations::Referenced::Many do
1441
1428
  end
1442
1429
 
1443
1430
  it "returns 0" do
1444
- movie.ratings.count.should eq(0)
1431
+ expect(movie.ratings.count).to eq(0)
1445
1432
  end
1446
1433
  end
1447
1434
 
@@ -1454,7 +1441,7 @@ describe Mongoid::Relations::Referenced::Many do
1454
1441
  end
1455
1442
 
1456
1443
  it "returns the count from the db" do
1457
- movie.ratings.count.should eq(1)
1444
+ expect(movie.ratings.count).to eq(1)
1458
1445
  end
1459
1446
  end
1460
1447
 
@@ -1465,7 +1452,7 @@ describe Mongoid::Relations::Referenced::Many do
1465
1452
  end
1466
1453
 
1467
1454
  it "returns the count from the db" do
1468
- movie.ratings.count.should eq(0)
1455
+ expect(movie.ratings.count).to eq(0)
1469
1456
  end
1470
1457
  end
1471
1458
  end
@@ -1473,24 +1460,30 @@ describe Mongoid::Relations::Referenced::Many do
1473
1460
 
1474
1461
  describe "#create" do
1475
1462
 
1476
- context "when providing scoped mass assignment" do
1463
+ context "when providing multiple attributes" do
1477
1464
 
1478
1465
  let(:person) do
1479
1466
  Person.create
1480
1467
  end
1481
1468
 
1482
- let(:drug) do
1483
- person.drugs.create(
1484
- { name: "Oxycontin", generic: false }, as: :admin
1485
- )
1469
+ let!(:posts) do
1470
+ person.posts.create([{ text: "Test1" }, { text: "Test2" }])
1471
+ end
1472
+
1473
+ it "creates multiple documents" do
1474
+ expect(posts.size).to eq(2)
1475
+ end
1476
+
1477
+ it "sets the first attributes" do
1478
+ expect(posts.first.text).to eq("Test1")
1486
1479
  end
1487
1480
 
1488
- it "sets the attributes for the provided role" do
1489
- drug.name.should eq("Oxycontin")
1481
+ it "sets the second attributes" do
1482
+ expect(posts.last.text).to eq("Test2")
1490
1483
  end
1491
1484
 
1492
- it "does not set the attributes for other roles" do
1493
- drug.generic.should be_nil
1485
+ it "persists the children" do
1486
+ expect(person.posts.count).to eq(2)
1494
1487
  end
1495
1488
  end
1496
1489
 
@@ -1511,7 +1504,7 @@ describe Mongoid::Relations::Referenced::Many do
1511
1504
  end
1512
1505
  end
1513
1506
 
1514
- context "when.with(safe: true).creating the document" do
1507
+ context "when.creating the document" do
1515
1508
 
1516
1509
  context "when the operation is successful" do
1517
1510
 
@@ -1520,11 +1513,11 @@ describe Mongoid::Relations::Referenced::Many do
1520
1513
  end
1521
1514
 
1522
1515
  let!(:post) do
1523
- person.posts.with(safe: true).create(text: "Testing")
1516
+ person.posts.create(text: "Testing")
1524
1517
  end
1525
1518
 
1526
1519
  it "creates the document" do
1527
- person.posts.should eq([ post ])
1520
+ expect(person.posts).to eq([ post ])
1528
1521
  end
1529
1522
  end
1530
1523
 
@@ -1540,7 +1533,7 @@ describe Mongoid::Relations::Referenced::Many do
1540
1533
 
1541
1534
  it "raises an error" do
1542
1535
  expect {
1543
- person.posts.with(safe: true).create do |doc|
1536
+ person.posts.create do |doc|
1544
1537
  doc._id = existing.id
1545
1538
  end
1546
1539
  }.to raise_error(Moped::Errors::OperationFailure)
@@ -1561,27 +1554,54 @@ describe Mongoid::Relations::Referenced::Many do
1561
1554
  end
1562
1555
 
1563
1556
  it "sets the foreign key on the relation" do
1564
- post.person_id.should eq(person.id)
1557
+ expect(post.person_id).to eq(person.id)
1565
1558
  end
1566
1559
 
1567
1560
  it "sets the base on the inverse relation" do
1568
- post.person.should eq(person)
1561
+ expect(post.person).to eq(person)
1569
1562
  end
1570
1563
 
1571
1564
  it "sets the attributes" do
1572
- post.text.should eq("Testing")
1565
+ expect(post.text).to eq("Testing")
1573
1566
  end
1574
1567
 
1575
1568
  it "saves the target" do
1576
- post.should_not be_a_new_record
1569
+ expect(post).to_not be_a_new_record
1577
1570
  end
1578
1571
 
1579
1572
  it "calls the passed block" do
1580
- post.content.should eq("The Content")
1573
+ expect(post.content).to eq("The Content")
1581
1574
  end
1582
1575
 
1583
1576
  it "adds the document to the target" do
1584
- person.posts.count.should eq(1)
1577
+ expect(person.posts.count).to eq(1)
1578
+ end
1579
+ end
1580
+
1581
+ context "when passing a new object" do
1582
+
1583
+ let!(:odd) do
1584
+ Odd.create(name: 'one')
1585
+ end
1586
+
1587
+ let!(:even) do
1588
+ odd.evens.create(name: 'two', odds: [Odd.new(name: 'three')])
1589
+ end
1590
+
1591
+ it "only push one even to the list" do
1592
+ expect(odd.evens.count).to eq(1)
1593
+ end
1594
+
1595
+ it "saves the reference back" do
1596
+ expect(odd.evens.first.odds.count).to eq(1)
1597
+ end
1598
+
1599
+ it "only saves one even" do
1600
+ expect(Even.count).to eq(1)
1601
+ end
1602
+
1603
+ it "saves the first odd and the second" do
1604
+ expect(Odd.count).to eq(2)
1585
1605
  end
1586
1606
  end
1587
1607
  end
@@ -1614,23 +1634,23 @@ describe Mongoid::Relations::Referenced::Many do
1614
1634
  end
1615
1635
 
1616
1636
  it "sets the foreign key on the relation" do
1617
- rating.ratable_id.should eq(movie.id)
1637
+ expect(rating.ratable_id).to eq(movie.id)
1618
1638
  end
1619
1639
 
1620
1640
  it "sets the base on the inverse relation" do
1621
- rating.ratable.should eq(movie)
1641
+ expect(rating.ratable).to eq(movie)
1622
1642
  end
1623
1643
 
1624
1644
  it "sets the attributes" do
1625
- rating.value.should eq(3)
1645
+ expect(rating.value).to eq(3)
1626
1646
  end
1627
1647
 
1628
1648
  it "saves the target" do
1629
- rating.should_not be_new_record
1649
+ expect(rating).to_not be_new_record
1630
1650
  end
1631
1651
 
1632
1652
  it "adds the document to the target" do
1633
- movie.ratings.count.should eq(1)
1653
+ expect(movie.ratings.count).to eq(1)
1634
1654
  end
1635
1655
  end
1636
1656
  end
@@ -1646,31 +1666,37 @@ describe Mongoid::Relations::Referenced::Many do
1646
1666
  end
1647
1667
 
1648
1668
  it 'saves pk value on fk field' do
1649
- drug.person_id.should eq('arthurnn')
1669
+ expect(drug.person_id).to eq('arthurnn')
1650
1670
  end
1651
1671
  end
1652
1672
  end
1653
1673
 
1654
1674
  describe "#create!" do
1655
1675
 
1656
- context "when providing mass scoping options" do
1676
+ context "when providing multiple attributes" do
1657
1677
 
1658
1678
  let(:person) do
1659
1679
  Person.create
1660
1680
  end
1661
1681
 
1662
- let(:drug) do
1663
- person.drugs.create!(
1664
- { name: "Oxycontin", generic: false }, as: :admin
1665
- )
1682
+ let!(:posts) do
1683
+ person.posts.create!([{ text: "Test1" }, { text: "Test2" }])
1684
+ end
1685
+
1686
+ it "creates multiple documents" do
1687
+ expect(posts.size).to eq(2)
1666
1688
  end
1667
1689
 
1668
- it "sets the attributes for the provided role" do
1669
- drug.name.should eq("Oxycontin")
1690
+ it "sets the first attributes" do
1691
+ expect(posts.first.text).to eq("Test1")
1670
1692
  end
1671
1693
 
1672
- it "does not set the attributes for other roles" do
1673
- drug.generic.should be_nil
1694
+ it "sets the second attributes" do
1695
+ expect(posts.last.text).to eq("Test2")
1696
+ end
1697
+
1698
+ it "persists the children" do
1699
+ expect(person.posts.count).to eq(2)
1674
1700
  end
1675
1701
  end
1676
1702
 
@@ -1702,23 +1728,23 @@ describe Mongoid::Relations::Referenced::Many do
1702
1728
  end
1703
1729
 
1704
1730
  it "sets the foreign key on the relation" do
1705
- post.person_id.should eq(person.id)
1731
+ expect(post.person_id).to eq(person.id)
1706
1732
  end
1707
1733
 
1708
1734
  it "sets the base on the inverse relation" do
1709
- post.person.should eq(person)
1735
+ expect(post.person).to eq(person)
1710
1736
  end
1711
1737
 
1712
1738
  it "sets the attributes" do
1713
- post.title.should eq("Testing")
1739
+ expect(post.title).to eq("Testing")
1714
1740
  end
1715
1741
 
1716
1742
  it "saves the target" do
1717
- post.should_not be_a_new_record
1743
+ expect(post).to_not be_a_new_record
1718
1744
  end
1719
1745
 
1720
1746
  it "adds the document to the target" do
1721
- person.posts.count.should eq(1)
1747
+ expect(person.posts.count).to eq(1)
1722
1748
  end
1723
1749
 
1724
1750
  context "when validation fails" do
@@ -1760,23 +1786,23 @@ describe Mongoid::Relations::Referenced::Many do
1760
1786
  end
1761
1787
 
1762
1788
  it "sets the foreign key on the relation" do
1763
- rating.ratable_id.should eq(movie.id)
1789
+ expect(rating.ratable_id).to eq(movie.id)
1764
1790
  end
1765
1791
 
1766
1792
  it "sets the base on the inverse relation" do
1767
- rating.ratable.should eq(movie)
1793
+ expect(rating.ratable).to eq(movie)
1768
1794
  end
1769
1795
 
1770
1796
  it "sets the attributes" do
1771
- rating.value.should eq(4)
1797
+ expect(rating.value).to eq(4)
1772
1798
  end
1773
1799
 
1774
1800
  it "saves the target" do
1775
- rating.should_not be_new_record
1801
+ expect(rating).to_not be_new_record
1776
1802
  end
1777
1803
 
1778
1804
  it "adds the document to the target" do
1779
- movie.ratings.count.should eq(1)
1805
+ expect(movie.ratings.count).to eq(1)
1780
1806
  end
1781
1807
 
1782
1808
  context "when validation fails" do
@@ -1794,7 +1820,7 @@ describe Mongoid::Relations::Referenced::Many do
1794
1820
  describe ".criteria" do
1795
1821
 
1796
1822
  let(:id) do
1797
- Moped::BSON::ObjectId.new
1823
+ BSON::ObjectId.new
1798
1824
  end
1799
1825
 
1800
1826
  context "when the relation is polymorphic" do
@@ -1808,11 +1834,10 @@ describe Mongoid::Relations::Referenced::Many do
1808
1834
  end
1809
1835
 
1810
1836
  it "includes the type in the criteria" do
1811
- criteria.selector.should eq(
1837
+ expect(criteria.selector).to eq(
1812
1838
  {
1813
1839
  "ratable_id" => id,
1814
- "ratable_type" => "Movie",
1815
- "ratable_field" => { "$in" => [ :ratings, nil ] }
1840
+ "ratable_type" => "Movie"
1816
1841
  }
1817
1842
  )
1818
1843
  end
@@ -1829,7 +1854,7 @@ describe Mongoid::Relations::Referenced::Many do
1829
1854
  end
1830
1855
 
1831
1856
  it "does not include the type in the criteria" do
1832
- criteria.selector.should eq({ "person_id" => id })
1857
+ expect(criteria.selector).to eq({ "person_id" => id })
1833
1858
  end
1834
1859
  end
1835
1860
  end
@@ -1863,7 +1888,7 @@ describe Mongoid::Relations::Referenced::Many do
1863
1888
  end
1864
1889
 
1865
1890
  it "does not cascade" do
1866
- deleted.changes.keys.should eq([ "person_id" ])
1891
+ expect(deleted.changes.keys).to eq([ "person_id" ])
1867
1892
  end
1868
1893
  end
1869
1894
 
@@ -1878,15 +1903,15 @@ describe Mongoid::Relations::Referenced::Many do
1878
1903
  end
1879
1904
 
1880
1905
  it "returns the document" do
1881
- deleted.should eq(drug)
1906
+ expect(deleted).to eq(drug)
1882
1907
  end
1883
1908
 
1884
1909
  it "deletes the foreign key" do
1885
- drug.person_id.should be_nil
1910
+ expect(drug.person_id).to be_nil
1886
1911
  end
1887
1912
 
1888
1913
  it "removes the document from the relation" do
1889
- person.drugs.should_not include(drug)
1914
+ expect(person.drugs).to_not include(drug)
1890
1915
  end
1891
1916
  end
1892
1917
 
@@ -1901,15 +1926,15 @@ describe Mongoid::Relations::Referenced::Many do
1901
1926
  end
1902
1927
 
1903
1928
  it "returns the document" do
1904
- deleted.should eq(drug)
1929
+ expect(deleted).to eq(drug)
1905
1930
  end
1906
1931
 
1907
1932
  it "deletes the foreign key" do
1908
- drug.person_id.should be_nil
1933
+ expect(drug.person_id).to be_nil
1909
1934
  end
1910
1935
 
1911
1936
  it "removes the document from the relation" do
1912
- person.drugs.should_not include(drug)
1937
+ expect(person.drugs).to_not include(drug)
1913
1938
  end
1914
1939
  end
1915
1940
  end
@@ -1927,15 +1952,15 @@ describe Mongoid::Relations::Referenced::Many do
1927
1952
  end
1928
1953
 
1929
1954
  it "returns the document" do
1930
- deleted.should eq(post)
1955
+ expect(deleted).to eq(post)
1931
1956
  end
1932
1957
 
1933
1958
  it "deletes the document" do
1934
- post.should be_destroyed
1959
+ expect(post).to be_destroyed
1935
1960
  end
1936
1961
 
1937
1962
  it "removes the document from the relation" do
1938
- person.posts.should_not include(post)
1963
+ expect(person.posts).to_not include(post)
1939
1964
  end
1940
1965
  end
1941
1966
 
@@ -1950,15 +1975,15 @@ describe Mongoid::Relations::Referenced::Many do
1950
1975
  end
1951
1976
 
1952
1977
  it "returns the document" do
1953
- deleted.should eq(post)
1978
+ expect(deleted).to eq(post)
1954
1979
  end
1955
1980
 
1956
1981
  it "deletes the document" do
1957
- post.should be_destroyed
1982
+ expect(post).to be_destroyed
1958
1983
  end
1959
1984
 
1960
1985
  it "removes the document from the relation" do
1961
- person.posts.should_not include(post)
1986
+ expect(person.posts).to_not include(post)
1962
1987
  end
1963
1988
  end
1964
1989
  end
@@ -1975,11 +2000,11 @@ describe Mongoid::Relations::Referenced::Many do
1975
2000
  end
1976
2001
 
1977
2002
  it "returns nil" do
1978
- deleted.should be_nil
2003
+ expect(deleted).to be_nil
1979
2004
  end
1980
2005
 
1981
2006
  it "does not delete the document" do
1982
- post.should be_persisted
2007
+ expect(post).to be_persisted
1983
2008
  end
1984
2009
  end
1985
2010
  end
@@ -2002,18 +2027,18 @@ describe Mongoid::Relations::Referenced::Many do
2002
2027
  end
2003
2028
 
2004
2029
  it "removes the correct posts" do
2005
- person.posts.send(method, conditions: { title: "Testing" })
2006
- person.posts.count.should eq(1)
2007
- person.reload.posts_count.should eq(1) if method == :destroy_all
2030
+ person.posts.send(method, { title: "Testing" })
2031
+ expect(person.posts.count).to eq(1)
2032
+ expect(person.reload.posts_count).to eq(1) if method == :destroy_all
2008
2033
  end
2009
2034
 
2010
2035
  it "deletes the documents from the database" do
2011
- person.posts.send(method, conditions: {title: "Testing" })
2012
- Post.where(title: "Testing").count.should eq(0)
2036
+ person.posts.send(method, { title: "Testing" })
2037
+ expect(Post.where(title: "Testing").count).to eq(0)
2013
2038
  end
2014
2039
 
2015
2040
  it "returns the number of documents deleted" do
2016
- person.posts.send(method, conditions: { title: "Testing" }).should eq(1)
2041
+ expect(person.posts.send(method, { title: "Testing" })).to eq(1)
2017
2042
  end
2018
2043
  end
2019
2044
 
@@ -2030,16 +2055,16 @@ describe Mongoid::Relations::Referenced::Many do
2030
2055
 
2031
2056
  it "removes the correct posts" do
2032
2057
  person.posts.send(method)
2033
- person.posts.count.should eq(0)
2058
+ expect(person.posts.count).to eq(0)
2034
2059
  end
2035
2060
 
2036
2061
  it "deletes the documents from the database" do
2037
2062
  person.posts.send(method)
2038
- Post.where(title: "Testing").count.should eq(0)
2063
+ expect(Post.where(title: "Testing").count).to eq(0)
2039
2064
  end
2040
2065
 
2041
2066
  it "returns the number of documents deleted" do
2042
- person.posts.send(method).should eq(2)
2067
+ expect(person.posts.send(method)).to eq(2)
2043
2068
  end
2044
2069
  end
2045
2070
  end
@@ -2058,17 +2083,17 @@ describe Mongoid::Relations::Referenced::Many do
2058
2083
  end
2059
2084
 
2060
2085
  it "removes the correct ratings" do
2061
- movie.ratings.send(method, conditions: { value: 1 })
2062
- movie.ratings.count.should eq(1)
2086
+ movie.ratings.send(method, { value: 1 })
2087
+ expect(movie.ratings.count).to eq(1)
2063
2088
  end
2064
2089
 
2065
2090
  it "deletes the documents from the database" do
2066
- movie.ratings.send(method, conditions: { value: 1 })
2067
- Rating.where(value: 1).count.should eq(0)
2091
+ movie.ratings.send(method, { value: 1 })
2092
+ expect(Rating.where(value: 1).count).to eq(0)
2068
2093
  end
2069
2094
 
2070
2095
  it "returns the number of documents deleted" do
2071
- movie.ratings.send(method, conditions: { value: 1 }).should eq(1)
2096
+ expect(movie.ratings.send(method, { value: 1 })).to eq(1)
2072
2097
  end
2073
2098
  end
2074
2099
 
@@ -2085,164 +2110,26 @@ describe Mongoid::Relations::Referenced::Many do
2085
2110
 
2086
2111
  it "removes the correct ratings" do
2087
2112
  movie.ratings.send(method)
2088
- movie.ratings.count.should eq(0)
2113
+ expect(movie.ratings.count).to eq(0)
2089
2114
  end
2090
2115
 
2091
2116
  it "deletes the documents from the database" do
2092
2117
  movie.ratings.send(method)
2093
- Rating.where(value: 1).count.should eq(0)
2118
+ expect(Rating.where(value: 1).count).to eq(0)
2094
2119
  end
2095
2120
 
2096
2121
  it "returns the number of documents deleted" do
2097
- movie.ratings.send(method).should eq(2)
2122
+ expect(movie.ratings.send(method)).to eq(2)
2098
2123
  end
2099
2124
  end
2100
2125
  end
2101
2126
  end
2102
2127
  end
2103
2128
 
2104
- describe ".eager_load" do
2105
-
2106
- before do
2107
- Mongoid.identity_map_enabled = true
2108
- end
2109
-
2110
- after do
2111
- Mongoid.identity_map_enabled = false
2112
- end
2113
-
2114
- context "when the relation is not polymorphic" do
2115
-
2116
- context "when the eager load has returned documents" do
2117
-
2118
- let!(:person) do
2119
- Person.create
2120
- end
2121
-
2122
- let!(:post) do
2123
- person.posts.create(title: "testing")
2124
- end
2125
-
2126
- let(:metadata) do
2127
- Person.relations["posts"]
2128
- end
2129
-
2130
- let!(:eager) do
2131
- described_class.eager_load(metadata, Person.all.map(&:_id))
2132
- end
2133
-
2134
- let(:map) do
2135
- Mongoid::IdentityMap.get(Post, {"person_id" => person.id})
2136
- end
2137
-
2138
- it "puts the documents in the identity map" do
2139
- map.should eq({ post.id => post })
2140
- end
2141
- end
2142
-
2143
- context "when the eager load has not returned documents" do
2144
-
2145
- let!(:person) do
2146
- Person.create
2147
- end
2148
-
2149
- let(:metadata) do
2150
- Person.relations["posts"]
2151
- end
2152
-
2153
- let!(:eager) do
2154
- described_class.eager_load(metadata, Person.all.map(&:_id))
2155
- end
2156
-
2157
- let(:map) do
2158
- Mongoid::IdentityMap.get(Post, {"person_id" => person.id})
2159
- end
2160
-
2161
- it "puts an empty array in the identity map" do
2162
- map.should be_empty
2163
- end
2164
- end
2165
-
2166
- context "when the eager load has not returned documents for some" do
2167
-
2168
- let!(:person_one) do
2169
- Person.create
2170
- end
2171
-
2172
- let!(:person_two) do
2173
- Person.create
2174
- end
2175
-
2176
- let!(:post) do
2177
- person_one.posts.create(title: "testing")
2178
- end
2179
-
2180
- let(:metadata) do
2181
- Person.relations["posts"]
2182
- end
2183
-
2184
- let!(:eager) do
2185
- described_class.eager_load(metadata, Person.all.map(&:_id))
2186
- end
2187
-
2188
- let(:map_one) do
2189
- Mongoid::IdentityMap.get(Post, {"person_id" => person_one.id})
2190
- end
2191
-
2192
- let(:map_two) do
2193
- Mongoid::IdentityMap.get(Post, {"person_id" => person_two.id})
2194
- end
2195
-
2196
- it "puts the found documents in the identity map" do
2197
- map_one.should eq({ post.id => post })
2198
- end
2199
-
2200
- it "puts an empty array for parents with no docs" do
2201
- map_two.should be_empty
2202
- end
2203
- end
2204
- end
2205
-
2206
- context "when the relation is polymorphic" do
2207
-
2208
- let!(:movie) do
2209
- Movie.create(name: "Bladerunner")
2210
- end
2211
-
2212
- let!(:book) do
2213
- Book.create(name: "Game of Thrones")
2214
- end
2215
-
2216
- let!(:movie_rating) do
2217
- movie.ratings.create(value: 10)
2218
- end
2219
-
2220
- let!(:book_rating) do
2221
- book.create_rating(value: 10)
2222
- end
2223
-
2224
- let(:metadata) do
2225
- Movie.relations["ratings"]
2226
- end
2227
-
2228
- let!(:eager) do
2229
- described_class.eager_load(metadata, Movie.all.map(&:_id))
2230
- end
2231
-
2232
- let(:map) do
2233
- Mongoid::IdentityMap.get(Rating, {"ratable_id" => movie.id})
2234
- end
2235
-
2236
- it "puts the documents in the identity map" do
2237
- map.should eq({ movie_rating.id => movie_rating })
2238
- end
2239
- end
2240
- end
2241
-
2242
2129
  describe ".embedded?" do
2243
2130
 
2244
2131
  it "returns false" do
2245
- described_class.should_not be_embedded
2132
+ expect(described_class).to_not be_embedded
2246
2133
  end
2247
2134
  end
2248
2135
 
@@ -2259,7 +2146,7 @@ describe Mongoid::Relations::Referenced::Many do
2259
2146
  end
2260
2147
 
2261
2148
  it "returns true" do
2262
- person.posts.exists?.should be_true
2149
+ expect(person.posts.exists?).to be true
2263
2150
  end
2264
2151
  end
2265
2152
 
@@ -2270,7 +2157,7 @@ describe Mongoid::Relations::Referenced::Many do
2270
2157
  end
2271
2158
 
2272
2159
  it "returns false" do
2273
- person.posts.exists?.should be_false
2160
+ expect(person.posts.exists?).to be false
2274
2161
  end
2275
2162
  end
2276
2163
  end
@@ -2279,14 +2166,6 @@ describe Mongoid::Relations::Referenced::Many do
2279
2166
 
2280
2167
  context "when the identity map is enabled" do
2281
2168
 
2282
- before do
2283
- Mongoid.identity_map_enabled = true
2284
- end
2285
-
2286
- after do
2287
- Mongoid.identity_map_enabled = false
2288
- end
2289
-
2290
2169
  context "when the document is in the map" do
2291
2170
 
2292
2171
  let(:person) do
@@ -2335,7 +2214,7 @@ describe Mongoid::Relations::Referenced::Many do
2335
2214
  end
2336
2215
 
2337
2216
  it "returns the matching document" do
2338
- post.should eq(post_one)
2217
+ expect(post).to eq(post_one)
2339
2218
  end
2340
2219
  end
2341
2220
 
@@ -2362,7 +2241,7 @@ describe Mongoid::Relations::Referenced::Many do
2362
2241
 
2363
2242
  it "raises an error" do
2364
2243
  expect {
2365
- person.posts.find(Moped::BSON::ObjectId.new)
2244
+ person.posts.find(BSON::ObjectId.new)
2366
2245
  }.to raise_error(Mongoid::Errors::DocumentNotFound)
2367
2246
  end
2368
2247
  end
@@ -2370,7 +2249,7 @@ describe Mongoid::Relations::Referenced::Many do
2370
2249
  context "when config set not to raise error" do
2371
2250
 
2372
2251
  let(:post) do
2373
- person.posts.find(Moped::BSON::ObjectId.new)
2252
+ person.posts.find(BSON::ObjectId.new)
2374
2253
  end
2375
2254
 
2376
2255
  before do
@@ -2382,7 +2261,7 @@ describe Mongoid::Relations::Referenced::Many do
2382
2261
  end
2383
2262
 
2384
2263
  it "returns nil" do
2385
- post.should be_nil
2264
+ expect(post).to be_nil
2386
2265
  end
2387
2266
  end
2388
2267
  end
@@ -2397,7 +2276,7 @@ describe Mongoid::Relations::Referenced::Many do
2397
2276
  end
2398
2277
 
2399
2278
  it "returns the matching documents" do
2400
- posts.should eq([ post_one, post_two ])
2279
+ expect(posts).to eq([ post_one, post_two ])
2401
2280
  end
2402
2281
  end
2403
2282
 
@@ -2411,7 +2290,7 @@ describe Mongoid::Relations::Referenced::Many do
2411
2290
 
2412
2291
  it "raises an error" do
2413
2292
  expect {
2414
- person.posts.find([ Moped::BSON::ObjectId.new ])
2293
+ person.posts.find([ BSON::ObjectId.new ])
2415
2294
  }.to raise_error(Mongoid::Errors::DocumentNotFound)
2416
2295
  end
2417
2296
  end
@@ -2419,7 +2298,7 @@ describe Mongoid::Relations::Referenced::Many do
2419
2298
  context "when config set not to raise error" do
2420
2299
 
2421
2300
  let(:posts) do
2422
- person.posts.find([ Moped::BSON::ObjectId.new ])
2301
+ person.posts.find([ BSON::ObjectId.new ])
2423
2302
  end
2424
2303
 
2425
2304
  before do
@@ -2431,7 +2310,7 @@ describe Mongoid::Relations::Referenced::Many do
2431
2310
  end
2432
2311
 
2433
2312
  it "returns an empty array" do
2434
- posts.should be_empty
2313
+ expect(posts).to be_empty
2435
2314
  end
2436
2315
  end
2437
2316
  end
@@ -2461,7 +2340,7 @@ describe Mongoid::Relations::Referenced::Many do
2461
2340
  end
2462
2341
 
2463
2342
  it "returns the matching document" do
2464
- rating.should eq(rating_one)
2343
+ expect(rating).to eq(rating_one)
2465
2344
  end
2466
2345
  end
2467
2346
 
@@ -2475,7 +2354,7 @@ describe Mongoid::Relations::Referenced::Many do
2475
2354
 
2476
2355
  it "raises an error" do
2477
2356
  expect {
2478
- movie.ratings.find(Moped::BSON::ObjectId.new)
2357
+ movie.ratings.find(BSON::ObjectId.new)
2479
2358
  }.to raise_error(Mongoid::Errors::DocumentNotFound)
2480
2359
  end
2481
2360
  end
@@ -2483,7 +2362,7 @@ describe Mongoid::Relations::Referenced::Many do
2483
2362
  context "when config set not to raise error" do
2484
2363
 
2485
2364
  let(:rating) do
2486
- movie.ratings.find(Moped::BSON::ObjectId.new)
2365
+ movie.ratings.find(BSON::ObjectId.new)
2487
2366
  end
2488
2367
 
2489
2368
  before do
@@ -2495,7 +2374,7 @@ describe Mongoid::Relations::Referenced::Many do
2495
2374
  end
2496
2375
 
2497
2376
  it "returns nil" do
2498
- rating.should be_nil
2377
+ expect(rating).to be_nil
2499
2378
  end
2500
2379
  end
2501
2380
  end
@@ -2509,8 +2388,16 @@ describe Mongoid::Relations::Referenced::Many do
2509
2388
  movie.ratings.find([ rating_one.id, rating_two.id ])
2510
2389
  end
2511
2390
 
2512
- it "returns the matching documents" do
2513
- ratings.should eq([ rating_one, rating_two ])
2391
+ it "returns the first matching document" do
2392
+ expect(ratings).to include(rating_one)
2393
+ end
2394
+
2395
+ it "returns the second matching document" do
2396
+ expect(ratings).to include(rating_two)
2397
+ end
2398
+
2399
+ it "returns the correct number of documents" do
2400
+ expect(ratings.size).to eq(2)
2514
2401
  end
2515
2402
  end
2516
2403
 
@@ -2524,7 +2411,7 @@ describe Mongoid::Relations::Referenced::Many do
2524
2411
 
2525
2412
  it "raises an error" do
2526
2413
  expect {
2527
- movie.ratings.find([ Moped::BSON::ObjectId.new ])
2414
+ movie.ratings.find([ BSON::ObjectId.new ])
2528
2415
  }.to raise_error(Mongoid::Errors::DocumentNotFound)
2529
2416
  end
2530
2417
  end
@@ -2532,7 +2419,7 @@ describe Mongoid::Relations::Referenced::Many do
2532
2419
  context "when config set not to raise error" do
2533
2420
 
2534
2421
  let(:ratings) do
2535
- movie.ratings.find([ Moped::BSON::ObjectId.new ])
2422
+ movie.ratings.find([ BSON::ObjectId.new ])
2536
2423
  end
2537
2424
 
2538
2425
  before do
@@ -2544,7 +2431,7 @@ describe Mongoid::Relations::Referenced::Many do
2544
2431
  end
2545
2432
 
2546
2433
  it "returns an empty array" do
2547
- ratings.should be_empty
2434
+ expect(ratings).to be_empty
2548
2435
  end
2549
2436
  end
2550
2437
  end
@@ -2571,11 +2458,11 @@ describe Mongoid::Relations::Referenced::Many do
2571
2458
  end
2572
2459
 
2573
2460
  it "returns the document" do
2574
- found.should eq(post)
2461
+ expect(found).to eq(post)
2575
2462
  end
2576
2463
 
2577
2464
  it "keeps the document in the relation" do
2578
- found.person.should eq(person)
2465
+ expect(found.person).to eq(person)
2579
2466
  end
2580
2467
  end
2581
2468
 
@@ -2590,19 +2477,19 @@ describe Mongoid::Relations::Referenced::Many do
2590
2477
  end
2591
2478
 
2592
2479
  it "sets the new document attributes" do
2593
- found.title.should eq("Test")
2480
+ expect(found.title).to eq("Test")
2594
2481
  end
2595
2482
 
2596
2483
  it "returns a newly persisted document" do
2597
- found.should be_persisted
2484
+ expect(found).to be_persisted
2598
2485
  end
2599
2486
 
2600
2487
  it "calls the passed block" do
2601
- found.content.should eq("The Content")
2488
+ expect(found.content).to eq("The Content")
2602
2489
  end
2603
2490
 
2604
2491
  it "keeps the document in the relation" do
2605
- found.person.should eq(person)
2492
+ expect(found.person).to eq(person)
2606
2493
  end
2607
2494
  end
2608
2495
 
@@ -2613,15 +2500,15 @@ describe Mongoid::Relations::Referenced::Many do
2613
2500
  end
2614
2501
 
2615
2502
  it "sets the new document attributes" do
2616
- found.title.should eq("Test")
2503
+ expect(found.title).to eq("Test")
2617
2504
  end
2618
2505
 
2619
2506
  it "returns a newly persisted document" do
2620
- found.should be_persisted
2507
+ expect(found).to be_persisted
2621
2508
  end
2622
2509
 
2623
2510
  it "keeps the document in the relation" do
2624
- found.person.should eq(person)
2511
+ expect(found.person).to eq(person)
2625
2512
  end
2626
2513
  end
2627
2514
  end
@@ -2644,11 +2531,11 @@ describe Mongoid::Relations::Referenced::Many do
2644
2531
  end
2645
2532
 
2646
2533
  it "returns the document" do
2647
- found.should eq(rating)
2534
+ expect(found).to eq(rating)
2648
2535
  end
2649
2536
 
2650
2537
  it "keeps the document in the relation" do
2651
- found.ratable.should eq(movie)
2538
+ expect(found.ratable).to eq(movie)
2652
2539
  end
2653
2540
  end
2654
2541
 
@@ -2659,15 +2546,145 @@ describe Mongoid::Relations::Referenced::Many do
2659
2546
  end
2660
2547
 
2661
2548
  it "sets the new document attributes" do
2662
- found.value.should eq(3)
2549
+ expect(found.value).to eq(3)
2663
2550
  end
2664
2551
 
2665
2552
  it "returns a newly persisted document" do
2666
- found.should be_persisted
2553
+ expect(found).to be_persisted
2667
2554
  end
2668
2555
 
2669
2556
  it "keeps the document in the relation" do
2670
- found.ratable.should eq(movie)
2557
+ expect(found.ratable).to eq(movie)
2558
+ end
2559
+ end
2560
+ end
2561
+ end
2562
+
2563
+ describe "#find_or_create_by!" do
2564
+
2565
+ context "when the relation is not polymorphic" do
2566
+
2567
+ let(:person) do
2568
+ Person.create
2569
+ end
2570
+
2571
+ let!(:post) do
2572
+ person.posts.create(title: "Testing")
2573
+ end
2574
+
2575
+ context "when the document exists" do
2576
+
2577
+ let(:found) do
2578
+ person.posts.find_or_create_by!(title: "Testing")
2579
+ end
2580
+
2581
+ it "returns the document" do
2582
+ expect(found).to eq(post)
2583
+ end
2584
+
2585
+ it "keeps the document in the relation" do
2586
+ expect(found.person).to eq(person)
2587
+ end
2588
+ end
2589
+
2590
+ context "when the document does not exist" do
2591
+
2592
+ context "when there is no criteria attached" do
2593
+
2594
+ let(:found) do
2595
+ person.posts.find_or_create_by!(title: "Test") do |post|
2596
+ post.content = "The Content"
2597
+ end
2598
+ end
2599
+
2600
+ it "sets the new document attributes" do
2601
+ expect(found.title).to eq("Test")
2602
+ end
2603
+
2604
+ it "returns a newly persisted document" do
2605
+ expect(found).to be_persisted
2606
+ end
2607
+
2608
+ it "calls the passed block" do
2609
+ expect(found.content).to eq("The Content")
2610
+ end
2611
+
2612
+ it "keeps the document in the relation" do
2613
+ expect(found.person).to eq(person)
2614
+ end
2615
+ end
2616
+
2617
+ context "when a criteria is attached" do
2618
+
2619
+ let(:found) do
2620
+ person.posts.recent.find_or_create_by!(title: "Test")
2621
+ end
2622
+
2623
+ it "sets the new document attributes" do
2624
+ expect(found.title).to eq("Test")
2625
+ end
2626
+
2627
+ it "returns a newly persisted document" do
2628
+ expect(found).to be_persisted
2629
+ end
2630
+
2631
+ it "keeps the document in the relation" do
2632
+ expect(found.person).to eq(person)
2633
+ end
2634
+ end
2635
+ end
2636
+ end
2637
+
2638
+ context "when the relation is polymorphic" do
2639
+
2640
+ let(:movie) do
2641
+ Movie.create
2642
+ end
2643
+
2644
+ let!(:rating) do
2645
+ movie.ratings.create(value: 1)
2646
+ end
2647
+
2648
+ context "when the document exists" do
2649
+
2650
+ let(:found) do
2651
+ movie.ratings.find_or_create_by!(value: 1)
2652
+ end
2653
+
2654
+ it "returns the document" do
2655
+ expect(found).to eq(rating)
2656
+ end
2657
+
2658
+ it "keeps the document in the relation" do
2659
+ expect(found.ratable).to eq(movie)
2660
+ end
2661
+ end
2662
+
2663
+ context "when the document does not exist" do
2664
+
2665
+ let(:found) do
2666
+ movie.ratings.find_or_create_by!(value: 3)
2667
+ end
2668
+
2669
+ it "sets the new document attributes" do
2670
+ expect(found.value).to eq(3)
2671
+ end
2672
+
2673
+ it "returns a newly persisted document" do
2674
+ expect(found).to be_persisted
2675
+ end
2676
+
2677
+ it "keeps the document in the relation" do
2678
+ expect(found.ratable).to eq(movie)
2679
+ end
2680
+
2681
+ context "when validation fails" do
2682
+
2683
+ it "raises an error" do
2684
+ expect {
2685
+ movie.comments.find_or_create_by!(title: "")
2686
+ }.to raise_error(Mongoid::Errors::Validations)
2687
+ end
2671
2688
  end
2672
2689
  end
2673
2690
  end
@@ -2692,7 +2709,7 @@ describe Mongoid::Relations::Referenced::Many do
2692
2709
  end
2693
2710
 
2694
2711
  it "returns the document" do
2695
- found.should eq(post)
2712
+ expect(found).to eq(post)
2696
2713
  end
2697
2714
  end
2698
2715
 
@@ -2705,15 +2722,15 @@ describe Mongoid::Relations::Referenced::Many do
2705
2722
  end
2706
2723
 
2707
2724
  it "sets the new document attributes" do
2708
- found.title.should eq("Test")
2725
+ expect(found.title).to eq("Test")
2709
2726
  end
2710
2727
 
2711
2728
  it "returns a non persisted document" do
2712
- found.should_not be_persisted
2729
+ expect(found).to_not be_persisted
2713
2730
  end
2714
2731
 
2715
2732
  it "calls the passed block" do
2716
- found.content.should eq("The Content")
2733
+ expect(found.content).to eq("The Content")
2717
2734
  end
2718
2735
  end
2719
2736
  end
@@ -2735,7 +2752,7 @@ describe Mongoid::Relations::Referenced::Many do
2735
2752
  end
2736
2753
 
2737
2754
  it "returns the document" do
2738
- found.should eq(rating)
2755
+ expect(found).to eq(rating)
2739
2756
  end
2740
2757
  end
2741
2758
 
@@ -2746,11 +2763,11 @@ describe Mongoid::Relations::Referenced::Many do
2746
2763
  end
2747
2764
 
2748
2765
  it "sets the new document attributes" do
2749
- found.value.should eq(3)
2766
+ expect(found.value).to eq(3)
2750
2767
  end
2751
2768
 
2752
2769
  it "returns a non persisted document" do
2753
- found.should_not be_persisted
2770
+ expect(found).to_not be_persisted
2754
2771
  end
2755
2772
  end
2756
2773
  end
@@ -2759,7 +2776,7 @@ describe Mongoid::Relations::Referenced::Many do
2759
2776
  describe ".foreign_key_suffix" do
2760
2777
 
2761
2778
  it "returns _id" do
2762
- described_class.foreign_key_suffix.should eq("_id")
2779
+ expect(described_class.foreign_key_suffix).to eq("_id")
2763
2780
  end
2764
2781
  end
2765
2782
 
@@ -2785,7 +2802,7 @@ describe Mongoid::Relations::Referenced::Many do
2785
2802
  end
2786
2803
 
2787
2804
  it "does not raise an error" do
2788
- post.roles.should be_empty
2805
+ expect(post.roles).to be_empty
2789
2806
  end
2790
2807
  end
2791
2808
  end
@@ -2793,7 +2810,7 @@ describe Mongoid::Relations::Referenced::Many do
2793
2810
  describe ".macro" do
2794
2811
 
2795
2812
  it "returns has_many" do
2796
- described_class.macro.should eq(:has_many)
2813
+ expect(described_class.macro).to eq(:has_many)
2797
2814
  end
2798
2815
  end
2799
2816
 
@@ -2822,7 +2839,7 @@ describe Mongoid::Relations::Referenced::Many do
2822
2839
  end
2823
2840
 
2824
2841
  it "returns the document with the max value of the supplied field" do
2825
- max.should eq(post_two)
2842
+ expect(max).to eq(post_two)
2826
2843
  end
2827
2844
  end
2828
2845
 
@@ -2849,7 +2866,7 @@ describe Mongoid::Relations::Referenced::Many do
2849
2866
  end
2850
2867
 
2851
2868
  it "returns the document with the max value of the supplied field" do
2852
- max.should eq(post_two)
2869
+ expect(max).to eq(post_two)
2853
2870
  end
2854
2871
  end
2855
2872
 
@@ -2874,7 +2891,7 @@ describe Mongoid::Relations::Referenced::Many do
2874
2891
  end
2875
2892
 
2876
2893
  it "applies the criteria to the documents" do
2877
- posts.should eq([ post_one ])
2894
+ expect(posts).to eq([ post_one ])
2878
2895
  end
2879
2896
  end
2880
2897
 
@@ -2885,7 +2902,7 @@ describe Mongoid::Relations::Referenced::Many do
2885
2902
  end
2886
2903
 
2887
2904
  it "applies the criteria to the documents" do
2888
- posts.should eq([ post_one ])
2905
+ expect(posts).to eq([ post_one ])
2889
2906
  end
2890
2907
  end
2891
2908
 
@@ -2896,7 +2913,7 @@ describe Mongoid::Relations::Referenced::Many do
2896
2913
  end
2897
2914
 
2898
2915
  it "applies the criteria to the documents" do
2899
- posts.should eq([ post_one ])
2916
+ expect(posts).to eq([ post_one ])
2900
2917
  end
2901
2918
  end
2902
2919
 
@@ -2904,8 +2921,13 @@ describe Mongoid::Relations::Referenced::Many do
2904
2921
 
2905
2922
  describe "#distinct" do
2906
2923
 
2924
+ let(:values) do
2925
+ person.posts.distinct(:title)
2926
+ end
2927
+
2907
2928
  it "returns the distinct values for the fields" do
2908
- person.posts.distinct(:title).should =~ [ "First", "Second"]
2929
+ expect(values).to include("First")
2930
+ expect(values).to include("Second")
2909
2931
  end
2910
2932
  end
2911
2933
  end
@@ -2936,7 +2958,7 @@ describe Mongoid::Relations::Referenced::Many do
2936
2958
  end
2937
2959
 
2938
2960
  it "returns the min value of the supplied field" do
2939
- min.should eq(post_one)
2961
+ expect(min).to eq(post_one)
2940
2962
  end
2941
2963
  end
2942
2964
 
@@ -2963,7 +2985,7 @@ describe Mongoid::Relations::Referenced::Many do
2963
2985
  end
2964
2986
 
2965
2987
  it "returns the min value of the supplied field" do
2966
- min.should eq(post_one)
2988
+ expect(min).to eq(post_one)
2967
2989
  end
2968
2990
  end
2969
2991
 
@@ -2992,16 +3014,16 @@ describe Mongoid::Relations::Referenced::Many do
2992
3014
  end
2993
3015
 
2994
3016
  it "loads the targets before nullifying" do
2995
- from_db.posts.should be_empty
3017
+ expect(from_db.posts).to be_empty
2996
3018
  end
2997
3019
 
2998
3020
  it "persists the base nullifications" do
2999
- Person.first.posts.should be_empty
3021
+ expect(Person.first.posts).to be_empty
3000
3022
  end
3001
3023
 
3002
3024
  it "persists the inverse nullifications" do
3003
3025
  Post.all.each do |post|
3004
- post.person.should be_nil
3026
+ expect(post.person).to be_nil
3005
3027
  end
3006
3028
  end
3007
3029
  end
@@ -3026,18 +3048,18 @@ describe Mongoid::Relations::Referenced::Many do
3026
3048
 
3027
3049
  it "removes all the foreign keys from the target" do
3028
3050
  [ post_one, post_two ].each do |post|
3029
- post.person_id.should be_nil
3051
+ expect(post.person_id).to be_nil
3030
3052
  end
3031
3053
  end
3032
3054
 
3033
3055
  it "removes all the references from the target" do
3034
3056
  [ post_one, post_two ].each do |post|
3035
- post.person.should be_nil
3057
+ expect(post.person).to be_nil
3036
3058
  end
3037
3059
  end
3038
3060
 
3039
3061
  it "saves the documents" do
3040
- post_one.reload.person.should be_nil
3062
+ expect(post_one.reload.person).to be_nil
3041
3063
  end
3042
3064
 
3043
3065
  context "when adding a nullified document back to the relation" do
@@ -3047,7 +3069,7 @@ describe Mongoid::Relations::Referenced::Many do
3047
3069
  end
3048
3070
 
3049
3071
  it "persists the relation" do
3050
- person.posts(true).should eq([ post_one ])
3072
+ expect(person.posts(true)).to eq([ post_one ])
3051
3073
  end
3052
3074
  end
3053
3075
  end
@@ -3072,13 +3094,13 @@ describe Mongoid::Relations::Referenced::Many do
3072
3094
 
3073
3095
  it "removes all the foreign keys from the target" do
3074
3096
  [ rating_one, rating_two ].each do |rating|
3075
- rating.ratable_id.should be_nil
3097
+ expect(rating.ratable_id).to be_nil
3076
3098
  end
3077
3099
  end
3078
3100
 
3079
3101
  it "removes all the references from the target" do
3080
3102
  [ rating_one, rating_two ].each do |rating|
3081
- rating.ratable.should be_nil
3103
+ expect(rating.ratable).to be_nil
3082
3104
  end
3083
3105
  end
3084
3106
  end
@@ -3099,7 +3121,7 @@ describe Mongoid::Relations::Referenced::Many do
3099
3121
  context "when checking #{method}" do
3100
3122
 
3101
3123
  it "returns true" do
3102
- posts.respond_to?(method).should be_true
3124
+ expect(posts.respond_to?(method)).to be true
3103
3125
  end
3104
3126
  end
3105
3127
  end
@@ -3109,7 +3131,7 @@ describe Mongoid::Relations::Referenced::Many do
3109
3131
  context "when checking #{method}" do
3110
3132
 
3111
3133
  it "returns true" do
3112
- posts.respond_to?(method).should be_true
3134
+ expect(posts.respond_to?(method)).to be true
3113
3135
  end
3114
3136
  end
3115
3137
  end
@@ -3119,7 +3141,7 @@ describe Mongoid::Relations::Referenced::Many do
3119
3141
  context "when checking #{method}" do
3120
3142
 
3121
3143
  it "returns true" do
3122
- posts.respond_to?(method).should be_true
3144
+ expect(posts.respond_to?(method)).to be true
3123
3145
  end
3124
3146
  end
3125
3147
  end
@@ -3128,7 +3150,7 @@ describe Mongoid::Relations::Referenced::Many do
3128
3150
  describe ".stores_foreign_key?" do
3129
3151
 
3130
3152
  it "returns false" do
3131
- described_class.stores_foreign_key?.should be_false
3153
+ expect(described_class.stores_foreign_key?).to be false
3132
3154
  end
3133
3155
  end
3134
3156
 
@@ -3143,11 +3165,11 @@ describe Mongoid::Relations::Referenced::Many do
3143
3165
  end
3144
3166
 
3145
3167
  it "returns the relation criteria" do
3146
- scoped.should be_a(Mongoid::Criteria)
3168
+ expect(scoped).to be_a(Mongoid::Criteria)
3147
3169
  end
3148
3170
 
3149
3171
  it "returns with an empty selector" do
3150
- scoped.selector.should eq({ "person_id" => person.id })
3172
+ expect(scoped.selector).to eq({ "person_id" => person.id })
3151
3173
  end
3152
3174
  end
3153
3175
 
@@ -3166,7 +3188,7 @@ describe Mongoid::Relations::Referenced::Many do
3166
3188
  end
3167
3189
 
3168
3190
  it "returns 1" do
3169
- movie.ratings.send(method).should eq(1)
3191
+ expect(movie.ratings.send(method)).to eq(1)
3170
3192
  end
3171
3193
  end
3172
3194
 
@@ -3178,7 +3200,7 @@ describe Mongoid::Relations::Referenced::Many do
3178
3200
  end
3179
3201
 
3180
3202
  it "returns the total number of documents" do
3181
- movie.ratings.send(method).should eq(2)
3203
+ expect(movie.ratings.send(method)).to eq(2)
3182
3204
  end
3183
3205
  end
3184
3206
  end
@@ -3205,7 +3227,7 @@ describe Mongoid::Relations::Referenced::Many do
3205
3227
  end
3206
3228
 
3207
3229
  it "returns only the associated documents" do
3208
- unscoped.should eq([ post_one ])
3230
+ expect(unscoped).to eq([ post_one ])
3209
3231
  end
3210
3232
  end
3211
3233
 
@@ -3228,11 +3250,11 @@ describe Mongoid::Relations::Referenced::Many do
3228
3250
  end
3229
3251
 
3230
3252
  it "only returns associated documents" do
3231
- unscoped.should eq([ acolyte_one ])
3253
+ expect(unscoped).to eq([ acolyte_one ])
3232
3254
  end
3233
3255
 
3234
3256
  it "removes the default scoping options" do
3235
- unscoped.options.should eq({})
3257
+ expect(unscoped.options).to eq({})
3236
3258
  end
3237
3259
  end
3238
3260
  end
@@ -3240,7 +3262,7 @@ describe Mongoid::Relations::Referenced::Many do
3240
3262
  describe ".valid_options" do
3241
3263
 
3242
3264
  it "returns the valid options" do
3243
- described_class.valid_options.should eq(
3265
+ expect(described_class.valid_options).to eq(
3244
3266
  [
3245
3267
  :after_add,
3246
3268
  :after_remove,
@@ -3260,7 +3282,7 @@ describe Mongoid::Relations::Referenced::Many do
3260
3282
  describe ".validation_default" do
3261
3283
 
3262
3284
  it "returns true" do
3263
- described_class.validation_default.should be_true
3285
+ expect(described_class.validation_default).to be true
3264
3286
  end
3265
3287
  end
3266
3288
 
@@ -3288,13 +3310,13 @@ describe Mongoid::Relations::Referenced::Many do
3288
3310
  end
3289
3311
 
3290
3312
  it "order documents" do
3291
- person.ordered_posts(true).should eq(
3313
+ expect(person.ordered_posts(true)).to eq(
3292
3314
  [post_two, post_three, post_one]
3293
3315
  )
3294
3316
  end
3295
3317
 
3296
3318
  it "chaining order criterias" do
3297
- person.ordered_posts.order_by(:title.desc).to_a.should eq(
3319
+ expect(person.ordered_posts.order_by(:title.desc).to_a).to eq(
3298
3320
  [post_three, post_two, post_one]
3299
3321
  )
3300
3322
  end
@@ -3330,7 +3352,7 @@ describe Mongoid::Relations::Referenced::Many do
3330
3352
  end
3331
3353
 
3332
3354
  it "reloads the document from the database" do
3333
- reloaded.first.title.should eq("reloaded")
3355
+ expect(reloaded.first.title).to eq("reloaded")
3334
3356
  end
3335
3357
  end
3336
3358
 
@@ -3345,11 +3367,11 @@ describe Mongoid::Relations::Referenced::Many do
3345
3367
  end
3346
3368
 
3347
3369
  it "reloads the first document from the database" do
3348
- reloaded.should include(post_one)
3370
+ expect(reloaded).to include(post_one)
3349
3371
  end
3350
3372
 
3351
3373
  it "reloads the new document from the database" do
3352
- reloaded.should include(post_two)
3374
+ expect(reloaded).to include(post_two)
3353
3375
  end
3354
3376
  end
3355
3377
  end
@@ -3363,7 +3385,7 @@ describe Mongoid::Relations::Referenced::Many do
3363
3385
  end
3364
3386
 
3365
3387
  it "allows creation of the document" do
3366
- jar.id.should eq(1)
3388
+ expect(jar.id).to eq(1)
3367
3389
  end
3368
3390
  end
3369
3391
 
@@ -3392,7 +3414,7 @@ describe Mongoid::Relations::Referenced::Many do
3392
3414
  end
3393
3415
 
3394
3416
  it "adds both documents" do
3395
- result.should eq([ post_one, post_two ])
3417
+ expect(result).to eq([ post_one, post_two ])
3396
3418
  end
3397
3419
  end
3398
3420
  end
@@ -3414,29 +3436,29 @@ describe Mongoid::Relations::Referenced::Many do
3414
3436
  end
3415
3437
 
3416
3438
  it "it executes method callbacks" do
3417
- artist.before_add_referenced_called.should be_true
3439
+ expect(artist.before_add_referenced_called).to be true
3418
3440
  end
3419
3441
 
3420
3442
  it "it executes proc callbacks" do
3421
- album.before_add_called.should be_true
3443
+ expect(album.before_add_called).to be true
3422
3444
  end
3423
3445
 
3424
3446
  it "adds the document to the relation" do
3425
- artist.albums.should eq([ album ])
3447
+ expect(artist.albums).to eq([ album ])
3426
3448
  end
3427
3449
  end
3428
3450
 
3429
3451
  context "when execution raises errors" do
3430
3452
 
3431
3453
  before do
3432
- artist.should_receive(:before_add_album).and_raise
3454
+ expect(artist).to receive(:before_add_album).and_raise
3433
3455
  end
3434
3456
 
3435
3457
  it "does not add the document to the relation" do
3436
3458
  expect {
3437
3459
  artist.albums << album
3438
3460
  }.to raise_error
3439
- artist.albums.should be_empty
3461
+ expect(artist.albums).to be_empty
3440
3462
  end
3441
3463
  end
3442
3464
  end
@@ -3453,20 +3475,20 @@ describe Mongoid::Relations::Referenced::Many do
3453
3475
 
3454
3476
  it "executes the callback" do
3455
3477
  artist.albums << album
3456
- artist.after_add_referenced_called.should be_true
3478
+ expect(artist.after_add_referenced_called).to be true
3457
3479
  end
3458
3480
 
3459
3481
  context "when execution raises errors" do
3460
3482
 
3461
3483
  before do
3462
- artist.should_receive(:after_add_album).and_raise
3484
+ expect(artist).to receive(:after_add_album).and_raise
3463
3485
  end
3464
3486
 
3465
3487
  it "adds the document to the relation" do
3466
3488
  expect {
3467
3489
  artist.albums << album
3468
3490
  }.to raise_error
3469
- artist.albums.should eq([ album ])
3491
+ expect(artist.albums).to eq([ album ])
3470
3492
  end
3471
3493
  end
3472
3494
  end
@@ -3494,11 +3516,11 @@ describe Mongoid::Relations::Referenced::Many do
3494
3516
  end
3495
3517
 
3496
3518
  it "executes the callback" do
3497
- artist.before_remove_referenced_called.should be_true
3519
+ expect(artist.before_remove_referenced_called).to be true
3498
3520
  end
3499
3521
 
3500
3522
  it "removes the document from the relation" do
3501
- artist.albums.should be_empty
3523
+ expect(artist.albums).to be_empty
3502
3524
  end
3503
3525
  end
3504
3526
 
@@ -3509,18 +3531,18 @@ describe Mongoid::Relations::Referenced::Many do
3509
3531
  end
3510
3532
 
3511
3533
  it "executes the callback" do
3512
- artist.before_remove_referenced_called.should be_true
3534
+ expect(artist.before_remove_referenced_called).to be true
3513
3535
  end
3514
3536
 
3515
3537
  it "clears the relation" do
3516
- artist.albums.should be_empty
3538
+ expect(artist.albums).to be_empty
3517
3539
  end
3518
3540
  end
3519
3541
 
3520
3542
  context "when execution raises errors" do
3521
3543
 
3522
3544
  before do
3523
- artist.should_receive(:before_remove_album).and_raise
3545
+ expect(artist).to receive(:before_remove_album).and_raise
3524
3546
  end
3525
3547
 
3526
3548
  describe "#delete" do
@@ -3532,7 +3554,7 @@ describe Mongoid::Relations::Referenced::Many do
3532
3554
  end
3533
3555
 
3534
3556
  it "does not remove the document from the relation" do
3535
- artist.albums.should eq([ album ])
3557
+ expect(artist.albums).to eq([ album ])
3536
3558
  end
3537
3559
  end
3538
3560
 
@@ -3545,7 +3567,7 @@ describe Mongoid::Relations::Referenced::Many do
3545
3567
  end
3546
3568
 
3547
3569
  it "does not clear the relation" do
3548
- artist.albums.should eq([ album ])
3570
+ expect(artist.albums).to eq([ album ])
3549
3571
  end
3550
3572
  end
3551
3573
  end
@@ -3575,7 +3597,7 @@ describe Mongoid::Relations::Referenced::Many do
3575
3597
  end
3576
3598
 
3577
3599
  it "executes the callback" do
3578
- artist.after_remove_referenced_called.should be_true
3600
+ expect(artist.after_remove_referenced_called).to be true
3579
3601
  end
3580
3602
  end
3581
3603
 
@@ -3587,7 +3609,7 @@ describe Mongoid::Relations::Referenced::Many do
3587
3609
 
3588
3610
  it "executes the callback" do
3589
3611
  artist.albums.clear
3590
- artist.after_remove_referenced_called.should be_true
3612
+ expect(artist.after_remove_referenced_called).to be true
3591
3613
  end
3592
3614
  end
3593
3615
  end
@@ -3595,7 +3617,7 @@ describe Mongoid::Relations::Referenced::Many do
3595
3617
  context "when errors are raised" do
3596
3618
 
3597
3619
  before do
3598
- artist.should_receive(:after_remove_album).and_raise
3620
+ expect(artist).to receive(:after_remove_album).and_raise
3599
3621
  end
3600
3622
 
3601
3623
  describe "#delete" do
@@ -3607,7 +3629,7 @@ describe Mongoid::Relations::Referenced::Many do
3607
3629
  end
3608
3630
 
3609
3631
  it "removes the documents from the relation" do
3610
- artist.albums.should be_empty
3632
+ expect(artist.albums).to be_empty
3611
3633
  end
3612
3634
  end
3613
3635
 
@@ -3620,7 +3642,7 @@ describe Mongoid::Relations::Referenced::Many do
3620
3642
  end
3621
3643
 
3622
3644
  it "removes the documents from the relation" do
3623
- artist.albums.should be_empty
3645
+ expect(artist.albums).to be_empty
3624
3646
  end
3625
3647
  end
3626
3648
  end
@@ -3645,7 +3667,45 @@ describe Mongoid::Relations::Referenced::Many do
3645
3667
  end
3646
3668
 
3647
3669
  it "does not drop the ordering" do
3648
- criteria.should eq([ post_two, post_one ])
3670
+ expect(criteria).to eq([ post_two, post_one ])
3671
+ end
3672
+ end
3673
+
3674
+ context "when accessing a scope named open" do
3675
+
3676
+ let(:person) do
3677
+ Person.create
3678
+ end
3679
+
3680
+ let!(:post) do
3681
+ person.posts.create(title: "open")
3682
+ end
3683
+
3684
+ it "returns the appropriate documents" do
3685
+ expect(person.posts.open).to eq([ post ])
3686
+ end
3687
+ end
3688
+
3689
+ context "when accessing a relation named parent" do
3690
+ let!(:parent) do
3691
+ Odd.create(name: "odd parent")
3692
+ end
3693
+
3694
+ let(:child) do
3695
+ Even.create(parent_id: parent.id, name: "original even child")
3696
+ end
3697
+
3698
+ it "updates the child after accessing the parent" do
3699
+ # Access parent relation on the child to make sure it is loaded
3700
+ child.parent
3701
+
3702
+ new_child_name = "updated even child"
3703
+
3704
+ child.name = new_child_name
3705
+ child.save!
3706
+
3707
+ reloaded = Even.find(child.id)
3708
+ expect(reloaded.name).to eq(new_child_name)
3649
3709
  end
3650
3710
  end
3651
3711
  end