mongoid 3.1.6 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (571) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +479 -8
  3. data/README.md +10 -7
  4. data/lib/config/locales/en.yml +34 -20
  5. data/lib/mongoid.rb +10 -76
  6. data/lib/mongoid/atomic.rb +3 -14
  7. data/lib/mongoid/atomic/paths/embedded.rb +0 -30
  8. data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
  9. data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
  10. data/lib/mongoid/atomic/paths/root.rb +0 -13
  11. data/lib/mongoid/attributes.rb +65 -101
  12. data/lib/mongoid/attributes/dynamic.rb +154 -0
  13. data/lib/mongoid/attributes/nested.rb +82 -0
  14. data/lib/mongoid/attributes/processing.rb +13 -66
  15. data/lib/mongoid/{dirty.rb → changeable.rb} +32 -2
  16. data/lib/mongoid/composable.rb +105 -0
  17. data/lib/mongoid/config.rb +3 -9
  18. data/lib/mongoid/config/options.rb +1 -1
  19. data/lib/mongoid/contextual.rb +2 -0
  20. data/lib/mongoid/contextual/aggregable/memory.rb +2 -2
  21. data/lib/mongoid/contextual/aggregable/mongo.rb +7 -9
  22. data/lib/mongoid/contextual/atomic.rb +53 -53
  23. data/lib/mongoid/contextual/geo_near.rb +1 -1
  24. data/lib/mongoid/contextual/map_reduce.rb +4 -2
  25. data/lib/mongoid/contextual/memory.rb +23 -11
  26. data/lib/mongoid/contextual/mongo.rb +75 -57
  27. data/lib/mongoid/contextual/none.rb +90 -0
  28. data/lib/mongoid/contextual/text_search.rb +178 -0
  29. data/lib/mongoid/copyable.rb +2 -3
  30. data/lib/mongoid/criteria.rb +39 -34
  31. data/lib/mongoid/criteria/#findable.rb# +141 -0
  32. data/lib/mongoid/{criterion → criteria}/findable.rb +7 -47
  33. data/lib/mongoid/{criterion/inspection.rb → criteria/inspectable.rb} +2 -2
  34. data/lib/mongoid/{criterion → criteria}/marshalable.rb +3 -1
  35. data/lib/mongoid/{criterion → criteria}/modifiable.rb +28 -8
  36. data/lib/mongoid/criteria/permission.rb +70 -0
  37. data/lib/mongoid/{criterion/scoping.rb → criteria/scopable.rb} +2 -2
  38. data/lib/mongoid/document.rb +39 -24
  39. data/lib/mongoid/errors.rb +4 -1
  40. data/lib/mongoid/errors/document_not_destroyed.rb +25 -0
  41. data/lib/mongoid/errors/document_not_found.rb +2 -1
  42. data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
  43. data/lib/mongoid/errors/invalid_storage_parent.rb +26 -0
  44. data/lib/mongoid/errors/invalid_value.rb +16 -0
  45. data/lib/mongoid/errors/mongoid_error.rb +1 -1
  46. data/lib/mongoid/errors/readonly_document.rb +24 -0
  47. data/lib/mongoid/extensions.rb +15 -7
  48. data/lib/mongoid/extensions/array.rb +3 -3
  49. data/lib/mongoid/extensions/big_decimal.rb +1 -1
  50. data/lib/mongoid/extensions/boolean.rb +15 -17
  51. data/lib/mongoid/extensions/date.rb +1 -1
  52. data/lib/mongoid/extensions/date_time.rb +3 -3
  53. data/lib/mongoid/extensions/float.rb +2 -1
  54. data/lib/mongoid/extensions/hash.rb +3 -3
  55. data/lib/mongoid/extensions/integer.rb +1 -1
  56. data/lib/mongoid/extensions/object.rb +7 -7
  57. data/lib/mongoid/extensions/object_id.rb +5 -5
  58. data/lib/mongoid/extensions/range.rb +9 -3
  59. data/lib/mongoid/extensions/regexp.rb +1 -1
  60. data/lib/mongoid/extensions/set.rb +1 -1
  61. data/lib/mongoid/extensions/string.rb +6 -18
  62. data/lib/mongoid/extensions/symbol.rb +1 -1
  63. data/lib/mongoid/extensions/time.rb +3 -3
  64. data/lib/mongoid/extensions/time_with_zone.rb +1 -1
  65. data/lib/mongoid/factory.rb +8 -6
  66. data/lib/mongoid/fields.rb +41 -8
  67. data/lib/mongoid/fields/foreign_key.rb +3 -3
  68. data/lib/mongoid/fields/localized.rb +1 -1
  69. data/lib/mongoid/fields/standard.rb +5 -17
  70. data/lib/mongoid/fields/validators/macro.rb +15 -5
  71. data/lib/mongoid/{finders.rb → findable.rb} +35 -7
  72. data/lib/mongoid/{indexes.rb → indexable.rb} +50 -55
  73. data/lib/mongoid/indexable/specification.rb +104 -0
  74. data/lib/mongoid/{indexes → indexable}/validators/options.rb +2 -1
  75. data/lib/mongoid/{inspection.rb → inspectable.rb} +15 -11
  76. data/lib/mongoid/{callbacks.rb → interceptable.rb} +30 -62
  77. data/lib/mongoid/log_subscriber.rb +55 -0
  78. data/lib/mongoid/matchable.rb +152 -0
  79. data/lib/mongoid/{matchers → matchable}/all.rb +1 -1
  80. data/lib/mongoid/{matchers → matchable}/and.rb +2 -2
  81. data/lib/mongoid/{matchers → matchable}/default.rb +1 -1
  82. data/lib/mongoid/{matchers → matchable}/exists.rb +1 -1
  83. data/lib/mongoid/{matchers → matchable}/gt.rb +1 -1
  84. data/lib/mongoid/{matchers → matchable}/gte.rb +1 -1
  85. data/lib/mongoid/{matchers → matchable}/in.rb +2 -2
  86. data/lib/mongoid/{matchers → matchable}/lt.rb +1 -1
  87. data/lib/mongoid/{matchers → matchable}/lte.rb +1 -1
  88. data/lib/mongoid/{matchers → matchable}/ne.rb +2 -2
  89. data/lib/mongoid/{matchers → matchable}/nin.rb +3 -2
  90. data/lib/mongoid/{matchers → matchable}/or.rb +2 -2
  91. data/lib/mongoid/{matchers → matchable}/size.rb +1 -1
  92. data/lib/mongoid/persistable.rb +216 -0
  93. data/lib/mongoid/persistable/creatable.rb +189 -0
  94. data/lib/mongoid/persistable/deletable.rb +149 -0
  95. data/lib/mongoid/persistable/destroyable.rb +60 -0
  96. data/lib/mongoid/persistable/incrementable.rb +36 -0
  97. data/lib/mongoid/persistable/logical.rb +38 -0
  98. data/lib/mongoid/persistable/poppable.rb +39 -0
  99. data/lib/mongoid/persistable/pullable.rb +55 -0
  100. data/lib/mongoid/persistable/pushable.rb +62 -0
  101. data/lib/mongoid/persistable/renamable.rb +35 -0
  102. data/lib/mongoid/persistable/savable.rb +52 -0
  103. data/lib/mongoid/persistable/settable.rb +33 -0
  104. data/lib/mongoid/persistable/unsettable.rb +36 -0
  105. data/lib/mongoid/persistable/updatable.rb +153 -0
  106. data/lib/mongoid/persistable/upsertable.rb +55 -0
  107. data/lib/mongoid/positional.rb +71 -0
  108. data/lib/mongoid/query_cache.rb +255 -0
  109. data/lib/mongoid/railtie.rb +34 -60
  110. data/lib/mongoid/railties/database.rake +9 -25
  111. data/lib/mongoid/relations.rb +11 -25
  112. data/lib/mongoid/relations/accessors.rb +15 -51
  113. data/lib/mongoid/relations/auto_save.rb +15 -36
  114. data/lib/mongoid/relations/binding.rb +2 -25
  115. data/lib/mongoid/relations/bindings/embedded/in.rb +1 -1
  116. data/lib/mongoid/relations/bindings/embedded/many.rb +1 -3
  117. data/lib/mongoid/relations/bindings/referenced/in.rb +3 -8
  118. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -2
  119. data/lib/mongoid/relations/builder.rb +1 -1
  120. data/lib/mongoid/relations/builders.rb +2 -2
  121. data/lib/mongoid/relations/builders/embedded/one.rb +1 -1
  122. data/lib/mongoid/relations/builders/nested_attributes/many.rb +10 -13
  123. data/lib/mongoid/relations/builders/nested_attributes/one.rb +5 -6
  124. data/lib/mongoid/relations/builders/referenced/in.rb +1 -1
  125. data/lib/mongoid/relations/builders/referenced/many.rb +1 -2
  126. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +1 -2
  127. data/lib/mongoid/relations/builders/referenced/one.rb +1 -1
  128. data/lib/mongoid/relations/cascading.rb +3 -5
  129. data/lib/mongoid/relations/constraint.rb +1 -1
  130. data/lib/mongoid/relations/conversions.rb +1 -1
  131. data/lib/mongoid/relations/counter_cache.rb +39 -15
  132. data/lib/mongoid/relations/eager.rb +46 -0
  133. data/lib/mongoid/relations/eager/base.rb +149 -0
  134. data/lib/mongoid/relations/eager/belongs_to.rb +31 -0
  135. data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +47 -0
  136. data/lib/mongoid/relations/eager/has_many.rb +38 -0
  137. data/lib/mongoid/relations/eager/has_one.rb +30 -0
  138. data/lib/mongoid/relations/embedded/batchable.rb +4 -5
  139. data/lib/mongoid/relations/embedded/in.rb +4 -4
  140. data/lib/mongoid/relations/embedded/many.rb +14 -32
  141. data/lib/mongoid/relations/embedded/one.rb +1 -1
  142. data/lib/mongoid/relations/macros.rb +3 -4
  143. data/lib/mongoid/relations/many.rb +51 -31
  144. data/lib/mongoid/relations/marshalable.rb +3 -3
  145. data/lib/mongoid/relations/metadata.rb +14 -79
  146. data/lib/mongoid/relations/nested_builder.rb +2 -2
  147. data/lib/mongoid/relations/one.rb +1 -1
  148. data/lib/mongoid/relations/options.rb +1 -0
  149. data/lib/mongoid/relations/polymorphic.rb +0 -1
  150. data/lib/mongoid/relations/proxy.rb +21 -41
  151. data/lib/mongoid/relations/referenced/in.rb +4 -20
  152. data/lib/mongoid/relations/referenced/many.rb +22 -35
  153. data/lib/mongoid/relations/referenced/many_to_many.rb +19 -42
  154. data/lib/mongoid/relations/referenced/one.rb +6 -25
  155. data/lib/mongoid/relations/synchronization.rb +4 -4
  156. data/lib/mongoid/relations/targets/enumerable.rb +10 -10
  157. data/lib/mongoid/relations/touchable.rb +34 -1
  158. data/lib/mongoid/{reloading.rb → reloadable.rb} +7 -5
  159. data/lib/mongoid/{scoping.rb → scopable.rb} +36 -36
  160. data/lib/mongoid/selectable.rb +59 -0
  161. data/lib/mongoid/{serialization.rb → serializable.rb} +11 -2
  162. data/lib/mongoid/sessions.rb +37 -345
  163. data/lib/mongoid/sessions/factory.rb +2 -0
  164. data/lib/mongoid/sessions/options.rb +185 -0
  165. data/lib/mongoid/sessions/storage_options.rb +140 -0
  166. data/lib/mongoid/sessions/thread_options.rb +19 -0
  167. data/lib/mongoid/sessions/validators/storage.rb +16 -3
  168. data/lib/mongoid/{sharding.rb → shardable.rb} +5 -1
  169. data/lib/mongoid/{state.rb → stateful.rb} +13 -1
  170. data/lib/mongoid/support/query_counter.rb +23 -0
  171. data/lib/mongoid/tasks/database.rake +31 -0
  172. data/lib/mongoid/tasks/database.rb +107 -0
  173. data/lib/mongoid/threaded.rb +26 -172
  174. data/lib/mongoid/threaded/lifecycle.rb +0 -28
  175. data/lib/mongoid/timestamps/updated/short.rb +2 -2
  176. data/lib/mongoid/{hierarchy.rb → traversable.rb} +15 -7
  177. data/lib/mongoid/{validations.rb → validatable.rb} +23 -10
  178. data/lib/mongoid/{validations → validatable}/associated.rb +4 -2
  179. data/lib/mongoid/{validations → validatable}/format.rb +1 -1
  180. data/lib/mongoid/{validations → validatable}/length.rb +1 -1
  181. data/lib/mongoid/{validations → validatable}/localizable.rb +1 -1
  182. data/lib/mongoid/{validations → validatable}/macros.rb +4 -3
  183. data/lib/mongoid/{validations → validatable}/presence.rb +1 -1
  184. data/lib/mongoid/{validations → validatable}/queryable.rb +1 -2
  185. data/lib/mongoid/{validations → validatable}/uniqueness.rb +25 -21
  186. data/lib/mongoid/version.rb +1 -1
  187. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +46 -25
  188. data/lib/rails/generators/mongoid/model/model_generator.rb +0 -1
  189. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +0 -3
  190. data/lib/rails/generators/mongoid_generator.rb +3 -40
  191. data/lib/rails/mongoid.rb +0 -122
  192. data/lib/support/ruby_version.rb +1 -1
  193. data/spec/app/models/account.rb +2 -6
  194. data/spec/app/models/acolyte.rb +2 -1
  195. data/spec/app/models/actor.rb +0 -1
  196. data/spec/app/models/address.rb +8 -3
  197. data/spec/app/models/animal.rb +1 -1
  198. data/spec/app/models/appointment.rb +3 -3
  199. data/spec/app/models/article.rb +1 -4
  200. data/spec/app/models/audio.rb +5 -0
  201. data/spec/app/models/author.rb +0 -2
  202. data/spec/app/models/band.rb +3 -2
  203. data/spec/app/models/bar.rb +1 -0
  204. data/spec/app/models/book.rb +1 -0
  205. data/spec/app/models/building.rb +0 -2
  206. data/spec/app/models/building_address.rb +0 -2
  207. data/spec/app/models/bus.rb +1 -1
  208. data/spec/app/models/canvas.rb +1 -1
  209. data/spec/app/models/contextable_item.rb +5 -0
  210. data/spec/app/models/contractor.rb +0 -2
  211. data/spec/app/models/country_code.rb +1 -1
  212. data/spec/app/models/definition.rb +2 -2
  213. data/spec/app/models/dog.rb +1 -1
  214. data/spec/app/models/draft.rb +9 -0
  215. data/spec/app/models/dragon.rb +4 -0
  216. data/spec/app/models/drug.rb +1 -3
  217. data/spec/app/models/dungeon.rb +4 -0
  218. data/spec/app/models/edit.rb +5 -0
  219. data/spec/app/models/even.rb +7 -0
  220. data/spec/app/models/event.rb +1 -1
  221. data/spec/app/models/filesystem.rb +1 -0
  222. data/spec/app/models/fish.rb +0 -1
  223. data/spec/app/models/fruits.rb +6 -0
  224. data/spec/app/models/game.rb +0 -2
  225. data/spec/app/models/house.rb +1 -3
  226. data/spec/app/models/id_key.rb +6 -0
  227. data/spec/app/models/item.rb +1 -5
  228. data/spec/app/models/jar.rb +1 -1
  229. data/spec/app/models/label.rb +4 -4
  230. data/spec/app/models/line_item.rb +1 -1
  231. data/spec/app/models/login.rb +1 -1
  232. data/spec/app/models/message.rb +8 -0
  233. data/spec/app/models/movie.rb +1 -0
  234. data/spec/app/models/name.rb +3 -3
  235. data/spec/app/models/note.rb +3 -1
  236. data/spec/app/models/odd.rb +7 -0
  237. data/spec/app/models/oscar.rb +1 -1
  238. data/spec/app/models/parent_doc.rb +1 -1
  239. data/spec/app/models/person.rb +16 -10
  240. data/spec/app/models/phone.rb +1 -3
  241. data/spec/app/models/player.rb +3 -3
  242. data/spec/app/models/post.rb +5 -3
  243. data/spec/app/models/preference.rb +1 -1
  244. data/spec/app/models/quiz.rb +0 -3
  245. data/spec/app/models/record.rb +10 -5
  246. data/spec/app/models/registry.rb +1 -1
  247. data/spec/app/models/server.rb +1 -1
  248. data/spec/app/models/service.rb +3 -3
  249. data/spec/app/models/sound.rb +5 -0
  250. data/spec/app/models/symptom.rb +1 -1
  251. data/spec/app/models/template.rb +1 -1
  252. data/spec/app/models/title.rb +0 -1
  253. data/spec/app/models/track.rb +5 -5
  254. data/spec/app/models/tree.rb +3 -3
  255. data/spec/app/models/video.rb +1 -5
  256. data/spec/app/models/wiki_page.rb +2 -5
  257. data/spec/app/models/word.rb +3 -0
  258. data/spec/app/models/word_origin.rb +1 -1
  259. data/spec/config/mongoid.yml +7 -8
  260. data/spec/helpers.rb +18 -0
  261. data/spec/mongoid/#atomic_spec.rb# +365 -0
  262. data/spec/mongoid/atomic/modifiers_spec.rb +22 -22
  263. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +8 -49
  264. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +7 -49
  265. data/spec/mongoid/atomic/paths/root_spec.rb +3 -61
  266. data/spec/mongoid/atomic/paths_spec.rb +19 -19
  267. data/spec/mongoid/atomic_spec.rb +19 -19
  268. data/spec/mongoid/{nested_attributes_spec.rb → attributes/nested_spec.rb} +474 -592
  269. data/spec/mongoid/attributes/readonly_spec.rb +58 -18
  270. data/spec/mongoid/attributes_spec.rb +349 -434
  271. data/spec/mongoid/{dirty_spec.rb → changeable_spec.rb} +203 -153
  272. data/spec/mongoid/{components_spec.rb → composable_spec.rb} +3 -3
  273. data/spec/mongoid/config/environment_spec.rb +3 -3
  274. data/spec/mongoid/config/options_spec.rb +6 -6
  275. data/spec/mongoid/config_spec.rb +24 -48
  276. data/spec/mongoid/contextual/aggregable/memory_spec.rb +12 -12
  277. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +78 -38
  278. data/spec/mongoid/contextual/atomic_spec.rb +60 -56
  279. data/spec/mongoid/contextual/find_and_modify_spec.rb +14 -14
  280. data/spec/mongoid/contextual/geo_near_spec.rb +22 -22
  281. data/spec/mongoid/contextual/map_reduce_spec.rb +27 -27
  282. data/spec/mongoid/contextual/memory_spec.rb +156 -94
  283. data/spec/mongoid/contextual/mongo_spec.rb +238 -150
  284. data/spec/mongoid/contextual/none_spec.rb +127 -0
  285. data/spec/mongoid/contextual/text_search_spec.rb +209 -0
  286. data/spec/mongoid/copyable_spec.rb +56 -68
  287. data/spec/mongoid/criteria/findable_spec.rb +991 -0
  288. data/spec/mongoid/{criterion/inspection_spec.rb → criteria/inspectable_spec.rb} +5 -5
  289. data/spec/mongoid/{criterion → criteria}/marshalable_spec.rb +2 -2
  290. data/spec/mongoid/criteria/modifiable_spec.rb +1252 -0
  291. data/spec/mongoid/{criterion/scoping_spec.rb → criteria/scopable_spec.rb} +37 -37
  292. data/spec/mongoid/criteria_spec.rb +715 -2421
  293. data/spec/mongoid/document_spec.rb +171 -121
  294. data/spec/mongoid/equality_spec.rb +22 -22
  295. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +3 -3
  296. data/spec/mongoid/errors/callback_spec.rb +3 -3
  297. data/spec/mongoid/errors/delete_restriction_spec.rb +3 -3
  298. data/spec/mongoid/errors/document_not_destroyed_spec.rb +33 -0
  299. data/spec/mongoid/errors/document_not_found_spec.rb +11 -11
  300. data/spec/mongoid/errors/eager_load_spec.rb +3 -3
  301. data/spec/mongoid/errors/invalid_collection_spec.rb +3 -3
  302. data/spec/mongoid/errors/invalid_config_option_spec.rb +3 -3
  303. data/spec/mongoid/errors/invalid_field_option_spec.rb +3 -3
  304. data/spec/mongoid/errors/invalid_field_spec.rb +3 -3
  305. data/spec/mongoid/errors/invalid_find_spec.rb +3 -3
  306. data/spec/mongoid/errors/invalid_includes_spec.rb +3 -3
  307. data/spec/mongoid/errors/invalid_index_spec.rb +3 -3
  308. data/spec/mongoid/errors/invalid_options_spec.rb +3 -3
  309. data/spec/mongoid/errors/invalid_path_spec.rb +3 -3
  310. data/spec/mongoid/errors/invalid_scope_spec.rb +5 -5
  311. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -3
  312. data/spec/mongoid/errors/invalid_storage_options_spec.rb +3 -3
  313. data/spec/mongoid/errors/invalid_time_spec.rb +3 -3
  314. data/spec/mongoid/errors/inverse_not_found_spec.rb +3 -3
  315. data/spec/mongoid/errors/mixed_relations_spec.rb +3 -3
  316. data/spec/mongoid/errors/mixed_session_configuration_spec.rb +3 -3
  317. data/spec/mongoid/errors/mongoid_error_spec.rb +8 -8
  318. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +3 -3
  319. data/spec/mongoid/errors/no_environment_spec.rb +3 -3
  320. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +3 -3
  321. data/spec/mongoid/errors/no_metadata_spec.rb +3 -3
  322. data/spec/mongoid/errors/no_parent_spec.rb +3 -3
  323. data/spec/mongoid/errors/no_session_config_spec.rb +3 -3
  324. data/spec/mongoid/errors/no_session_database_spec.rb +3 -3
  325. data/spec/mongoid/errors/no_session_hosts_spec.rb +3 -3
  326. data/spec/mongoid/errors/no_sessions_config_spec.rb +3 -3
  327. data/spec/mongoid/errors/readonly_attribute_spec.rb +3 -3
  328. data/spec/mongoid/errors/readonly_document_spec.rb +29 -0
  329. data/spec/mongoid/errors/scope_overwrite_spec.rb +3 -3
  330. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +3 -3
  331. data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -5
  332. data/spec/mongoid/errors/unsaved_document_spec.rb +3 -3
  333. data/spec/mongoid/errors/unsupported_javascript_spec.rb +3 -3
  334. data/spec/mongoid/errors/validations_spec.rb +7 -7
  335. data/spec/mongoid/extensions/array_spec.rb +61 -61
  336. data/spec/mongoid/extensions/big_decimal_spec.rb +11 -11
  337. data/spec/mongoid/extensions/binary_spec.rb +12 -12
  338. data/spec/mongoid/extensions/boolean_spec.rb +18 -18
  339. data/spec/mongoid/extensions/date_spec.rb +13 -13
  340. data/spec/mongoid/extensions/date_time_spec.rb +8 -8
  341. data/spec/mongoid/extensions/false_class_spec.rb +5 -5
  342. data/spec/mongoid/extensions/float_spec.rb +29 -15
  343. data/spec/mongoid/extensions/hash_spec.rb +29 -29
  344. data/spec/mongoid/extensions/integer_spec.rb +15 -15
  345. data/spec/mongoid/extensions/module_spec.rb +2 -2
  346. data/spec/mongoid/extensions/nil_class_spec.rb +1 -1
  347. data/spec/mongoid/extensions/object_id_spec.rb +134 -134
  348. data/spec/mongoid/extensions/object_spec.rb +26 -26
  349. data/spec/mongoid/extensions/range_spec.rb +61 -12
  350. data/spec/mongoid/extensions/regexp_spec.rb +4 -4
  351. data/spec/mongoid/extensions/set_spec.rb +4 -4
  352. data/spec/mongoid/extensions/string_spec.rb +35 -46
  353. data/spec/mongoid/extensions/symbol_spec.rb +9 -9
  354. data/spec/mongoid/extensions/time_spec.rb +49 -49
  355. data/spec/mongoid/extensions/time_with_zone_spec.rb +34 -34
  356. data/spec/mongoid/extensions/true_class_spec.rb +5 -5
  357. data/spec/mongoid/extensions_spec.rb +29 -0
  358. data/spec/mongoid/factory_spec.rb +15 -15
  359. data/spec/mongoid/fields/foreign_key_spec.rb +73 -66
  360. data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +15 -15
  361. data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +22 -22
  362. data/spec/mongoid/fields/localized_spec.rb +38 -23
  363. data/spec/mongoid/fields/standard_spec.rb +12 -12
  364. data/spec/mongoid/fields_spec.rb +263 -217
  365. data/spec/mongoid/findable_spec.rb +509 -0
  366. data/spec/mongoid/indexable/specification_spec.rb +102 -0
  367. data/spec/mongoid/{indexes_spec.rb → indexable_spec.rb} +171 -51
  368. data/spec/mongoid/{inspection_spec.rb → inspectable_spec.rb} +6 -14
  369. data/spec/mongoid/{callbacks_spec.rb → interceptable_spec.rb} +117 -116
  370. data/spec/mongoid/log_subscriber_spec.rb +75 -0
  371. data/spec/mongoid/loggable_spec.rb +1 -1
  372. data/spec/mongoid/{matchers → matchable}/all_spec.rb +4 -4
  373. data/spec/mongoid/{matchers → matchable}/and_spec.rb +11 -11
  374. data/spec/mongoid/{matchers → matchable}/default_spec.rb +15 -15
  375. data/spec/mongoid/{matchers → matchable}/exists_spec.rb +5 -5
  376. data/spec/mongoid/{matchers → matchable}/gt_spec.rb +9 -8
  377. data/spec/mongoid/{matchers → matchable}/gte_spec.rb +7 -7
  378. data/spec/mongoid/matchable/in_spec.rb +49 -0
  379. data/spec/mongoid/{matchers → matchable}/lt_spec.rb +7 -7
  380. data/spec/mongoid/{matchers → matchable}/lte_spec.rb +7 -7
  381. data/spec/mongoid/matchable/ne_spec.rb +46 -0
  382. data/spec/mongoid/matchable/nin_spec.rb +48 -0
  383. data/spec/mongoid/{matchers → matchable}/or_spec.rb +6 -6
  384. data/spec/mongoid/{matchers → matchable}/size_spec.rb +3 -3
  385. data/spec/mongoid/{matchers_spec.rb → matchable_spec.rb} +41 -41
  386. data/spec/mongoid/persistable/creatable_spec.rb +553 -0
  387. data/spec/mongoid/persistable/deletable_spec.rb +218 -0
  388. data/spec/mongoid/persistable/destroyable_spec.rb +192 -0
  389. data/spec/mongoid/persistable/incrementable_spec.rb +173 -0
  390. data/spec/mongoid/persistable/logical_spec.rb +143 -0
  391. data/spec/mongoid/persistable/poppable_spec.rb +115 -0
  392. data/spec/mongoid/persistable/pullable_spec.rb +228 -0
  393. data/spec/mongoid/persistable/pushable_spec.rb +258 -0
  394. data/spec/mongoid/persistable/renamable_spec.rb +135 -0
  395. data/spec/mongoid/persistable/savable_spec.rb +498 -0
  396. data/spec/mongoid/persistable/settable_spec.rb +162 -0
  397. data/spec/mongoid/persistable/unsettable_spec.rb +155 -0
  398. data/spec/mongoid/persistable/updatable_spec.rb +558 -0
  399. data/spec/mongoid/persistable/upsertable_spec.rb +106 -0
  400. data/spec/mongoid/persistable_spec.rb +206 -0
  401. data/spec/mongoid/{atomic/positionable_spec.rb → positional_spec.rb} +14 -19
  402. data/spec/mongoid/query_cache_spec.rb +263 -0
  403. data/spec/mongoid/railties/document_spec.rb +2 -2
  404. data/spec/mongoid/relations/accessors_spec.rb +53 -145
  405. data/spec/mongoid/relations/auto_save_spec.rb +37 -17
  406. data/spec/mongoid/relations/bindings/embedded/in_spec.rb +12 -12
  407. data/spec/mongoid/relations/bindings/embedded/many_spec.rb +3 -3
  408. data/spec/mongoid/relations/bindings/embedded/one_spec.rb +5 -5
  409. data/spec/mongoid/relations/bindings/referenced/in_spec.rb +26 -26
  410. data/spec/mongoid/relations/bindings/referenced/many_spec.rb +10 -10
  411. data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +19 -19
  412. data/spec/mongoid/relations/bindings/referenced/one_spec.rb +12 -12
  413. data/spec/mongoid/relations/builders/embedded/in_spec.rb +4 -4
  414. data/spec/mongoid/relations/builders/embedded/many_spec.rb +18 -18
  415. data/spec/mongoid/relations/builders/embedded/one_spec.rb +11 -11
  416. data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +12 -13
  417. data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +14 -14
  418. data/spec/mongoid/relations/builders/referenced/in_spec.rb +24 -35
  419. data/spec/mongoid/relations/builders/referenced/many_spec.rb +15 -15
  420. data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +18 -18
  421. data/spec/mongoid/relations/builders/referenced/one_spec.rb +12 -25
  422. data/spec/mongoid/relations/builders_spec.rb +21 -21
  423. data/spec/mongoid/relations/cascading/delete_spec.rb +9 -9
  424. data/spec/mongoid/relations/cascading/destroy_spec.rb +6 -6
  425. data/spec/mongoid/relations/cascading/nullify_spec.rb +4 -4
  426. data/spec/mongoid/relations/cascading/restrict_spec.rb +7 -7
  427. data/spec/mongoid/relations/cascading_spec.rb +16 -16
  428. data/spec/mongoid/relations/constraint_spec.rb +8 -7
  429. data/spec/mongoid/relations/conversions_spec.rb +16 -14
  430. data/spec/mongoid/relations/counter_cache_spec.rb +85 -0
  431. data/spec/mongoid/relations/cyclic_spec.rb +18 -18
  432. data/spec/mongoid/relations/eager/belongs_to_spec.rb +154 -0
  433. data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +117 -0
  434. data/spec/mongoid/relations/eager/has_many_spec.rb +207 -0
  435. data/spec/mongoid/relations/eager/has_one_spec.rb +163 -0
  436. data/spec/mongoid/relations/eager_spec.rb +228 -0
  437. data/spec/mongoid/relations/embedded/dirty_spec.rb +8 -8
  438. data/spec/mongoid/relations/embedded/in_spec.rb +56 -57
  439. data/spec/mongoid/relations/embedded/many_spec.rb +467 -372
  440. data/spec/mongoid/relations/embedded/one_spec.rb +108 -141
  441. data/spec/mongoid/relations/macros_spec.rb +108 -102
  442. data/spec/mongoid/relations/metadata_spec.rb +180 -255
  443. data/spec/mongoid/relations/options_spec.rb +1 -1
  444. data/spec/mongoid/relations/polymorphic_spec.rb +13 -17
  445. data/spec/mongoid/relations/proxy_spec.rb +2 -2
  446. data/spec/mongoid/relations/referenced/in_spec.rb +128 -303
  447. data/spec/mongoid/relations/referenced/many_spec.rb +587 -527
  448. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +401 -424
  449. data/spec/mongoid/relations/referenced/one_spec.rb +149 -264
  450. data/spec/mongoid/relations/reflections_spec.rb +6 -6
  451. data/spec/mongoid/relations/synchronization_spec.rb +46 -50
  452. data/spec/mongoid/relations/targets/enumerable_spec.rb +118 -118
  453. data/spec/mongoid/relations/touchable_spec.rb +333 -0
  454. data/spec/mongoid/relations_spec.rb +16 -15
  455. data/spec/mongoid/{reloading_spec.rb → reloadable_spec.rb} +38 -55
  456. data/spec/mongoid/{scoping_spec.rb → scopable_spec.rb} +89 -164
  457. data/spec/mongoid/selectable_spec.rb +134 -0
  458. data/spec/mongoid/{serialization_spec.rb → serializable_spec.rb} +129 -82
  459. data/spec/mongoid/sessions/factory_spec.rb +49 -28
  460. data/spec/mongoid/sessions/mongo_uri_spec.rb +7 -7
  461. data/spec/mongoid/sessions/options_spec.rb +108 -0
  462. data/spec/mongoid/sessions_spec.rb +319 -178
  463. data/spec/mongoid/{sharding_spec.rb → shardable_spec.rb} +8 -8
  464. data/spec/mongoid/{state_spec.rb → stateful_spec.rb} +36 -11
  465. data/spec/mongoid/tasks/database_rake_spec.rb +285 -0
  466. data/spec/mongoid/tasks/database_spec.rb +160 -0
  467. data/spec/mongoid/threaded_spec.rb +17 -70
  468. data/spec/mongoid/timestamps/created/short_spec.rb +6 -6
  469. data/spec/mongoid/timestamps/created_spec.rb +5 -5
  470. data/spec/mongoid/timestamps/timeless_spec.rb +6 -6
  471. data/spec/mongoid/timestamps/updated/short_spec.rb +11 -11
  472. data/spec/mongoid/timestamps/updated_spec.rb +9 -13
  473. data/spec/mongoid/timestamps_spec.rb +9 -13
  474. data/spec/mongoid/{hierarchy_spec.rb → traversable_spec.rb} +19 -19
  475. data/spec/mongoid/{validations → validatable}/associated_spec.rb +45 -22
  476. data/spec/mongoid/{validations → validatable}/format_spec.rb +6 -6
  477. data/spec/mongoid/{validations → validatable}/length_spec.rb +14 -14
  478. data/spec/mongoid/{validations → validatable}/numericality_spec.rb +1 -1
  479. data/spec/mongoid/{validations → validatable}/presence_spec.rb +37 -44
  480. data/spec/mongoid/{validations → validatable}/uniqueness_spec.rb +184 -192
  481. data/spec/mongoid/{validations_spec.rb → validatable_spec.rb} +28 -28
  482. data/spec/mongoid_spec.rb +8 -8
  483. data/spec/rails/mongoid_spec.rb +19 -335
  484. data/spec/spec_helper.rb +31 -13
  485. metadata +303 -283
  486. data/lib/mongoid/atomic/positionable.rb +0 -73
  487. data/lib/mongoid/components.rb +0 -92
  488. data/lib/mongoid/config/inflections.rb +0 -6
  489. data/lib/mongoid/contextual/eager.rb +0 -158
  490. data/lib/mongoid/errors/versioning_not_on_root.rb +0 -23
  491. data/lib/mongoid/identity_map.rb +0 -163
  492. data/lib/mongoid/json.rb +0 -16
  493. data/lib/mongoid/matchers.rb +0 -32
  494. data/lib/mongoid/matchers/strategies.rb +0 -97
  495. data/lib/mongoid/multi_parameter_attributes.rb +0 -105
  496. data/lib/mongoid/nested_attributes.rb +0 -78
  497. data/lib/mongoid/observer.rb +0 -192
  498. data/lib/mongoid/paranoia.rb +0 -136
  499. data/lib/mongoid/persistence.rb +0 -357
  500. data/lib/mongoid/persistence/atomic.rb +0 -231
  501. data/lib/mongoid/persistence/atomic/add_to_set.rb +0 -47
  502. data/lib/mongoid/persistence/atomic/bit.rb +0 -35
  503. data/lib/mongoid/persistence/atomic/inc.rb +0 -45
  504. data/lib/mongoid/persistence/atomic/operation.rb +0 -154
  505. data/lib/mongoid/persistence/atomic/pop.rb +0 -32
  506. data/lib/mongoid/persistence/atomic/pull.rb +0 -32
  507. data/lib/mongoid/persistence/atomic/pull_all.rb +0 -32
  508. data/lib/mongoid/persistence/atomic/push.rb +0 -25
  509. data/lib/mongoid/persistence/atomic/push_all.rb +0 -25
  510. data/lib/mongoid/persistence/atomic/rename.rb +0 -30
  511. data/lib/mongoid/persistence/atomic/sets.rb +0 -28
  512. data/lib/mongoid/persistence/atomic/unset.rb +0 -27
  513. data/lib/mongoid/persistence/deletion.rb +0 -31
  514. data/lib/mongoid/persistence/insertion.rb +0 -38
  515. data/lib/mongoid/persistence/modification.rb +0 -35
  516. data/lib/mongoid/persistence/operations.rb +0 -214
  517. data/lib/mongoid/persistence/operations/embedded/insert.rb +0 -46
  518. data/lib/mongoid/persistence/operations/embedded/remove.rb +0 -43
  519. data/lib/mongoid/persistence/operations/insert.rb +0 -34
  520. data/lib/mongoid/persistence/operations/remove.rb +0 -33
  521. data/lib/mongoid/persistence/operations/update.rb +0 -59
  522. data/lib/mongoid/persistence/operations/upsert.rb +0 -28
  523. data/lib/mongoid/persistence/upsertion.rb +0 -31
  524. data/lib/mongoid/unit_of_work.rb +0 -61
  525. data/lib/mongoid/versioning.rb +0 -217
  526. data/lib/rack/mongoid.rb +0 -2
  527. data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
  528. data/lib/rails/generators/mongoid/observer/observer_generator.rb +0 -17
  529. data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +0 -4
  530. data/spec/app/models/actor_observer.rb +0 -15
  531. data/spec/app/models/callback_recorder.rb +0 -25
  532. data/spec/app/models/paranoid_phone.rb +0 -25
  533. data/spec/app/models/paranoid_post.rb +0 -36
  534. data/spec/app/models/phone_observer.rb +0 -6
  535. data/spec/mongoid/attributes/processing_spec.rb +0 -149
  536. data/spec/mongoid/criterion/destructive_spec.rb +0 -101
  537. data/spec/mongoid/criterion/modifiable_spec.rb +0 -409
  538. data/spec/mongoid/criterion/modification_spec.rb +0 -402
  539. data/spec/mongoid/errors/versioning_not_on_root_spec.rb +0 -29
  540. data/spec/mongoid/finders_spec.rb +0 -321
  541. data/spec/mongoid/identity_map_spec.rb +0 -564
  542. data/spec/mongoid/json_spec.rb +0 -33
  543. data/spec/mongoid/matchers/in_spec.rb +0 -25
  544. data/spec/mongoid/matchers/ne_spec.rb +0 -25
  545. data/spec/mongoid/matchers/nin_spec.rb +0 -25
  546. data/spec/mongoid/multi_parameter_attributes_spec.rb +0 -128
  547. data/spec/mongoid/observer_spec.rb +0 -290
  548. data/spec/mongoid/paranoia_spec.rb +0 -759
  549. data/spec/mongoid/persistence/atomic/add_to_set_spec.rb +0 -262
  550. data/spec/mongoid/persistence/atomic/bit_spec.rb +0 -88
  551. data/spec/mongoid/persistence/atomic/inc_spec.rb +0 -133
  552. data/spec/mongoid/persistence/atomic/pop_spec.rb +0 -111
  553. data/spec/mongoid/persistence/atomic/pull_all_spec.rb +0 -77
  554. data/spec/mongoid/persistence/atomic/pull_spec.rb +0 -80
  555. data/spec/mongoid/persistence/atomic/push_all_spec.rb +0 -77
  556. data/spec/mongoid/persistence/atomic/push_spec.rb +0 -77
  557. data/spec/mongoid/persistence/atomic/rename_spec.rb +0 -42
  558. data/spec/mongoid/persistence/atomic/sets_spec.rb +0 -154
  559. data/spec/mongoid/persistence/atomic/unset_spec.rb +0 -65
  560. data/spec/mongoid/persistence/atomic_spec.rb +0 -216
  561. data/spec/mongoid/persistence/operations/embedded/insert_spec.rb +0 -191
  562. data/spec/mongoid/persistence/operations/embedded/remove_spec.rb +0 -8
  563. data/spec/mongoid/persistence/operations/insert_spec.rb +0 -149
  564. data/spec/mongoid/persistence/operations/remove_spec.rb +0 -113
  565. data/spec/mongoid/persistence/operations/update_spec.rb +0 -141
  566. data/spec/mongoid/persistence/operations/upsert_spec.rb +0 -59
  567. data/spec/mongoid/persistence/operations_spec.rb +0 -313
  568. data/spec/mongoid/persistence_spec.rb +0 -2279
  569. data/spec/mongoid/unit_of_work_spec.rb +0 -196
  570. data/spec/mongoid/versioning_spec.rb +0 -540
  571. data/spec/rack/mongoid/middleware/identity_map_spec.rb +0 -72
