mongoid 3.1.6 → 4.0.0

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 (562) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +432 -8
  3. data/README.md +5 -6
  4. data/lib/config/locales/en.yml +32 -18
  5. data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
  6. data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
  7. data/lib/mongoid/atomic/paths/embedded.rb +0 -30
  8. data/lib/mongoid/atomic/paths/root.rb +0 -13
  9. data/lib/mongoid/atomic.rb +1 -12
  10. data/lib/mongoid/attributes/dynamic.rb +154 -0
  11. data/lib/mongoid/attributes/nested.rb +82 -0
  12. data/lib/mongoid/attributes/processing.rb +13 -66
  13. data/lib/mongoid/attributes.rb +63 -101
  14. data/lib/mongoid/{dirty.rb → changeable.rb} +32 -2
  15. data/lib/mongoid/composable.rb +105 -0
  16. data/lib/mongoid/config/options.rb +1 -1
  17. data/lib/mongoid/config.rb +3 -9
  18. data/lib/mongoid/contextual/aggregable/mongo.rb +7 -9
  19. data/lib/mongoid/contextual/atomic.rb +53 -53
  20. data/lib/mongoid/contextual/geo_near.rb +1 -1
  21. data/lib/mongoid/contextual/map_reduce.rb +4 -2
  22. data/lib/mongoid/contextual/memory.rb +18 -6
  23. data/lib/mongoid/contextual/mongo.rb +64 -56
  24. data/lib/mongoid/contextual/none.rb +90 -0
  25. data/lib/mongoid/contextual/text_search.rb +178 -0
  26. data/lib/mongoid/contextual.rb +2 -0
  27. data/lib/mongoid/copyable.rb +2 -3
  28. data/lib/mongoid/{criterion → criteria}/findable.rb +7 -47
  29. data/lib/mongoid/{criterion/inspection.rb → criteria/inspectable.rb} +2 -2
  30. data/lib/mongoid/{criterion → criteria}/marshalable.rb +3 -1
  31. data/lib/mongoid/{criterion → criteria}/modifiable.rb +28 -8
  32. data/lib/mongoid/criteria/permission.rb +70 -0
  33. data/lib/mongoid/{criterion/scoping.rb → criteria/scopable.rb} +2 -2
  34. data/lib/mongoid/criteria.rb +39 -34
  35. data/lib/mongoid/document.rb +32 -17
  36. data/lib/mongoid/errors/document_not_destroyed.rb +25 -0
  37. data/lib/mongoid/errors/document_not_found.rb +2 -1
  38. data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
  39. data/lib/mongoid/errors/invalid_storage_parent.rb +26 -0
  40. data/lib/mongoid/errors/invalid_value.rb +16 -0
  41. data/lib/mongoid/errors/mongoid_error.rb +1 -1
  42. data/lib/mongoid/errors/readonly_document.rb +24 -0
  43. data/lib/mongoid/errors.rb +4 -1
  44. data/lib/mongoid/extensions/array.rb +3 -3
  45. data/lib/mongoid/extensions/big_decimal.rb +1 -1
  46. data/lib/mongoid/extensions/boolean.rb +15 -17
  47. data/lib/mongoid/extensions/date.rb +1 -1
  48. data/lib/mongoid/extensions/date_time.rb +3 -3
  49. data/lib/mongoid/extensions/float.rb +2 -1
  50. data/lib/mongoid/extensions/hash.rb +3 -3
  51. data/lib/mongoid/extensions/integer.rb +1 -1
  52. data/lib/mongoid/extensions/object.rb +7 -7
  53. data/lib/mongoid/extensions/object_id.rb +5 -5
  54. data/lib/mongoid/extensions/range.rb +9 -3
  55. data/lib/mongoid/extensions/regexp.rb +1 -1
  56. data/lib/mongoid/extensions/set.rb +1 -1
  57. data/lib/mongoid/extensions/string.rb +6 -18
  58. data/lib/mongoid/extensions/symbol.rb +1 -1
  59. data/lib/mongoid/extensions/time.rb +3 -3
  60. data/lib/mongoid/extensions/time_with_zone.rb +1 -1
  61. data/lib/mongoid/extensions.rb +2 -7
  62. data/lib/mongoid/factory.rb +8 -6
  63. data/lib/mongoid/fields/foreign_key.rb +3 -3
  64. data/lib/mongoid/fields/localized.rb +1 -1
  65. data/lib/mongoid/fields/standard.rb +5 -17
  66. data/lib/mongoid/fields/validators/macro.rb +15 -5
  67. data/lib/mongoid/fields.rb +41 -8
  68. data/lib/mongoid/{finders.rb → findable.rb} +8 -2
  69. data/lib/mongoid/indexable/specification.rb +104 -0
  70. data/lib/mongoid/{indexes → indexable}/validators/options.rb +2 -1
  71. data/lib/mongoid/{indexes.rb → indexable.rb} +50 -55
  72. data/lib/mongoid/{inspection.rb → inspectable.rb} +15 -11
  73. data/lib/mongoid/{callbacks.rb → interceptable.rb} +30 -62
  74. data/lib/mongoid/log_subscriber.rb +55 -0
  75. data/lib/mongoid/{matchers → matchable}/all.rb +1 -1
  76. data/lib/mongoid/{matchers → matchable}/and.rb +2 -2
  77. data/lib/mongoid/{matchers → matchable}/default.rb +1 -1
  78. data/lib/mongoid/{matchers → matchable}/exists.rb +1 -1
  79. data/lib/mongoid/{matchers → matchable}/gt.rb +1 -1
  80. data/lib/mongoid/{matchers → matchable}/gte.rb +1 -1
  81. data/lib/mongoid/{matchers → matchable}/in.rb +2 -2
  82. data/lib/mongoid/{matchers → matchable}/lt.rb +1 -1
  83. data/lib/mongoid/{matchers → matchable}/lte.rb +1 -1
  84. data/lib/mongoid/{matchers → matchable}/ne.rb +2 -2
  85. data/lib/mongoid/{matchers → matchable}/nin.rb +3 -2
  86. data/lib/mongoid/{matchers → matchable}/or.rb +2 -2
  87. data/lib/mongoid/{matchers → matchable}/size.rb +1 -1
  88. data/lib/mongoid/matchable.rb +152 -0
  89. data/lib/mongoid/persistable/creatable.rb +188 -0
  90. data/lib/mongoid/persistable/deletable.rb +149 -0
  91. data/lib/mongoid/persistable/destroyable.rb +60 -0
  92. data/lib/mongoid/persistable/incrementable.rb +36 -0
  93. data/lib/mongoid/persistable/logical.rb +38 -0
  94. data/lib/mongoid/persistable/poppable.rb +39 -0
  95. data/lib/mongoid/persistable/pullable.rb +55 -0
  96. data/lib/mongoid/persistable/pushable.rb +62 -0
  97. data/lib/mongoid/persistable/renamable.rb +35 -0
  98. data/lib/mongoid/persistable/savable.rb +52 -0
  99. data/lib/mongoid/persistable/settable.rb +33 -0
  100. data/lib/mongoid/persistable/unsettable.rb +36 -0
  101. data/lib/mongoid/persistable/updatable.rb +152 -0
  102. data/lib/mongoid/persistable/upsertable.rb +55 -0
  103. data/lib/mongoid/persistable.rb +216 -0
  104. data/lib/mongoid/positional.rb +71 -0
  105. data/lib/mongoid/query_cache.rb +247 -0
  106. data/lib/mongoid/railtie.rb +32 -45
  107. data/lib/mongoid/railties/database.rake +9 -25
  108. data/lib/mongoid/relations/accessors.rb +13 -49
  109. data/lib/mongoid/relations/auto_save.rb +15 -36
  110. data/lib/mongoid/relations/binding.rb +1 -24
  111. data/lib/mongoid/relations/bindings/embedded/in.rb +1 -1
  112. data/lib/mongoid/relations/bindings/embedded/many.rb +1 -3
  113. data/lib/mongoid/relations/bindings/referenced/in.rb +3 -8
  114. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +3 -1
  115. data/lib/mongoid/relations/builder.rb +1 -1
  116. data/lib/mongoid/relations/builders/nested_attributes/many.rb +10 -13
  117. data/lib/mongoid/relations/builders/nested_attributes/one.rb +4 -5
  118. data/lib/mongoid/relations/builders/referenced/in.rb +1 -1
  119. data/lib/mongoid/relations/builders/referenced/many.rb +1 -2
  120. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +1 -2
  121. data/lib/mongoid/relations/builders/referenced/one.rb +1 -1
  122. data/lib/mongoid/relations/builders.rb +2 -2
  123. data/lib/mongoid/relations/cascading.rb +3 -5
  124. data/lib/mongoid/relations/constraint.rb +1 -1
  125. data/lib/mongoid/relations/conversions.rb +1 -1
  126. data/lib/mongoid/relations/counter_cache.rb +39 -15
  127. data/lib/mongoid/relations/eager/base.rb +149 -0
  128. data/lib/mongoid/relations/eager/belongs_to.rb +31 -0
  129. data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +47 -0
  130. data/lib/mongoid/relations/eager/has_many.rb +38 -0
  131. data/lib/mongoid/relations/eager/has_one.rb +30 -0
  132. data/lib/mongoid/relations/eager.rb +46 -0
  133. data/lib/mongoid/relations/embedded/batchable.rb +4 -5
  134. data/lib/mongoid/relations/embedded/in.rb +4 -4
  135. data/lib/mongoid/relations/embedded/many.rb +14 -32
  136. data/lib/mongoid/relations/embedded/one.rb +1 -1
  137. data/lib/mongoid/relations/macros.rb +3 -4
  138. data/lib/mongoid/relations/many.rb +30 -31
  139. data/lib/mongoid/relations/marshalable.rb +3 -3
  140. data/lib/mongoid/relations/metadata.rb +14 -79
  141. data/lib/mongoid/relations/nested_builder.rb +2 -2
  142. data/lib/mongoid/relations/options.rb +1 -0
  143. data/lib/mongoid/relations/polymorphic.rb +0 -1
  144. data/lib/mongoid/relations/proxy.rb +21 -41
  145. data/lib/mongoid/relations/referenced/in.rb +4 -20
  146. data/lib/mongoid/relations/referenced/many.rb +19 -32
  147. data/lib/mongoid/relations/referenced/many_to_many.rb +15 -38
  148. data/lib/mongoid/relations/referenced/one.rb +6 -25
  149. data/lib/mongoid/relations/synchronization.rb +3 -3
  150. data/lib/mongoid/relations/touchable.rb +34 -1
  151. data/lib/mongoid/relations.rb +11 -25
  152. data/lib/mongoid/{reloading.rb → reloadable.rb} +6 -4
  153. data/lib/mongoid/{scoping.rb → scopable.rb} +36 -36
  154. data/lib/mongoid/selectable.rb +59 -0
  155. data/lib/mongoid/{serialization.rb → serializable.rb} +11 -2
  156. data/lib/mongoid/sessions/factory.rb +2 -0
  157. data/lib/mongoid/sessions/options.rb +180 -0
  158. data/lib/mongoid/sessions/storage_options.rb +140 -0
  159. data/lib/mongoid/sessions/thread_options.rb +19 -0
  160. data/lib/mongoid/sessions/validators/storage.rb +16 -3
  161. data/lib/mongoid/sessions.rb +37 -345
  162. data/lib/mongoid/{sharding.rb → shardable.rb} +5 -1
  163. data/lib/mongoid/{state.rb → stateful.rb} +13 -1
  164. data/lib/mongoid/support/query_counter.rb +23 -0
  165. data/lib/mongoid/tasks/database.rake +31 -0
  166. data/lib/mongoid/tasks/database.rb +107 -0
  167. data/lib/mongoid/threaded/lifecycle.rb +0 -28
  168. data/lib/mongoid/threaded.rb +0 -157
  169. data/lib/mongoid/timestamps/updated/short.rb +2 -2
  170. data/lib/mongoid/{hierarchy.rb → traversable.rb} +9 -5
  171. data/lib/mongoid/{validations → validatable}/associated.rb +4 -2
  172. data/lib/mongoid/{validations → validatable}/format.rb +1 -1
  173. data/lib/mongoid/{validations → validatable}/length.rb +1 -1
  174. data/lib/mongoid/{validations → validatable}/localizable.rb +1 -1
  175. data/lib/mongoid/{validations → validatable}/macros.rb +4 -3
  176. data/lib/mongoid/{validations → validatable}/presence.rb +1 -1
  177. data/lib/mongoid/{validations → validatable}/queryable.rb +1 -2
  178. data/lib/mongoid/{validations → validatable}/uniqueness.rb +23 -19
  179. data/lib/mongoid/{validations.rb → validatable.rb} +23 -10
  180. data/lib/mongoid/version.rb +1 -1
  181. data/lib/mongoid.rb +10 -76
  182. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +13 -24
  183. data/lib/rails/generators/mongoid/model/model_generator.rb +0 -1
  184. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +0 -3
  185. data/lib/rails/generators/mongoid_generator.rb +3 -40
  186. data/lib/rails/mongoid.rb +0 -122
  187. data/lib/support/ruby_version.rb +1 -1
  188. data/spec/app/models/account.rb +2 -6
  189. data/spec/app/models/acolyte.rb +2 -1
  190. data/spec/app/models/actor.rb +0 -1
  191. data/spec/app/models/address.rb +8 -3
  192. data/spec/app/models/animal.rb +1 -1
  193. data/spec/app/models/appointment.rb +3 -3
  194. data/spec/app/models/article.rb +1 -4
  195. data/spec/app/models/audio.rb +5 -0
  196. data/spec/app/models/author.rb +0 -2
  197. data/spec/app/models/band.rb +3 -2
  198. data/spec/app/models/bar.rb +1 -0
  199. data/spec/app/models/book.rb +1 -0
  200. data/spec/app/models/building.rb +0 -2
  201. data/spec/app/models/building_address.rb +0 -2
  202. data/spec/app/models/bus.rb +1 -1
  203. data/spec/app/models/canvas.rb +1 -1
  204. data/spec/app/models/contractor.rb +0 -2
  205. data/spec/app/models/country_code.rb +1 -1
  206. data/spec/app/models/definition.rb +2 -2
  207. data/spec/app/models/dog.rb +1 -1
  208. data/spec/app/models/draft.rb +9 -0
  209. data/spec/app/models/dragon.rb +4 -0
  210. data/spec/app/models/drug.rb +1 -3
  211. data/spec/app/models/dungeon.rb +4 -0
  212. data/spec/app/models/edit.rb +5 -0
  213. data/spec/app/models/even.rb +7 -0
  214. data/spec/app/models/event.rb +1 -1
  215. data/spec/app/models/filesystem.rb +1 -0
  216. data/spec/app/models/fish.rb +0 -1
  217. data/spec/app/models/fruits.rb +6 -0
  218. data/spec/app/models/game.rb +0 -2
  219. data/spec/app/models/house.rb +1 -3
  220. data/spec/app/models/item.rb +1 -5
  221. data/spec/app/models/jar.rb +1 -1
  222. data/spec/app/models/label.rb +4 -4
  223. data/spec/app/models/line_item.rb +1 -1
  224. data/spec/app/models/login.rb +1 -1
  225. data/spec/app/models/message.rb +8 -0
  226. data/spec/app/models/movie.rb +1 -0
  227. data/spec/app/models/name.rb +3 -3
  228. data/spec/app/models/note.rb +3 -1
  229. data/spec/app/models/odd.rb +7 -0
  230. data/spec/app/models/oscar.rb +1 -1
  231. data/spec/app/models/parent_doc.rb +1 -1
  232. data/spec/app/models/person.rb +16 -10
  233. data/spec/app/models/phone.rb +1 -3
  234. data/spec/app/models/player.rb +3 -3
  235. data/spec/app/models/post.rb +5 -3
  236. data/spec/app/models/preference.rb +1 -1
  237. data/spec/app/models/quiz.rb +0 -3
  238. data/spec/app/models/record.rb +10 -5
  239. data/spec/app/models/registry.rb +1 -1
  240. data/spec/app/models/server.rb +1 -1
  241. data/spec/app/models/service.rb +3 -3
  242. data/spec/app/models/sound.rb +5 -0
  243. data/spec/app/models/symptom.rb +1 -1
  244. data/spec/app/models/template.rb +1 -1
  245. data/spec/app/models/title.rb +0 -1
  246. data/spec/app/models/track.rb +5 -5
  247. data/spec/app/models/tree.rb +3 -3
  248. data/spec/app/models/video.rb +1 -5
  249. data/spec/app/models/wiki_page.rb +2 -5
  250. data/spec/app/models/word.rb +3 -0
  251. data/spec/app/models/word_origin.rb +1 -1
  252. data/spec/config/mongoid.yml +7 -8
  253. data/spec/helpers.rb +18 -0
  254. data/spec/mongoid/atomic/modifiers_spec.rb +22 -22
  255. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +8 -49
  256. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +7 -49
  257. data/spec/mongoid/atomic/paths/root_spec.rb +3 -61
  258. data/spec/mongoid/atomic/paths_spec.rb +19 -19
  259. data/spec/mongoid/atomic_spec.rb +19 -19
  260. data/spec/mongoid/{nested_attributes_spec.rb → attributes/nested_spec.rb} +335 -448
  261. data/spec/mongoid/attributes/readonly_spec.rb +58 -18
  262. data/spec/mongoid/attributes_spec.rb +315 -436
  263. data/spec/mongoid/{dirty_spec.rb → changeable_spec.rb} +203 -153
  264. data/spec/mongoid/{components_spec.rb → composable_spec.rb} +3 -3
  265. data/spec/mongoid/config/environment_spec.rb +3 -3
  266. data/spec/mongoid/config/options_spec.rb +6 -6
  267. data/spec/mongoid/config_spec.rb +24 -48
  268. data/spec/mongoid/contextual/aggregable/memory_spec.rb +12 -12
  269. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +78 -38
  270. data/spec/mongoid/contextual/atomic_spec.rb +68 -58
  271. data/spec/mongoid/contextual/find_and_modify_spec.rb +14 -14
  272. data/spec/mongoid/contextual/geo_near_spec.rb +22 -22
  273. data/spec/mongoid/contextual/map_reduce_spec.rb +27 -27
  274. data/spec/mongoid/contextual/memory_spec.rb +151 -94
  275. data/spec/mongoid/contextual/mongo_spec.rb +238 -150
  276. data/spec/mongoid/contextual/none_spec.rb +127 -0
  277. data/spec/mongoid/contextual/text_search_spec.rb +209 -0
  278. data/spec/mongoid/copyable_spec.rb +56 -68
  279. data/spec/mongoid/criteria/findable_spec.rb +991 -0
  280. data/spec/mongoid/{criterion/inspection_spec.rb → criteria/inspectable_spec.rb} +5 -5
  281. data/spec/mongoid/{criterion → criteria}/marshalable_spec.rb +2 -2
  282. data/spec/mongoid/criteria/modifiable_spec.rb +1255 -0
  283. data/spec/mongoid/{criterion/scoping_spec.rb → criteria/scopable_spec.rb} +37 -37
  284. data/spec/mongoid/criteria_spec.rb +578 -2295
  285. data/spec/mongoid/document_spec.rb +166 -120
  286. data/spec/mongoid/equality_spec.rb +22 -22
  287. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +3 -3
  288. data/spec/mongoid/errors/callback_spec.rb +3 -3
  289. data/spec/mongoid/errors/delete_restriction_spec.rb +3 -3
  290. data/spec/mongoid/errors/document_not_destroyed_spec.rb +33 -0
  291. data/spec/mongoid/errors/document_not_found_spec.rb +11 -11
  292. data/spec/mongoid/errors/eager_load_spec.rb +3 -3
  293. data/spec/mongoid/errors/invalid_collection_spec.rb +3 -3
  294. data/spec/mongoid/errors/invalid_config_option_spec.rb +3 -3
  295. data/spec/mongoid/errors/invalid_field_option_spec.rb +3 -3
  296. data/spec/mongoid/errors/invalid_field_spec.rb +3 -3
  297. data/spec/mongoid/errors/invalid_find_spec.rb +3 -3
  298. data/spec/mongoid/errors/invalid_includes_spec.rb +3 -3
  299. data/spec/mongoid/errors/invalid_index_spec.rb +3 -3
  300. data/spec/mongoid/errors/invalid_options_spec.rb +3 -3
  301. data/spec/mongoid/errors/invalid_path_spec.rb +3 -3
  302. data/spec/mongoid/errors/invalid_scope_spec.rb +5 -5
  303. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -3
  304. data/spec/mongoid/errors/invalid_storage_options_spec.rb +3 -3
  305. data/spec/mongoid/errors/invalid_time_spec.rb +3 -3
  306. data/spec/mongoid/errors/inverse_not_found_spec.rb +3 -3
  307. data/spec/mongoid/errors/mixed_relations_spec.rb +3 -3
  308. data/spec/mongoid/errors/mixed_session_configuration_spec.rb +3 -3
  309. data/spec/mongoid/errors/mongoid_error_spec.rb +8 -8
  310. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +3 -3
  311. data/spec/mongoid/errors/no_environment_spec.rb +3 -3
  312. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +3 -3
  313. data/spec/mongoid/errors/no_metadata_spec.rb +3 -3
  314. data/spec/mongoid/errors/no_parent_spec.rb +3 -3
  315. data/spec/mongoid/errors/no_session_config_spec.rb +3 -3
  316. data/spec/mongoid/errors/no_session_database_spec.rb +3 -3
  317. data/spec/mongoid/errors/no_session_hosts_spec.rb +3 -3
  318. data/spec/mongoid/errors/no_sessions_config_spec.rb +3 -3
  319. data/spec/mongoid/errors/readonly_attribute_spec.rb +3 -3
  320. data/spec/mongoid/errors/readonly_document_spec.rb +29 -0
  321. data/spec/mongoid/errors/scope_overwrite_spec.rb +3 -3
  322. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +3 -3
  323. data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -5
  324. data/spec/mongoid/errors/unsaved_document_spec.rb +3 -3
  325. data/spec/mongoid/errors/unsupported_javascript_spec.rb +3 -3
  326. data/spec/mongoid/errors/validations_spec.rb +7 -7
  327. data/spec/mongoid/extensions/array_spec.rb +61 -61
  328. data/spec/mongoid/extensions/big_decimal_spec.rb +11 -11
  329. data/spec/mongoid/extensions/binary_spec.rb +12 -12
  330. data/spec/mongoid/extensions/boolean_spec.rb +18 -18
  331. data/spec/mongoid/extensions/date_spec.rb +13 -13
  332. data/spec/mongoid/extensions/date_time_spec.rb +8 -8
  333. data/spec/mongoid/extensions/false_class_spec.rb +5 -5
  334. data/spec/mongoid/extensions/float_spec.rb +29 -15
  335. data/spec/mongoid/extensions/hash_spec.rb +29 -29
  336. data/spec/mongoid/extensions/integer_spec.rb +15 -15
  337. data/spec/mongoid/extensions/module_spec.rb +2 -2
  338. data/spec/mongoid/extensions/nil_class_spec.rb +1 -1
  339. data/spec/mongoid/extensions/object_id_spec.rb +134 -134
  340. data/spec/mongoid/extensions/object_spec.rb +26 -26
  341. data/spec/mongoid/extensions/range_spec.rb +61 -12
  342. data/spec/mongoid/extensions/regexp_spec.rb +4 -4
  343. data/spec/mongoid/extensions/set_spec.rb +4 -4
  344. data/spec/mongoid/extensions/string_spec.rb +35 -46
  345. data/spec/mongoid/extensions/symbol_spec.rb +9 -9
  346. data/spec/mongoid/extensions/time_spec.rb +49 -49
  347. data/spec/mongoid/extensions/time_with_zone_spec.rb +34 -34
  348. data/spec/mongoid/extensions/true_class_spec.rb +5 -5
  349. data/spec/mongoid/extensions_spec.rb +15 -0
  350. data/spec/mongoid/factory_spec.rb +15 -15
  351. data/spec/mongoid/fields/foreign_key_spec.rb +73 -66
  352. data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +15 -15
  353. data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +22 -22
  354. data/spec/mongoid/fields/localized_spec.rb +38 -23
  355. data/spec/mongoid/fields/standard_spec.rb +12 -12
  356. data/spec/mongoid/fields_spec.rb +263 -217
  357. data/spec/mongoid/{finders_spec.rb → findable_spec.rb} +127 -27
  358. data/spec/mongoid/indexable/specification_spec.rb +102 -0
  359. data/spec/mongoid/{indexes_spec.rb → indexable_spec.rb} +171 -51
  360. data/spec/mongoid/{inspection_spec.rb → inspectable_spec.rb} +6 -14
  361. data/spec/mongoid/{callbacks_spec.rb → interceptable_spec.rb} +117 -116
  362. data/spec/mongoid/log_subscriber_spec.rb +75 -0
  363. data/spec/mongoid/loggable_spec.rb +1 -1
  364. data/spec/mongoid/{matchers → matchable}/all_spec.rb +4 -4
  365. data/spec/mongoid/{matchers → matchable}/and_spec.rb +11 -11
  366. data/spec/mongoid/{matchers → matchable}/default_spec.rb +15 -15
  367. data/spec/mongoid/{matchers → matchable}/exists_spec.rb +5 -5
  368. data/spec/mongoid/{matchers → matchable}/gt_spec.rb +9 -8
  369. data/spec/mongoid/{matchers → matchable}/gte_spec.rb +7 -7
  370. data/spec/mongoid/matchable/in_spec.rb +49 -0
  371. data/spec/mongoid/{matchers → matchable}/lt_spec.rb +7 -7
  372. data/spec/mongoid/{matchers → matchable}/lte_spec.rb +7 -7
  373. data/spec/mongoid/matchable/ne_spec.rb +46 -0
  374. data/spec/mongoid/matchable/nin_spec.rb +48 -0
  375. data/spec/mongoid/{matchers → matchable}/or_spec.rb +6 -6
  376. data/spec/mongoid/{matchers → matchable}/size_spec.rb +3 -3
  377. data/spec/mongoid/{matchers_spec.rb → matchable_spec.rb} +41 -41
  378. data/spec/mongoid/persistable/creatable_spec.rb +512 -0
  379. data/spec/mongoid/persistable/deletable_spec.rb +218 -0
  380. data/spec/mongoid/persistable/destroyable_spec.rb +192 -0
  381. data/spec/mongoid/persistable/incrementable_spec.rb +173 -0
  382. data/spec/mongoid/persistable/logical_spec.rb +143 -0
  383. data/spec/mongoid/persistable/poppable_spec.rb +115 -0
  384. data/spec/mongoid/persistable/pullable_spec.rb +228 -0
  385. data/spec/mongoid/persistable/pushable_spec.rb +258 -0
  386. data/spec/mongoid/persistable/renamable_spec.rb +135 -0
  387. data/spec/mongoid/persistable/savable_spec.rb +461 -0
  388. data/spec/mongoid/persistable/settable_spec.rb +139 -0
  389. data/spec/mongoid/persistable/unsettable_spec.rb +155 -0
  390. data/spec/mongoid/persistable/updatable_spec.rb +558 -0
  391. data/spec/mongoid/persistable/upsertable_spec.rb +106 -0
  392. data/spec/mongoid/persistable_spec.rb +206 -0
  393. data/spec/mongoid/{atomic/positionable_spec.rb → positional_spec.rb} +9 -9
  394. data/spec/mongoid/query_cache_spec.rb +231 -0
  395. data/spec/mongoid/railties/document_spec.rb +2 -2
  396. data/spec/mongoid/relations/accessors_spec.rb +53 -145
  397. data/spec/mongoid/relations/auto_save_spec.rb +37 -17
  398. data/spec/mongoid/relations/bindings/embedded/in_spec.rb +12 -12
  399. data/spec/mongoid/relations/bindings/embedded/many_spec.rb +3 -3
  400. data/spec/mongoid/relations/bindings/embedded/one_spec.rb +5 -5
  401. data/spec/mongoid/relations/bindings/referenced/in_spec.rb +26 -26
  402. data/spec/mongoid/relations/bindings/referenced/many_spec.rb +10 -10
  403. data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +19 -19
  404. data/spec/mongoid/relations/bindings/referenced/one_spec.rb +12 -12
  405. data/spec/mongoid/relations/builders/embedded/in_spec.rb +4 -4
  406. data/spec/mongoid/relations/builders/embedded/many_spec.rb +18 -18
  407. data/spec/mongoid/relations/builders/embedded/one_spec.rb +11 -11
  408. data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +12 -13
  409. data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +14 -14
  410. data/spec/mongoid/relations/builders/referenced/in_spec.rb +24 -35
  411. data/spec/mongoid/relations/builders/referenced/many_spec.rb +15 -15
  412. data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +18 -18
  413. data/spec/mongoid/relations/builders/referenced/one_spec.rb +12 -25
  414. data/spec/mongoid/relations/builders_spec.rb +21 -21
  415. data/spec/mongoid/relations/cascading/delete_spec.rb +9 -9
  416. data/spec/mongoid/relations/cascading/destroy_spec.rb +6 -6
  417. data/spec/mongoid/relations/cascading/nullify_spec.rb +4 -4
  418. data/spec/mongoid/relations/cascading/restrict_spec.rb +7 -7
  419. data/spec/mongoid/relations/cascading_spec.rb +16 -16
  420. data/spec/mongoid/relations/constraint_spec.rb +8 -7
  421. data/spec/mongoid/relations/conversions_spec.rb +16 -14
  422. data/spec/mongoid/relations/counter_cache_spec.rb +85 -0
  423. data/spec/mongoid/relations/cyclic_spec.rb +18 -18
  424. data/spec/mongoid/relations/eager/belongs_to_spec.rb +154 -0
  425. data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +117 -0
  426. data/spec/mongoid/relations/eager/has_many_spec.rb +207 -0
  427. data/spec/mongoid/relations/eager/has_one_spec.rb +163 -0
  428. data/spec/mongoid/relations/eager_spec.rb +228 -0
  429. data/spec/mongoid/relations/embedded/dirty_spec.rb +8 -8
  430. data/spec/mongoid/relations/embedded/in_spec.rb +56 -57
  431. data/spec/mongoid/relations/embedded/many_spec.rb +393 -372
  432. data/spec/mongoid/relations/embedded/one_spec.rb +108 -141
  433. data/spec/mongoid/relations/macros_spec.rb +108 -102
  434. data/spec/mongoid/relations/metadata_spec.rb +180 -255
  435. data/spec/mongoid/relations/options_spec.rb +1 -1
  436. data/spec/mongoid/relations/polymorphic_spec.rb +13 -17
  437. data/spec/mongoid/relations/proxy_spec.rb +2 -2
  438. data/spec/mongoid/relations/referenced/in_spec.rb +128 -303
  439. data/spec/mongoid/relations/referenced/many_spec.rb +434 -527
  440. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +352 -424
  441. data/spec/mongoid/relations/referenced/one_spec.rb +149 -264
  442. data/spec/mongoid/relations/reflections_spec.rb +6 -6
  443. data/spec/mongoid/relations/synchronization_spec.rb +46 -50
  444. data/spec/mongoid/relations/targets/enumerable_spec.rb +118 -118
  445. data/spec/mongoid/relations/touchable_spec.rb +333 -0
  446. data/spec/mongoid/relations_spec.rb +16 -15
  447. data/spec/mongoid/{reloading_spec.rb → reloadable_spec.rb} +20 -60
  448. data/spec/mongoid/{scoping_spec.rb → scopable_spec.rb} +89 -164
  449. data/spec/mongoid/selectable_spec.rb +134 -0
  450. data/spec/mongoid/{serialization_spec.rb → serializable_spec.rb} +129 -82
  451. data/spec/mongoid/sessions/factory_spec.rb +49 -28
  452. data/spec/mongoid/sessions/mongo_uri_spec.rb +7 -7
  453. data/spec/mongoid/sessions/options_spec.rb +107 -0
  454. data/spec/mongoid/sessions_spec.rb +289 -178
  455. data/spec/mongoid/{sharding_spec.rb → shardable_spec.rb} +8 -8
  456. data/spec/mongoid/{state_spec.rb → stateful_spec.rb} +36 -11
  457. data/spec/mongoid/tasks/database_rake_spec.rb +285 -0
  458. data/spec/mongoid/tasks/database_spec.rb +160 -0
  459. data/spec/mongoid/threaded_spec.rb +17 -70
  460. data/spec/mongoid/timestamps/created/short_spec.rb +6 -6
  461. data/spec/mongoid/timestamps/created_spec.rb +5 -5
  462. data/spec/mongoid/timestamps/timeless_spec.rb +6 -6
  463. data/spec/mongoid/timestamps/updated/short_spec.rb +11 -11
  464. data/spec/mongoid/timestamps/updated_spec.rb +9 -13
  465. data/spec/mongoid/timestamps_spec.rb +9 -13
  466. data/spec/mongoid/{hierarchy_spec.rb → traversable_spec.rb} +19 -19
  467. data/spec/mongoid/{validations → validatable}/associated_spec.rb +45 -22
  468. data/spec/mongoid/{validations → validatable}/format_spec.rb +6 -6
  469. data/spec/mongoid/{validations → validatable}/length_spec.rb +14 -14
  470. data/spec/mongoid/{validations → validatable}/numericality_spec.rb +1 -1
  471. data/spec/mongoid/{validations → validatable}/presence_spec.rb +37 -44
  472. data/spec/mongoid/{validations → validatable}/uniqueness_spec.rb +184 -192
  473. data/spec/mongoid/{validations_spec.rb → validatable_spec.rb} +28 -28
  474. data/spec/mongoid_spec.rb +8 -8
  475. data/spec/rails/mongoid_spec.rb +19 -335
  476. data/spec/spec_helper.rb +29 -13
  477. metadata +296 -283
  478. data/lib/mongoid/atomic/positionable.rb +0 -73
  479. data/lib/mongoid/components.rb +0 -92
  480. data/lib/mongoid/config/inflections.rb +0 -6
  481. data/lib/mongoid/contextual/eager.rb +0 -158
  482. data/lib/mongoid/errors/versioning_not_on_root.rb +0 -23
  483. data/lib/mongoid/identity_map.rb +0 -163
  484. data/lib/mongoid/json.rb +0 -16
  485. data/lib/mongoid/matchers/strategies.rb +0 -97
  486. data/lib/mongoid/matchers.rb +0 -32
  487. data/lib/mongoid/multi_parameter_attributes.rb +0 -105
  488. data/lib/mongoid/nested_attributes.rb +0 -78
  489. data/lib/mongoid/observer.rb +0 -192
  490. data/lib/mongoid/paranoia.rb +0 -136
  491. data/lib/mongoid/persistence/atomic/add_to_set.rb +0 -47
  492. data/lib/mongoid/persistence/atomic/bit.rb +0 -35
  493. data/lib/mongoid/persistence/atomic/inc.rb +0 -45
  494. data/lib/mongoid/persistence/atomic/operation.rb +0 -154
  495. data/lib/mongoid/persistence/atomic/pop.rb +0 -32
  496. data/lib/mongoid/persistence/atomic/pull.rb +0 -32
  497. data/lib/mongoid/persistence/atomic/pull_all.rb +0 -32
  498. data/lib/mongoid/persistence/atomic/push.rb +0 -25
  499. data/lib/mongoid/persistence/atomic/push_all.rb +0 -25
  500. data/lib/mongoid/persistence/atomic/rename.rb +0 -30
  501. data/lib/mongoid/persistence/atomic/sets.rb +0 -28
  502. data/lib/mongoid/persistence/atomic/unset.rb +0 -27
  503. data/lib/mongoid/persistence/atomic.rb +0 -231
  504. data/lib/mongoid/persistence/deletion.rb +0 -31
  505. data/lib/mongoid/persistence/insertion.rb +0 -38
  506. data/lib/mongoid/persistence/modification.rb +0 -35
  507. data/lib/mongoid/persistence/operations/embedded/insert.rb +0 -46
  508. data/lib/mongoid/persistence/operations/embedded/remove.rb +0 -43
  509. data/lib/mongoid/persistence/operations/insert.rb +0 -34
  510. data/lib/mongoid/persistence/operations/remove.rb +0 -33
  511. data/lib/mongoid/persistence/operations/update.rb +0 -59
  512. data/lib/mongoid/persistence/operations/upsert.rb +0 -28
  513. data/lib/mongoid/persistence/operations.rb +0 -214
  514. data/lib/mongoid/persistence/upsertion.rb +0 -31
  515. data/lib/mongoid/persistence.rb +0 -357
  516. data/lib/mongoid/unit_of_work.rb +0 -61
  517. data/lib/mongoid/versioning.rb +0 -217
  518. data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
  519. data/lib/rack/mongoid.rb +0 -2
  520. data/lib/rails/generators/mongoid/observer/observer_generator.rb +0 -17
  521. data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +0 -4
  522. data/spec/app/models/actor_observer.rb +0 -15
  523. data/spec/app/models/callback_recorder.rb +0 -25
  524. data/spec/app/models/paranoid_phone.rb +0 -25
  525. data/spec/app/models/paranoid_post.rb +0 -36
  526. data/spec/app/models/phone_observer.rb +0 -6
  527. data/spec/mongoid/attributes/processing_spec.rb +0 -149
  528. data/spec/mongoid/criterion/destructive_spec.rb +0 -101
  529. data/spec/mongoid/criterion/modifiable_spec.rb +0 -409
  530. data/spec/mongoid/criterion/modification_spec.rb +0 -402
  531. data/spec/mongoid/errors/versioning_not_on_root_spec.rb +0 -29
  532. data/spec/mongoid/identity_map_spec.rb +0 -564
  533. data/spec/mongoid/json_spec.rb +0 -33
  534. data/spec/mongoid/matchers/in_spec.rb +0 -25
  535. data/spec/mongoid/matchers/ne_spec.rb +0 -25
  536. data/spec/mongoid/matchers/nin_spec.rb +0 -25
  537. data/spec/mongoid/multi_parameter_attributes_spec.rb +0 -128
  538. data/spec/mongoid/observer_spec.rb +0 -290
  539. data/spec/mongoid/paranoia_spec.rb +0 -759
  540. data/spec/mongoid/persistence/atomic/add_to_set_spec.rb +0 -262
  541. data/spec/mongoid/persistence/atomic/bit_spec.rb +0 -88
  542. data/spec/mongoid/persistence/atomic/inc_spec.rb +0 -133
  543. data/spec/mongoid/persistence/atomic/pop_spec.rb +0 -111
  544. data/spec/mongoid/persistence/atomic/pull_all_spec.rb +0 -77
  545. data/spec/mongoid/persistence/atomic/pull_spec.rb +0 -80
  546. data/spec/mongoid/persistence/atomic/push_all_spec.rb +0 -77
  547. data/spec/mongoid/persistence/atomic/push_spec.rb +0 -77
  548. data/spec/mongoid/persistence/atomic/rename_spec.rb +0 -42
  549. data/spec/mongoid/persistence/atomic/sets_spec.rb +0 -154
  550. data/spec/mongoid/persistence/atomic/unset_spec.rb +0 -65
  551. data/spec/mongoid/persistence/atomic_spec.rb +0 -216
  552. data/spec/mongoid/persistence/operations/embedded/insert_spec.rb +0 -191
  553. data/spec/mongoid/persistence/operations/embedded/remove_spec.rb +0 -8
  554. data/spec/mongoid/persistence/operations/insert_spec.rb +0 -149
  555. data/spec/mongoid/persistence/operations/remove_spec.rb +0 -113
  556. data/spec/mongoid/persistence/operations/update_spec.rb +0 -141
  557. data/spec/mongoid/persistence/operations/upsert_spec.rb +0 -59
  558. data/spec/mongoid/persistence/operations_spec.rb +0 -313
  559. data/spec/mongoid/persistence_spec.rb +0 -2279
  560. data/spec/mongoid/unit_of_work_spec.rb +0 -196
  561. data/spec/mongoid/versioning_spec.rb +0 -540
  562. 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" }])
