mongoid 3.1.7 → 4.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (521) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +317 -11
  3. data/README.md +4 -5
  4. data/lib/config/locales/en.yml +9 -12
  5. data/lib/mongoid.rb +6 -75
  6. data/lib/mongoid/atomic.rb +0 -11
  7. data/lib/mongoid/atomic/paths/embedded.rb +0 -30
  8. data/lib/mongoid/atomic/paths/root.rb +0 -13
  9. data/lib/mongoid/attributes.rb +30 -108
  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/{dirty.rb → changeable.rb} +5 -2
  14. data/lib/mongoid/composable.rb +104 -0
  15. data/lib/mongoid/config.rb +3 -9
  16. data/lib/mongoid/config/options.rb +1 -1
  17. data/lib/mongoid/contextual/aggregable/mongo.rb +5 -9
  18. data/lib/mongoid/contextual/atomic.rb +53 -53
  19. data/lib/mongoid/contextual/command.rb +26 -0
  20. data/lib/mongoid/contextual/map_reduce.rb +1 -1
  21. data/lib/mongoid/contextual/memory.rb +6 -5
  22. data/lib/mongoid/contextual/mongo.rb +59 -28
  23. data/lib/mongoid/contextual/text_search.rb +180 -0
  24. data/lib/mongoid/copyable.rb +2 -3
  25. data/lib/mongoid/criteria.rb +13 -33
  26. data/lib/mongoid/criteria/{#findable.rb# → findable.rb} +0 -2
  27. data/lib/mongoid/{criterion/inspection.rb → criteria/inspectable.rb} +2 -2
  28. data/lib/mongoid/{criterion → criteria}/marshalable.rb +3 -1
  29. data/lib/mongoid/{criterion → criteria}/modifiable.rb +1 -1
  30. data/lib/mongoid/{criterion/scoping.rb → criteria/scopable.rb} +2 -2
  31. data/lib/mongoid/document.rb +28 -12
  32. data/lib/mongoid/errors.rb +1 -1
  33. data/lib/mongoid/errors/document_not_found.rb +2 -1
  34. data/lib/mongoid/errors/invalid_value.rb +16 -0
  35. data/lib/mongoid/errors/mongoid_error.rb +1 -1
  36. data/lib/mongoid/extensions.rb +2 -7
  37. data/lib/mongoid/extensions/array.rb +2 -2
  38. data/lib/mongoid/extensions/boolean.rb +14 -17
  39. data/lib/mongoid/extensions/float.rb +1 -0
  40. data/lib/mongoid/extensions/hash.rb +1 -1
  41. data/lib/mongoid/extensions/object.rb +4 -4
  42. data/lib/mongoid/extensions/object_id.rb +5 -5
  43. data/lib/mongoid/extensions/range.rb +8 -2
  44. data/lib/mongoid/extensions/string.rb +5 -17
  45. data/lib/mongoid/extensions/time.rb +2 -2
  46. data/lib/mongoid/factory.rb +3 -3
  47. data/lib/mongoid/fields.rb +9 -8
  48. data/lib/mongoid/fields/foreign_key.rb +3 -3
  49. data/lib/mongoid/fields/standard.rb +4 -16
  50. data/lib/mongoid/fields/validators/macro.rb +11 -3
  51. data/lib/mongoid/{finders.rb → findable.rb} +6 -2
  52. data/lib/mongoid/{indexes.rb → indexable.rb} +50 -55
  53. data/lib/mongoid/indexable/specification.rb +104 -0
  54. data/lib/mongoid/{indexes → indexable}/validators/options.rb +2 -1
  55. data/lib/mongoid/{inspection.rb → inspectable.rb} +15 -11
  56. data/lib/mongoid/{callbacks.rb → interceptable.rb} +3 -52
  57. data/lib/mongoid/log_subscriber.rb +22 -0
  58. data/lib/mongoid/matchable.rb +152 -0
  59. data/lib/mongoid/{matchers → matchable}/all.rb +1 -1
  60. data/lib/mongoid/{matchers → matchable}/and.rb +2 -2
  61. data/lib/mongoid/{matchers → matchable}/default.rb +1 -1
  62. data/lib/mongoid/{matchers → matchable}/exists.rb +1 -1
  63. data/lib/mongoid/{matchers → matchable}/gt.rb +1 -1
  64. data/lib/mongoid/{matchers → matchable}/gte.rb +1 -1
  65. data/lib/mongoid/{matchers → matchable}/in.rb +2 -2
  66. data/lib/mongoid/{matchers → matchable}/lt.rb +1 -1
  67. data/lib/mongoid/{matchers → matchable}/lte.rb +1 -1
  68. data/lib/mongoid/{matchers → matchable}/ne.rb +1 -1
  69. data/lib/mongoid/{matchers → matchable}/nin.rb +3 -2
  70. data/lib/mongoid/{matchers → matchable}/or.rb +2 -2
  71. data/lib/mongoid/{matchers → matchable}/size.rb +1 -1
  72. data/lib/mongoid/persistable.rb +212 -0
  73. data/lib/mongoid/persistable/creatable.rb +188 -0
  74. data/lib/mongoid/persistable/deletable.rb +148 -0
  75. data/lib/mongoid/persistable/destroyable.rb +55 -0
  76. data/lib/mongoid/persistable/incrementable.rb +36 -0
  77. data/lib/mongoid/persistable/logical.rb +38 -0
  78. data/lib/mongoid/persistable/poppable.rb +39 -0
  79. data/lib/mongoid/persistable/pullable.rb +55 -0
  80. data/lib/mongoid/persistable/pushable.rb +62 -0
  81. data/lib/mongoid/persistable/renamable.rb +35 -0
  82. data/lib/mongoid/persistable/savable.rb +52 -0
  83. data/lib/mongoid/persistable/settable.rb +33 -0
  84. data/lib/mongoid/persistable/unsettable.rb +36 -0
  85. data/lib/mongoid/persistable/updatable.rb +151 -0
  86. data/lib/mongoid/persistable/upsertable.rb +55 -0
  87. data/lib/mongoid/positional.rb +71 -0
  88. data/lib/mongoid/railtie.rb +32 -45
  89. data/lib/mongoid/railties/database.rake +12 -6
  90. data/lib/mongoid/relations.rb +3 -3
  91. data/lib/mongoid/relations/accessors.rb +13 -46
  92. data/lib/mongoid/relations/auto_save.rb +15 -36
  93. data/lib/mongoid/relations/binding.rb +0 -23
  94. data/lib/mongoid/relations/bindings/embedded/many.rb +1 -3
  95. data/lib/mongoid/relations/bindings/referenced/in.rb +3 -8
  96. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +3 -1
  97. data/lib/mongoid/relations/builder.rb +1 -1
  98. data/lib/mongoid/relations/builders.rb +2 -2
  99. data/lib/mongoid/relations/builders/nested_attributes/many.rb +10 -13
  100. data/lib/mongoid/relations/builders/nested_attributes/one.rb +4 -5
  101. data/lib/mongoid/relations/builders/referenced/in.rb +1 -1
  102. data/lib/mongoid/relations/builders/referenced/many.rb +1 -2
  103. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +1 -2
  104. data/lib/mongoid/relations/builders/referenced/one.rb +1 -1
  105. data/lib/mongoid/relations/cascading.rb +3 -5
  106. data/lib/mongoid/relations/constraint.rb +1 -1
  107. data/lib/mongoid/relations/conversions.rb +1 -1
  108. data/lib/mongoid/relations/counter_cache.rb +39 -15
  109. data/lib/mongoid/relations/eager.rb +47 -0
  110. data/lib/mongoid/relations/eager/base.rb +57 -0
  111. data/lib/mongoid/relations/eager/belongs_to.rb +30 -0
  112. data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +40 -0
  113. data/lib/mongoid/relations/eager/has_many.rb +37 -0
  114. data/lib/mongoid/relations/eager/has_one.rb +29 -0
  115. data/lib/mongoid/relations/embedded/batchable.rb +3 -4
  116. data/lib/mongoid/relations/embedded/many.rb +7 -27
  117. data/lib/mongoid/relations/macros.rb +2 -4
  118. data/lib/mongoid/relations/many.rb +30 -31
  119. data/lib/mongoid/relations/metadata.rb +6 -75
  120. data/lib/mongoid/relations/nested_builder.rb +2 -2
  121. data/lib/mongoid/relations/options.rb +1 -0
  122. data/lib/mongoid/relations/polymorphic.rb +0 -1
  123. data/lib/mongoid/relations/proxy.rb +10 -32
  124. data/lib/mongoid/relations/referenced/in.rb +2 -18
  125. data/lib/mongoid/relations/referenced/many.rb +9 -22
  126. data/lib/mongoid/relations/referenced/many_to_many.rb +10 -33
  127. data/lib/mongoid/relations/referenced/one.rb +2 -21
  128. data/lib/mongoid/relations/synchronization.rb +3 -3
  129. data/lib/mongoid/relations/touchable.rb +33 -0
  130. data/lib/mongoid/{reloading.rb → reloadable.rb} +6 -4
  131. data/lib/mongoid/{scoping.rb → scopable.rb} +26 -3
  132. data/lib/mongoid/selectable.rb +59 -0
  133. data/lib/mongoid/{serialization.rb → serializable.rb} +10 -1
  134. data/lib/mongoid/sessions.rb +37 -345
  135. data/lib/mongoid/sessions/factory.rb +2 -0
  136. data/lib/mongoid/sessions/options.rb +176 -0
  137. data/lib/mongoid/sessions/storage_options.rb +140 -0
  138. data/lib/mongoid/sessions/thread_options.rb +19 -0
  139. data/lib/mongoid/sessions/validators/storage.rb +15 -1
  140. data/lib/mongoid/{sharding.rb → shardable.rb} +5 -1
  141. data/lib/mongoid/support/query_counter.rb +23 -0
  142. data/lib/mongoid/threaded.rb +0 -110
  143. data/lib/mongoid/threaded/lifecycle.rb +0 -28
  144. data/lib/mongoid/timestamps/updated/short.rb +2 -2
  145. data/lib/mongoid/{hierarchy.rb → traversable.rb} +9 -5
  146. data/lib/mongoid/{validations.rb → validatable.rb} +23 -9
  147. data/lib/mongoid/{validations → validatable}/associated.rb +3 -1
  148. data/lib/mongoid/{validations → validatable}/format.rb +1 -1
  149. data/lib/mongoid/{validations → validatable}/length.rb +1 -1
  150. data/lib/mongoid/{validations → validatable}/localizable.rb +1 -1
  151. data/lib/mongoid/{validations → validatable}/macros.rb +4 -3
  152. data/lib/mongoid/{validations → validatable}/presence.rb +1 -1
  153. data/lib/mongoid/{validations → validatable}/queryable.rb +1 -2
  154. data/lib/mongoid/{validations → validatable}/uniqueness.rb +3 -3
  155. data/lib/mongoid/version.rb +1 -1
  156. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +9 -13
  157. data/lib/rails/generators/mongoid/model/model_generator.rb +0 -1
  158. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +0 -3
  159. data/lib/rails/generators/mongoid_generator.rb +3 -40
  160. data/lib/rails/mongoid.rb +59 -57
  161. data/lib/support/ruby_version.rb +1 -1
  162. data/spec/app/models/account.rb +2 -6
  163. data/spec/app/models/acolyte.rb +1 -0
  164. data/spec/app/models/actor.rb +0 -1
  165. data/spec/app/models/address.rb +6 -1
  166. data/spec/app/models/animal.rb +1 -1
  167. data/spec/app/models/appointment.rb +2 -2
  168. data/spec/app/models/article.rb +1 -4
  169. data/spec/app/models/audio.rb +5 -0
  170. data/spec/app/models/author.rb +0 -2
  171. data/spec/app/models/band.rb +3 -2
  172. data/spec/app/models/bar.rb +1 -0
  173. data/spec/app/models/book.rb +1 -0
  174. data/spec/app/models/building.rb +0 -2
  175. data/spec/app/models/building_address.rb +0 -2
  176. data/spec/app/models/bus.rb +1 -1
  177. data/spec/app/models/canvas.rb +1 -1
  178. data/spec/app/models/contractor.rb +0 -2
  179. data/spec/app/models/country_code.rb +1 -1
  180. data/spec/app/models/definition.rb +2 -2
  181. data/spec/app/models/dragon.rb +4 -0
  182. data/spec/app/models/drug.rb +1 -3
  183. data/spec/app/models/dungeon.rb +4 -0
  184. data/spec/app/models/filesystem.rb +1 -0
  185. data/spec/app/models/fish.rb +0 -1
  186. data/spec/app/models/fruits.rb +6 -0
  187. data/spec/app/models/game.rb +0 -2
  188. data/spec/app/models/house.rb +0 -2
  189. data/spec/app/models/item.rb +1 -5
  190. data/spec/app/models/jar.rb +1 -1
  191. data/spec/app/models/label.rb +4 -4
  192. data/spec/app/models/login.rb +1 -1
  193. data/spec/app/models/movie.rb +1 -0
  194. data/spec/app/models/name.rb +3 -3
  195. data/spec/app/models/note.rb +1 -1
  196. data/spec/app/models/oscar.rb +1 -1
  197. data/spec/app/models/parent_doc.rb +1 -1
  198. data/spec/app/models/person.rb +13 -8
  199. data/spec/app/models/phone.rb +1 -3
  200. data/spec/app/models/player.rb +1 -1
  201. data/spec/app/models/post.rb +2 -1
  202. data/spec/app/models/quiz.rb +0 -3
  203. data/spec/app/models/record.rb +5 -5
  204. data/spec/app/models/registry.rb +1 -1
  205. data/spec/app/models/server.rb +1 -1
  206. data/spec/app/models/service.rb +3 -3
  207. data/spec/app/models/sound.rb +5 -0
  208. data/spec/app/models/template.rb +1 -1
  209. data/spec/app/models/title.rb +0 -1
  210. data/spec/app/models/track.rb +5 -5
  211. data/spec/app/models/tree.rb +1 -1
  212. data/spec/app/models/video.rb +0 -4
  213. data/spec/app/models/wiki_page.rb +1 -4
  214. data/spec/app/models/word.rb +3 -0
  215. data/spec/app/models/word_origin.rb +1 -1
  216. data/spec/config/mongoid.yml +7 -8
  217. data/spec/helpers.rb +18 -0
  218. data/spec/mongoid/atomic/modifiers_spec.rb +22 -22
  219. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +8 -49
  220. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +7 -49
  221. data/spec/mongoid/atomic/paths/root_spec.rb +3 -61
  222. data/spec/mongoid/atomic/paths_spec.rb +19 -19
  223. data/spec/mongoid/atomic_spec.rb +19 -19
  224. data/spec/mongoid/{nested_attributes_spec.rb → attributes/nested_spec.rb} +335 -448
  225. data/spec/mongoid/attributes/readonly_spec.rb +16 -16
  226. data/spec/mongoid/attributes_spec.rb +188 -434
  227. data/spec/mongoid/{dirty_spec.rb → changeable_spec.rb} +117 -148
  228. data/spec/mongoid/{components_spec.rb → composable_spec.rb} +3 -3
  229. data/spec/mongoid/config/environment_spec.rb +3 -3
  230. data/spec/mongoid/config/options_spec.rb +6 -6
  231. data/spec/mongoid/config_spec.rb +24 -48
  232. data/spec/mongoid/contextual/aggregable/memory_spec.rb +12 -12
  233. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +46 -38
  234. data/spec/mongoid/contextual/atomic_spec.rb +60 -56
  235. data/spec/mongoid/contextual/find_and_modify_spec.rb +14 -14
  236. data/spec/mongoid/contextual/geo_near_spec.rb +22 -22
  237. data/spec/mongoid/contextual/map_reduce_spec.rb +27 -27
  238. data/spec/mongoid/contextual/memory_spec.rb +94 -94
  239. data/spec/mongoid/contextual/mongo_spec.rb +225 -139
  240. data/spec/mongoid/contextual/text_search_spec.rb +207 -0
  241. data/spec/mongoid/copyable_spec.rb +56 -68
  242. data/spec/mongoid/criteria/findable_spec.rb +991 -0
  243. data/spec/mongoid/{criterion/inspection_spec.rb → criteria/inspectable_spec.rb} +5 -5
  244. data/spec/mongoid/{criterion → criteria}/marshalable_spec.rb +2 -2
  245. data/spec/mongoid/criteria/modifiable_spec.rb +1063 -0
  246. data/spec/mongoid/{criterion/scoping_spec.rb → criteria/scopable_spec.rb} +31 -31
  247. data/spec/mongoid/criteria_spec.rb +530 -2207
  248. data/spec/mongoid/document_spec.rb +166 -120
  249. data/spec/mongoid/equality_spec.rb +22 -22
  250. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +3 -3
  251. data/spec/mongoid/errors/callback_spec.rb +3 -3
  252. data/spec/mongoid/errors/delete_restriction_spec.rb +3 -3
  253. data/spec/mongoid/errors/document_not_found_spec.rb +11 -11
  254. data/spec/mongoid/errors/eager_load_spec.rb +3 -3
  255. data/spec/mongoid/errors/invalid_collection_spec.rb +3 -3
  256. data/spec/mongoid/errors/invalid_config_option_spec.rb +3 -3
  257. data/spec/mongoid/errors/invalid_field_option_spec.rb +3 -3
  258. data/spec/mongoid/errors/invalid_field_spec.rb +3 -3
  259. data/spec/mongoid/errors/invalid_find_spec.rb +3 -3
  260. data/spec/mongoid/errors/invalid_includes_spec.rb +3 -3
  261. data/spec/mongoid/errors/invalid_index_spec.rb +3 -3
  262. data/spec/mongoid/errors/invalid_options_spec.rb +3 -3
  263. data/spec/mongoid/errors/invalid_path_spec.rb +3 -3
  264. data/spec/mongoid/errors/invalid_scope_spec.rb +3 -3
  265. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -3
  266. data/spec/mongoid/errors/invalid_storage_options_spec.rb +3 -3
  267. data/spec/mongoid/errors/invalid_time_spec.rb +3 -3
  268. data/spec/mongoid/errors/inverse_not_found_spec.rb +3 -3
  269. data/spec/mongoid/errors/mixed_relations_spec.rb +3 -3
  270. data/spec/mongoid/errors/mixed_session_configuration_spec.rb +3 -3
  271. data/spec/mongoid/errors/mongoid_error_spec.rb +7 -7
  272. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +3 -3
  273. data/spec/mongoid/errors/no_environment_spec.rb +3 -3
  274. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +3 -3
  275. data/spec/mongoid/errors/no_metadata_spec.rb +3 -3
  276. data/spec/mongoid/errors/no_parent_spec.rb +3 -3
  277. data/spec/mongoid/errors/no_session_config_spec.rb +3 -3
  278. data/spec/mongoid/errors/no_session_database_spec.rb +3 -3
  279. data/spec/mongoid/errors/no_session_hosts_spec.rb +3 -3
  280. data/spec/mongoid/errors/no_sessions_config_spec.rb +3 -3
  281. data/spec/mongoid/errors/readonly_attribute_spec.rb +3 -3
  282. data/spec/mongoid/errors/scope_overwrite_spec.rb +3 -3
  283. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +3 -3
  284. data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -5
  285. data/spec/mongoid/errors/unsaved_document_spec.rb +3 -3
  286. data/spec/mongoid/errors/unsupported_javascript_spec.rb +3 -3
  287. data/spec/mongoid/errors/validations_spec.rb +7 -7
  288. data/spec/mongoid/extensions/array_spec.rb +61 -61
  289. data/spec/mongoid/extensions/big_decimal_spec.rb +11 -11
  290. data/spec/mongoid/extensions/binary_spec.rb +12 -12
  291. data/spec/mongoid/extensions/boolean_spec.rb +18 -18
  292. data/spec/mongoid/extensions/date_spec.rb +13 -13
  293. data/spec/mongoid/extensions/date_time_spec.rb +9 -9
  294. data/spec/mongoid/extensions/false_class_spec.rb +5 -5
  295. data/spec/mongoid/extensions/float_spec.rb +29 -15
  296. data/spec/mongoid/extensions/hash_spec.rb +29 -29
  297. data/spec/mongoid/extensions/integer_spec.rb +15 -15
  298. data/spec/mongoid/extensions/module_spec.rb +2 -2
  299. data/spec/mongoid/extensions/nil_class_spec.rb +1 -1
  300. data/spec/mongoid/extensions/object_id_spec.rb +134 -134
  301. data/spec/mongoid/extensions/object_spec.rb +26 -26
  302. data/spec/mongoid/extensions/range_spec.rb +61 -12
  303. data/spec/mongoid/extensions/regexp_spec.rb +4 -4
  304. data/spec/mongoid/extensions/set_spec.rb +4 -4
  305. data/spec/mongoid/extensions/string_spec.rb +35 -46
  306. data/spec/mongoid/extensions/symbol_spec.rb +9 -9
  307. data/spec/mongoid/extensions/time_spec.rb +49 -49
  308. data/spec/mongoid/extensions/time_with_zone_spec.rb +34 -34
  309. data/spec/mongoid/extensions/true_class_spec.rb +5 -5
  310. data/spec/mongoid/extensions_spec.rb +15 -0
  311. data/spec/mongoid/factory_spec.rb +15 -15
  312. data/spec/mongoid/fields/foreign_key_spec.rb +73 -66
  313. data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +15 -15
  314. data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +22 -22
  315. data/spec/mongoid/fields/localized_spec.rb +23 -23
  316. data/spec/mongoid/fields/standard_spec.rb +12 -12
  317. data/spec/mongoid/fields_spec.rb +168 -209
  318. data/spec/mongoid/{finders_spec.rb → findable_spec.rb} +62 -27
  319. data/spec/mongoid/indexable/specification_spec.rb +102 -0
  320. data/spec/mongoid/{indexes_spec.rb → indexable_spec.rb} +171 -51
  321. data/spec/mongoid/{inspection_spec.rb → inspectable_spec.rb} +6 -14
  322. data/spec/mongoid/{callbacks_spec.rb → interceptable_spec.rb} +105 -105
  323. data/spec/mongoid/log_subscriber_spec.rb +74 -0
  324. data/spec/mongoid/loggable_spec.rb +1 -1
  325. data/spec/mongoid/{matchers → matchable}/all_spec.rb +4 -4
  326. data/spec/mongoid/{matchers → matchable}/and_spec.rb +11 -11
  327. data/spec/mongoid/{matchers → matchable}/default_spec.rb +15 -15
  328. data/spec/mongoid/{matchers → matchable}/exists_spec.rb +5 -5
  329. data/spec/mongoid/{matchers → matchable}/gt_spec.rb +9 -8
  330. data/spec/mongoid/{matchers → matchable}/gte_spec.rb +7 -7
  331. data/spec/mongoid/matchable/in_spec.rb +49 -0
  332. data/spec/mongoid/{matchers → matchable}/lt_spec.rb +7 -7
  333. data/spec/mongoid/{matchers → matchable}/lte_spec.rb +7 -7
  334. data/spec/mongoid/{matchers → matchable}/ne_spec.rb +3 -3
  335. data/spec/mongoid/matchable/nin_spec.rb +48 -0
  336. data/spec/mongoid/{matchers → matchable}/or_spec.rb +6 -6
  337. data/spec/mongoid/{matchers → matchable}/size_spec.rb +3 -3
  338. data/spec/mongoid/{matchers_spec.rb → matchable_spec.rb} +41 -41
  339. data/spec/mongoid/persistable/creatable_spec.rb +512 -0
  340. data/spec/mongoid/persistable/deletable_spec.rb +205 -0
  341. data/spec/mongoid/persistable/destroyable_spec.rb +148 -0
  342. data/spec/mongoid/persistable/incrementable_spec.rb +173 -0
  343. data/spec/mongoid/persistable/logical_spec.rb +143 -0
  344. data/spec/mongoid/persistable/poppable_spec.rb +115 -0
  345. data/spec/mongoid/persistable/pullable_spec.rb +228 -0
  346. data/spec/mongoid/persistable/pushable_spec.rb +258 -0
  347. data/spec/mongoid/persistable/renamable_spec.rb +135 -0
  348. data/spec/mongoid/persistable/savable_spec.rb +432 -0
  349. data/spec/mongoid/persistable/settable_spec.rb +139 -0
  350. data/spec/mongoid/persistable/unsettable_spec.rb +155 -0
  351. data/spec/mongoid/persistable/updatable_spec.rb +558 -0
  352. data/spec/mongoid/persistable/upsertable_spec.rb +106 -0
  353. data/spec/mongoid/persistable_spec.rb +206 -0
  354. data/spec/mongoid/{atomic/positionable_spec.rb → positional_spec.rb} +19 -14
  355. data/spec/mongoid/railties/document_spec.rb +2 -2
  356. data/spec/mongoid/relations/accessors_spec.rb +53 -145
  357. data/spec/mongoid/relations/auto_save_spec.rb +36 -16
  358. data/spec/mongoid/relations/bindings/embedded/in_spec.rb +6 -6
  359. data/spec/mongoid/relations/bindings/embedded/many_spec.rb +2 -2
  360. data/spec/mongoid/relations/bindings/embedded/one_spec.rb +3 -3
  361. data/spec/mongoid/relations/bindings/referenced/in_spec.rb +12 -12
  362. data/spec/mongoid/relations/bindings/referenced/many_spec.rb +6 -6
  363. data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +9 -9
  364. data/spec/mongoid/relations/bindings/referenced/one_spec.rb +6 -6
  365. data/spec/mongoid/relations/builders/embedded/in_spec.rb +4 -4
  366. data/spec/mongoid/relations/builders/embedded/many_spec.rb +18 -18
  367. data/spec/mongoid/relations/builders/embedded/one_spec.rb +11 -11
  368. data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +12 -13
  369. data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +14 -14
  370. data/spec/mongoid/relations/builders/referenced/in_spec.rb +22 -33
  371. data/spec/mongoid/relations/builders/referenced/many_spec.rb +15 -15
  372. data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +18 -18
  373. data/spec/mongoid/relations/builders/referenced/one_spec.rb +11 -24
  374. data/spec/mongoid/relations/builders_spec.rb +21 -21
  375. data/spec/mongoid/relations/cascading/delete_spec.rb +7 -7
  376. data/spec/mongoid/relations/cascading/destroy_spec.rb +2 -2
  377. data/spec/mongoid/relations/cascading/nullify_spec.rb +2 -2
  378. data/spec/mongoid/relations/cascading/restrict_spec.rb +3 -3
  379. data/spec/mongoid/relations/cascading_spec.rb +16 -16
  380. data/spec/mongoid/relations/constraint_spec.rb +8 -7
  381. data/spec/mongoid/relations/conversions_spec.rb +16 -14
  382. data/spec/mongoid/relations/counter_cache_spec.rb +85 -0
  383. data/spec/mongoid/relations/cyclic_spec.rb +18 -18
  384. data/spec/mongoid/relations/eager/belongs_to_spec.rb +154 -0
  385. data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +143 -0
  386. data/spec/mongoid/relations/eager/has_many_spec.rb +207 -0
  387. data/spec/mongoid/relations/eager/has_one_spec.rb +163 -0
  388. data/spec/mongoid/relations/eager_spec.rb +228 -0
  389. data/spec/mongoid/relations/embedded/dirty_spec.rb +8 -8
  390. data/spec/mongoid/relations/embedded/in_spec.rb +55 -56
  391. data/spec/mongoid/relations/embedded/many_spec.rb +357 -367
  392. data/spec/mongoid/relations/embedded/one_spec.rb +98 -139
  393. data/spec/mongoid/relations/macros_spec.rb +108 -102
  394. data/spec/mongoid/relations/metadata_spec.rb +147 -241
  395. data/spec/mongoid/relations/options_spec.rb +1 -1
  396. data/spec/mongoid/relations/polymorphic_spec.rb +13 -17
  397. data/spec/mongoid/relations/proxy_spec.rb +2 -2
  398. data/spec/mongoid/relations/referenced/in_spec.rb +128 -303
  399. data/spec/mongoid/relations/referenced/many_spec.rb +379 -522
  400. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +345 -417
  401. data/spec/mongoid/relations/referenced/one_spec.rb +148 -263
  402. data/spec/mongoid/relations/reflections_spec.rb +6 -6
  403. data/spec/mongoid/relations/synchronization_spec.rb +46 -50
  404. data/spec/mongoid/relations/targets/enumerable_spec.rb +116 -116
  405. data/spec/mongoid/relations/touchable_spec.rb +296 -0
  406. data/spec/mongoid/relations_spec.rb +16 -15
  407. data/spec/mongoid/{reloading_spec.rb → reloadable_spec.rb} +20 -60
  408. data/spec/mongoid/{scoping_spec.rb → scopable_spec.rb} +74 -126
  409. data/spec/mongoid/selectable_spec.rb +134 -0
  410. data/spec/mongoid/{serialization_spec.rb → serializable_spec.rb} +111 -82
  411. data/spec/mongoid/sessions/factory_spec.rb +49 -28
  412. data/spec/mongoid/sessions/mongo_uri_spec.rb +7 -7
  413. data/spec/mongoid/sessions/options_spec.rb +92 -0
  414. data/spec/mongoid/sessions_spec.rb +288 -177
  415. data/spec/mongoid/{sharding_spec.rb → shardable_spec.rb} +8 -8
  416. data/spec/mongoid/state_spec.rb +10 -10
  417. data/spec/mongoid/threaded_spec.rb +17 -70
  418. data/spec/mongoid/timestamps/created/short_spec.rb +6 -6
  419. data/spec/mongoid/timestamps/created_spec.rb +5 -5
  420. data/spec/mongoid/timestamps/updated/short_spec.rb +10 -10
  421. data/spec/mongoid/timestamps/updated_spec.rb +8 -12
  422. data/spec/mongoid/timestamps_spec.rb +7 -11
  423. data/spec/mongoid/{hierarchy_spec.rb → traversable_spec.rb} +19 -19
  424. data/spec/mongoid/{validations → validatable}/associated_spec.rb +18 -18
  425. data/spec/mongoid/{validations → validatable}/format_spec.rb +6 -6
  426. data/spec/mongoid/{validations → validatable}/length_spec.rb +7 -7
  427. data/spec/mongoid/{validations → validatable}/numericality_spec.rb +1 -1
  428. data/spec/mongoid/{validations → validatable}/presence_spec.rb +31 -38
  429. data/spec/mongoid/{validations → validatable}/uniqueness_spec.rb +126 -183
  430. data/spec/mongoid/{validations_spec.rb → validatable_spec.rb} +28 -28
  431. data/spec/mongoid_spec.rb +8 -8
  432. data/spec/rails/mongoid_spec.rb +72 -87
  433. data/spec/spec_helper.rb +19 -17
  434. metadata +261 -283
  435. data/lib/mongoid/atomic/positionable.rb +0 -73
  436. data/lib/mongoid/components.rb +0 -92
  437. data/lib/mongoid/config/inflections.rb +0 -6
  438. data/lib/mongoid/contextual/eager.rb +0 -158
  439. data/lib/mongoid/criterion/findable.rb +0 -179
  440. data/lib/mongoid/errors/versioning_not_on_root.rb +0 -23
  441. data/lib/mongoid/identity_map.rb +0 -163
  442. data/lib/mongoid/json.rb +0 -16
  443. data/lib/mongoid/matchers.rb +0 -32
  444. data/lib/mongoid/matchers/strategies.rb +0 -97
  445. data/lib/mongoid/multi_parameter_attributes.rb +0 -105
  446. data/lib/mongoid/nested_attributes.rb +0 -78
  447. data/lib/mongoid/observer.rb +0 -192
  448. data/lib/mongoid/paranoia.rb +0 -136
  449. data/lib/mongoid/persistence.rb +0 -357
  450. data/lib/mongoid/persistence/atomic.rb +0 -231
  451. data/lib/mongoid/persistence/atomic/add_to_set.rb +0 -47
  452. data/lib/mongoid/persistence/atomic/bit.rb +0 -35
  453. data/lib/mongoid/persistence/atomic/inc.rb +0 -45
  454. data/lib/mongoid/persistence/atomic/operation.rb +0 -154
  455. data/lib/mongoid/persistence/atomic/pop.rb +0 -32
  456. data/lib/mongoid/persistence/atomic/pull.rb +0 -32
  457. data/lib/mongoid/persistence/atomic/pull_all.rb +0 -32
  458. data/lib/mongoid/persistence/atomic/push.rb +0 -25
  459. data/lib/mongoid/persistence/atomic/push_all.rb +0 -25
  460. data/lib/mongoid/persistence/atomic/rename.rb +0 -30
  461. data/lib/mongoid/persistence/atomic/sets.rb +0 -28
  462. data/lib/mongoid/persistence/atomic/unset.rb +0 -27
  463. data/lib/mongoid/persistence/deletion.rb +0 -31
  464. data/lib/mongoid/persistence/insertion.rb +0 -38
  465. data/lib/mongoid/persistence/modification.rb +0 -35
  466. data/lib/mongoid/persistence/operations.rb +0 -214
  467. data/lib/mongoid/persistence/operations/embedded/insert.rb +0 -46
  468. data/lib/mongoid/persistence/operations/embedded/remove.rb +0 -43
  469. data/lib/mongoid/persistence/operations/insert.rb +0 -34
  470. data/lib/mongoid/persistence/operations/remove.rb +0 -33
  471. data/lib/mongoid/persistence/operations/update.rb +0 -59
  472. data/lib/mongoid/persistence/operations/upsert.rb +0 -28
  473. data/lib/mongoid/persistence/upsertion.rb +0 -31
  474. data/lib/mongoid/unit_of_work.rb +0 -61
  475. data/lib/mongoid/versioning.rb +0 -217
  476. data/lib/rack/mongoid.rb +0 -2
  477. data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
  478. data/lib/rails/generators/mongoid/observer/observer_generator.rb +0 -17
  479. data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +0 -4
  480. data/spec/app/models/actor_observer.rb +0 -15
  481. data/spec/app/models/callback_recorder.rb +0 -25
  482. data/spec/app/models/draft.rb +0 -9
  483. data/spec/app/models/paranoid_phone.rb +0 -25
  484. data/spec/app/models/paranoid_post.rb +0 -36
  485. data/spec/app/models/phone_observer.rb +0 -6
  486. data/spec/mongoid/#atomic_spec.rb# +0 -365
  487. data/spec/mongoid/attributes/processing_spec.rb +0 -149
  488. data/spec/mongoid/criterion/destructive_spec.rb +0 -101
  489. data/spec/mongoid/criterion/modifiable_spec.rb +0 -409
  490. data/spec/mongoid/criterion/modification_spec.rb +0 -402
  491. data/spec/mongoid/errors/versioning_not_on_root_spec.rb +0 -29
  492. data/spec/mongoid/identity_map_spec.rb +0 -564
  493. data/spec/mongoid/json_spec.rb +0 -33
  494. data/spec/mongoid/matchers/in_spec.rb +0 -25
  495. data/spec/mongoid/matchers/nin_spec.rb +0 -25
  496. data/spec/mongoid/multi_parameter_attributes_spec.rb +0 -128
  497. data/spec/mongoid/observer_spec.rb +0 -290
  498. data/spec/mongoid/paranoia_spec.rb +0 -759
  499. data/spec/mongoid/persistence/atomic/add_to_set_spec.rb +0 -262
  500. data/spec/mongoid/persistence/atomic/bit_spec.rb +0 -88
  501. data/spec/mongoid/persistence/atomic/inc_spec.rb +0 -133
  502. data/spec/mongoid/persistence/atomic/pop_spec.rb +0 -111
  503. data/spec/mongoid/persistence/atomic/pull_all_spec.rb +0 -77
  504. data/spec/mongoid/persistence/atomic/pull_spec.rb +0 -80
  505. data/spec/mongoid/persistence/atomic/push_all_spec.rb +0 -77
  506. data/spec/mongoid/persistence/atomic/push_spec.rb +0 -77
  507. data/spec/mongoid/persistence/atomic/rename_spec.rb +0 -42
  508. data/spec/mongoid/persistence/atomic/sets_spec.rb +0 -154
  509. data/spec/mongoid/persistence/atomic/unset_spec.rb +0 -65
  510. data/spec/mongoid/persistence/atomic_spec.rb +0 -216
  511. data/spec/mongoid/persistence/operations/embedded/insert_spec.rb +0 -191
  512. data/spec/mongoid/persistence/operations/embedded/remove_spec.rb +0 -8
  513. data/spec/mongoid/persistence/operations/insert_spec.rb +0 -149
  514. data/spec/mongoid/persistence/operations/remove_spec.rb +0 -113
  515. data/spec/mongoid/persistence/operations/update_spec.rb +0 -141
  516. data/spec/mongoid/persistence/operations/upsert_spec.rb +0 -59
  517. data/spec/mongoid/persistence/operations_spec.rb +0 -313
  518. data/spec/mongoid/persistence_spec.rb +0 -2279
  519. data/spec/mongoid/unit_of_work_spec.rb +0 -196
  520. data/spec/mongoid/versioning_spec.rb +0 -540
  521. data/spec/rack/mongoid/middleware/identity_map_spec.rb +0 -72
@@ -4,7 +4,6 @@ describe Mongoid::Relations::Referenced::ManyToMany do
4
4
 
5
5
  before(:all) do
6
6
  Mongoid.raise_not_found_error = true
7
- Person.autosaved_relations.delete_one(:preferences)
8
7
  Person.autosave(Person.relations["preferences"].merge!(autosave: true))
9
8
  Person.synced(Person.relations["preferences"])
10
9
  end
@@ -35,7 +34,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
35
34
  end
36
35
 
37
36
  it "persists the child document" do
38
- preference.should be_persisted
37
+ expect(preference).to be_persisted
39
38
  end
40
39
  end
41
40
 
@@ -67,7 +66,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
67
66
  end
68
67
 
69
68
  it "returns an array of loaded documents" do
70
- result.should eq([ preference ])
69
+ expect(result).to eq([ preference ])
71
70
  end
72
71
  end
73
72
 
@@ -86,7 +85,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
86
85
  end
87
86
 
88
87
  it "returns an array of loaded documents" do
89
- result.should eq([ preference ])
88
+ expect(result).to eq([ preference ])
90
89
  end
91
90
  end
92
91
 
@@ -107,11 +106,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
107
106
  end
108
107
 
109
108
  it "appends the document to the relation" do
110
- person.houses.should eq([ house ])
109
+ expect(person.houses).to eq([ house ])
111
110
  end
112
111
 
113
112
  it "sets the foreign key on the relation" do
114
- person.house_ids.should eq([ house.id ])
113
+ expect(person.house_ids).to eq([ house.id ])
115
114
  end
116
115
  end
117
116
 
@@ -128,27 +127,27 @@ describe Mongoid::Relations::Referenced::ManyToMany do
128
127
  end
129
128
 
130
129
  it "adds the documents to the relation" do
131
- person.preferences.should eq([ preference ])
130
+ expect(person.preferences).to eq([ preference ])
132
131
  end
133
132
 
134
133
  it "sets the foreign key on the relation" do
135
- person.preference_ids.should eq([ preference.id ])
134
+ expect(person.preference_ids).to eq([ preference.id ])
136
135
  end
137
136
 
138
137
  it "sets the foreign key on the inverse relation" do
139
- preference.person_ids.should eq([ person.id ])
138
+ expect(preference.person_ids).to eq([ person.id ])
140
139
  end
141
140
 
142
141
  it "saves the target" do
143
- preference.should be_persisted
142
+ expect(preference).to be_persisted
144
143
  end
145
144
 
146
145
  it "adds the correct number of documents" do
147
- person.preferences.size.should eq(1)
146
+ expect(person.preferences.size).to eq(1)
148
147
  end
149
148
 
150
149
  it "persists the link" do
151
- person.reload.preferences.should eq([ preference ])
150
+ expect(person.reload.preferences).to eq([ preference ])
152
151
  end
153
152
  end
154
153
 
@@ -169,23 +168,23 @@ describe Mongoid::Relations::Referenced::ManyToMany do
169
168
  end
170
169
 
171
170
  it "adds the documents to the relation" do
172
- person.preferences.should eq([ preference ])
171
+ expect(person.preferences).to eq([ preference ])
173
172
  end
174
173
 
175
174
  it "sets the foreign key on the relation" do
176
- person.preference_ids.should eq([ preference.id ])
175
+ expect(person.preference_ids).to eq([ preference.id ])
177
176
  end
178
177
 
179
178
  it "sets the foreign key on the inverse relation" do
180
- preference.person_ids.should eq([ person.id ])
179
+ expect(preference.person_ids).to eq([ person.id ])
181
180
  end
182
181
 
183
182
  it "does not save the target" do
184
- preference.should be_new_record
183
+ expect(preference).to be_new_record
185
184
  end
186
185
 
187
186
  it "adds the correct number of documents" do
188
- person.preferences.size.should eq(1)
187
+ expect(person.preferences.size).to eq(1)
189
188
  end
190
189
 
191
190
  context "when appending a second time" do
@@ -195,11 +194,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
195
194
  end
196
195
 
197
196
  it "does not allow the document to be added again" do
198
- person.preferences.should eq([ preference ])
197
+ expect(person.preferences).to eq([ preference ])
199
198
  end
200
199
 
201
200
  it "does not allow duplicate ids" do
202
- person.preference_ids.should eq([ preference.id ])
201
+ expect(person.preference_ids).to eq([ preference.id ])
203
202
  end
204
203
  end
205
204
  end
@@ -220,27 +219,27 @@ describe Mongoid::Relations::Referenced::ManyToMany do
220
219
  end
221
220
 
222
221
  it "adds the documents to the relation" do
223
- person.preferences.should eq([ preference ])
222
+ expect(person.preferences).to eq([ preference ])
224
223
  end
225
224
 
226
225
  it "sets the foreign key on the relation" do
227
- person.preference_ids.should eq([ preference.id ])
226
+ expect(person.preference_ids).to eq([ preference.id ])
228
227
  end
229
228
 
230
229
  it "sets the foreign key on the inverse relation" do
231
- preference.person_ids.should eq([ person.id ])
230
+ expect(preference.person_ids).to eq([ person.id ])
232
231
  end
233
232
 
234
233
  it "saves the target" do
235
- preference.should be_persisted
234
+ expect(preference).to be_persisted
236
235
  end
237
236
 
238
237
  it "adds the correct number of documents" do
239
- person.preferences.size.should eq(1)
238
+ expect(person.preferences.size).to eq(1)
240
239
  end
241
240
 
242
241
  it "persists the link" do
243
- person.reload.preferences.should eq([ preference ])
242
+ expect(person.reload.preferences).to eq([ preference ])
244
243
  end
245
244
  end
246
245
 
@@ -263,23 +262,23 @@ describe Mongoid::Relations::Referenced::ManyToMany do
263
262
  end
264
263
 
265
264
  it "adds the documents to the relation" do
266
- person.preferences.should eq([ preference ])
265
+ expect(person.preferences).to eq([ preference ])
267
266
  end
268
267
 
269
268
  it "sets the foreign key on the relation" do
270
- person.preference_ids.should eq([ preference.id ])
269
+ expect(person.preference_ids).to eq([ preference.id ])
271
270
  end
272
271
 
273
272
  it "sets the foreign key on the inverse relation" do
274
- preference.reload.person_ids.should eq([ person.id ])
273
+ expect(preference.reload.person_ids).to eq([ person.id ])
275
274
  end
276
275
 
277
276
  it "adds the correct number of documents" do
278
- person.preferences.size.should eq(1)
277
+ expect(person.preferences.size).to eq(1)
279
278
  end
280
279
 
281
280
  it "persists the link" do
282
- person.reload.preferences.should eq([ preference ])
281
+ expect(person.reload.preferences).to eq([ preference ])
283
282
  end
284
283
  end
285
284
  end
@@ -299,31 +298,31 @@ describe Mongoid::Relations::Referenced::ManyToMany do
299
298
  end
300
299
 
301
300
  it "adds the documents to the relation" do
302
- person.preferences.should eq([ preference ])
301
+ expect(person.preferences).to eq([ preference ])
303
302
  end
304
303
 
305
304
  it "sets the foreign key on the relation" do
306
- person.preference_ids.should eq([ preference.id ])
305
+ expect(person.preference_ids).to eq([ preference.id ])
307
306
  end
308
307
 
309
308
  it "sets the foreign key on the inverse relation" do
310
- preference.person_ids.should eq([ person.id ])
309
+ expect(preference.person_ids).to eq([ person.id ])
311
310
  end
312
311
 
313
312
  it "sets the base on the inverse relation" do
314
- preference.people.should eq([ person ])
313
+ expect(preference.people).to eq([ person ])
315
314
  end
316
315
 
317
316
  it "sets the same instance on the inverse relation" do
318
- preference.people.first.should eql(person)
317
+ expect(preference.people.first).to eql(person)
319
318
  end
320
319
 
321
320
  it "saves the target" do
322
- preference.should_not be_new_record
321
+ expect(preference).to_not be_new_record
323
322
  end
324
323
 
325
324
  it "adds the document to the target" do
326
- person.preferences.count.should eq(1)
325
+ expect(person.preferences.count).to eq(1)
327
326
  end
328
327
 
329
328
  context "when documents already exist on the relation" do
@@ -337,31 +336,31 @@ describe Mongoid::Relations::Referenced::ManyToMany do
337
336
  end
338
337
 
339
338
  it "adds the documents to the relation" do
340
- person.preferences.should eq([ preference, preference_two ])
339
+ expect(person.preferences).to eq([ preference, preference_two ])
341
340
  end
342
341
 
343
342
  it "sets the foreign key on the relation" do
344
- person.preference_ids.should eq([ preference.id, preference_two.id ])
343
+ expect(person.preference_ids).to eq([ preference.id, preference_two.id ])
345
344
  end
346
345
 
347
346
  it "sets the foreign key on the inverse relation" do
348
- preference_two.person_ids.should eq([ person.id ])
347
+ expect(preference_two.person_ids).to eq([ person.id ])
349
348
  end
350
349
 
351
350
  it "sets the base on the inverse relation" do
352
- preference_two.people.should eq([ person ])
351
+ expect(preference_two.people).to eq([ person ])
353
352
  end
354
353
 
355
354
  it "sets the same instance on the inverse relation" do
356
- preference_two.people.first.should eql(person)
355
+ expect(preference_two.people.first).to eql(person)
357
356
  end
358
357
 
359
358
  it "saves the target" do
360
- preference.should_not be_new_record
359
+ expect(preference).to_not be_new_record
361
360
  end
362
361
 
363
362
  it "adds the document to the target" do
364
- person.preferences.count.should eq(2)
363
+ expect(person.preferences.count).to eq(2)
365
364
  end
366
365
  end
367
366
  end
@@ -381,21 +380,21 @@ describe Mongoid::Relations::Referenced::ManyToMany do
381
380
  end
382
381
 
383
382
  it "sets the front side of the relation" do
384
- person.administrated_events.should eq([ event ])
383
+ expect(person.administrated_events).to eq([ event ])
385
384
  end
386
385
 
387
386
  it "sets the inverse side of the relation" do
388
- event.administrators(true).should eq([ person ])
387
+ expect(event.administrators(true)).to eq([ person ])
389
388
  end
390
389
 
391
390
  context "when reloading" do
392
391
 
393
392
  it "sets the front side of the relation" do
394
- person.reload.administrated_events.should eq([ event ])
393
+ expect(person.reload.administrated_events).to eq([ event ])
395
394
  end
396
395
 
397
396
  it "sets the inverse side of the relation" do
398
- event.reload.administrators.should eq([ person ])
397
+ expect(event.reload.administrators).to eq([ person ])
399
398
  end
400
399
  end
401
400
 
@@ -410,11 +409,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
410
409
  end
411
410
 
412
411
  it "sets the front side of the relation" do
413
- loaded_person.administrated_events.should eq([ event ])
412
+ expect(loaded_person.administrated_events).to eq([ event ])
414
413
  end
415
414
 
416
415
  it "sets the inverse side of the relation" do
417
- loaded_event.administrators.should eq([ person ])
416
+ expect(loaded_event.administrators).to eq([ person ])
418
417
  end
419
418
  end
420
419
  end
@@ -438,7 +437,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
438
437
  end
439
438
 
440
439
  it "creates a single artwork object" do
441
- Artwork.count.should eq(1)
440
+ expect(Artwork.count).to eq(1)
442
441
  end
443
442
  end
444
443
 
@@ -457,21 +456,21 @@ describe Mongoid::Relations::Referenced::ManyToMany do
457
456
  end
458
457
 
459
458
  it "sets the front side of the relation" do
460
- tag_one.related.should eq([ tag_two ])
459
+ expect(tag_one.related).to eq([ tag_two ])
461
460
  end
462
461
 
463
462
  it "sets the inverse side of the relation" do
464
- tag_two.related(true).should eq([ tag_one ])
463
+ expect(tag_two.related(true)).to eq([ tag_one ])
465
464
  end
466
465
 
467
466
  context "when reloading" do
468
467
 
469
468
  it "sets the front side of the relation" do
470
- tag_one.reload.related.should eq([ tag_two ])
469
+ expect(tag_one.reload.related).to eq([ tag_two ])
471
470
  end
472
471
 
473
472
  it "sets the inverse side of the relation" do
474
- tag_two.reload.related.should eq([ tag_one ])
473
+ expect(tag_two.reload.related).to eq([ tag_one ])
475
474
  end
476
475
  end
477
476
 
@@ -486,11 +485,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
486
485
  end
487
486
 
488
487
  it "sets the front side of the relation" do
489
- loaded_tag_one.related.should eq([ tag_two ])
488
+ expect(loaded_tag_one.related).to eq([ tag_two ])
490
489
  end
491
490
 
492
491
  it "sets the inverse side of the relation" do
493
- loaded_tag_two.related.should eq([ tag_one ])
492
+ expect(loaded_tag_two.related).to eq([ tag_one ])
494
493
  end
495
494
  end
496
495
  end
@@ -510,7 +509,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
510
509
 
511
510
  it "executes the callback" do
512
511
  post.tags.send(method, tag)
513
- post.before_add_called.should be_true
512
+ expect(post.before_add_called).to be true
514
513
  end
515
514
 
516
515
  context "when errors are raised" do
@@ -523,7 +522,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
523
522
  expect {
524
523
  post.tags.send(method, tag)
525
524
  }.to raise_error
526
- post.tags.should be_empty
525
+ expect(post.tags).to be_empty
527
526
  end
528
527
  end
529
528
  end
@@ -532,7 +531,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
532
531
 
533
532
  it "executes the callback" do
534
533
  post.tags.send(method, tag)
535
- post.after_add_called.should be_true
534
+ expect(post.after_add_called).to be true
536
535
  end
537
536
 
538
537
  context "when errors are raised" do
@@ -545,7 +544,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
545
544
  expect {
546
545
  post.tags.send(method, tag)
547
546
  }.to raise_error
548
- post.tags.should eq([ tag ])
547
+ expect(post.tags).to eq([ tag ])
549
548
  end
550
549
  end
551
550
  end
@@ -572,11 +571,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
572
571
  context "when the document is new" do
573
572
 
574
573
  it "does not add the duplicates" do
575
- person.preferences.should eq([ preference ])
574
+ expect(person.preferences).to eq([ preference ])
576
575
  end
577
576
 
578
577
  it "does not create duplicate keys" do
579
- person.preference_ids.should eq([ preference.id ])
578
+ expect(person.preference_ids).to eq([ preference.id ])
580
579
  end
581
580
  end
582
581
 
@@ -587,19 +586,29 @@ describe Mongoid::Relations::Referenced::ManyToMany do
587
586
  end
588
587
 
589
588
  it "does not add the duplicates" do
590
- person.preferences.should eq([ preference ])
589
+ expect(person.preferences).to eq([ preference ])
591
590
  end
592
591
 
593
592
  it "does not create duplicate keys" do
594
- person.preference_ids.should eq([ preference.id ])
593
+ expect(person.preference_ids).to eq([ preference.id ])
595
594
  end
596
595
 
597
596
  it "does not add duplicates on the inverse" do
598
- preference.people.should eq([ person ])
597
+ expect(preference.people).to eq([ person ])
599
598
  end
600
599
 
601
600
  it "does not add duplicate inverse keys" do
602
- preference.person_ids.should eq([ person.id ])
601
+ expect(preference.person_ids).to eq([ person.id ])
602
+ end
603
+
604
+ context "when reloading document from db" do
605
+
606
+ let(:from_db) { Preference.last }
607
+
608
+ it "does not create duplicate keys" do
609
+ person.preferences = [ from_db ]
610
+ expect(from_db.person_ids).to eq([ person.id ])
611
+ end
603
612
  end
604
613
  end
605
614
  end
@@ -621,19 +630,19 @@ describe Mongoid::Relations::Referenced::ManyToMany do
621
630
  end
622
631
 
623
632
  it "sets the relation" do
624
- person.preferences.should eq([ preference ])
633
+ expect(person.preferences).to eq([ preference ])
625
634
  end
626
635
 
627
636
  it "sets the foreign key on the relation" do
628
- person.preference_ids.should eq([ preference.id ])
637
+ expect(person.preference_ids).to eq([ preference.id ])
629
638
  end
630
639
 
631
640
  it "sets the foreign key on the inverse relation" do
632
- preference.person_ids.should eq([ person.id ])
641
+ expect(preference.person_ids).to eq([ person.id ])
633
642
  end
634
643
 
635
644
  it "does not save the target" do
636
- preference.should be_new_record
645
+ expect(preference).to be_new_record
637
646
  end
638
647
  end
639
648
 
@@ -652,15 +661,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
652
661
  end
653
662
 
654
663
  it "sets the relation" do
655
- person.preferences.should eq([ preference ])
664
+ expect(person.preferences).to eq([ preference ])
656
665
  end
657
666
 
658
667
  it "sets the foreign key on the relation" do
659
- person.preference_ids.should eq([ preference.id ])
668
+ expect(person.preference_ids).to eq([ preference.id ])
660
669
  end
661
670
 
662
671
  it "sets the foreign key on the inverse relation" do
663
- preference.person_ids.should eq([ person.id ])
672
+ expect(preference.person_ids).to eq([ person.id ])
664
673
  end
665
674
 
666
675
  context "and the parent is persisted" do
@@ -671,19 +680,19 @@ describe Mongoid::Relations::Referenced::ManyToMany do
671
680
  end
672
681
 
673
682
  it "maintains the relation" do
674
- person.preferences.should eq([ preference ])
683
+ expect(person.preferences).to eq([ preference ])
675
684
  end
676
685
 
677
686
  it "maintains the foreign key on the relation" do
678
- person.preference_ids.should eq([ preference.id ])
687
+ expect(person.preference_ids).to eq([ preference.id ])
679
688
  end
680
689
 
681
690
  it "maintains the foreign key on the inverse relation" do
682
- preference.person_ids.should eq([ person.id ])
691
+ expect(preference.person_ids).to eq([ person.id ])
683
692
  end
684
693
 
685
694
  it "maintains the base on the inverse relation" do
686
- preference.people.first.should eq(person)
695
+ expect(preference.people.first).to eq(person)
687
696
  end
688
697
  end
689
698
  end
@@ -703,23 +712,23 @@ describe Mongoid::Relations::Referenced::ManyToMany do
703
712
  end
704
713
 
705
714
  it "sets the relation" do
706
- person.preferences.should eq([ preference ])
715
+ expect(person.preferences).to eq([ preference ])
707
716
  end
708
717
 
709
718
  it "sets the foreign key on the relation" do
710
- person.preference_ids.should eq([ preference.id ])
719
+ expect(person.preference_ids).to eq([ preference.id ])
711
720
  end
712
721
 
713
722
  it "sets the foreign key on the inverse relation" do
714
- preference.person_ids.should eq([ person.id ])
723
+ expect(preference.person_ids).to eq([ person.id ])
715
724
  end
716
725
 
717
726
  it "sets the base on the inverse relation" do
718
- preference.people.first.should eq(person)
727
+ expect(preference.people.first).to eq(person)
719
728
  end
720
729
 
721
730
  it "saves the target" do
722
- preference.should be_persisted
731
+ expect(preference).to be_persisted
723
732
  end
724
733
 
725
734
  it "persists the relation" do
@@ -737,19 +746,19 @@ describe Mongoid::Relations::Referenced::ManyToMany do
737
746
  end
738
747
 
739
748
  it "sets the relation" do
740
- person.preferences.should eq([ another_preference ])
749
+ expect(person.preferences).to eq([ another_preference ])
741
750
  end
742
751
 
743
752
  it "saves the target" do
744
- another_preference.should be_persisted
753
+ expect(another_preference).to be_persisted
745
754
  end
746
755
 
747
756
  it "does not leave foreign keys of the previous relation" do
748
- person.preference_ids.should eq([ another_preference.id ])
757
+ expect(person.preference_ids).to eq([ another_preference.id ])
749
758
  end
750
759
 
751
760
  it "clears its own key on the foreign relation" do
752
- preference.person_ids.should be_empty
761
+ expect(preference.person_ids).to be_empty
753
762
  end
754
763
 
755
764
  context "and then overwriting it again with the same value" do
@@ -759,7 +768,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
759
768
  end
760
769
 
761
770
  it "persists the relation between another_preference and person" do
762
- another_preference.reload.people.should eq([ person ])
771
+ expect(another_preference.reload.people).to eq([ person ])
763
772
  end
764
773
 
765
774
  end
@@ -772,15 +781,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
772
781
  end
773
782
 
774
783
  it "persists the relation between person and another_preference" do
775
- person.preferences.should eq([ another_preference ])
784
+ expect(person.preferences).to eq([ another_preference ])
776
785
  end
777
786
 
778
787
  it "persists the relation between another_prefrence and person" do
779
- another_preference.people.should eq([ person ])
788
+ expect(another_preference.people).to eq([ person ])
780
789
  end
781
790
 
782
791
  it "no longer has any relation between preference and person" do
783
- preference.people.should be_empty
792
+ expect(preference.people).to be_empty
784
793
  end
785
794
  end
786
795
 
@@ -793,15 +802,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
793
802
  end
794
803
 
795
804
  it "persists the relation between person and another_preference" do
796
- person.preferences.should eq([ another_preference ])
805
+ expect(person.preferences).to eq([ another_preference ])
797
806
  end
798
807
 
799
808
  it "persists the relation between another_prefrence and person" do
800
- another_preference.people.should eq([ person ])
809
+ expect(another_preference.people).to eq([ person ])
801
810
  end
802
811
 
803
812
  it "no longer has any relation between preference and person" do
804
- preference.people.should be_empty
813
+ expect(preference.people).to be_empty
805
814
  end
806
815
  end
807
816
  end
@@ -831,11 +840,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
831
840
  end
832
841
 
833
842
  it "clears the relation" do
834
- person.houses.should be_empty
843
+ expect(person.houses).to be_empty
835
844
  end
836
845
 
837
846
  it "clears the foreign keys" do
838
- person.house_ids.should be_empty
847
+ expect(person.house_ids).to be_empty
839
848
  end
840
849
  end
841
850
 
@@ -855,19 +864,19 @@ describe Mongoid::Relations::Referenced::ManyToMany do
855
864
  end
856
865
 
857
866
  it "sets the relation to an empty array" do
858
- person.preferences.should be_empty
867
+ expect(person.preferences).to be_empty
859
868
  end
860
869
 
861
870
  it "removed the inverse relation" do
862
- preference.people.should be_empty
871
+ expect(preference.people).to be_empty
863
872
  end
864
873
 
865
874
  it "removes the foreign key values" do
866
- person.preference_ids.should be_empty
875
+ expect(person.preference_ids).to be_empty
867
876
  end
868
877
 
869
878
  it "removes the inverse foreign key values" do
870
- preference.person_ids.should be_empty
879
+ expect(preference.person_ids).to be_empty
871
880
  end
872
881
  end
873
882
 
@@ -889,23 +898,23 @@ describe Mongoid::Relations::Referenced::ManyToMany do
889
898
  end
890
899
 
891
900
  it "sets the relation to an empty array" do
892
- person.preferences.should be_empty
901
+ expect(person.preferences).to be_empty
893
902
  end
894
903
 
895
904
  it "removed the inverse relation" do
896
- preference.people.should be_empty
905
+ expect(preference.people).to be_empty
897
906
  end
898
907
 
899
908
  it "removes the foreign key values" do
900
- person.preference_ids.should be_empty
909
+ expect(person.preference_ids).to be_empty
901
910
  end
902
911
 
903
912
  it "removes the inverse foreign key values" do
904
- preference.person_ids.should be_empty
913
+ expect(preference.person_ids).to be_empty
905
914
  end
906
915
 
907
916
  it "does not delete the target from the database" do
908
- preference.should_not be_destroyed
917
+ expect(preference).to_not be_destroyed
909
918
  end
910
919
  end
911
920
 
@@ -930,11 +939,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
930
939
  end
931
940
 
932
941
  it "sets the relation to an empty array" do
933
- from_db.preferences.should be_empty
942
+ expect(from_db.preferences).to be_empty
934
943
  end
935
944
 
936
945
  it "removes the foreign key values" do
937
- from_db.preference_ids.should be_empty
946
+ expect(from_db.preference_ids).to be_empty
938
947
  end
939
948
  end
940
949
  end
@@ -946,28 +955,6 @@ describe Mongoid::Relations::Referenced::ManyToMany do
946
955
 
947
956
  describe "##{method}" do
948
957
 
949
- context "when providing scoped mass assignment" do
950
-
951
- let(:person) do
952
- Person.new
953
- end
954
-
955
- let(:house) do
956
- person.houses.send(
957
- method,
958
- { name: "Dream", model: "Home" }, as: :admin
959
- )
960
- end
961
-
962
- it "sets the attributes for the provided role" do
963
- house.name.should eq("Dream")
964
- end
965
-
966
- it "does not set the attributes for other roles" do
967
- house.model.should be_nil
968
- end
969
- end
970
-
971
958
  context "when the relation is not polymorphic" do
972
959
 
973
960
  context "when the parent is a new record" do
@@ -981,27 +968,27 @@ describe Mongoid::Relations::Referenced::ManyToMany do
981
968
  end
982
969
 
983
970
  it "adds the document to the relation" do
984
- person.preferences.should eq([ preference ])
971
+ expect(person.preferences).to eq([ preference ])
985
972
  end
986
973
 
987
974
  it "sets the foreign key on the relation" do
988
- person.preference_ids.should eq([ preference.id ])
975
+ expect(person.preference_ids).to eq([ preference.id ])
989
976
  end
990
977
 
991
978
  it "sets the inverse foreign key on the relation" do
992
- preference.person_ids.should eq([ person.id ])
979
+ expect(preference.person_ids).to eq([ person.id ])
993
980
  end
994
981
 
995
982
  it "sets the attributes" do
996
- preference.name.should eq("settings")
983
+ expect(preference.name).to eq("settings")
997
984
  end
998
985
 
999
986
  it "does not save the target" do
1000
- preference.should be_new_record
987
+ expect(preference).to be_new_record
1001
988
  end
1002
989
 
1003
990
  it "adds the correct number of documents" do
1004
- person.preferences.size.should eq(1)
991
+ expect(person.preferences.size).to eq(1)
1005
992
  end
1006
993
  end
1007
994
 
@@ -1016,31 +1003,31 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1016
1003
  end
1017
1004
 
1018
1005
  it "adds the document to the relation" do
1019
- person.preferences.should eq([ preference ])
1006
+ expect(person.preferences).to eq([ preference ])
1020
1007
  end
1021
1008
 
1022
1009
  it "sets the foreign key on the relation" do
1023
- person.preference_ids.should eq([ preference.id ])
1010
+ expect(person.preference_ids).to eq([ preference.id ])
1024
1011
  end
1025
1012
 
1026
1013
  it "sets the inverse foreign key on the relation" do
1027
- preference.person_ids.should eq([ person.id ])
1014
+ expect(preference.person_ids).to eq([ person.id ])
1028
1015
  end
1029
1016
 
1030
1017
  it "sets the base on the inverse relation" do
1031
- preference.people.should eq([ person ])
1018
+ expect(preference.people).to eq([ person ])
1032
1019
  end
1033
1020
 
1034
1021
  it "sets the attributes" do
1035
- preference.name.should eq("settings")
1022
+ expect(preference.name).to eq("settings")
1036
1023
  end
1037
1024
 
1038
1025
  it "does not save the target" do
1039
- preference.should be_new_record
1026
+ expect(preference).to be_new_record
1040
1027
  end
1041
1028
 
1042
1029
  it "adds the correct number of documents" do
1043
- person.preferences.size.should eq(1)
1030
+ expect(person.preferences.size).to eq(1)
1044
1031
  end
1045
1032
 
1046
1033
  context "when saving the target" do
@@ -1050,7 +1037,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1050
1037
  end
1051
1038
 
1052
1039
  it "persists the parent keys" do
1053
- person.reload.preference_ids.should eq([ preference.id ])
1040
+ expect(person.reload.preference_ids).to eq([ preference.id ])
1054
1041
  end
1055
1042
  end
1056
1043
  end
@@ -1065,16 +1052,17 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1065
1052
  end
1066
1053
 
1067
1054
  let(:document) do
1068
- stub
1055
+ double
1069
1056
  end
1070
1057
 
1071
1058
  let(:metadata) do
1072
- stub(extension?: false)
1059
+ double(extension?: false)
1073
1060
  end
1074
1061
 
1075
1062
  it "returns the embedded in builder" do
1076
- described_class.builder(nil, metadata, document).should
1077
- be_a_kind_of(builder_klass)
1063
+ expect(
1064
+ described_class.builder(nil, metadata, document)
1065
+ ).to be_a_kind_of(builder_klass)
1078
1066
  end
1079
1067
  end
1080
1068
 
@@ -1099,31 +1087,31 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1099
1087
  end
1100
1088
 
1101
1089
  it "clears out the relation" do
1102
- person.preferences.should be_empty
1090
+ expect(person.preferences).to be_empty
1103
1091
  end
1104
1092
 
1105
1093
  it "removes the parent from the inverse relation" do
1106
- preference.people.should_not include(person)
1094
+ expect(preference.people).to_not include(person)
1107
1095
  end
1108
1096
 
1109
1097
  it "removes the foreign keys" do
1110
- person.preference_ids.should be_empty
1098
+ expect(person.preference_ids).to be_empty
1111
1099
  end
1112
1100
 
1113
1101
  it "removes the parent key from the inverse" do
1114
- preference.person_ids.should_not include(person.id)
1102
+ expect(preference.person_ids).to_not include(person.id)
1115
1103
  end
1116
1104
 
1117
1105
  it "does not delete the documents" do
1118
- preference.should_not be_destroyed
1106
+ expect(preference).to_not be_destroyed
1119
1107
  end
1120
1108
 
1121
1109
  it "persists the nullification" do
1122
- person.reload.preferences.should be_empty
1110
+ expect(person.reload.preferences).to be_empty
1123
1111
  end
1124
1112
 
1125
1113
  it "returns the relation" do
1126
- relation.should be_empty
1114
+ expect(relation).to be_empty
1127
1115
  end
1128
1116
  end
1129
1117
 
@@ -1138,7 +1126,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1138
1126
  end
1139
1127
 
1140
1128
  it "clears out the relation" do
1141
- person.preferences.should be_empty
1129
+ expect(person.preferences).to be_empty
1142
1130
  end
1143
1131
  end
1144
1132
  end
@@ -1158,7 +1146,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1158
1146
  end
1159
1147
 
1160
1148
  it "clears out the relation" do
1161
- person.preferences.should be_empty
1149
+ expect(person.preferences).to be_empty
1162
1150
  end
1163
1151
  end
1164
1152
  end
@@ -1186,11 +1174,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1186
1174
  end
1187
1175
 
1188
1176
  it "executes the callback" do
1189
- post.before_remove_called.should be_true
1177
+ expect(post.before_remove_called).to be true
1190
1178
  end
1191
1179
 
1192
1180
  it "removes the document from the relation" do
1193
- post.tags.should be_empty
1181
+ expect(post.tags).to be_empty
1194
1182
  end
1195
1183
  end
1196
1184
 
@@ -1204,7 +1192,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1204
1192
  expect {
1205
1193
  post.tags.clear
1206
1194
  }.to raise_error
1207
- post.tags.should eq([ tag ])
1195
+ expect(post.tags).to eq([ tag ])
1208
1196
  end
1209
1197
  end
1210
1198
  end
@@ -1218,11 +1206,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1218
1206
  end
1219
1207
 
1220
1208
  it "executes the callback" do
1221
- post.after_remove_called.should be_true
1209
+ expect(post.after_remove_called).to be true
1222
1210
  end
1223
1211
 
1224
1212
  it "removes the document from the relation" do
1225
- post.tags.should be_empty
1213
+ expect(post.tags).to be_empty
1226
1214
  end
1227
1215
  end
1228
1216
 
@@ -1236,7 +1224,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1236
1224
  expect {
1237
1225
  post.tags.clear
1238
1226
  }.to raise_error
1239
- post.tags.should be_empty
1227
+ expect(post.tags).to be_empty
1240
1228
  end
1241
1229
  end
1242
1230
  end
@@ -1260,7 +1248,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1260
1248
  end
1261
1249
 
1262
1250
  it "returns an array of loaded documents" do
1263
- result.should eq([ preference ])
1251
+ expect(result).to eq([ preference ])
1264
1252
  end
1265
1253
  end
1266
1254
 
@@ -1279,7 +1267,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1279
1267
  end
1280
1268
 
1281
1269
  it "returns an array of loaded documents" do
1282
- result.should eq([ preference ])
1270
+ expect(result).to eq([ preference ])
1283
1271
  end
1284
1272
  end
1285
1273
 
@@ -1300,11 +1288,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1300
1288
  end
1301
1289
 
1302
1290
  it "appends the document to the relation" do
1303
- person.houses.should eq([ house ])
1291
+ expect(person.houses).to eq([ house ])
1304
1292
  end
1305
1293
 
1306
1294
  it "sets the foreign key on the relation" do
1307
- person.house_ids.should eq([ house.id ])
1295
+ expect(person.house_ids).to eq([ house.id ])
1308
1296
  end
1309
1297
  end
1310
1298
 
@@ -1321,27 +1309,27 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1321
1309
  end
1322
1310
 
1323
1311
  it "adds the documents to the relation" do
1324
- person.preferences.should eq([ preference ])
1312
+ expect(person.preferences).to eq([ preference ])
1325
1313
  end
1326
1314
 
1327
1315
  it "sets the foreign key on the relation" do
1328
- person.preference_ids.should eq([ preference.id ])
1316
+ expect(person.preference_ids).to eq([ preference.id ])
1329
1317
  end
1330
1318
 
1331
1319
  it "sets the foreign key on the inverse relation" do
1332
- preference.person_ids.should eq([ person.id ])
1320
+ expect(preference.person_ids).to eq([ person.id ])
1333
1321
  end
1334
1322
 
1335
1323
  it "saves the target" do
1336
- preference.should be_persisted
1324
+ expect(preference).to be_persisted
1337
1325
  end
1338
1326
 
1339
1327
  it "adds the correct number of documents" do
1340
- person.preferences.size.should eq(1)
1328
+ expect(person.preferences.size).to eq(1)
1341
1329
  end
1342
1330
 
1343
1331
  it "persists the link" do
1344
- person.reload.preferences.should eq([ preference ])
1332
+ expect(person.reload.preferences).to eq([ preference ])
1345
1333
  end
1346
1334
  end
1347
1335
 
@@ -1362,23 +1350,23 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1362
1350
  end
1363
1351
 
1364
1352
  it "adds the documents to the relation" do
1365
- person.preferences.should eq([ preference ])
1353
+ expect(person.preferences).to eq([ preference ])
1366
1354
  end
1367
1355
 
1368
1356
  it "sets the foreign key on the relation" do
1369
- person.preference_ids.should eq([ preference.id ])
1357
+ expect(person.preference_ids).to eq([ preference.id ])
1370
1358
  end
1371
1359
 
1372
1360
  it "sets the foreign key on the inverse relation" do
1373
- preference.person_ids.should eq([ person.id ])
1361
+ expect(preference.person_ids).to eq([ person.id ])
1374
1362
  end
1375
1363
 
1376
1364
  it "does not save the target" do
1377
- preference.should be_new_record
1365
+ expect(preference).to be_new_record
1378
1366
  end
1379
1367
 
1380
1368
  it "adds the correct number of documents" do
1381
- person.preferences.size.should eq(1)
1369
+ expect(person.preferences.size).to eq(1)
1382
1370
  end
1383
1371
 
1384
1372
  context "when appending a second time" do
@@ -1388,11 +1376,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1388
1376
  end
1389
1377
 
1390
1378
  it "does not allow the document to be added again" do
1391
- person.preferences.should eq([ preference ])
1379
+ expect(person.preferences).to eq([ preference ])
1392
1380
  end
1393
1381
 
1394
1382
  it "does not allow duplicate ids" do
1395
- person.preference_ids.should eq([ preference.id ])
1383
+ expect(person.preference_ids).to eq([ preference.id ])
1396
1384
  end
1397
1385
  end
1398
1386
  end
@@ -1413,27 +1401,27 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1413
1401
  end
1414
1402
 
1415
1403
  it "adds the documents to the relation" do
1416
- person.preferences.should eq([ preference ])
1404
+ expect(person.preferences).to eq([ preference ])
1417
1405
  end
1418
1406
 
1419
1407
  it "sets the foreign key on the relation" do
1420
- person.preference_ids.should eq([ preference.id ])
1408
+ expect(person.preference_ids).to eq([ preference.id ])
1421
1409
  end
1422
1410
 
1423
1411
  it "sets the foreign key on the inverse relation" do
1424
- preference.person_ids.should eq([ person.id ])
1412
+ expect(preference.person_ids).to eq([ person.id ])
1425
1413
  end
1426
1414
 
1427
1415
  it "saves the target" do
1428
- preference.should be_persisted
1416
+ expect(preference).to be_persisted
1429
1417
  end
1430
1418
 
1431
1419
  it "adds the correct number of documents" do
1432
- person.preferences.size.should eq(1)
1420
+ expect(person.preferences.size).to eq(1)
1433
1421
  end
1434
1422
 
1435
1423
  it "persists the link" do
1436
- person.reload.preferences.should eq([ preference ])
1424
+ expect(person.reload.preferences).to eq([ preference ])
1437
1425
  end
1438
1426
  end
1439
1427
 
@@ -1456,23 +1444,23 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1456
1444
  end
1457
1445
 
1458
1446
  it "adds the documents to the relation" do
1459
- person.preferences.should eq([ preference ])
1447
+ expect(person.preferences).to eq([ preference ])
1460
1448
  end
1461
1449
 
1462
1450
  it "sets the foreign key on the relation" do
1463
- person.preference_ids.should eq([ preference.id ])
1451
+ expect(person.preference_ids).to eq([ preference.id ])
1464
1452
  end
1465
1453
 
1466
1454
  it "sets the foreign key on the inverse relation" do
1467
- preference.reload.person_ids.should eq([ person.id ])
1455
+ expect(preference.reload.person_ids).to eq([ person.id ])
1468
1456
  end
1469
1457
 
1470
1458
  it "adds the correct number of documents" do
1471
- person.preferences.size.should eq(1)
1459
+ expect(person.preferences.size).to eq(1)
1472
1460
  end
1473
1461
 
1474
1462
  it "persists the link" do
1475
- person.reload.preferences.should eq([ preference ])
1463
+ expect(person.reload.preferences).to eq([ preference ])
1476
1464
  end
1477
1465
  end
1478
1466
  end
@@ -1492,31 +1480,31 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1492
1480
  end
1493
1481
 
1494
1482
  it "adds the documents to the relation" do
1495
- person.preferences.should eq([ preference ])
1483
+ expect(person.preferences).to eq([ preference ])
1496
1484
  end
1497
1485
 
1498
1486
  it "sets the foreign key on the relation" do
1499
- person.preference_ids.should eq([ preference.id ])
1487
+ expect(person.preference_ids).to eq([ preference.id ])
1500
1488
  end
1501
1489
 
1502
1490
  it "sets the foreign key on the inverse relation" do
1503
- preference.person_ids.should eq([ person.id ])
1491
+ expect(preference.person_ids).to eq([ person.id ])
1504
1492
  end
1505
1493
 
1506
1494
  it "sets the base on the inverse relation" do
1507
- preference.people.should eq([ person ])
1495
+ expect(preference.people).to eq([ person ])
1508
1496
  end
1509
1497
 
1510
1498
  it "sets the same instance on the inverse relation" do
1511
- preference.people.first.should eql(person)
1499
+ expect(preference.people.first).to eql(person)
1512
1500
  end
1513
1501
 
1514
1502
  it "saves the target" do
1515
- preference.should_not be_new_record
1503
+ expect(preference).to_not be_new_record
1516
1504
  end
1517
1505
 
1518
1506
  it "adds the document to the target" do
1519
- person.preferences.count.should eq(1)
1507
+ expect(person.preferences.count).to eq(1)
1520
1508
  end
1521
1509
 
1522
1510
  context "when documents already exist on the relation" do
@@ -1530,31 +1518,31 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1530
1518
  end
1531
1519
 
1532
1520
  it "adds the documents to the relation" do
1533
- person.preferences.should eq([ preference, preference_two ])
1521
+ expect(person.preferences).to eq([ preference, preference_two ])
1534
1522
  end
1535
1523
 
1536
1524
  it "sets the foreign key on the relation" do
1537
- person.preference_ids.should eq([ preference.id, preference_two.id ])
1525
+ expect(person.preference_ids).to eq([ preference.id, preference_two.id ])
1538
1526
  end
1539
1527
 
1540
1528
  it "sets the foreign key on the inverse relation" do
1541
- preference_two.person_ids.should eq([ person.id ])
1529
+ expect(preference_two.person_ids).to eq([ person.id ])
1542
1530
  end
1543
1531
 
1544
1532
  it "sets the base on the inverse relation" do
1545
- preference_two.people.should eq([ person ])
1533
+ expect(preference_two.people).to eq([ person ])
1546
1534
  end
1547
1535
 
1548
1536
  it "sets the same instance on the inverse relation" do
1549
- preference_two.people.first.should eql(person)
1537
+ expect(preference_two.people.first).to eql(person)
1550
1538
  end
1551
1539
 
1552
1540
  it "saves the target" do
1553
- preference.should_not be_new_record
1541
+ expect(preference).to_not be_new_record
1554
1542
  end
1555
1543
 
1556
1544
  it "adds the document to the target" do
1557
- person.preferences.count.should eq(2)
1545
+ expect(person.preferences.count).to eq(2)
1558
1546
  end
1559
1547
  end
1560
1548
  end
@@ -1574,21 +1562,21 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1574
1562
  end
1575
1563
 
1576
1564
  it "sets the front side of the relation" do
1577
- person.administrated_events.should eq([ event ])
1565
+ expect(person.administrated_events).to eq([ event ])
1578
1566
  end
1579
1567
 
1580
1568
  it "sets the inverse side of the relation" do
1581
- event.administrators(true).should eq([ person ])
1569
+ expect(event.administrators(true)).to eq([ person ])
1582
1570
  end
1583
1571
 
1584
1572
  context "when reloading" do
1585
1573
 
1586
1574
  it "sets the front side of the relation" do
1587
- person.reload.administrated_events.should eq([ event ])
1575
+ expect(person.reload.administrated_events).to eq([ event ])
1588
1576
  end
1589
1577
 
1590
1578
  it "sets the inverse side of the relation" do
1591
- event.reload.administrators.should eq([ person ])
1579
+ expect(event.reload.administrators).to eq([ person ])
1592
1580
  end
1593
1581
  end
1594
1582
 
@@ -1603,11 +1591,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1603
1591
  end
1604
1592
 
1605
1593
  it "sets the front side of the relation" do
1606
- loaded_person.administrated_events.should eq([ event ])
1594
+ expect(loaded_person.administrated_events).to eq([ event ])
1607
1595
  end
1608
1596
 
1609
1597
  it "sets the inverse side of the relation" do
1610
- loaded_event.administrators.should eq([ person ])
1598
+ expect(loaded_event.administrators).to eq([ person ])
1611
1599
  end
1612
1600
  end
1613
1601
  end
@@ -1631,7 +1619,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1631
1619
  end
1632
1620
 
1633
1621
  it "creates a single artwork object" do
1634
- Artwork.count.should eq(1)
1622
+ expect(Artwork.count).to eq(1)
1635
1623
  end
1636
1624
  end
1637
1625
 
@@ -1650,21 +1638,21 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1650
1638
  end
1651
1639
 
1652
1640
  it "sets the front side of the relation" do
1653
- tag_one.related.should eq([ tag_two ])
1641
+ expect(tag_one.related).to eq([ tag_two ])
1654
1642
  end
1655
1643
 
1656
1644
  it "sets the inverse side of the relation" do
1657
- tag_two.related(true).should eq([ tag_one ])
1645
+ expect(tag_two.related(true)).to eq([ tag_one ])
1658
1646
  end
1659
1647
 
1660
1648
  context "when reloading" do
1661
1649
 
1662
1650
  it "sets the front side of the relation" do
1663
- tag_one.reload.related.should eq([ tag_two ])
1651
+ expect(tag_one.reload.related).to eq([ tag_two ])
1664
1652
  end
1665
1653
 
1666
1654
  it "sets the inverse side of the relation" do
1667
- tag_two.reload.related.should eq([ tag_one ])
1655
+ expect(tag_two.reload.related).to eq([ tag_one ])
1668
1656
  end
1669
1657
  end
1670
1658
 
@@ -1679,11 +1667,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1679
1667
  end
1680
1668
 
1681
1669
  it "sets the front side of the relation" do
1682
- loaded_tag_one.related.should eq([ tag_two ])
1670
+ expect(loaded_tag_one.related).to eq([ tag_two ])
1683
1671
  end
1684
1672
 
1685
1673
  it "sets the inverse side of the relation" do
1686
- loaded_tag_two.related.should eq([ tag_one ])
1674
+ expect(loaded_tag_two.related).to eq([ tag_one ])
1687
1675
  end
1688
1676
  end
1689
1677
  end
@@ -1710,7 +1698,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1710
1698
 
1711
1699
  it "returns zero" do
1712
1700
  sandwich.destroy
1713
- sandwich.meats.count.should eq(0)
1701
+ expect(sandwich.meats.count).to eq(0)
1714
1702
  end
1715
1703
  end
1716
1704
  end
@@ -1722,7 +1710,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1722
1710
  end
1723
1711
 
1724
1712
  it "returns the number of persisted documents" do
1725
- person.preferences.count.should eq(1)
1713
+ expect(person.preferences.count).to eq(1)
1726
1714
  end
1727
1715
  end
1728
1716
 
@@ -1738,7 +1726,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1738
1726
  end
1739
1727
 
1740
1728
  it "returns the number of persisted documents" do
1741
- person.preferences.count.should eq(2)
1729
+ expect(person.preferences.count).to eq(2)
1742
1730
  end
1743
1731
  end
1744
1732
 
@@ -1749,7 +1737,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1749
1737
  end
1750
1738
 
1751
1739
  it "returns 0" do
1752
- person.preferences.count.should eq(0)
1740
+ expect(person.preferences.count).to eq(0)
1753
1741
  end
1754
1742
  end
1755
1743
 
@@ -1762,7 +1750,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1762
1750
  end
1763
1751
 
1764
1752
  it "returns the count from the db" do
1765
- person.reload.preferences.count.should eq(1)
1753
+ expect(person.reload.preferences.count).to eq(1)
1766
1754
  end
1767
1755
  end
1768
1756
 
@@ -1773,7 +1761,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1773
1761
  end
1774
1762
 
1775
1763
  it "returns the count from the db" do
1776
- person.preferences.count.should eq(0)
1764
+ expect(person.preferences.count).to eq(0)
1777
1765
  end
1778
1766
  end
1779
1767
  end
@@ -1787,7 +1775,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1787
1775
  end
1788
1776
 
1789
1777
  it "returns the number of persisted documents" do
1790
- person.houses.count.should eq(1)
1778
+ expect(person.houses.count).to eq(1)
1791
1779
  end
1792
1780
  end
1793
1781
 
@@ -1798,7 +1786,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1798
1786
  end
1799
1787
 
1800
1788
  it "returns 0" do
1801
- person.preferences.count.should eq(0)
1789
+ expect(person.preferences.count).to eq(0)
1802
1790
  end
1803
1791
  end
1804
1792
  end
@@ -1808,28 +1796,6 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1808
1796
 
1809
1797
  describe "##{method}" do
1810
1798
 
1811
- context "when providing scoped mass assignment" do
1812
-
1813
- let(:person) do
1814
- Person.create
1815
- end
1816
-
1817
- let(:house) do
1818
- person.houses.send(
1819
- method,
1820
- { name: "Dream", model: "Home" }, as: :admin
1821
- )
1822
- end
1823
-
1824
- it "sets the attributes for the provided role" do
1825
- house.name.should eq("Dream")
1826
- end
1827
-
1828
- it "does not set the attributes for other roles" do
1829
- house.model.should be_nil
1830
- end
1831
- end
1832
-
1833
1799
  context "when the relation is not polymorphic" do
1834
1800
 
1835
1801
  context "when using string keys" do
@@ -1843,7 +1809,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1843
1809
  end
1844
1810
 
1845
1811
  it "does not convert the string key to an object id" do
1846
- agent.account_ids.should eq([ "testing-again" ])
1812
+ expect(agent.account_ids).to eq([ "testing-again" ])
1847
1813
  end
1848
1814
  end
1849
1815
 
@@ -1871,39 +1837,39 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1871
1837
  end
1872
1838
 
1873
1839
  it "sets the foreign key on the relation" do
1874
- person.preference_ids.should eq([ preference.id ])
1840
+ expect(person.preference_ids).to eq([ preference.id ])
1875
1841
  end
1876
1842
 
1877
1843
  it "sets the foreign key on the inverse relation" do
1878
- preference.person_ids.should eq([ person.id ])
1844
+ expect(preference.person_ids).to eq([ person.id ])
1879
1845
  end
1880
1846
 
1881
1847
  it "adds the document" do
1882
- person.preferences.should eq([ preference ])
1848
+ expect(person.preferences).to eq([ preference ])
1883
1849
  end
1884
1850
 
1885
1851
  it "sets the base on the inverse relation" do
1886
- preference.people.should eq([ person ])
1852
+ expect(preference.people).to eq([ person ])
1887
1853
  end
1888
1854
 
1889
1855
  it "sets the attributes" do
1890
- preference.name.should eq("Testing")
1856
+ expect(preference.name).to eq("Testing")
1891
1857
  end
1892
1858
 
1893
1859
  it "saves the target" do
1894
- preference.should be_persisted
1860
+ expect(preference).to be_persisted
1895
1861
  end
1896
1862
 
1897
1863
  it "adds the document to the target" do
1898
- person.preferences.count.should eq(1)
1864
+ expect(person.preferences.count).to eq(1)
1899
1865
  end
1900
1866
 
1901
1867
  it "does not duplicate documents" do
1902
- person.reload.preferences.count.should eq(1)
1868
+ expect(person.reload.preferences.count).to eq(1)
1903
1869
  end
1904
1870
 
1905
1871
  it "does not duplicate ids" do
1906
- person.reload.preference_ids.count.should eq(1)
1872
+ expect(person.reload.preference_ids.count).to eq(1)
1907
1873
  end
1908
1874
  end
1909
1875
  end
@@ -1954,23 +1920,23 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1954
1920
  end
1955
1921
 
1956
1922
  it "removes the document from the relation" do
1957
- person.preferences.should eq([ preference_two ])
1923
+ expect(person.preferences).to eq([ preference_two ])
1958
1924
  end
1959
1925
 
1960
1926
  it "returns the document" do
1961
- deleted.should eq(preference_one)
1927
+ expect(deleted).to eq(preference_one)
1962
1928
  end
1963
1929
 
1964
1930
  it "removes the document key from the foreign key" do
1965
- person.preference_ids.should eq([ preference_two.id ])
1931
+ expect(person.preference_ids).to eq([ preference_two.id ])
1966
1932
  end
1967
1933
 
1968
1934
  it "removes the inverse reference" do
1969
- deleted.reload.people.should be_empty
1935
+ expect(deleted.reload.people).to be_empty
1970
1936
  end
1971
1937
 
1972
1938
  it "removes the base id from the inverse keys" do
1973
- deleted.reload.person_ids.should be_empty
1939
+ expect(deleted.reload.person_ids).to be_empty
1974
1940
  end
1975
1941
 
1976
1942
  context "and person and preferences are reloaded" do
@@ -1982,11 +1948,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1982
1948
  end
1983
1949
 
1984
1950
  it "nullifies the deleted preference" do
1985
- person.preferences.should eq([ preference_two ])
1951
+ expect(person.preferences).to eq([ preference_two ])
1986
1952
  end
1987
1953
 
1988
1954
  it "retains the ids for one preference" do
1989
- person.preference_ids.should eq([ preference_two.id ])
1955
+ expect(person.preference_ids).to eq([ preference_two.id ])
1990
1956
  end
1991
1957
  end
1992
1958
  end
@@ -1998,15 +1964,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
1998
1964
  end
1999
1965
 
2000
1966
  it "returns nil" do
2001
- deleted.should be_nil
1967
+ expect(deleted).to be_nil
2002
1968
  end
2003
1969
 
2004
1970
  it "does not modify the relation" do
2005
- person.preferences.should eq([ preference_one, preference_two ])
1971
+ expect(person.preferences).to eq([ preference_one, preference_two ])
2006
1972
  end
2007
1973
 
2008
1974
  it "does not modify the keys" do
2009
- person.preference_ids.should eq([ preference_one.id, preference_two.id ])
1975
+ expect(person.preference_ids).to eq([ preference_one.id, preference_two.id ])
2010
1976
  end
2011
1977
  end
2012
1978
 
@@ -2023,7 +1989,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2023
1989
  end
2024
1990
 
2025
1991
  it "deletes the document" do
2026
- event.delete.should be_true
1992
+ expect(event.delete).to be true
2027
1993
  end
2028
1994
  end
2029
1995
  end
@@ -2049,19 +2015,19 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2049
2015
  end
2050
2016
 
2051
2017
  it "deletes the document from the relation" do
2052
- tag_one.related.should be_empty
2018
+ expect(tag_one.related).to be_empty
2053
2019
  end
2054
2020
 
2055
2021
  it "deletes the foreign key from the relation" do
2056
- tag_one.related_ids.should be_empty
2022
+ expect(tag_one.related_ids).to be_empty
2057
2023
  end
2058
2024
 
2059
2025
  it "removes the reference from the inverse" do
2060
- deleted.related.should be_empty
2026
+ expect(deleted.related).to be_empty
2061
2027
  end
2062
2028
 
2063
2029
  it "removes the foreign keys from the inverse" do
2064
- deleted.related_ids.should be_empty
2030
+ expect(deleted.related_ids).to be_empty
2065
2031
  end
2066
2032
  end
2067
2033
 
@@ -2078,19 +2044,19 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2078
2044
  end
2079
2045
 
2080
2046
  it "deletes the document from the relation" do
2081
- reloaded.related.should be_empty
2047
+ expect(reloaded.related).to be_empty
2082
2048
  end
2083
2049
 
2084
2050
  it "deletes the foreign key from the relation" do
2085
- reloaded.related_ids.should be_empty
2051
+ expect(reloaded.related_ids).to be_empty
2086
2052
  end
2087
2053
 
2088
2054
  it "removes the reference from the inverse" do
2089
- deleted.related.should be_empty
2055
+ expect(deleted.related).to be_empty
2090
2056
  end
2091
2057
 
2092
2058
  it "removes the foreign keys from the inverse" do
2093
- deleted.related_ids.should be_empty
2059
+ expect(deleted.related_ids).to be_empty
2094
2060
  end
2095
2061
  end
2096
2062
 
@@ -2105,15 +2071,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2105
2071
  end
2106
2072
 
2107
2073
  it "deletes the document from the relation" do
2108
- reloaded.related.should be_empty
2074
+ expect(reloaded.related).to be_empty
2109
2075
  end
2110
2076
 
2111
2077
  it "deletes the foreign key from the relation" do
2112
- reloaded.related_ids.should be_empty
2078
+ expect(reloaded.related_ids).to be_empty
2113
2079
  end
2114
2080
 
2115
2081
  it "removes the foreign keys from the inverse" do
2116
- deleted.related_ids.should be_empty
2082
+ expect(deleted.related_ids).to be_empty
2117
2083
  end
2118
2084
  end
2119
2085
  end
@@ -2142,11 +2108,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2142
2108
  end
2143
2109
 
2144
2110
  it "executes the callback" do
2145
- post.before_remove_called.should be_true
2111
+ expect(post.before_remove_called).to be true
2146
2112
  end
2147
2113
 
2148
2114
  it "removes the document from the relation" do
2149
- post.tags.should be_empty
2115
+ expect(post.tags).to be_empty
2150
2116
  end
2151
2117
  end
2152
2118
 
@@ -2160,7 +2126,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2160
2126
  expect {
2161
2127
  post.tags.delete tag
2162
2128
  }.to raise_error
2163
- post.tags.should eq([ tag ])
2129
+ expect(post.tags).to eq([ tag ])
2164
2130
  end
2165
2131
  end
2166
2132
  end
@@ -2174,11 +2140,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2174
2140
  end
2175
2141
 
2176
2142
  it "executes the callback" do
2177
- post.after_remove_called.should be_true
2143
+ expect(post.after_remove_called).to be true
2178
2144
  end
2179
2145
 
2180
2146
  it "removes the document from the relation" do
2181
- post.tags.should be_empty
2147
+ expect(post.tags).to be_empty
2182
2148
  end
2183
2149
  end
2184
2150
 
@@ -2192,7 +2158,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2192
2158
  expect {
2193
2159
  post.tags.delete(tag)
2194
2160
  }.to raise_error
2195
- post.tags.should be_empty
2161
+ expect(post.tags).to be_empty
2196
2162
  end
2197
2163
  end
2198
2164
  end
@@ -2227,19 +2193,19 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2227
2193
  end
2228
2194
 
2229
2195
  it "removes the correct preferences" do
2230
- person.preferences.count.should eq(1)
2196
+ expect(person.preferences.count).to eq(1)
2231
2197
  end
2232
2198
 
2233
2199
  it "deletes the documents from the database" do
2234
- Preference.where(name: "Testing").count.should eq(0)
2200
+ expect(Preference.where(name: "Testing").count).to eq(0)
2235
2201
  end
2236
2202
 
2237
2203
  it "returns the number of documents deleted" do
2238
- deleted.should eq(1)
2204
+ expect(deleted).to eq(1)
2239
2205
  end
2240
2206
 
2241
2207
  it "removes the ids from the foreign key" do
2242
- person.preference_ids.should eq([ preference_two.id ])
2208
+ expect(person.preference_ids).to eq([ preference_two.id ])
2243
2209
  end
2244
2210
  end
2245
2211
 
@@ -2257,67 +2223,25 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2257
2223
  end
2258
2224
 
2259
2225
  it "removes the correct preferences" do
2260
- person.preferences.count.should eq(0)
2226
+ expect(person.preferences.count).to eq(0)
2261
2227
  end
2262
2228
 
2263
2229
  it "deletes the documents from the database" do
2264
- Preference.count.should eq(0)
2230
+ expect(Preference.count).to eq(0)
2265
2231
  end
2266
2232
 
2267
2233
  it "returns the number of documents deleted" do
2268
- deleted.should eq(2)
2234
+ expect(deleted).to eq(2)
2269
2235
  end
2270
2236
  end
2271
2237
  end
2272
2238
  end
2273
2239
  end
2274
2240
 
2275
- describe ".eager_load" do
2276
-
2277
- before do
2278
- Mongoid.identity_map_enabled = true
2279
- end
2280
-
2281
- after do
2282
- Mongoid.identity_map_enabled = false
2283
- end
2284
-
2285
- context "when the relation is not polymorphic" do
2286
-
2287
- let!(:person) do
2288
- Person.create
2289
- end
2290
-
2291
- let!(:preference) do
2292
- person.preferences.create(name: "testing")
2293
- end
2294
-
2295
- let(:metadata) do
2296
- Person.relations["preferences"]
2297
- end
2298
-
2299
- let(:ids) do
2300
- [ preference.id ]
2301
- end
2302
-
2303
- let!(:eager) do
2304
- described_class.eager_load(metadata, ids)
2305
- end
2306
-
2307
- let(:map) do
2308
- Mongoid::IdentityMap.get(Preference, ids)
2309
- end
2310
-
2311
- it "puts the documents in the identity map" do
2312
- map.should eq([ preference ])
2313
- end
2314
- end
2315
- end
2316
-
2317
2241
  describe ".embedded?" do
2318
2242
 
2319
2243
  it "returns false" do
2320
- described_class.should_not be_embedded
2244
+ expect(described_class).to_not be_embedded
2321
2245
  end
2322
2246
  end
2323
2247
 
@@ -2334,7 +2258,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2334
2258
  end
2335
2259
 
2336
2260
  it "returns true" do
2337
- person.preferences.exists?.should be_true
2261
+ expect(person.preferences.exists?).to be true
2338
2262
  end
2339
2263
  end
2340
2264
 
@@ -2345,7 +2269,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2345
2269
  end
2346
2270
 
2347
2271
  it "returns false" do
2348
- person.preferences.exists?.should be_false
2272
+ expect(person.preferences.exists?).to be false
2349
2273
  end
2350
2274
  end
2351
2275
  end
@@ -2383,7 +2307,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2383
2307
  end
2384
2308
 
2385
2309
  it "returns the matching document" do
2386
- preference.should eq(preference_one)
2310
+ expect(preference).to eq(preference_one)
2387
2311
  end
2388
2312
  end
2389
2313
 
@@ -2410,7 +2334,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2410
2334
 
2411
2335
  it "raises an error" do
2412
2336
  expect {
2413
- person.preferences.find(Moped::BSON::ObjectId.new)
2337
+ person.preferences.find(BSON::ObjectId.new)
2414
2338
  }.to raise_error(Mongoid::Errors::DocumentNotFound)
2415
2339
  end
2416
2340
  end
@@ -2418,7 +2342,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2418
2342
  context "when config set not to raise error" do
2419
2343
 
2420
2344
  let(:preference) do
2421
- person.preferences.find(Moped::BSON::ObjectId.new)
2345
+ person.preferences.find(BSON::ObjectId.new)
2422
2346
  end
2423
2347
 
2424
2348
  before do
@@ -2430,7 +2354,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2430
2354
  end
2431
2355
 
2432
2356
  it "returns nil" do
2433
- preference.should be_nil
2357
+ expect(preference).to be_nil
2434
2358
  end
2435
2359
  end
2436
2360
  end
@@ -2445,7 +2369,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2445
2369
  end
2446
2370
 
2447
2371
  it "returns the matching documents" do
2448
- preferences.should eq([ preference_one, preference_two ])
2372
+ expect(preferences).to eq([ preference_one, preference_two ])
2449
2373
  end
2450
2374
  end
2451
2375
 
@@ -2474,7 +2398,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2474
2398
 
2475
2399
  it "raises an error" do
2476
2400
  expect {
2477
- person.preferences.find([ Moped::BSON::ObjectId.new ])
2401
+ person.preferences.find([ BSON::ObjectId.new ])
2478
2402
  }.to raise_error(Mongoid::Errors::DocumentNotFound)
2479
2403
  end
2480
2404
  end
@@ -2482,7 +2406,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2482
2406
  context "when config set not to raise error" do
2483
2407
 
2484
2408
  let(:preferences) do
2485
- person.preferences.find([ Moped::BSON::ObjectId.new ])
2409
+ person.preferences.find([ BSON::ObjectId.new ])
2486
2410
  end
2487
2411
 
2488
2412
  before do
@@ -2494,7 +2418,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2494
2418
  end
2495
2419
 
2496
2420
  it "returns an empty array" do
2497
- preferences.should be_empty
2421
+ expect(preferences).to be_empty
2498
2422
  end
2499
2423
  end
2500
2424
  end
@@ -2521,7 +2445,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2521
2445
  end
2522
2446
 
2523
2447
  it "returns the document" do
2524
- found.should eq(preference)
2448
+ expect(found).to eq(preference)
2525
2449
  end
2526
2450
  end
2527
2451
 
@@ -2532,11 +2456,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2532
2456
  end
2533
2457
 
2534
2458
  it "sets the new document attributes" do
2535
- found.name.should eq("Test")
2459
+ expect(found.name).to eq("Test")
2536
2460
  end
2537
2461
 
2538
2462
  it "returns a newly persisted document" do
2539
- found.should be_persisted
2463
+ expect(found).to be_persisted
2540
2464
  end
2541
2465
  end
2542
2466
  end
@@ -2561,7 +2485,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2561
2485
  end
2562
2486
 
2563
2487
  it "returns the document" do
2564
- found.should eq(preference)
2488
+ expect(found).to eq(preference)
2565
2489
  end
2566
2490
  end
2567
2491
 
@@ -2572,11 +2496,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2572
2496
  end
2573
2497
 
2574
2498
  it "sets the new document attributes" do
2575
- found.name.should eq("Test")
2499
+ expect(found.name).to eq("Test")
2576
2500
  end
2577
2501
 
2578
2502
  it "returns a non persisted document" do
2579
- found.should_not be_persisted
2503
+ expect(found).to_not be_persisted
2580
2504
  end
2581
2505
  end
2582
2506
  end
@@ -2585,14 +2509,14 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2585
2509
  describe ".foreign_key_suffix" do
2586
2510
 
2587
2511
  it "returns _ids" do
2588
- described_class.foreign_key_suffix.should eq("_ids")
2512
+ expect(described_class.foreign_key_suffix).to eq("_ids")
2589
2513
  end
2590
2514
  end
2591
2515
 
2592
2516
  describe ".macro" do
2593
2517
 
2594
2518
  it "returns has_and_belongs_to_many" do
2595
- described_class.macro.should eq(:has_and_belongs_to_many)
2519
+ expect(described_class.macro).to eq(:has_and_belongs_to_many)
2596
2520
  end
2597
2521
  end
2598
2522
 
@@ -2621,7 +2545,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2621
2545
  end
2622
2546
 
2623
2547
  it "returns the document with the max value of the supplied field" do
2624
- max.should eq(preference_two)
2548
+ expect(max).to eq(preference_two)
2625
2549
  end
2626
2550
  end
2627
2551
 
@@ -2648,7 +2572,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2648
2572
  end
2649
2573
 
2650
2574
  it "returns the document with the max value of the supplied field" do
2651
- max.should eq(preference_two)
2575
+ expect(max).to eq(preference_two)
2652
2576
  end
2653
2577
  end
2654
2578
 
@@ -2677,7 +2601,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2677
2601
  end
2678
2602
 
2679
2603
  it "applies the criteria to the documents" do
2680
- preferences.should eq([ preference_one ])
2604
+ expect(preferences).to eq([ preference_one ])
2681
2605
  end
2682
2606
  end
2683
2607
 
@@ -2688,7 +2612,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2688
2612
  end
2689
2613
 
2690
2614
  it "does not return unrelated documents" do
2691
- preferences.should be_empty
2615
+ expect(preferences).to be_empty
2692
2616
  end
2693
2617
  end
2694
2618
 
@@ -2699,7 +2623,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2699
2623
  end
2700
2624
 
2701
2625
  it "applies the criteria to the documents" do
2702
- preferences.should eq([ preference_one ])
2626
+ expect(preferences).to eq([ preference_one ])
2703
2627
  end
2704
2628
  end
2705
2629
 
@@ -2710,7 +2634,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2710
2634
  end
2711
2635
 
2712
2636
  it "applies the criteria to the documents" do
2713
- preferences.should eq([ preference_one ])
2637
+ expect(preferences).to eq([ preference_one ])
2714
2638
  end
2715
2639
  end
2716
2640
 
@@ -2718,9 +2642,13 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2718
2642
 
2719
2643
  describe "#distinct" do
2720
2644
 
2645
+ let(:values) do
2646
+ person.preferences.distinct(:name)
2647
+ end
2648
+
2721
2649
  it "returns the distinct values for the fields" do
2722
- person.preferences.distinct(:name).should =~
2723
- [ "First", "Second"]
2650
+ expect(values).to include("First")
2651
+ expect(values).to include("Second")
2724
2652
  end
2725
2653
 
2726
2654
  context "when the inverse relation is not defined" do
@@ -2730,7 +2658,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2730
2658
  end
2731
2659
 
2732
2660
  it "returns the distinct values for the fields" do
2733
- person.houses.distinct(:name).should eq([ house.name ])
2661
+ expect(person.houses.distinct(:name)).to eq([ house.name ])
2734
2662
  end
2735
2663
  end
2736
2664
  end
@@ -2762,7 +2690,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2762
2690
  end
2763
2691
 
2764
2692
  it "returns the min value of the supplied field" do
2765
- min.should eq(preference_one)
2693
+ expect(min).to eq(preference_one)
2766
2694
  end
2767
2695
  end
2768
2696
 
@@ -2789,14 +2717,14 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2789
2717
  end
2790
2718
 
2791
2719
  it "returns the min value of the supplied field" do
2792
- min.should eq(preference_one)
2720
+ expect(min).to eq(preference_one)
2793
2721
  end
2794
2722
  end
2795
2723
 
2796
2724
  describe "#nil?" do
2797
2725
 
2798
2726
  it "returns false" do
2799
- Person.new.preferences.should_not be_nil
2727
+ expect(Person.new.preferences).to_not be_nil
2800
2728
  end
2801
2729
  end
2802
2730
 
@@ -2820,30 +2748,30 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2820
2748
 
2821
2749
  it "removes the foreign key from the base document" do
2822
2750
  [ preference_one, preference_two ].each do |preference|
2823
- person.preference_ids.should_not include(preference.id)
2751
+ expect(person.preference_ids).to_not include(preference.id)
2824
2752
  end
2825
2753
  end
2826
2754
 
2827
2755
  it "removes the foreign key from the target documents" do
2828
2756
  [ preference_one, preference_two ].each do |preference|
2829
- preference.person_ids.should_not include(person.id)
2757
+ expect(preference.person_ids).to_not include(person.id)
2830
2758
  end
2831
2759
  end
2832
2760
 
2833
2761
  it "removes the reference from the base document" do
2834
2762
  [ preference_one, preference_two ].each do |preference|
2835
- person.preferences.should_not include(preference)
2763
+ expect(person.preferences).to_not include(preference)
2836
2764
  end
2837
2765
  end
2838
2766
 
2839
2767
  it "removes the reference from the target documents" do
2840
2768
  [ preference_one, preference_two ].each do |preference|
2841
- preference.people.should_not include(person)
2769
+ expect(preference.people).to_not include(person)
2842
2770
  end
2843
2771
  end
2844
2772
 
2845
2773
  it "saves the documents" do
2846
- preference_one.reload.people.should_not include(person)
2774
+ expect(preference_one.reload.people).to_not include(person)
2847
2775
  end
2848
2776
  end
2849
2777
 
@@ -2862,7 +2790,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2862
2790
  context "when checking #{method}" do
2863
2791
 
2864
2792
  it "returns true" do
2865
- preferences.respond_to?(method).should be_true
2793
+ expect(preferences.respond_to?(method)).to be true
2866
2794
  end
2867
2795
  end
2868
2796
  end
@@ -2872,7 +2800,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2872
2800
  context "when checking #{method}" do
2873
2801
 
2874
2802
  it "returns true" do
2875
- preferences.respond_to?(method).should be_true
2803
+ expect(preferences.respond_to?(method)).to be true
2876
2804
  end
2877
2805
  end
2878
2806
  end
@@ -2882,7 +2810,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2882
2810
  context "when checking #{method}" do
2883
2811
 
2884
2812
  it "returns true" do
2885
- preferences.respond_to?(method).should be_true
2813
+ expect(preferences.respond_to?(method)).to be true
2886
2814
  end
2887
2815
  end
2888
2816
  end
@@ -2891,7 +2819,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2891
2819
  describe ".stores_foreign_key?" do
2892
2820
 
2893
2821
  it "returns true" do
2894
- described_class.stores_foreign_key?.should be_true
2822
+ expect(described_class.stores_foreign_key?).to be true
2895
2823
  end
2896
2824
  end
2897
2825
 
@@ -2906,11 +2834,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2906
2834
  end
2907
2835
 
2908
2836
  it "returns the relation criteria" do
2909
- scoped.should be_a(Mongoid::Criteria)
2837
+ expect(scoped).to be_a(Mongoid::Criteria)
2910
2838
  end
2911
2839
 
2912
2840
  it "returns with an empty selector" do
2913
- scoped.selector.should eq({ "$and" => [{ "_id" => { "$in" => [] }}]})
2841
+ expect(scoped.selector).to eq({ "$and" => [{ "_id" => { "$in" => [] }}]})
2914
2842
  end
2915
2843
  end
2916
2844
 
@@ -2929,7 +2857,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2929
2857
  end
2930
2858
 
2931
2859
  it "returns the number of documents" do
2932
- person.preferences.send(method).should eq(1)
2860
+ expect(person.preferences.send(method)).to eq(1)
2933
2861
  end
2934
2862
  end
2935
2863
 
@@ -2941,7 +2869,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2941
2869
  end
2942
2870
 
2943
2871
  it "returns the total number of documents" do
2944
- person.preferences.send(method).should eq(2)
2872
+ expect(person.preferences.send(method)).to eq(2)
2945
2873
  end
2946
2874
  end
2947
2875
  end
@@ -2968,7 +2896,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2968
2896
  end
2969
2897
 
2970
2898
  it "returns only the associated documents" do
2971
- unscoped.should eq([ preference_one ])
2899
+ expect(unscoped).to eq([ preference_one ])
2972
2900
  end
2973
2901
  end
2974
2902
 
@@ -2991,11 +2919,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2991
2919
  end
2992
2920
 
2993
2921
  it "only returns associated documents" do
2994
- unscoped.should eq([ house_one ])
2922
+ expect(unscoped).to eq([ house_one ])
2995
2923
  end
2996
2924
 
2997
2925
  it "removes the default scoping options" do
2998
- unscoped.options.should eq({})
2926
+ expect(unscoped.options).to eq({})
2999
2927
  end
3000
2928
  end
3001
2929
  end
@@ -3003,7 +2931,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3003
2931
  describe ".valid_options" do
3004
2932
 
3005
2933
  it "returns the valid options" do
3006
- described_class.valid_options.should eq(
2934
+ expect(described_class.valid_options).to eq(
3007
2935
  [
3008
2936
  :after_add,
3009
2937
  :after_remove,
@@ -3023,7 +2951,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3023
2951
  describe ".validation_default" do
3024
2952
 
3025
2953
  it "returns true" do
3026
- described_class.validation_default.should be_true
2954
+ expect(described_class.validation_default).to be true
3027
2955
  end
3028
2956
  end
3029
2957
 
@@ -3055,7 +2983,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3055
2983
  context "when reloading" do
3056
2984
 
3057
2985
  it "properly sets the references" do
3058
- person.houses(true).should eq([ girlfriend_house ])
2986
+ expect(person.houses(true)).to eq([ girlfriend_house ])
3059
2987
  end
3060
2988
  end
3061
2989
  end
@@ -3077,15 +3005,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3077
3005
  end
3078
3006
 
3079
3007
  it "sets the businesses" do
3080
- user.businesses.should eq([ business ])
3008
+ expect(user.businesses).to eq([ business ])
3081
3009
  end
3082
3010
 
3083
3011
  it "sets the inverse users" do
3084
- user.businesses.first.owners.first.should eq(user)
3012
+ expect(user.businesses.first.owners.first).to eq(user)
3085
3013
  end
3086
3014
 
3087
3015
  it "sets the inverse businesses" do
3088
- business.owners.should eq([ user ])
3016
+ expect(business.owners).to eq([ user ])
3089
3017
  end
3090
3018
  end
3091
3019
 
@@ -3104,15 +3032,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3104
3032
  end
3105
3033
 
3106
3034
  it "sets the businesses" do
3107
- user.businesses.should eq([ business ])
3035
+ expect(user.businesses).to eq([ business ])
3108
3036
  end
3109
3037
 
3110
3038
  it "sets the inverse users" do
3111
- user.businesses.first.owners.first.should eq(user)
3039
+ expect(user.businesses.first.owners.first).to eq(user)
3112
3040
  end
3113
3041
 
3114
3042
  it "sets the inverse businesses" do
3115
- business.owners.should eq([ user ])
3043
+ expect(business.owners).to eq([ user ])
3116
3044
  end
3117
3045
 
3118
3046
  context "when reloading" do
@@ -3123,15 +3051,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3123
3051
  end
3124
3052
 
3125
3053
  it "persists the businesses" do
3126
- user.businesses.should eq([ business ])
3054
+ expect(user.businesses).to eq([ business ])
3127
3055
  end
3128
3056
 
3129
3057
  it "persists the inverse users" do
3130
- user.businesses.first.owners.first.should eq(user)
3058
+ expect(user.businesses.first.owners.first).to eq(user)
3131
3059
  end
3132
3060
 
3133
3061
  it "persists the inverse businesses" do
3134
- business.owners.should eq([ user ])
3062
+ expect(business.owners).to eq([ user ])
3135
3063
  end
3136
3064
  end
3137
3065
  end
@@ -3151,15 +3079,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3151
3079
  end
3152
3080
 
3153
3081
  it "sets the businesses" do
3154
- user.businesses.should eq([ business ])
3082
+ expect(user.businesses).to eq([ business ])
3155
3083
  end
3156
3084
 
3157
3085
  it "sets the inverse users" do
3158
- user.businesses.first.owners.first.should eq(user)
3086
+ expect(user.businesses.first.owners.first).to eq(user)
3159
3087
  end
3160
3088
 
3161
3089
  it "sets the inverse businesses" do
3162
- business.owners.should eq([ user ])
3090
+ expect(business.owners).to eq([ user ])
3163
3091
  end
3164
3092
 
3165
3093
  context "when reloading" do
@@ -3170,15 +3098,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3170
3098
  end
3171
3099
 
3172
3100
  it "persists the businesses" do
3173
- user.businesses.should eq([ business ])
3101
+ expect(user.businesses).to eq([ business ])
3174
3102
  end
3175
3103
 
3176
3104
  it "persists the inverse users" do
3177
- user.businesses.first.owners.first.should eq(user)
3105
+ expect(user.businesses.first.owners.first).to eq(user)
3178
3106
  end
3179
3107
 
3180
3108
  it "persists the inverse businesses" do
3181
- business.owners.should eq([ user ])
3109
+ expect(business.owners).to eq([ user ])
3182
3110
  end
3183
3111
  end
3184
3112
  end
@@ -3197,13 +3125,13 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3197
3125
  before do
3198
3126
  2.times do
3199
3127
  person.preferences.each do |preference|
3200
- preference.person_ids.should eq([ person.id ])
3128
+ expect(preference.person_ids).to eq([ person.id ])
3201
3129
  end
3202
3130
  end
3203
3131
  end
3204
3132
 
3205
3133
  it "does not duplicate foreign keys" do
3206
- person.preference_ids.should eq([ preference.id ])
3134
+ expect(person.preference_ids).to eq([ preference.id ])
3207
3135
  end
3208
3136
  end
3209
3137
 
@@ -3231,13 +3159,13 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3231
3159
  end
3232
3160
 
3233
3161
  it "orders the documents" do
3234
- person.ordered_preferences(true).should eq(
3162
+ expect(person.ordered_preferences(true)).to eq(
3235
3163
  [preference_two, preference_three, preference_one]
3236
3164
  )
3237
3165
  end
3238
3166
 
3239
3167
  it "chains default criteria with additional" do
3240
- person.ordered_preferences.order_by(:name.desc).to_a.should eq(
3168
+ expect(person.ordered_preferences.order_by(:name.desc).to_a).to eq(
3241
3169
  [preference_three, preference_two, preference_one]
3242
3170
  )
3243
3171
  end
@@ -3261,17 +3189,17 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3261
3189
  end
3262
3190
 
3263
3191
  it "sets the relation to an empty array" do
3264
- person.preferences.should be_empty
3192
+ expect(person.preferences).to be_empty
3265
3193
  end
3266
3194
 
3267
3195
  it "removes the foreign key values" do
3268
- person.preference_ids.should be_empty
3196
+ expect(person.preference_ids).to be_empty
3269
3197
  end
3270
3198
 
3271
3199
  it "does not delete the target from the database" do
3272
3200
  expect {
3273
3201
  preference.reload
3274
- }.not_to raise_error(Mongoid::Errors::DocumentNotFound)
3202
+ }.not_to raise_error
3275
3203
  end
3276
3204
  end
3277
3205
 
@@ -3305,7 +3233,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3305
3233
  end
3306
3234
 
3307
3235
  it "reloads the document from the database" do
3308
- reloaded.first.name.should eq("reloaded")
3236
+ expect(reloaded.first.name).to eq("reloaded")
3309
3237
  end
3310
3238
  end
3311
3239
 
@@ -3320,7 +3248,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3320
3248
  end
3321
3249
 
3322
3250
  it "reloads the new document from the database" do
3323
- reloaded.should eq([ preference_one, preference_two ])
3251
+ expect(reloaded).to eq([ preference_one, preference_two ])
3324
3252
  end
3325
3253
  end
3326
3254
  end
@@ -3342,19 +3270,19 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3342
3270
  end
3343
3271
 
3344
3272
  it "persists the first preference" do
3345
- preference_one.should_not be_nil
3273
+ expect(preference_one).to_not be_nil
3346
3274
  end
3347
3275
 
3348
3276
  it "sets the first inverse" do
3349
- preference_one.people.should eq([ person ])
3277
+ expect(preference_one.people).to eq([ person ])
3350
3278
  end
3351
3279
 
3352
3280
  it "persists the second preference" do
3353
- preference_two.should_not be_nil
3281
+ expect(preference_two).to_not be_nil
3354
3282
  end
3355
3283
 
3356
3284
  it "sets the second inverse keys" do
3357
- preference_two.people.should eq([ person ])
3285
+ expect(preference_two.people).to eq([ person ])
3358
3286
  end
3359
3287
  end
3360
3288
  end
@@ -3390,7 +3318,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3390
3318
  end
3391
3319
 
3392
3320
  it "persists the change in id order" do
3393
- reloaded.preference_ids.should eq(
3321
+ expect(reloaded.preference_ids).to eq(
3394
3322
  [ preference_two.id, preference_one.id ]
3395
3323
  )
3396
3324
  end
@@ -3413,7 +3341,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3413
3341
  end
3414
3342
 
3415
3343
  it "also persists the change in id order" do
3416
- reloaded.preference_ids.should eq(
3344
+ expect(reloaded.preference_ids).to eq(
3417
3345
  [ preference_two.id, preference_one.id, preference_three.id ]
3418
3346
  )
3419
3347
  end
@@ -3439,7 +3367,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3439
3367
  end
3440
3368
 
3441
3369
  it "also persists the change in id order" do
3442
- reloaded.preference_ids.should eq(
3370
+ expect(reloaded.preference_ids).to eq(
3443
3371
  [ preference_three.id, preference_two.id ]
3444
3372
  )
3445
3373
  end
@@ -3471,7 +3399,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3471
3399
  end
3472
3400
 
3473
3401
  it "adds both documents" do
3474
- result.should eq([ preference_one, preference_two ])
3402
+ expect(result).to eq([ preference_one, preference_two ])
3475
3403
  end
3476
3404
  end
3477
3405
  end
@@ -3497,7 +3425,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3497
3425
  end
3498
3426
 
3499
3427
  it "sets the new documents on the relation" do
3500
- person.preferences.should eq([ pref_two ])
3428
+ expect(person.preferences).to eq([ pref_two ])
3501
3429
  end
3502
3430
  end
3503
3431
  end