@@ -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
 
@@ -46,7 +45,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
46
45
  end
47
46
 
48
47
  it "does not persist the child document" do
49
- preference.should_receive(:save).never
48
+ expect(preference).to receive(:save).never
50
49
  article.preferences.send(method, preference)
51
50
  end
52
51
  end
@@ -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,20 +509,20 @@ 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
517
516
 
518
517
  before do
519
- post.should_receive(:before_add_tag).and_raise
518
+ expect(post).to receive(:before_add_tag).and_raise
520
519
  end
521
520
 
522
521
  it "does not add the document to the relation" 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,20 +531,20 @@ 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
539
538
 
540
539
  before do
541
- post.should_receive(:after_add_tag).and_raise
540
+ expect(post).to receive(:after_add_tag).and_raise
542
541
  end
543
542
 
544
543
  it "adds the document to the relation" 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,25 +1174,25 @@ 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
 
1197
1185
  context "when errors are raised" do
1198
1186
 
1199
1187
  before do
1200
- post.should_receive(:before_remove_tag).and_raise
1188
+ expect(post).to receive(:before_remove_tag).and_raise
1201
1189
  end
1202
1190
 
1203
1191
  it "does not remove the document from the relation" 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,25 +1206,25 @@ 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
 
1229
1217
  context "when errors are raised" do