1666
1684
  end
1667
1685
 
1668
- it "sets the attributes for the provided role" do
1669
- drug.name.should eq("Oxycontin")
1686
+ it "creates multiple documents" do
1687
+ expect(posts.size).to eq(2)
1670
1688
  end
1671
1689
 
1672
- it "does not set the attributes for other roles" do
1673
- drug.generic.should be_nil
1690
+ it "sets the first attributes" do
1691
+ expect(posts.first.text).to eq("Test1")
1692
+ end
1693
+
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,15 @@ 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)
2671
2558
  end
2672
2559
  end
2673
2560
  end
@@ -2692,7 +2579,7 @@ describe Mongoid::Relations::Referenced::Many do
2692
2579
  end
2693
2580
 
2694
2581
  it "returns the document" do
2695
- found.should eq(post)
2582
+ expect(found).to eq(post)
2696
2583
  end
2697
2584
  end
2698
2585
 
@@ -2705,15 +2592,15 @@ describe Mongoid::Relations::Referenced::Many do
2705
2592
  end
2706
2593
 
2707
2594
  it "sets the new document attributes" do
2708
- found.title.should eq("Test")
2595
+ expect(found.title).to eq("Test")
2709
2596
  end
2710
2597
 
2711
2598
  it "returns a non persisted document" do
