mongoid 3.1.7 → 4.0.0.alpha1

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