1230
1218
 
1231
1219
  before do
1232
- post.should_receive(:after_remove_tag).and_raise
1220
+ expect(post).to receive(:after_remove_tag).and_raise
1233
1221
  end
1234
1222
 
1235
1223
  it "removes the document from the relation" 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,25 +2108,25 @@ 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
 
2153
2119
  context "when errors are raised" do
2154
2120
 
2155
2121
  before do
2156
- post.should_receive(:before_remove_tag).and_raise
2122
+ expect(post).to receive(:before_remove_tag).and_raise
2157
2123
  end
2158
2124
 
2159
2125
  it "does not remove the document from the relation" 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,25 +2140,25 @@ 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
 
2185
2151
  context "when errors are raised" do
2186
2152
 
2187
2153
  before do
2188
- post.should_receive(:after_remove_tag).and_raise
2154
+ expect(post).to receive(:after_remove_tag).and_raise
2189
2155
  end
2190
2156
 
2191
2157
  it "removes the document from the relation" 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,60 @@ 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")
2460
+ end
2461
+
2462
+ it "returns a newly persisted document" do
2463
+ expect(found).to be_persisted
2464
+ end
2465
+ end
2466
+ end
2467
+ end
2468
+
2469
+ describe "#find_or_create_by!" do
2470
+
2471
+ context "when the relation is not polymorphic" do
2472
+
2473
+ let(:person) do
2474
+ Person.create
2475
+ end
2476
+
2477
+ let!(:preference) do
2478
+ person.preferences.create(name: "Testing")
2479
+ end
2480
+
2481
+ context "when the document exists" do
2482
+
2483
+ let(:found) do
2484
+ person.preferences.find_or_create_by!(name: "Testing")
2485
+ end
2486
+
2487
+ it "returns the document" do
2488
+ expect(found).to eq(preference)
2489
+ end
2490
+ end
2491
+
2492
+ context "when the document does not exist" do
2493
+
2494
+ let(:found) do
2495
+ person.preferences.find_or_create_by!(name: "Test")
2496
+ end
2497
+
2498
+ it "sets the new document attributes" do
2499
+ expect(found.name).to eq("Test")
2536
2500
  end