2712
- found.should_not be_persisted
2599
+ expect(found).to_not be_persisted
2713
2600
  end
2714
2601
 
2715
2602
  it "calls the passed block" do
2716
- found.content.should eq("The Content")
2603
+ expect(found.content).to eq("The Content")
2717
2604
  end
2718
2605
  end
2719
2606
  end
@@ -2735,7 +2622,7 @@ describe Mongoid::Relations::Referenced::Many do
2735
2622
  end
2736
2623
 
2737
2624
  it "returns the document" do
2738
- found.should eq(rating)
2625
+ expect(found).to eq(rating)
2739
2626
  end
2740
2627
  end
2741
2628
 
@@ -2746,11 +2633,11 @@ describe Mongoid::Relations::Referenced::Many do
2746
2633
  end
2747
2634
 
2748
2635
  it "sets the new document attributes" do
2749
- found.value.should eq(3)
2636
+ expect(found.value).to eq(3)
2750
2637
  end
2751
2638
 
2752
2639
  it "returns a non persisted document" do
2753
- found.should_not be_persisted
2640
+ expect(found).to_not be_persisted
2754
2641
  end
2755
2642
  end
2756
2643
  end
@@ -2759,7 +2646,7 @@ describe Mongoid::Relations::Referenced::Many do
2759
2646
  describe ".foreign_key_suffix" do
2760
2647
 
2761
2648
  it "returns _id" do
2762
- described_class.foreign_key_suffix.should eq("_id")
2649
+ expect(described_class.foreign_key_suffix).to eq("_id")
2763
2650
  end
2764
2651
  end
2765
2652
 
@@ -2785,7 +2672,7 @@ describe Mongoid::Relations::Referenced::Many do
2785
2672
  end
2786
2673
 
2787
2674
  it "does not raise an error" do
2788
- post.roles.should be_empty
2675
+ expect(post.roles).to be_empty
2789
2676
  end
2790
2677
  end
2791
2678
  end
@@ -2793,7 +2680,7 @@ describe Mongoid::Relations::Referenced::Many do
2793
2680
  describe ".macro" do
2794
2681
 
2795
2682
  it "returns has_many" do
2796
- described_class.macro.should eq(:has_many)
2683
+ expect(described_class.macro).to eq(:has_many)
2797
2684
  end
2798
2685
  end
2799
2686
 
@@ -2822,7 +2709,7 @@ describe Mongoid::Relations::Referenced::Many do
2822
2709
  end
2823
2710
 
2824
2711
  it "returns the document with the max value of the supplied field" do
2825
- max.should eq(post_two)
2712
+ expect(max).to eq(post_two)
2826
2713
  end