2537
2501
 
2538
2502
  it "returns a newly persisted document" do
2539
- found.should be_persisted
2503
+ expect(found).to be_persisted
2504
+ end
2505
+
2506
+ context "when validation fails" do
2507
+
2508
+ it "raises an error" do
2509
+ expect {
2510
+ person.preferences.find_or_create_by!(name: "A")
2511
+ }.to raise_error(Mongoid::Errors::Validations)
2512
+ end
2540
2513
  end
2541
2514
  end
2542
2515
  end
@@ -2561,7 +2534,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2561
2534
  end
2562
2535
 
2563
2536
  it "returns the document" do
2564
- found.should eq(preference)
2537
+ expect(found).to eq(preference)
2565
2538
  end
2566
2539
  end
2567
2540
 
@@ -2572,11 +2545,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2572
2545
  end
2573
2546
 
2574
2547
  it "sets the new document attributes" do
2575
- found.name.should eq("Test")
2548
+ expect(found.name).to eq("Test")
2576
2549
  end
2577
2550
 
2578
2551
  it "returns a non persisted document" do
2579
- found.should_not be_persisted
2552
+ expect(found).to_not be_persisted
2580
2553
  end
2581
2554
  end
2582
2555
  end
@@ -2585,14 +2558,14 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2585
2558
  describe ".foreign_key_suffix" do
2586
2559
 
2587
2560
  it "returns _ids" do
2588
- described_class.foreign_key_suffix.should eq("_ids")
2561
+ expect(described_class.foreign_key_suffix).to eq("_ids")
2589
2562
  end
2590
2563
  end
2591
2564
 
2592
2565
  describe ".macro" do
2593
2566
 
2594
2567
  it "returns has_and_belongs_to_many" do
2595
- described_class.macro.should eq(:has_and_belongs_to_many)
2568
+ expect(described_class.macro).to eq(:has_and_belongs_to_many)
2596
2569
  end
2597
2570
  end
2598
2571
 
@@ -2621,7 +2594,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2621
2594
  end
2622
2595
 
2623
2596
  it "returns the document with the max value of the supplied field" do
2624
- max.should eq(preference_two)
2597
+ expect(max).to eq(preference_two)
2625
2598
  end
2626
2599
  end
2627
2600
 
@@ -2648,7 +2621,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2648
2621
  end
2649
2622
 
2650
2623
  it "returns the document with the max value of the supplied field" do
2651
- max.should eq(preference_two)
2624
+ expect(max).to eq(preference_two)
2652
2625
  end
2653
2626
  end
2654
2627
 
@@ -2677,7 +2650,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2677
2650
  end
2678
2651
 