2827
2714
  end
2828
2715
 
@@ -2849,7 +2736,7 @@ describe Mongoid::Relations::Referenced::Many do
2849
2736
  end
2850
2737
 
2851
2738
  it "returns the document with the max value of the supplied field" do
2852
- max.should eq(post_two)
2739
+ expect(max).to eq(post_two)
2853
2740
  end
2854
2741
  end
2855
2742
 
@@ -2874,7 +2761,7 @@ describe Mongoid::Relations::Referenced::Many do
2874
2761
  end
2875
2762
 
2876
2763
  it "applies the criteria to the documents" do
2877
- posts.should eq([ post_one ])
2764
+ expect(posts).to eq([ post_one ])
2878
2765
  end
2879
2766
  end
2880
2767
 
@@ -2885,7 +2772,7 @@ describe Mongoid::Relations::Referenced::Many do
2885
2772
  end
2886
2773
 
2887
2774
  it "applies the criteria to the documents" do
2888
- posts.should eq([ post_one ])
2775
+ expect(posts).to eq([ post_one ])
2889
2776
  end
2890
2777
  end
2891
2778
 
@@ -2896,7 +2783,7 @@ describe Mongoid::Relations::Referenced::Many do
2896
2783
  end
2897
2784
 
2898
2785
  it "applies the criteria to the documents" do