2679
2652
  it "applies the criteria to the documents" do
2680
- preferences.should eq([ preference_one ])
2653
+ expect(preferences).to eq([ preference_one ])
2681
2654
  end
2682
2655
  end
2683
2656
 
@@ -2688,7 +2661,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2688
2661
  end
2689
2662
 
2690
2663
  it "does not return unrelated documents" do
2691
- preferences.should be_empty
2664
+ expect(preferences).to be_empty
2692
2665
  end
2693
2666
  end
2694
2667
 
@@ -2699,7 +2672,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2699
2672
  end
2700
2673
 
2701
2674
  it "applies the criteria to the documents" do
2702
- preferences.should eq([ preference_one ])
2675
+ expect(preferences).to eq([ preference_one ])
2703
2676
  end
2704
2677
  end
2705
2678
 
@@ -2710,7 +2683,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2710
2683
  end
2711
2684
 
2712
2685
  it "applies the criteria to the documents" do
2713
- preferences.should eq([ preference_one ])
2686
+ expect(preferences).to eq([ preference_one ])
2714
2687
  end
2715
2688
  end
2716
2689
 
@@ -2718,9 +2691,13 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2718
2691
 
2719
2692
  describe "#distinct" do
2720
2693
 
2694
+ let(:values) do
2695
+ person.preferences.distinct(:name)
2696
+ end
2697
+
2721
2698
  it "returns the distinct values for the fields" do
2722
- person.preferences.distinct(:name).should =~
2723
- [ "First", "Second"]
2699
+ expect(values).to include("First")
2700
+ expect(values).to include("Second")
2724
2701
  end
2725
2702
 
2726
2703
  context "when the inverse relation is not defined" do
@@ -2730,7 +2707,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2730
2707
  end
2731
2708
 
2732
2709
  it "returns the distinct values for the fields" do
2733
- person.houses.distinct(:name).should eq([ house.name ])
2710
+ expect(person.houses.distinct(:name)).to eq([ house.name ])
2734
2711
  end
2735
2712
  end
2736
2713
  end
@@ -2762,7 +2739,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2762
2739
  end
2763
2740
 
2764
2741
  it "returns the min value of the supplied field" do
2765
- min.should eq(preference_one)
2742
+ expect(min).to eq(preference_one)
2766
2743
  end
2767
2744
  end
2768
2745
 
@@ -2789,14 +2766,14 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2789
2766
  end
2790
2767
 
2791
2768
  it "returns the min value of the supplied field" do
2792
- min.should eq(preference_one)
2769
+ expect(min).to eq(preference_one)
2793
2770
  end
2794
2771
  end
2795
2772
 
2796
2773
  describe "#nil?" do
2797
2774
 
2798
2775
  it "returns false" do
2799
- Person.new.preferences.should_not be_nil
2776
+ expect(Person.new.preferences).to_not be_nil
2800
2777
  end
2801
2778
  end
2802
2779
 
@@ -2820,30 +2797,30 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2820
2797
 
2821
2798
  it "removes the foreign key from the base document" do
2822
2799
  [ preference_one, preference_two ].each do |preference|
2823
- person.preference_ids.should_not include(preference.id)
2800
+ expect(person.preference_ids).to_not include(preference.id)
2824
2801
  end
2825
2802
  end
2826
2803
 
2827
2804
  it "removes the foreign key from the target documents" do
2828
2805
  [ preference_one, preference_two ].each do |preference|
2829
- preference.person_ids.should_not include(person.id)
2806
+ expect(preference.person_ids).to_not include(person.id)
2830
2807
  end
2831
2808
  end
2832
2809
 
2833
2810
  it "removes the reference from the base document" do
2834
2811
  [ preference_one, preference_two ].each do |preference|
2835
- person.preferences.should_not include(preference)
2812
+ expect(person.preferences).to_not include(preference)
2836
2813
  end
2837
2814
  end
2838
2815
 
2839
2816
  it "removes the reference from the target documents" do
2840
2817
  [ preference_one, preference_two ].each do |preference|
2841
- preference.people.should_not include(person)
2818
+ expect(preference.people).to_not include(person)
2842
2819
  end
2843
2820
  end
2844
2821
 
2845
2822
  it "saves the documents" do
2846
- preference_one.reload.people.should_not include(person)
2823
+ expect(preference_one.reload.people).to_not include(person)
2847
2824
  end
2848
2825
  end
2849
2826
 
@@ -2862,7 +2839,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2862
2839
  context "when checking #{method}" do
2863
2840
 
2864
2841
  it "returns true" do
2865
- preferences.respond_to?(method).should be_true
2842
+ expect(preferences.respond_to?(method)).to be true
2866
2843
  end
2867
2844
  end
2868
2845
  end
@@ -2872,7 +2849,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2872
2849
  context "when checking #{method}" do
2873
2850
 
2874
2851
  it "returns true" do
2875
- preferences.respond_to?(method).should be_true
2852
+ expect(preferences.respond_to?(method)).to be true
2876
2853
  end
2877
2854
  end
2878
2855
  end
@@ -2882,7 +2859,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2882
2859
  context "when checking #{method}" do
2883
2860
 
2884
2861
  it "returns true" do
2885
- preferences.respond_to?(method).should be_true
2862
+ expect(preferences.respond_to?(method)).to be true
2886
2863
  end
2887
2864
  end
2888
2865
  end
@@ -2891,7 +2868,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2891
2868
  describe ".stores_foreign_key?" do
2892
2869
 
2893
2870
  it "returns true" do
2894
- described_class.stores_foreign_key?.should be_true
2871
+ expect(described_class.stores_foreign_key?).to be true
2895
2872
  end
2896
2873
  end
2897
2874
 
@@ -2906,11 +2883,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2906
2883
  end
2907
2884
 
2908
2885
  it "returns the relation criteria" do
2909
- scoped.should be_a(Mongoid::Criteria)
2886
+ expect(scoped).to be_a(Mongoid::Criteria)
2910
2887
  end
2911
2888
 
2912
2889
  it "returns with an empty selector" do
2913
- scoped.selector.should eq({ "$and" => [{ "_id" => { "$in" => [] }}]})
2890
+ expect(scoped.selector).to eq({ "$and" => [{ "_id" => { "$in" => [] }}]})
2914
2891
  end
2915
2892
  end
2916
2893
 
@@ -2929,7 +2906,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2929
2906
  end
2930
2907
 
2931
2908
  it "returns the number of documents" do
2932
- person.preferences.send(method).should eq(1)
2909
+ expect(person.preferences.send(method)).to eq(1)
2933
2910
  end
2934
2911
  end
2935
2912
 
@@ -2941,7 +2918,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2941
2918
  end
2942
2919
 
2943
2920
  it "returns the total number of documents" do
2944
- person.preferences.send(method).should eq(2)
2921
+ expect(person.preferences.send(method)).to eq(2)
2945
2922
  end
2946
2923
  end
2947
2924
  end
@@ -2968,7 +2945,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2968
2945
  end
2969
2946
 
2970
2947
  it "returns only the associated documents" do
2971
- unscoped.should eq([ preference_one ])
2948
+ expect(unscoped).to eq([ preference_one ])
2972
2949
  end
2973
2950
  end
2974
2951
 
@@ -2991,11 +2968,11 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2991
2968
  end
2992
2969
 
2993
2970
  it "only returns associated documents" do
2994
- unscoped.should eq([ house_one ])
2971
+ expect(unscoped).to eq([ house_one ])
2995
2972
  end
2996
2973
 
2997
2974
  it "removes the default scoping options" do
2998
- unscoped.options.should eq({})
2975
+ expect(unscoped.options).to eq({})
2999
2976
  end
3000
2977
  end
3001
2978
  end
@@ -3003,7 +2980,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3003
2980
  describe ".valid_options" do
3004
2981
 
3005
2982
  it "returns the valid options" do