2899
- posts.should eq([ post_one ])
2786
+ expect(posts).to eq([ post_one ])
2900
2787
  end
2901
2788
  end
2902
2789
 
@@ -2904,8 +2791,13 @@ describe Mongoid::Relations::Referenced::Many do
2904
2791
 
2905
2792
  describe "#distinct" do
2906
2793
 
2794
+ let(:values) do
2795
+ person.posts.distinct(:title)
2796
+ end
2797
+
2907
2798
  it "returns the distinct values for the fields" do
2908
- person.posts.distinct(:title).should =~ [ "First", "Second"]
2799
+ expect(values).to include("First")
2800
+ expect(values).to include("Second")
2909
2801
  end
2910
2802
  end
2911
2803
  end
@@ -2936,7 +2828,7 @@ describe Mongoid::Relations::Referenced::Many do
2936
2828
  end
2937
2829
 
2938
2830
  it "returns the min value of the supplied field" do
2939
- min.should eq(post_one)
2831
+ expect(min).to eq(post_one)
2940
2832
  end
2941
2833
  end
2942
2834
 
@@ -2963,7 +2855,7 @@ describe Mongoid::Relations::Referenced::Many do
2963
2855
  end
2964
2856
 
2965
2857
  it "returns the min value of the supplied field" do
2966
- min.should eq(post_one)
2858
+ expect(min).to eq(post_one)
2967
2859
  end
2968
2860
  end
2969
2861
 
@@ -2992,16 +2884,16 @@ describe Mongoid::Relations::Referenced::Many do
2992
2884
  end
2993
2885
 
2994
2886
  it "loads the targets before nullifying" do
2995
- from_db.posts.should be_empty
2887
+ expect(from_db.posts).to be_empty
2996
2888
  end
2997
2889
 
2998
2890
  it "persists the base nullifications" do
2999
- Person.first.posts.should be_empty
2891
+ expect(Person.first.posts).to be_empty
3000
2892
  end
3001
2893
 
3002
2894
  it "persists the inverse nullifications" do
3003
2895
  Post.all.each do |post|