3006
- described_class.valid_options.should eq(
2983
+ expect(described_class.valid_options).to eq(
3007
2984
  [
3008
2985
  :after_add,
3009
2986
  :after_remove,
@@ -3023,7 +3000,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3023
3000
  describe ".validation_default" do
3024
3001
 
3025
3002
  it "returns true" do
3026
- described_class.validation_default.should be_true
3003
+ expect(described_class.validation_default).to be true
3027
3004
  end
3028
3005
  end
3029
3006
 
@@ -3055,7 +3032,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3055
3032
  context "when reloading" do
3056
3033
 
3057
3034
  it "properly sets the references" do
3058
- person.houses(true).should eq([ girlfriend_house ])
3035
+ expect(person.houses(true)).to eq([ girlfriend_house ])
3059
3036
  end
3060
3037
  end
3061
3038
  end
@@ -3077,15 +3054,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3077
3054
  end
3078
3055
 
3079
3056
  it "sets the businesses" do
3080
- user.businesses.should eq([ business ])
3057
+ expect(user.businesses).to eq([ business ])
3081
3058
  end
3082
3059
 
3083
3060
  it "sets the inverse users" do
3084
- user.businesses.first.owners.first.should eq(user)
3061
+ expect(user.businesses.first.owners.first).to eq(user)
3085
3062
  end
3086
3063
 
3087
3064
  it "sets the inverse businesses" do
3088
- business.owners.should eq([ user ])
3065
+ expect(business.owners).to eq([ user ])
3089
3066
  end
3090
3067
  end
3091
3068
 
@@ -3104,15 +3081,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3104
3081
  end
3105
3082
 
3106
3083
  it "sets the businesses" do
3107
- user.businesses.should eq([ business ])
3084
+ expect(user.businesses).to eq([ business ])
3108
3085
  end
3109
3086
 
3110
3087
  it "sets the inverse users" do
3111
- user.businesses.first.owners.first.should eq(user)
3088
+ expect(user.businesses.first.owners.first).to eq(user)
3112
3089
  end
3113
3090
 
3114
3091
  it "sets the inverse businesses" do
3115
- business.owners.should eq([ user ])
3092
+ expect(business.owners).to eq([ user ])
3116
3093
  end
3117
3094
 
3118
3095
  context "when reloading" do
@@ -3123,15 +3100,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3123
3100
  end
3124
3101
 
3125
3102
  it "persists the businesses" do
3126
- user.businesses.should eq([ business ])
3103
+ expect(user.businesses).to eq([ business ])
3127
3104
  end
3128
3105
 
3129
3106
  it "persists the inverse users" do
3130
- user.businesses.first.owners.first.should eq(user)
3107
+ expect(user.businesses.first.owners.first).to eq(user)
3131
3108
  end
3132
3109
 
3133
3110
  it "persists the inverse businesses" do
3134
- business.owners.should eq([ user ])
3111
+ expect(business.owners).to eq([ user ])
3135
3112
  end
3136
3113
  end
3137
3114
  end
@@ -3151,15 +3128,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3151
3128
  end
3152
3129
 
3153
3130
  it "sets the businesses" do
3154
- user.businesses.should eq([ business ])
3131
+ expect(user.businesses).to eq([ business ])
3155
3132
  end
3156
3133
 
3157
3134
  it "sets the inverse users" do
3158
- user.businesses.first.owners.first.should eq(user)
3135
+ expect(user.businesses.first.owners.first).to eq(user)
3159
3136
  end
3160
3137
 
3161
3138
  it "sets the inverse businesses" do
3162
- business.owners.should eq([ user ])
3139
+ expect(business.owners).to eq([ user ])
3163
3140
  end
3164
3141
 
3165
3142
  context "when reloading" do
@@ -3170,15 +3147,15 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3170
3147
  end
3171
3148
 
3172
3149
  it "persists the businesses" do
3173
- user.businesses.should eq([ business ])
3150
+ expect(user.businesses).to eq([ business ])
3174
3151
  end
3175
3152
 
3176
3153
  it "persists the inverse users" do
3177
- user.businesses.first.owners.first.should eq(user)
3154
+ expect(user.businesses.first.owners.first).to eq(user)
3178
3155
  end
3179
3156
 
3180
3157
  it "persists the inverse businesses" do
3181
- business.owners.should eq([ user ])
3158
+ expect(business.owners).to eq([ user ])
3182
3159
  end
3183
3160
  end
3184
3161
  end
@@ -3197,13 +3174,13 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3197
3174
  before do
3198
3175
  2.times do
3199
3176
  person.preferences.each do |preference|
3200
- preference.person_ids.should eq([ person.id ])
3177
+ expect(preference.person_ids).to eq([ person.id ])
3201
3178
  end
3202
3179
  end
3203
3180
  end
3204
3181
 
3205
3182
  it "does not duplicate foreign keys" do
3206
- person.preference_ids.should eq([ preference.id ])
3183
+ expect(person.preference_ids).to eq([ preference.id ])
3207
3184
  end
3208
3185
  end
3209
3186
 
@@ -3231,13 +3208,13 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3231
3208
  end
3232
3209
 
3233
3210
  it "orders the documents" do
3234
- person.ordered_preferences(true).should eq(
3211
+ expect(person.ordered_preferences(true)).to eq(
3235
3212
  [preference_two, preference_three, preference_one]
3236
3213
  )
3237
3214
  end
3238
3215
 
3239
3216
  it "chains default criteria with additional" do
3240
- person.ordered_preferences.order_by(:name.desc).to_a.should eq(
3217
+ expect(person.ordered_preferences.order_by(:name.desc).to_a).to eq(
3241
3218
  [preference_three, preference_two, preference_one]
3242
3219
  )
3243
3220
  end
@@ -3261,17 +3238,17 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3261
3238
  end
3262
3239
 
3263
3240
  it "sets the relation to an empty array" do
3264
- person.preferences.should be_empty
3241
+ expect(person.preferences).to be_empty
3265
3242
  end
3266
3243
 
3267
3244
  it "removes the foreign key values" do
3268
- person.preference_ids.should be_empty
3245
+ expect(person.preference_ids).to be_empty
3269
3246
  end
3270
3247
 
3271
3248
  it "does not delete the target from the database" do
3272
3249
  expect {
3273
3250
  preference.reload
3274
- }.not_to raise_error(Mongoid::Errors::DocumentNotFound)
3251
+ }.not_to raise_error
3275
3252
  end
3276
3253
  end
3277
3254
 
@@ -3305,7 +3282,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3305
3282
  end
3306
3283
 
3307
3284
  it "reloads the document from the database" do
3308
- reloaded.first.name.should eq("reloaded")
3285
+ expect(reloaded.first.name).to eq("reloaded")
3309
3286
  end
3310
3287
  end
3311
3288
 
@@ -3320,7 +3297,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3320
3297
  end
3321
3298
 
3322
3299
  it "reloads the new document from the database" do
3323
- reloaded.should eq([ preference_one, preference_two ])
3300
+ expect(reloaded).to eq([ preference_one, preference_two ])
3324
3301
  end
3325
3302
  end
3326
3303
  end
@@ -3342,19 +3319,19 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3342
3319
  end
3343
3320
 
3344
3321
  it "persists the first preference" do
3345
- preference_one.should_not be_nil
3322
+ expect(preference_one).to_not be_nil
3346
3323
  end
3347
3324
 
3348
3325
  it "sets the first inverse" do
3349
- preference_one.people.should eq([ person ])
3326
+ expect(preference_one.people).to eq([ person ])
3350
3327
  end
3351
3328
 
3352
3329
  it "persists the second preference" do
3353
- preference_two.should_not be_nil
3330
+ expect(preference_two).to_not be_nil
3354
3331
  end
3355
3332
 
3356
3333
  it "sets the second inverse keys" do
3357
- preference_two.people.should eq([ person ])
3334
+ expect(preference_two.people).to eq([ person ])
3358
3335
  end
3359
3336
  end
3360
3337
  end
@@ -3390,7 +3367,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3390
3367
  end
3391
3368
 
3392
3369
  it "persists the change in id order" do
3393
- reloaded.preference_ids.should eq(
3370
+ expect(reloaded.preference_ids).to eq(
3394
3371
  [ preference_two.id, preference_one.id ]
3395
3372
  )
3396
3373
  end
@@ -3413,7 +3390,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3413
3390
  end
3414
3391
 
3415
3392
  it "also persists the change in id order" do
3416
- reloaded.preference_ids.should eq(
3393
+ expect(reloaded.preference_ids).to eq(
3417
3394
  [ preference_two.id, preference_one.id, preference_three.id ]
3418
3395
  )
3419
3396
  end
@@ -3439,7 +3416,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3439
3416
  end
3440
3417
 
3441
3418
  it "also persists the change in id order" do
3442
- reloaded.preference_ids.should eq(
3419
+ expect(reloaded.preference_ids).to eq(
3443
3420
  [ preference_three.id, preference_two.id ]
3444
3421
  )
3445
3422
  end
@@ -3471,7 +3448,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3471
3448
  end
3472
3449
 
3473
3450
  it "adds both documents" do
3474
- result.should eq([ preference_one, preference_two ])
3451
+ expect(result).to eq([ preference_one, preference_two ])
3475
3452
  end
3476
3453
  end
3477
3454
  end
@@ -3497,7 +3474,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
3497
3474
  end
3498
3475
 
3499
3476
  it "sets the new documents on the relation" do
3500
- person.preferences.should eq([ pref_two ])
3477
+ expect(person.preferences).to eq([ pref_two ])
3501
3478
  end
3502
3479
  end
3503
3480
  end