3004
- post.person.should be_nil
2896
+ expect(post.person).to be_nil
3005
2897
  end
3006
2898
  end
3007
2899
  end
@@ -3026,18 +2918,18 @@ describe Mongoid::Relations::Referenced::Many do
3026
2918
 
3027
2919
  it "removes all the foreign keys from the target" do
3028
2920
  [ post_one, post_two ].each do |post|
3029
- post.person_id.should be_nil
2921
+ expect(post.person_id).to be_nil
3030
2922
  end
3031
2923
  end
3032
2924
 
3033
2925
  it "removes all the references from the target" do
3034
2926
  [ post_one, post_two ].each do |post|
3035
- post.person.should be_nil
2927
+ expect(post.person).to be_nil
3036
2928
  end
3037
2929
  end
3038
2930
 
3039
2931
  it "saves the documents" do
3040
- post_one.reload.person.should be_nil
2932
+ expect(post_one.reload.person).to be_nil
3041
2933
  end
3042
2934
 
3043
2935
  context "when adding a nullified document back to the relation" do
@@ -3047,7 +2939,7 @@ describe Mongoid::Relations::Referenced::Many do
3047
2939
  end
3048
2940
 
3049
2941
  it "persists the relation" do
3050
- person.posts(true).should eq([ post_one ])
2942
+ expect(person.posts(true)).to eq([ post_one ])
3051
2943
  end
3052
2944
  end
3053
2945
  end
@@ -3072,13 +2964,13 @@ describe Mongoid::Relations::Referenced::Many do
3072
2964
 
3073
2965
  it "removes all the foreign keys from the target" do
3074
2966
  [ rating_one, rating_two ].each do |rating|
3075
- rating.ratable_id.should be_nil
2967
+ expect(rating.ratable_id).to be_nil
3076
2968
  end
3077
2969
  end
3078
2970
 
3079
2971
  it "removes all the references from the target" do
3080
2972
  [ rating_one, rating_two ].each do |rating|
3081
- rating.ratable.should be_nil
2973
+ expect(rating.ratable).to be_nil
3082
2974
  end
3083
2975
  end
3084
2976
  end
@@ -3099,7 +2991,7 @@ describe Mongoid::Relations::Referenced::Many do
3099
2991
  context "when checking #{method}" do
3100
2992
 
3101
2993
  it "returns true" do
3102
- posts.respond_to?(method).should be_true
2994
+ expect(posts.respond_to?(method)).to be true
3103
2995
  end
3104
2996
  end
3105
2997
  end
@@ -3109,7 +3001,7 @@ describe Mongoid::Relations::Referenced::Many do
3109
3001
  context "when checking #{method}" do
3110
3002
 
3111
3003
  it "returns true" do
3112
- posts.respond_to?(method).should be_true
3004
+ expect(posts.respond_to?(method)).to be true
3113
3005
  end
3114
3006
  end
3115
3007
  end
@@ -3119,7 +3011,7 @@ describe Mongoid::Relations::Referenced::Many do
3119
3011
  context "when checking #{method}" do
3120
3012
 
3121
3013
  it "returns true" do
3122
- posts.respond_to?(method).should be_true
3014
+ expect(posts.respond_to?(method)).to be true
3123
3015
  end
3124
3016
  end
3125
3017
  end
@@ -3128,7 +3020,7 @@ describe Mongoid::Relations::Referenced::Many do
3128
3020
  describe ".stores_foreign_key?" do
3129
3021
 
3130
3022
  it "returns false" do
3131
- described_class.stores_foreign_key?.should be_false
3023
+ expect(described_class.stores_foreign_key?).to be false
3132
3024
  end
3133
3025
  end
3134
3026
 
@@ -3143,11 +3035,11 @@ describe Mongoid::Relations::Referenced::Many do
3143
3035
  end
3144
3036
 
3145
3037
  it "returns the relation criteria" do
3146
- scoped.should be_a(Mongoid::Criteria)
3038
+ expect(scoped).to be_a(Mongoid::Criteria)
3147
3039
  end
3148
3040
 
3149
3041
  it "returns with an empty selector" do
3150
- scoped.selector.should eq({ "person_id" => person.id })
3042
+ expect(scoped.selector).to eq({ "person_id" => person.id })
3151
3043
  end
3152
3044
  end
3153
3045
 
@@ -3166,7 +3058,7 @@ describe Mongoid::Relations::Referenced::Many do
3166
3058
  end
3167
3059
 
3168
3060
  it "returns 1" do
3169
- movie.ratings.send(method).should eq(1)
3061
+ expect(movie.ratings.send(method)).to eq(1)
3170
3062
  end
3171
3063
  end
3172
3064
 
@@ -3178,7 +3070,7 @@ describe Mongoid::Relations::Referenced::Many do
3178
3070
  end
3179
3071
 
3180
3072
  it "returns the total number of documents" do
3181
- movie.ratings.send(method).should eq(2)
3073
+ expect(movie.ratings.send(method)).to eq(2)
3182
3074
  end
3183
3075
  end
3184
3076
  end
@@ -3205,7 +3097,7 @@ describe Mongoid::Relations::Referenced::Many do
3205
3097
  end
3206
3098
 
3207
3099
  it "returns only the associated documents" do
3208
- unscoped.should eq([ post_one ])
3100
+ expect(unscoped).to eq([ post_one ])
3209
3101
  end
3210
3102
  end
3211
3103
 
@@ -3228,11 +3120,11 @@ describe Mongoid::Relations::Referenced::Many do
3228
3120
  end
3229
3121
 
3230
3122
  it "only returns associated documents" do
3231
- unscoped.should eq([ acolyte_one ])
3123
+ expect(unscoped).to eq([ acolyte_one ])
3232
3124
  end
3233
3125
 
3234
3126
  it "removes the default scoping options" do
3235
- unscoped.options.should eq({})
3127
+ expect(unscoped.options).to eq({})
3236
3128
  end
3237
3129
  end
3238
3130
  end
@@ -3240,7 +3132,7 @@ describe Mongoid::Relations::Referenced::Many do
3240
3132
  describe ".valid_options" do
3241
3133
 
3242
3134
  it "returns the valid options" do
3243
- described_class.valid_options.should eq(
3135
+ expect(described_class.valid_options).to eq(
3244
3136
  [
3245
3137
  :after_add,
3246
3138
  :after_remove,
@@ -3260,7 +3152,7 @@ describe Mongoid::Relations::Referenced::Many do
3260
3152
  describe ".validation_default" do
3261
3153
 
3262
3154
  it "returns true" do
3263
- described_class.validation_default.should be_true
3155
+ expect(described_class.validation_default).to be true
3264
3156
  end
3265
3157
  end
3266
3158
 
@@ -3288,13 +3180,13 @@ describe Mongoid::Relations::Referenced::Many do
3288
3180
  end
3289
3181
 
3290
3182
  it "order documents" do
3291
- person.ordered_posts(true).should eq(
3183
+ expect(person.ordered_posts(true)).to eq(
3292
3184
  [post_two, post_three, post_one]
3293
3185
  )
3294
3186
  end
3295
3187
 
3296
3188
  it "chaining order criterias" do
3297
- person.ordered_posts.order_by(:title.desc).to_a.should eq(
3189
+ expect(person.ordered_posts.order_by(:title.desc).to_a).to eq(
3298
3190
  [post_three, post_two, post_one]
3299
3191
  )
3300
3192
  end
@@ -3330,7 +3222,7 @@ describe Mongoid::Relations::Referenced::Many do
3330
3222
  end
3331
3223
 
3332
3224
  it "reloads the document from the database" do
3333
- reloaded.first.title.should eq("reloaded")
3225
+ expect(reloaded.first.title).to eq("reloaded")
3334
3226
  end
3335
3227
  end
3336
3228
 
@@ -3345,11 +3237,11 @@ describe Mongoid::Relations::Referenced::Many do
3345
3237
  end
3346
3238
 
3347
3239
  it "reloads the first document from the database" do
3348
- reloaded.should include(post_one)
3240
+ expect(reloaded).to include(post_one)
3349
3241
  end
3350
3242
 
3351
3243
  it "reloads the new document from the database" do
3352
- reloaded.should include(post_two)
3244
+ expect(reloaded).to include(post_two)
3353
3245
  end
3354
3246
  end
3355
3247
  end
@@ -3363,7 +3255,7 @@ describe Mongoid::Relations::Referenced::Many do
3363
3255
  end
3364
3256
 
3365
3257
  it "allows creation of the document" do
3366
- jar.id.should eq(1)
3258
+ expect(jar.id).to eq(1)
3367
3259
  end
3368
3260
  end
3369
3261
 
@@ -3392,7 +3284,7 @@ describe Mongoid::Relations::Referenced::Many do
3392
3284
  end
3393
3285
 
3394
3286
  it "adds both documents" do
3395
- result.should eq([ post_one, post_two ])
3287
+ expect(result).to eq([ post_one, post_two ])
3396
3288
  end
3397
3289
  end
3398
3290
  end
@@ -3414,29 +3306,29 @@ describe Mongoid::Relations::Referenced::Many do
3414
3306
  end
3415
3307
 
3416
3308
  it "it executes method callbacks" do
3417
- artist.before_add_referenced_called.should be_true
3309
+ expect(artist.before_add_referenced_called).to be true
3418
3310
  end
3419
3311
 
3420
3312
  it "it executes proc callbacks" do
3421
- album.before_add_called.should be_true
3313
+ expect(album.before_add_called).to be true
3422
3314
  end
3423
3315
 
3424
3316
  it "adds the document to the relation" do
3425
- artist.albums.should eq([ album ])
3317
+ expect(artist.albums).to eq([ album ])
3426
3318
  end
3427
3319
  end
3428
3320
 
3429
3321
  context "when execution raises errors" do
3430
3322
 
3431
3323
  before do
3432
- artist.should_receive(:before_add_album).and_raise
3324
+ expect(artist).to receive(:before_add_album).and_raise
3433
3325
  end
3434
3326
 
3435
3327
  it "does not add the document to the relation" do
3436
3328
  expect {
3437
3329
  artist.albums << album
3438
3330
  }.to raise_error
3439
- artist.albums.should be_empty
3331
+ expect(artist.albums).to be_empty
3440
3332
  end
3441
3333
  end
3442
3334
  end
@@ -3453,20 +3345,20 @@ describe Mongoid::Relations::Referenced::Many do
3453
3345
 
3454
3346
  it "executes the callback" do
3455
3347
  artist.albums << album
3456
- artist.after_add_referenced_called.should be_true
3348
+ expect(artist.after_add_referenced_called).to be true
3457
3349
  end
3458
3350
 
3459
3351
  context "when execution raises errors" do
3460
3352
 
3461
3353
  before do
3462
- artist.should_receive(:after_add_album).and_raise
3354
+ expect(artist).to receive(:after_add_album).and_raise
3463
3355
  end
3464
3356
 
3465
3357
  it "adds the document to the relation" do
3466
3358
  expect {
3467
3359
  artist.albums << album
3468
3360
  }.to raise_error
3469
- artist.albums.should eq([ album ])
3361
+ expect(artist.albums).to eq([ album ])
3470
3362
  end
3471
3363
  end
3472
3364
  end
@@ -3494,11 +3386,11 @@ describe Mongoid::Relations::Referenced::Many do
3494
3386
  end
3495
3387
 
3496
3388
  it "executes the callback" do
3497
- artist.before_remove_referenced_called.should be_true
3389
+ expect(artist.before_remove_referenced_called).to be true
3498
3390
  end
3499
3391
 
3500
3392
  it "removes the document from the relation" do
3501
- artist.albums.should be_empty
3393
+ expect(artist.albums).to be_empty
3502
3394
  end
3503
3395
  end
3504
3396
 
@@ -3509,18 +3401,18 @@ describe Mongoid::Relations::Referenced::Many do
3509
3401
  end
3510
3402
 
3511
3403
  it "executes the callback" do
3512
- artist.before_remove_referenced_called.should be_true
3404
+ expect(artist.before_remove_referenced_called).to be true
3513
3405
  end
3514
3406
 
3515
3407
  it "clears the relation" do
3516
- artist.albums.should be_empty
3408
+ expect(artist.albums).to be_empty
3517
3409
  end
3518
3410
  end
3519
3411
 
3520
3412
  context "when execution raises errors" do
3521
3413
 
3522
3414
  before do
3523
- artist.should_receive(:before_remove_album).and_raise
3415
+ expect(artist).to receive(:before_remove_album).and_raise
3524
3416
  end
3525
3417
 
3526
3418
  describe "#delete" do
@@ -3532,7 +3424,7 @@ describe Mongoid::Relations::Referenced::Many do
3532
3424
  end
3533
3425
 
3534
3426
  it "does not remove the document from the relation" do
3535
- artist.albums.should eq([ album ])
3427
+ expect(artist.albums).to eq([ album ])
3536
3428
  end
3537
3429
  end
3538
3430
 
@@ -3545,7 +3437,7 @@ describe Mongoid::Relations::Referenced::Many do
3545
3437
  end
3546
3438
 
3547
3439
  it "does not clear the relation" do
3548
- artist.albums.should eq([ album ])
3440
+ expect(artist.albums).to eq([ album ])
3549
3441
  end
3550
3442
  end
3551
3443
  end
@@ -3575,7 +3467,7 @@ describe Mongoid::Relations::Referenced::Many do
3575
3467
  end
3576
3468
 
3577
3469
  it "executes the callback" do
3578
- artist.after_remove_referenced_called.should be_true
3470
+ expect(artist.after_remove_referenced_called).to be true
3579
3471
  end
3580
3472
  end
3581
3473
 
@@ -3587,7 +3479,7 @@ describe Mongoid::Relations::Referenced::Many do
3587
3479
 
3588
3480
  it "executes the callback" do
3589
3481
  artist.albums.clear
3590
- artist.after_remove_referenced_called.should be_true
3482
+ expect(artist.after_remove_referenced_called).to be true
3591
3483
  end
3592
3484
  end
3593
3485
  end
@@ -3595,7 +3487,7 @@ describe Mongoid::Relations::Referenced::Many do
3595
3487
  context "when errors are raised" do
3596
3488
 
3597
3489
  before do
3598
- artist.should_receive(:after_remove_album).and_raise
3490
+ expect(artist).to receive(:after_remove_album).and_raise
3599
3491
  end
3600
3492
 
3601
3493
  describe "#delete" do
@@ -3607,7 +3499,7 @@ describe Mongoid::Relations::Referenced::Many do
3607
3499
  end
3608
3500
 
3609
3501
  it "removes the documents from the relation" do
3610
- artist.albums.should be_empty
3502
+ expect(artist.albums).to be_empty
3611
3503
  end
3612
3504
  end
3613
3505
 
@@ -3620,7 +3512,7 @@ describe Mongoid::Relations::Referenced::Many do
3620
3512
  end
3621
3513
 
3622
3514
  it "removes the documents from the relation" do
3623
- artist.albums.should be_empty
3515
+ expect(artist.albums).to be_empty
3624
3516
  end
3625
3517
  end
3626
3518
  end
@@ -3645,7 +3537,22 @@ describe Mongoid::Relations::Referenced::Many do
3645
3537
  end
3646
3538
 
3647
3539
  it "does not drop the ordering" do
3648
- criteria.should eq([ post_two, post_one ])
3540
+ expect(criteria).to eq([ post_two, post_one ])
3541
+ end
3542
+ end
3543
+
3544
+ context "when accessing a scope named open" do
3545
+
3546
+ let(:person) do
3547
+ Person.create
3548
+ end
3549
+
3550
+ let!(:post) do
3551
+ person.posts.create(title: "open")
3552
+ end
3553
+
3554
+ it "returns the appropriate documents" do
3555
+ expect(person.posts.open).to eq([ post ])
3649
3556
  end
3650
3557
  end
3651
3558
  end