mongoid 3.1.6 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (562) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +432 -8
  3. data/README.md +5 -6
  4. data/lib/config/locales/en.yml +32 -18
  5. data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
  6. data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
  7. data/lib/mongoid/atomic/paths/embedded.rb +0 -30
  8. data/lib/mongoid/atomic/paths/root.rb +0 -13
  9. data/lib/mongoid/atomic.rb +1 -12
  10. data/lib/mongoid/attributes/dynamic.rb +154 -0
  11. data/lib/mongoid/attributes/nested.rb +82 -0
  12. data/lib/mongoid/attributes/processing.rb +13 -66
  13. data/lib/mongoid/attributes.rb +63 -101
  14. data/lib/mongoid/{dirty.rb → changeable.rb} +32 -2
  15. data/lib/mongoid/composable.rb +105 -0
  16. data/lib/mongoid/config/options.rb +1 -1
  17. data/lib/mongoid/config.rb +3 -9
  18. data/lib/mongoid/contextual/aggregable/mongo.rb +7 -9
  19. data/lib/mongoid/contextual/atomic.rb +53 -53
  20. data/lib/mongoid/contextual/geo_near.rb +1 -1
  21. data/lib/mongoid/contextual/map_reduce.rb +4 -2
  22. data/lib/mongoid/contextual/memory.rb +18 -6
  23. data/lib/mongoid/contextual/mongo.rb +64 -56
  24. data/lib/mongoid/contextual/none.rb +90 -0
  25. data/lib/mongoid/contextual/text_search.rb +178 -0
  26. data/lib/mongoid/contextual.rb +2 -0
  27. data/lib/mongoid/copyable.rb +2 -3
  28. data/lib/mongoid/{criterion → criteria}/findable.rb +7 -47
  29. data/lib/mongoid/{criterion/inspection.rb → criteria/inspectable.rb} +2 -2
  30. data/lib/mongoid/{criterion → criteria}/marshalable.rb +3 -1
  31. data/lib/mongoid/{criterion → criteria}/modifiable.rb +28 -8
  32. data/lib/mongoid/criteria/permission.rb +70 -0
  33. data/lib/mongoid/{criterion/scoping.rb → criteria/scopable.rb} +2 -2
  34. data/lib/mongoid/criteria.rb +39 -34
  35. data/lib/mongoid/document.rb +32 -17
  36. data/lib/mongoid/errors/document_not_destroyed.rb +25 -0
  37. data/lib/mongoid/errors/document_not_found.rb +2 -1
  38. data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
  39. data/lib/mongoid/errors/invalid_storage_parent.rb +26 -0
  40. data/lib/mongoid/errors/invalid_value.rb +16 -0
  41. data/lib/mongoid/errors/mongoid_error.rb +1 -1
  42. data/lib/mongoid/errors/readonly_document.rb +24 -0
  43. data/lib/mongoid/errors.rb +4 -1
  44. data/lib/mongoid/extensions/array.rb +3 -3
  45. data/lib/mongoid/extensions/big_decimal.rb +1 -1
  46. data/lib/mongoid/extensions/boolean.rb +15 -17
  47. data/lib/mongoid/extensions/date.rb +1 -1
  48. data/lib/mongoid/extensions/date_time.rb +3 -3
  49. data/lib/mongoid/extensions/float.rb +2 -1
  50. data/lib/mongoid/extensions/hash.rb +3 -3
  51. data/lib/mongoid/extensions/integer.rb +1 -1
  52. data/lib/mongoid/extensions/object.rb +7 -7
  53. data/lib/mongoid/extensions/object_id.rb +5 -5
  54. data/lib/mongoid/extensions/range.rb +9 -3
  55. data/lib/mongoid/extensions/regexp.rb +1 -1
  56. data/lib/mongoid/extensions/set.rb +1 -1
  57. data/lib/mongoid/extensions/string.rb +6 -18
  58. data/lib/mongoid/extensions/symbol.rb +1 -1
  59. data/lib/mongoid/extensions/time.rb +3 -3
  60. data/lib/mongoid/extensions/time_with_zone.rb +1 -1
  61. data/lib/mongoid/extensions.rb +2 -7
  62. data/lib/mongoid/factory.rb +8 -6
  63. data/lib/mongoid/fields/foreign_key.rb +3 -3
  64. data/lib/mongoid/fields/localized.rb +1 -1
  65. data/lib/mongoid/fields/standard.rb +5 -17
  66. data/lib/mongoid/fields/validators/macro.rb +15 -5
  67. data/lib/mongoid/fields.rb +41 -8
  68. data/lib/mongoid/{finders.rb → findable.rb} +8 -2
  69. data/lib/mongoid/indexable/specification.rb +104 -0
  70. data/lib/mongoid/{indexes → indexable}/validators/options.rb +2 -1
  71. data/lib/mongoid/{indexes.rb → indexable.rb} +50 -55
  72. data/lib/mongoid/{inspection.rb → inspectable.rb} +15 -11
  73. data/lib/mongoid/{callbacks.rb → interceptable.rb} +30 -62
  74. data/lib/mongoid/log_subscriber.rb +55 -0
  75. data/lib/mongoid/{matchers → matchable}/all.rb +1 -1
  76. data/lib/mongoid/{matchers → matchable}/and.rb +2 -2
  77. data/lib/mongoid/{matchers → matchable}/default.rb +1 -1
  78. data/lib/mongoid/{matchers → matchable}/exists.rb +1 -1
  79. data/lib/mongoid/{matchers → matchable}/gt.rb +1 -1
  80. data/lib/mongoid/{matchers → matchable}/gte.rb +1 -1
  81. data/lib/mongoid/{matchers → matchable}/in.rb +2 -2
  82. data/lib/mongoid/{matchers → matchable}/lt.rb +1 -1
  83. data/lib/mongoid/{matchers → matchable}/lte.rb +1 -1
  84. data/lib/mongoid/{matchers → matchable}/ne.rb +2 -2
  85. data/lib/mongoid/{matchers → matchable}/nin.rb +3 -2
  86. data/lib/mongoid/{matchers → matchable}/or.rb +2 -2
  87. data/lib/mongoid/{matchers → matchable}/size.rb +1 -1
  88. data/lib/mongoid/matchable.rb +152 -0
  89. data/lib/mongoid/persistable/creatable.rb +188 -0
  90. data/lib/mongoid/persistable/deletable.rb +149 -0
  91. data/lib/mongoid/persistable/destroyable.rb +60 -0
  92. data/lib/mongoid/persistable/incrementable.rb +36 -0
  93. data/lib/mongoid/persistable/logical.rb +38 -0
  94. data/lib/mongoid/persistable/poppable.rb +39 -0
  95. data/lib/mongoid/persistable/pullable.rb +55 -0
  96. data/lib/mongoid/persistable/pushable.rb +62 -0
  97. data/lib/mongoid/persistable/renamable.rb +35 -0
  98. data/lib/mongoid/persistable/savable.rb +52 -0
  99. data/lib/mongoid/persistable/settable.rb +33 -0
  100. data/lib/mongoid/persistable/unsettable.rb +36 -0
  101. data/lib/mongoid/persistable/updatable.rb +152 -0
  102. data/lib/mongoid/persistable/upsertable.rb +55 -0
  103. data/lib/mongoid/persistable.rb +216 -0
  104. data/lib/mongoid/positional.rb +71 -0
  105. data/lib/mongoid/query_cache.rb +247 -0
  106. data/lib/mongoid/railtie.rb +32 -45
  107. data/lib/mongoid/railties/database.rake +9 -25
  108. data/lib/mongoid/relations/accessors.rb +13 -49
  109. data/lib/mongoid/relations/auto_save.rb +15 -36
  110. data/lib/mongoid/relations/binding.rb +1 -24
  111. data/lib/mongoid/relations/bindings/embedded/in.rb +1 -1
  112. data/lib/mongoid/relations/bindings/embedded/many.rb +1 -3
  113. data/lib/mongoid/relations/bindings/referenced/in.rb +3 -8
  114. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +3 -1
  115. data/lib/mongoid/relations/builder.rb +1 -1
  116. data/lib/mongoid/relations/builders/nested_attributes/many.rb +10 -13
  117. data/lib/mongoid/relations/builders/nested_attributes/one.rb +4 -5
  118. data/lib/mongoid/relations/builders/referenced/in.rb +1 -1
  119. data/lib/mongoid/relations/builders/referenced/many.rb +1 -2
  120. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +1 -2
  121. data/lib/mongoid/relations/builders/referenced/one.rb +1 -1
  122. data/lib/mongoid/relations/builders.rb +2 -2
  123. data/lib/mongoid/relations/cascading.rb +3 -5
  124. data/lib/mongoid/relations/constraint.rb +1 -1
  125. data/lib/mongoid/relations/conversions.rb +1 -1
  126. data/lib/mongoid/relations/counter_cache.rb +39 -15
  127. data/lib/mongoid/relations/eager/base.rb +149 -0
  128. data/lib/mongoid/relations/eager/belongs_to.rb +31 -0
  129. data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +47 -0
  130. data/lib/mongoid/relations/eager/has_many.rb +38 -0
  131. data/lib/mongoid/relations/eager/has_one.rb +30 -0
  132. data/lib/mongoid/relations/eager.rb +46 -0
  133. data/lib/mongoid/relations/embedded/batchable.rb +4 -5
  134. data/lib/mongoid/relations/embedded/in.rb +4 -4
  135. data/lib/mongoid/relations/embedded/many.rb +14 -32
  136. data/lib/mongoid/relations/embedded/one.rb +1 -1
  137. data/lib/mongoid/relations/macros.rb +3 -4
  138. data/lib/mongoid/relations/many.rb +30 -31
  139. data/lib/mongoid/relations/marshalable.rb +3 -3
  140. data/lib/mongoid/relations/metadata.rb +14 -79
  141. data/lib/mongoid/relations/nested_builder.rb +2 -2
  142. data/lib/mongoid/relations/options.rb +1 -0
  143. data/lib/mongoid/relations/polymorphic.rb +0 -1
  144. data/lib/mongoid/relations/proxy.rb +21 -41
  145. data/lib/mongoid/relations/referenced/in.rb +4 -20
  146. data/lib/mongoid/relations/referenced/many.rb +19 -32
  147. data/lib/mongoid/relations/referenced/many_to_many.rb +15 -38
  148. data/lib/mongoid/relations/referenced/one.rb +6 -25
  149. data/lib/mongoid/relations/synchronization.rb +3 -3
  150. data/lib/mongoid/relations/touchable.rb +34 -1
  151. data/lib/mongoid/relations.rb +11 -25
  152. data/lib/mongoid/{reloading.rb → reloadable.rb} +6 -4
  153. data/lib/mongoid/{scoping.rb → scopable.rb} +36 -36
  154. data/lib/mongoid/selectable.rb +59 -0
  155. data/lib/mongoid/{serialization.rb → serializable.rb} +11 -2
  156. data/lib/mongoid/sessions/factory.rb +2 -0
  157. data/lib/mongoid/sessions/options.rb +180 -0
  158. data/lib/mongoid/sessions/storage_options.rb +140 -0
  159. data/lib/mongoid/sessions/thread_options.rb +19 -0
  160. data/lib/mongoid/sessions/validators/storage.rb +16 -3
  161. data/lib/mongoid/sessions.rb +37 -345
  162. data/lib/mongoid/{sharding.rb → shardable.rb} +5 -1
  163. data/lib/mongoid/{state.rb → stateful.rb} +13 -1
  164. data/lib/mongoid/support/query_counter.rb +23 -0
  165. data/lib/mongoid/tasks/database.rake +31 -0
  166. data/lib/mongoid/tasks/database.rb +107 -0
  167. data/lib/mongoid/threaded/lifecycle.rb +0 -28
  168. data/lib/mongoid/threaded.rb +0 -157
  169. data/lib/mongoid/timestamps/updated/short.rb +2 -2
  170. data/lib/mongoid/{hierarchy.rb → traversable.rb} +9 -5
  171. data/lib/mongoid/{validations → validatable}/associated.rb +4 -2
  172. data/lib/mongoid/{validations → validatable}/format.rb +1 -1
  173. data/lib/mongoid/{validations → validatable}/length.rb +1 -1
  174. data/lib/mongoid/{validations → validatable}/localizable.rb +1 -1
  175. data/lib/mongoid/{validations → validatable}/macros.rb +4 -3
  176. data/lib/mongoid/{validations → validatable}/presence.rb +1 -1
  177. data/lib/mongoid/{validations → validatable}/queryable.rb +1 -2
  178. data/lib/mongoid/{validations → validatable}/uniqueness.rb +23 -19
  179. data/lib/mongoid/{validations.rb → validatable.rb} +23 -10
  180. data/lib/mongoid/version.rb +1 -1
  181. data/lib/mongoid.rb +10 -76
  182. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +13 -24
  183. data/lib/rails/generators/mongoid/model/model_generator.rb +0 -1
  184. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +0 -3
  185. data/lib/rails/generators/mongoid_generator.rb +3 -40
  186. data/lib/rails/mongoid.rb +0 -122
  187. data/lib/support/ruby_version.rb +1 -1
  188. data/spec/app/models/account.rb +2 -6
  189. data/spec/app/models/acolyte.rb +2 -1
  190. data/spec/app/models/actor.rb +0 -1
  191. data/spec/app/models/address.rb +8 -3
  192. data/spec/app/models/animal.rb +1 -1
  193. data/spec/app/models/appointment.rb +3 -3
  194. data/spec/app/models/article.rb +1 -4
  195. data/spec/app/models/audio.rb +5 -0
  196. data/spec/app/models/author.rb +0 -2
  197. data/spec/app/models/band.rb +3 -2
  198. data/spec/app/models/bar.rb +1 -0
  199. data/spec/app/models/book.rb +1 -0
  200. data/spec/app/models/building.rb +0 -2
  201. data/spec/app/models/building_address.rb +0 -2
  202. data/spec/app/models/bus.rb +1 -1
  203. data/spec/app/models/canvas.rb +1 -1
  204. data/spec/app/models/contractor.rb +0 -2
  205. data/spec/app/models/country_code.rb +1 -1
  206. data/spec/app/models/definition.rb +2 -2
  207. data/spec/app/models/dog.rb +1 -1
  208. data/spec/app/models/draft.rb +9 -0
  209. data/spec/app/models/dragon.rb +4 -0
  210. data/spec/app/models/drug.rb +1 -3
  211. data/spec/app/models/dungeon.rb +4 -0
  212. data/spec/app/models/edit.rb +5 -0
  213. data/spec/app/models/even.rb +7 -0
  214. data/spec/app/models/event.rb +1 -1
  215. data/spec/app/models/filesystem.rb +1 -0
  216. data/spec/app/models/fish.rb +0 -1
  217. data/spec/app/models/fruits.rb +6 -0
  218. data/spec/app/models/game.rb +0 -2
  219. data/spec/app/models/house.rb +1 -3
  220. data/spec/app/models/item.rb +1 -5
  221. data/spec/app/models/jar.rb +1 -1
  222. data/spec/app/models/label.rb +4 -4
  223. data/spec/app/models/line_item.rb +1 -1
  224. data/spec/app/models/login.rb +1 -1
  225. data/spec/app/models/message.rb +8 -0
  226. data/spec/app/models/movie.rb +1 -0
  227. data/spec/app/models/name.rb +3 -3
  228. data/spec/app/models/note.rb +3 -1
  229. data/spec/app/models/odd.rb +7 -0
  230. data/spec/app/models/oscar.rb +1 -1
  231. data/spec/app/models/parent_doc.rb +1 -1
  232. data/spec/app/models/person.rb +16 -10
  233. data/spec/app/models/phone.rb +1 -3
  234. data/spec/app/models/player.rb +3 -3
  235. data/spec/app/models/post.rb +5 -3
  236. data/spec/app/models/preference.rb +1 -1
  237. data/spec/app/models/quiz.rb +0 -3
  238. data/spec/app/models/record.rb +10 -5
  239. data/spec/app/models/registry.rb +1 -1
  240. data/spec/app/models/server.rb +1 -1
  241. data/spec/app/models/service.rb +3 -3
  242. data/spec/app/models/sound.rb +5 -0
  243. data/spec/app/models/symptom.rb +1 -1
  244. data/spec/app/models/template.rb +1 -1
  245. data/spec/app/models/title.rb +0 -1
  246. data/spec/app/models/track.rb +5 -5
  247. data/spec/app/models/tree.rb +3 -3
  248. data/spec/app/models/video.rb +1 -5
  249. data/spec/app/models/wiki_page.rb +2 -5
  250. data/spec/app/models/word.rb +3 -0
  251. data/spec/app/models/word_origin.rb +1 -1
  252. data/spec/config/mongoid.yml +7 -8
  253. data/spec/helpers.rb +18 -0
  254. data/spec/mongoid/atomic/modifiers_spec.rb +22 -22
  255. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +8 -49
  256. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +7 -49
  257. data/spec/mongoid/atomic/paths/root_spec.rb +3 -61
  258. data/spec/mongoid/atomic/paths_spec.rb +19 -19
  259. data/spec/mongoid/atomic_spec.rb +19 -19
  260. data/spec/mongoid/{nested_attributes_spec.rb → attributes/nested_spec.rb} +335 -448
  261. data/spec/mongoid/attributes/readonly_spec.rb +58 -18
  262. data/spec/mongoid/attributes_spec.rb +315 -436
  263. data/spec/mongoid/{dirty_spec.rb → changeable_spec.rb} +203 -153
  264. data/spec/mongoid/{components_spec.rb → composable_spec.rb} +3 -3
  265. data/spec/mongoid/config/environment_spec.rb +3 -3
  266. data/spec/mongoid/config/options_spec.rb +6 -6
  267. data/spec/mongoid/config_spec.rb +24 -48
  268. data/spec/mongoid/contextual/aggregable/memory_spec.rb +12 -12
  269. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +78 -38
  270. data/spec/mongoid/contextual/atomic_spec.rb +68 -58
  271. data/spec/mongoid/contextual/find_and_modify_spec.rb +14 -14
  272. data/spec/mongoid/contextual/geo_near_spec.rb +22 -22
  273. data/spec/mongoid/contextual/map_reduce_spec.rb +27 -27
  274. data/spec/mongoid/contextual/memory_spec.rb +151 -94
  275. data/spec/mongoid/contextual/mongo_spec.rb +238 -150
  276. data/spec/mongoid/contextual/none_spec.rb +127 -0
  277. data/spec/mongoid/contextual/text_search_spec.rb +209 -0
  278. data/spec/mongoid/copyable_spec.rb +56 -68
  279. data/spec/mongoid/criteria/findable_spec.rb +991 -0
  280. data/spec/mongoid/{criterion/inspection_spec.rb → criteria/inspectable_spec.rb} +5 -5
  281. data/spec/mongoid/{criterion → criteria}/marshalable_spec.rb +2 -2
  282. data/spec/mongoid/criteria/modifiable_spec.rb +1255 -0
  283. data/spec/mongoid/{criterion/scoping_spec.rb → criteria/scopable_spec.rb} +37 -37
  284. data/spec/mongoid/criteria_spec.rb +578 -2295
  285. data/spec/mongoid/document_spec.rb +166 -120
  286. data/spec/mongoid/equality_spec.rb +22 -22
  287. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +3 -3
  288. data/spec/mongoid/errors/callback_spec.rb +3 -3
  289. data/spec/mongoid/errors/delete_restriction_spec.rb +3 -3
  290. data/spec/mongoid/errors/document_not_destroyed_spec.rb +33 -0
  291. data/spec/mongoid/errors/document_not_found_spec.rb +11 -11
  292. data/spec/mongoid/errors/eager_load_spec.rb +3 -3
  293. data/spec/mongoid/errors/invalid_collection_spec.rb +3 -3
  294. data/spec/mongoid/errors/invalid_config_option_spec.rb +3 -3
  295. data/spec/mongoid/errors/invalid_field_option_spec.rb +3 -3
  296. data/spec/mongoid/errors/invalid_field_spec.rb +3 -3
  297. data/spec/mongoid/errors/invalid_find_spec.rb +3 -3
  298. data/spec/mongoid/errors/invalid_includes_spec.rb +3 -3
  299. data/spec/mongoid/errors/invalid_index_spec.rb +3 -3
  300. data/spec/mongoid/errors/invalid_options_spec.rb +3 -3
  301. data/spec/mongoid/errors/invalid_path_spec.rb +3 -3
  302. data/spec/mongoid/errors/invalid_scope_spec.rb +5 -5
  303. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -3
  304. data/spec/mongoid/errors/invalid_storage_options_spec.rb +3 -3
  305. data/spec/mongoid/errors/invalid_time_spec.rb +3 -3
  306. data/spec/mongoid/errors/inverse_not_found_spec.rb +3 -3
  307. data/spec/mongoid/errors/mixed_relations_spec.rb +3 -3
  308. data/spec/mongoid/errors/mixed_session_configuration_spec.rb +3 -3
  309. data/spec/mongoid/errors/mongoid_error_spec.rb +8 -8
  310. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +3 -3
  311. data/spec/mongoid/errors/no_environment_spec.rb +3 -3
  312. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +3 -3
  313. data/spec/mongoid/errors/no_metadata_spec.rb +3 -3
  314. data/spec/mongoid/errors/no_parent_spec.rb +3 -3
  315. data/spec/mongoid/errors/no_session_config_spec.rb +3 -3
  316. data/spec/mongoid/errors/no_session_database_spec.rb +3 -3
  317. data/spec/mongoid/errors/no_session_hosts_spec.rb +3 -3
  318. data/spec/mongoid/errors/no_sessions_config_spec.rb +3 -3
  319. data/spec/mongoid/errors/readonly_attribute_spec.rb +3 -3
  320. data/spec/mongoid/errors/readonly_document_spec.rb +29 -0
  321. data/spec/mongoid/errors/scope_overwrite_spec.rb +3 -3
  322. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +3 -3
  323. data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -5
  324. data/spec/mongoid/errors/unsaved_document_spec.rb +3 -3
  325. data/spec/mongoid/errors/unsupported_javascript_spec.rb +3 -3
  326. data/spec/mongoid/errors/validations_spec.rb +7 -7
  327. data/spec/mongoid/extensions/array_spec.rb +61 -61
  328. data/spec/mongoid/extensions/big_decimal_spec.rb +11 -11
  329. data/spec/mongoid/extensions/binary_spec.rb +12 -12
  330. data/spec/mongoid/extensions/boolean_spec.rb +18 -18
  331. data/spec/mongoid/extensions/date_spec.rb +13 -13
  332. data/spec/mongoid/extensions/date_time_spec.rb +8 -8
  333. data/spec/mongoid/extensions/false_class_spec.rb +5 -5
  334. data/spec/mongoid/extensions/float_spec.rb +29 -15
  335. data/spec/mongoid/extensions/hash_spec.rb +29 -29
  336. data/spec/mongoid/extensions/integer_spec.rb +15 -15
  337. data/spec/mongoid/extensions/module_spec.rb +2 -2
  338. data/spec/mongoid/extensions/nil_class_spec.rb +1 -1
  339. data/spec/mongoid/extensions/object_id_spec.rb +134 -134
  340. data/spec/mongoid/extensions/object_spec.rb +26 -26
  341. data/spec/mongoid/extensions/range_spec.rb +61 -12
  342. data/spec/mongoid/extensions/regexp_spec.rb +4 -4
  343. data/spec/mongoid/extensions/set_spec.rb +4 -4
  344. data/spec/mongoid/extensions/string_spec.rb +35 -46
  345. data/spec/mongoid/extensions/symbol_spec.rb +9 -9
  346. data/spec/mongoid/extensions/time_spec.rb +49 -49
  347. data/spec/mongoid/extensions/time_with_zone_spec.rb +34 -34
  348. data/spec/mongoid/extensions/true_class_spec.rb +5 -5
  349. data/spec/mongoid/extensions_spec.rb +15 -0
  350. data/spec/mongoid/factory_spec.rb +15 -15
  351. data/spec/mongoid/fields/foreign_key_spec.rb +73 -66
  352. data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +15 -15
  353. data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +22 -22
  354. data/spec/mongoid/fields/localized_spec.rb +38 -23
  355. data/spec/mongoid/fields/standard_spec.rb +12 -12
  356. data/spec/mongoid/fields_spec.rb +263 -217
  357. data/spec/mongoid/{finders_spec.rb → findable_spec.rb} +127 -27
  358. data/spec/mongoid/indexable/specification_spec.rb +102 -0
  359. data/spec/mongoid/{indexes_spec.rb → indexable_spec.rb} +171 -51
  360. data/spec/mongoid/{inspection_spec.rb → inspectable_spec.rb} +6 -14
  361. data/spec/mongoid/{callbacks_spec.rb → interceptable_spec.rb} +117 -116
  362. data/spec/mongoid/log_subscriber_spec.rb +75 -0
  363. data/spec/mongoid/loggable_spec.rb +1 -1
  364. data/spec/mongoid/{matchers → matchable}/all_spec.rb +4 -4
  365. data/spec/mongoid/{matchers → matchable}/and_spec.rb +11 -11
  366. data/spec/mongoid/{matchers → matchable}/default_spec.rb +15 -15
  367. data/spec/mongoid/{matchers → matchable}/exists_spec.rb +5 -5
  368. data/spec/mongoid/{matchers → matchable}/gt_spec.rb +9 -8
  369. data/spec/mongoid/{matchers → matchable}/gte_spec.rb +7 -7
  370. data/spec/mongoid/matchable/in_spec.rb +49 -0
  371. data/spec/mongoid/{matchers → matchable}/lt_spec.rb +7 -7
  372. data/spec/mongoid/{matchers → matchable}/lte_spec.rb +7 -7
  373. data/spec/mongoid/matchable/ne_spec.rb +46 -0
  374. data/spec/mongoid/matchable/nin_spec.rb +48 -0
  375. data/spec/mongoid/{matchers → matchable}/or_spec.rb +6 -6
  376. data/spec/mongoid/{matchers → matchable}/size_spec.rb +3 -3
  377. data/spec/mongoid/{matchers_spec.rb → matchable_spec.rb} +41 -41
  378. data/spec/mongoid/persistable/creatable_spec.rb +512 -0
  379. data/spec/mongoid/persistable/deletable_spec.rb +218 -0
  380. data/spec/mongoid/persistable/destroyable_spec.rb +192 -0
  381. data/spec/mongoid/persistable/incrementable_spec.rb +173 -0
  382. data/spec/mongoid/persistable/logical_spec.rb +143 -0
  383. data/spec/mongoid/persistable/poppable_spec.rb +115 -0
  384. data/spec/mongoid/persistable/pullable_spec.rb +228 -0
  385. data/spec/mongoid/persistable/pushable_spec.rb +258 -0
  386. data/spec/mongoid/persistable/renamable_spec.rb +135 -0
  387. data/spec/mongoid/persistable/savable_spec.rb +461 -0
  388. data/spec/mongoid/persistable/settable_spec.rb +139 -0
  389. data/spec/mongoid/persistable/unsettable_spec.rb +155 -0
  390. data/spec/mongoid/persistable/updatable_spec.rb +558 -0
  391. data/spec/mongoid/persistable/upsertable_spec.rb +106 -0
  392. data/spec/mongoid/persistable_spec.rb +206 -0
  393. data/spec/mongoid/{atomic/positionable_spec.rb → positional_spec.rb} +9 -9
  394. data/spec/mongoid/query_cache_spec.rb +231 -0
  395. data/spec/mongoid/railties/document_spec.rb +2 -2
  396. data/spec/mongoid/relations/accessors_spec.rb +53 -145
  397. data/spec/mongoid/relations/auto_save_spec.rb +37 -17
  398. data/spec/mongoid/relations/bindings/embedded/in_spec.rb +12 -12
  399. data/spec/mongoid/relations/bindings/embedded/many_spec.rb +3 -3
  400. data/spec/mongoid/relations/bindings/embedded/one_spec.rb +5 -5
  401. data/spec/mongoid/relations/bindings/referenced/in_spec.rb +26 -26
  402. data/spec/mongoid/relations/bindings/referenced/many_spec.rb +10 -10
  403. data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +19 -19
  404. data/spec/mongoid/relations/bindings/referenced/one_spec.rb +12 -12
  405. data/spec/mongoid/relations/builders/embedded/in_spec.rb +4 -4
  406. data/spec/mongoid/relations/builders/embedded/many_spec.rb +18 -18
  407. data/spec/mongoid/relations/builders/embedded/one_spec.rb +11 -11
  408. data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +12 -13
  409. data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +14 -14
  410. data/spec/mongoid/relations/builders/referenced/in_spec.rb +24 -35
  411. data/spec/mongoid/relations/builders/referenced/many_spec.rb +15 -15
  412. data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +18 -18
  413. data/spec/mongoid/relations/builders/referenced/one_spec.rb +12 -25
  414. data/spec/mongoid/relations/builders_spec.rb +21 -21
  415. data/spec/mongoid/relations/cascading/delete_spec.rb +9 -9
  416. data/spec/mongoid/relations/cascading/destroy_spec.rb +6 -6
  417. data/spec/mongoid/relations/cascading/nullify_spec.rb +4 -4
  418. data/spec/mongoid/relations/cascading/restrict_spec.rb +7 -7
  419. data/spec/mongoid/relations/cascading_spec.rb +16 -16
  420. data/spec/mongoid/relations/constraint_spec.rb +8 -7
  421. data/spec/mongoid/relations/conversions_spec.rb +16 -14
  422. data/spec/mongoid/relations/counter_cache_spec.rb +85 -0
  423. data/spec/mongoid/relations/cyclic_spec.rb +18 -18
  424. data/spec/mongoid/relations/eager/belongs_to_spec.rb +154 -0
  425. data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +117 -0
  426. data/spec/mongoid/relations/eager/has_many_spec.rb +207 -0
  427. data/spec/mongoid/relations/eager/has_one_spec.rb +163 -0
  428. data/spec/mongoid/relations/eager_spec.rb +228 -0
  429. data/spec/mongoid/relations/embedded/dirty_spec.rb +8 -8
  430. data/spec/mongoid/relations/embedded/in_spec.rb +56 -57
  431. data/spec/mongoid/relations/embedded/many_spec.rb +393 -372
  432. data/spec/mongoid/relations/embedded/one_spec.rb +108 -141
  433. data/spec/mongoid/relations/macros_spec.rb +108 -102
  434. data/spec/mongoid/relations/metadata_spec.rb +180 -255
  435. data/spec/mongoid/relations/options_spec.rb +1 -1
  436. data/spec/mongoid/relations/polymorphic_spec.rb +13 -17
  437. data/spec/mongoid/relations/proxy_spec.rb +2 -2
  438. data/spec/mongoid/relations/referenced/in_spec.rb +128 -303
  439. data/spec/mongoid/relations/referenced/many_spec.rb +434 -527
  440. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +352 -424
  441. data/spec/mongoid/relations/referenced/one_spec.rb +149 -264
  442. data/spec/mongoid/relations/reflections_spec.rb +6 -6
  443. data/spec/mongoid/relations/synchronization_spec.rb +46 -50
  444. data/spec/mongoid/relations/targets/enumerable_spec.rb +118 -118
  445. data/spec/mongoid/relations/touchable_spec.rb +333 -0
  446. data/spec/mongoid/relations_spec.rb +16 -15
  447. data/spec/mongoid/{reloading_spec.rb → reloadable_spec.rb} +20 -60
  448. data/spec/mongoid/{scoping_spec.rb → scopable_spec.rb} +89 -164
  449. data/spec/mongoid/selectable_spec.rb +134 -0
  450. data/spec/mongoid/{serialization_spec.rb → serializable_spec.rb} +129 -82
  451. data/spec/mongoid/sessions/factory_spec.rb +49 -28
  452. data/spec/mongoid/sessions/mongo_uri_spec.rb +7 -7
  453. data/spec/mongoid/sessions/options_spec.rb +107 -0
  454. data/spec/mongoid/sessions_spec.rb +289 -178
  455. data/spec/mongoid/{sharding_spec.rb → shardable_spec.rb} +8 -8
  456. data/spec/mongoid/{state_spec.rb → stateful_spec.rb} +36 -11
  457. data/spec/mongoid/tasks/database_rake_spec.rb +285 -0
  458. data/spec/mongoid/tasks/database_spec.rb +160 -0
  459. data/spec/mongoid/threaded_spec.rb +17 -70
  460. data/spec/mongoid/timestamps/created/short_spec.rb +6 -6
  461. data/spec/mongoid/timestamps/created_spec.rb +5 -5
  462. data/spec/mongoid/timestamps/timeless_spec.rb +6 -6
  463. data/spec/mongoid/timestamps/updated/short_spec.rb +11 -11
  464. data/spec/mongoid/timestamps/updated_spec.rb +9 -13
  465. data/spec/mongoid/timestamps_spec.rb +9 -13
  466. data/spec/mongoid/{hierarchy_spec.rb → traversable_spec.rb} +19 -19
  467. data/spec/mongoid/{validations → validatable}/associated_spec.rb +45 -22
  468. data/spec/mongoid/{validations → validatable}/format_spec.rb +6 -6
  469. data/spec/mongoid/{validations → validatable}/length_spec.rb +14 -14
  470. data/spec/mongoid/{validations → validatable}/numericality_spec.rb +1 -1
  471. data/spec/mongoid/{validations → validatable}/presence_spec.rb +37 -44
  472. data/spec/mongoid/{validations → validatable}/uniqueness_spec.rb +184 -192
  473. data/spec/mongoid/{validations_spec.rb → validatable_spec.rb} +28 -28
  474. data/spec/mongoid_spec.rb +8 -8
  475. data/spec/rails/mongoid_spec.rb +19 -335
  476. data/spec/spec_helper.rb +29 -13
  477. metadata +296 -283
  478. data/lib/mongoid/atomic/positionable.rb +0 -73
  479. data/lib/mongoid/components.rb +0 -92
  480. data/lib/mongoid/config/inflections.rb +0 -6
  481. data/lib/mongoid/contextual/eager.rb +0 -158
  482. data/lib/mongoid/errors/versioning_not_on_root.rb +0 -23
  483. data/lib/mongoid/identity_map.rb +0 -163
  484. data/lib/mongoid/json.rb +0 -16
  485. data/lib/mongoid/matchers/strategies.rb +0 -97
  486. data/lib/mongoid/matchers.rb +0 -32
  487. data/lib/mongoid/multi_parameter_attributes.rb +0 -105
  488. data/lib/mongoid/nested_attributes.rb +0 -78
  489. data/lib/mongoid/observer.rb +0 -192
  490. data/lib/mongoid/paranoia.rb +0 -136
  491. data/lib/mongoid/persistence/atomic/add_to_set.rb +0 -47
  492. data/lib/mongoid/persistence/atomic/bit.rb +0 -35
  493. data/lib/mongoid/persistence/atomic/inc.rb +0 -45
  494. data/lib/mongoid/persistence/atomic/operation.rb +0 -154
  495. data/lib/mongoid/persistence/atomic/pop.rb +0 -32
  496. data/lib/mongoid/persistence/atomic/pull.rb +0 -32
  497. data/lib/mongoid/persistence/atomic/pull_all.rb +0 -32
  498. data/lib/mongoid/persistence/atomic/push.rb +0 -25
  499. data/lib/mongoid/persistence/atomic/push_all.rb +0 -25
  500. data/lib/mongoid/persistence/atomic/rename.rb +0 -30
  501. data/lib/mongoid/persistence/atomic/sets.rb +0 -28
  502. data/lib/mongoid/persistence/atomic/unset.rb +0 -27
  503. data/lib/mongoid/persistence/atomic.rb +0 -231
  504. data/lib/mongoid/persistence/deletion.rb +0 -31
  505. data/lib/mongoid/persistence/insertion.rb +0 -38
  506. data/lib/mongoid/persistence/modification.rb +0 -35
  507. data/lib/mongoid/persistence/operations/embedded/insert.rb +0 -46
  508. data/lib/mongoid/persistence/operations/embedded/remove.rb +0 -43
  509. data/lib/mongoid/persistence/operations/insert.rb +0 -34
  510. data/lib/mongoid/persistence/operations/remove.rb +0 -33
  511. data/lib/mongoid/persistence/operations/update.rb +0 -59
  512. data/lib/mongoid/persistence/operations/upsert.rb +0 -28
  513. data/lib/mongoid/persistence/operations.rb +0 -214
  514. data/lib/mongoid/persistence/upsertion.rb +0 -31
  515. data/lib/mongoid/persistence.rb +0 -357
  516. data/lib/mongoid/unit_of_work.rb +0 -61
  517. data/lib/mongoid/versioning.rb +0 -217
  518. data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
  519. data/lib/rack/mongoid.rb +0 -2
  520. data/lib/rails/generators/mongoid/observer/observer_generator.rb +0 -17
  521. data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +0 -4
  522. data/spec/app/models/actor_observer.rb +0 -15
  523. data/spec/app/models/callback_recorder.rb +0 -25
  524. data/spec/app/models/paranoid_phone.rb +0 -25
  525. data/spec/app/models/paranoid_post.rb +0 -36
  526. data/spec/app/models/phone_observer.rb +0 -6
  527. data/spec/mongoid/attributes/processing_spec.rb +0 -149
  528. data/spec/mongoid/criterion/destructive_spec.rb +0 -101
  529. data/spec/mongoid/criterion/modifiable_spec.rb +0 -409
  530. data/spec/mongoid/criterion/modification_spec.rb +0 -402
  531. data/spec/mongoid/errors/versioning_not_on_root_spec.rb +0 -29
  532. data/spec/mongoid/identity_map_spec.rb +0 -564
  533. data/spec/mongoid/json_spec.rb +0 -33
  534. data/spec/mongoid/matchers/in_spec.rb +0 -25
  535. data/spec/mongoid/matchers/ne_spec.rb +0 -25
  536. data/spec/mongoid/matchers/nin_spec.rb +0 -25
  537. data/spec/mongoid/multi_parameter_attributes_spec.rb +0 -128
  538. data/spec/mongoid/observer_spec.rb +0 -290
  539. data/spec/mongoid/paranoia_spec.rb +0 -759
  540. data/spec/mongoid/persistence/atomic/add_to_set_spec.rb +0 -262
  541. data/spec/mongoid/persistence/atomic/bit_spec.rb +0 -88
  542. data/spec/mongoid/persistence/atomic/inc_spec.rb +0 -133
  543. data/spec/mongoid/persistence/atomic/pop_spec.rb +0 -111
  544. data/spec/mongoid/persistence/atomic/pull_all_spec.rb +0 -77
  545. data/spec/mongoid/persistence/atomic/pull_spec.rb +0 -80
  546. data/spec/mongoid/persistence/atomic/push_all_spec.rb +0 -77
  547. data/spec/mongoid/persistence/atomic/push_spec.rb +0 -77
  548. data/spec/mongoid/persistence/atomic/rename_spec.rb +0 -42
  549. data/spec/mongoid/persistence/atomic/sets_spec.rb +0 -154
  550. data/spec/mongoid/persistence/atomic/unset_spec.rb +0 -65
  551. data/spec/mongoid/persistence/atomic_spec.rb +0 -216
  552. data/spec/mongoid/persistence/operations/embedded/insert_spec.rb +0 -191
  553. data/spec/mongoid/persistence/operations/embedded/remove_spec.rb +0 -8
  554. data/spec/mongoid/persistence/operations/insert_spec.rb +0 -149
  555. data/spec/mongoid/persistence/operations/remove_spec.rb +0 -113
  556. data/spec/mongoid/persistence/operations/update_spec.rb +0 -141
  557. data/spec/mongoid/persistence/operations/upsert_spec.rb +0 -59
  558. data/spec/mongoid/persistence/operations_spec.rb +0 -313
  559. data/spec/mongoid/persistence_spec.rb +0 -2279
  560. data/spec/mongoid/unit_of_work_spec.rb +0 -196
  561. data/spec/mongoid/versioning_spec.rb +0 -540
  562. data/spec/rack/mongoid/middleware/identity_map_spec.rb +0 -72
@@ -21,35 +21,35 @@ describe Mongoid::Relations::Embedded::Many do
21
21
  end
22
22
 
23
23
  it "appends to the target" do
24
- person.addresses.should eq([ address ])
24
+ expect(person.addresses).to eq([ address ])
25
25
  end
26
26
 
27
27
  it "sets the base on the inverse relation" do
28
- address.addressable.should eq(person)
28
+ expect(address.addressable).to eq(person)
29
29
  end
30
30
 
31
31
  it "sets the same instance on the inverse relation" do
32
- address.addressable.should eql(person)
32
+ expect(address.addressable).to eql(person)
33
33
  end
34
34
 
35
35
  it "does not save the new document" do
36
- address.should_not be_persisted
36
+ expect(address).to_not be_persisted
37
37
  end
38
38
 
39
39
  it "sets the parent on the child" do
40
- address._parent.should eq(person)
40
+ expect(address._parent).to eq(person)
41
41
  end
42
42
 
43
43
  it "sets the metadata on the child" do
44
- address.metadata.should_not be_nil
44
+ expect(address.__metadata).to_not be_nil
45
45
  end
46
46
 
47
47
  it "sets the index on the child" do
48
- address._index.should eq(0)
48
+ expect(address._index).to eq(0)
49
49
  end
50
50
 
51
51
  it "returns the relation" do
52
- added.should eq(person.addresses)
52
+ expect(added).to eq(person.addresses)
53
53
  end
54
54
 
55
55
  context "with a limiting default scope" do
@@ -65,11 +65,11 @@ describe Mongoid::Relations::Embedded::Many do
65
65
  end
66
66
 
67
67
  it "appends to the target" do
68
- person.appointments.target.should eq([ active ])
68
+ expect(person.appointments.target).to eq([ active ])
69
69
  end
70
70
 
71
71
  it "appends to the _unscoped" do
72
- person.appointments.send(:_unscoped).should eq([ active ])
72
+ expect(person.appointments.send(:_unscoped)).to eq([ active ])
73
73
  end
74
74
  end
75
75
 
@@ -84,11 +84,11 @@ describe Mongoid::Relations::Embedded::Many do
84
84
  end
85
85
 
86
86
  it "doesn't append to the target" do
87
- person.appointments.target.should_not eq([ inactive ])
87
+ expect(person.appointments.target).to_not eq([ inactive ])
88
88
  end
89
89
 
90
90
  it "appends to the _unscoped" do
91
- person.appointments.send(:_unscoped).should eq([ inactive ])
91
+ expect(person.appointments.send(:_unscoped)).to eq([ inactive ])
92
92
  end
93
93
  end
94
94
  end
@@ -109,7 +109,7 @@ describe Mongoid::Relations::Embedded::Many do
109
109
  end
110
110
 
111
111
  it "saves the new document" do
112
- address.should be_persisted
112
+ expect(address).to be_persisted
113
113
  end
114
114
  end
115
115
 
@@ -132,15 +132,15 @@ describe Mongoid::Relations::Embedded::Many do
132
132
  end
133
133
 
134
134
  it "saves the first document" do
135
- address_one.should be_persisted
135
+ expect(address_one).to be_persisted
136
136
  end
137
137
 
138
138
  it "saves the second document" do
139
- address_two.should be_persisted
139
+ expect(address_two).to be_persisted
140
140
  end
141
141
 
142
142
  it "returns the relation" do
143
- added.should eq(person.addresses)
143
+ expect(added).to eq(person.addresses)
144
144
  end
145
145
  end
146
146
 
@@ -161,31 +161,31 @@ describe Mongoid::Relations::Embedded::Many do
161
161
  end
162
162
 
163
163
  it "appends to the target" do
164
- parent_role.child_roles.should eq([ child_role ])
164
+ expect(parent_role.child_roles).to eq([ child_role ])
165
165
  end
166
166
 
167
167
  it "sets the base on the inverse relation" do
168
- child_role.parent_role.should eq(parent_role)
168
+ expect(child_role.parent_role).to eq(parent_role)
169
169
  end
170
170
 
171
171
  it "sets the same instance on the inverse relation" do
172
- child_role.parent_role.should eql(parent_role)
172
+ expect(child_role.parent_role).to eql(parent_role)
173
173
  end
174
174
 
175
175
  it "does not save the new document" do
176
- child_role.should_not be_persisted
176
+ expect(child_role).to_not be_persisted
177
177
  end
178
178
 
179
179
  it "sets the parent on the child" do
180
- child_role._parent.should eq(parent_role)
180
+ expect(child_role._parent).to eq(parent_role)
181
181
  end
182
182
 
183
183
  it "sets the metadata on the child" do
184
- child_role.metadata.should_not be_nil
184
+ expect(child_role.__metadata).to_not be_nil
185
185
  end
186
186
 
187
187
  it "sets the index on the child" do
188
- child_role._index.should eq(0)
188
+ expect(child_role._index).to eq(0)
189
189
  end
190
190
  end
191
191
 
@@ -204,7 +204,38 @@ describe Mongoid::Relations::Embedded::Many do
204
204
  end
205
205
 
206
206
  it "saves the new document" do
207
- child_role.should be_persisted
207
+ expect(child_role).to be_persisted
208
+ end
209
+ end
210
+ end
211
+
212
+ context "when the child has one sided many to many relation" do
213
+ let(:person) do
214
+ Person.create
215
+ end
216
+
217
+ let(:message) do
218
+ Message.new
219
+ end
220
+
221
+ context "assign parent first" do
222
+ before do
223
+ message.person = person
224
+ message.receviers.send(method, person)
225
+ end
226
+
227
+ it "appends to the relation array" do
228
+ expect(message.receviers).to include(person)
229
+ end
230
+ end
231
+
232
+ context "not assign parent" do
233
+ before do
234
+ message.receviers.send(method, person)
235
+ end
236
+
237
+ it "appends to the relation array" do
238
+ expect(message.receviers).to include(person)
208
239
  end
209
240
  end
210
241
  end
@@ -228,35 +259,35 @@ describe Mongoid::Relations::Embedded::Many do
228
259
  end
229
260
 
230
261
  it "sets the target of the relation" do
231
- person.addresses.should eq([ address ])
262
+ expect(person.addresses).to eq([ address ])
232
263
  end
233
264
 
234
265
  it "sets the _unscoped of the relation" do
235
- person.addresses.send(:_unscoped).should eq([ address ])
266
+ expect(person.addresses.send(:_unscoped)).to eq([ address ])
236
267
  end
237
268
 
238
269
  it "sets the base on the inverse relation" do
239
- address.addressable.should eq(person)
270
+ expect(address.addressable).to eq(person)
240
271
  end
241
272
 
242
273
  it "sets the same instance on the inverse relation" do
243
- address.addressable.should eql(person)
274
+ expect(address.addressable).to eql(person)
244
275
  end
245
276
 
246
277
  it "does not save the target" do
247
- address.should_not be_persisted
278
+ expect(address).to_not be_persisted
248
279
  end
249
280
 
250
281
  it "sets the parent on the child" do
251
- address._parent.should eq(person)
282
+ expect(address._parent).to eq(person)
252
283
  end
253
284
 
254
285
  it "sets the metadata on the child" do
255
- address.metadata.should_not be_nil
286
+ expect(address.__metadata).to_not be_nil
256
287
  end
257
288
 
258
289
  it "sets the index on the child" do
259
- address._index.should eq(0)
290
+ expect(address._index).to eq(0)
260
291
  end
261
292
  end
262
293
 
@@ -277,7 +308,7 @@ describe Mongoid::Relations::Embedded::Many do
277
308
  end
278
309
 
279
310
  it "saves the target" do
280
- address.should be_persisted
311
+ expect(address).to be_persisted
281
312
  end
282
313
  end
283
314
 
@@ -300,7 +331,7 @@ describe Mongoid::Relations::Embedded::Many do
300
331
  end
301
332
 
302
333
  it "overwrites the existing addresses" do
303
- person.reload.addresses.should eq([ new_address ])
334
+ expect(person.reload.addresses).to eq([ new_address ])
304
335
  end
305
336
  end
306
337
 
@@ -311,11 +342,11 @@ describe Mongoid::Relations::Embedded::Many do
311
342
  end
312
343
 
313
344
  it "sets the relation" do
314
- person.addresses.should eq([ address ])
345
+ expect(person.addresses).to eq([ address ])
315
346
  end
316
347
 
317
348
  it "does not save the target" do
318
- address.should_not be_persisted
349
+ expect(address).to_not be_persisted
319
350
  end
320
351
 
321
352
  context "when setting the relation multiple times" do
@@ -330,11 +361,11 @@ describe Mongoid::Relations::Embedded::Many do
330
361
  end
331
362
 
332
363
  it "sets the new documents" do
333
- person.addresses.should eq([ address_two ])
364
+ expect(person.addresses).to eq([ address_two ])
334
365
  end
335
366
 
336
367
  it "persits only the new documents" do
337
- person.reload.addresses.should eq([ address_two ])
368
+ expect(person.reload.addresses).to eq([ address_two ])
338
369
  end
339
370
  end
340
371
  end
@@ -364,11 +395,11 @@ describe Mongoid::Relations::Embedded::Many do
364
395
  end
365
396
 
366
397
  it "sets the documents" do
367
- doctor.addresses.should eq([ address_one ])
398
+ expect(doctor.addresses).to eq([ address_one ])
368
399
  end
369
400
 
370
401
  it "persists the document" do
371
- doctor.reload.addresses.should eq([ address_one ])
402
+ expect(doctor.reload.addresses).to eq([ address_one ])
372
403
  end
373
404
 
374
405
  context "when setting the relation multiple times" do
@@ -383,11 +414,11 @@ describe Mongoid::Relations::Embedded::Many do
383
414
  end
384
415
 
385
416
  it "sets the new documents" do
386
- doctor.addresses.should eq([ address_two ])
417
+ expect(doctor.addresses).to eq([ address_two ])
387
418
  end
388
419
 
389
420
  it "persits only the new documents" do
390
- doctor.reload.addresses.should eq([ address_two ])
421
+ expect(doctor.reload.addresses).to eq([ address_two ])
391
422
  end
392
423
  end
393
424
  end
@@ -412,7 +443,7 @@ describe Mongoid::Relations::Embedded::Many do
412
443
  end
413
444
 
414
445
  it "deletes the old documents" do
415
- person.reload.addresses.should eq([ address ])
446
+ expect(person.reload.addresses).to eq([ address ])
416
447
  end
417
448
  end
418
449
 
@@ -434,7 +465,6 @@ describe Mongoid::Relations::Embedded::Many do
434
465
  field :old_state, type: String
435
466
  field :new_state, type: String
436
467
  field :when_changed, type: DateTime
437
- attr_protected :_id
438
468
  embedded_in :tracking_id, class_name: "MyCompany::Model::TrackingId"
439
469
  end
440
470
  end
@@ -453,15 +483,15 @@ describe Mongoid::Relations::Embedded::Many do
453
483
  end
454
484
 
455
485
  it "allows creation of the embedded document" do
456
- tracking_id.validation_history.size.should eq(1)
486
+ expect(tracking_id.validation_history.size).to eq(1)
457
487
  end
458
488
 
459
489
  it "saves the relation" do
460
- history.should be_persisted
490
+ expect(history).to be_persisted
461
491
  end
462
492
 
463
493
  it "remains on reload" do
464
- tracking_id.reload.validation_history.size.should eq(1)
494
+ expect(tracking_id.reload.validation_history.size).to eq(1)
465
495
  end
466
496
  end
467
497
 
@@ -480,7 +510,7 @@ describe Mongoid::Relations::Embedded::Many do
480
510
  end
481
511
 
482
512
  it "requires an inflection to determine the class" do
483
- slave.reload.address_numbers.size.should eq(1)
513
+ expect(slave.reload.address_numbers.size).to eq(1)
484
514
  end
485
515
  end
486
516
 
@@ -510,11 +540,11 @@ describe Mongoid::Relations::Embedded::Many do
510
540
  end
511
541
 
512
542
  it "sets the new attributes" do
513
- person.addresses.first.city.should eq("Berlin")
543
+ expect(person.addresses.first.city).to eq("Berlin")
514
544
  end
515
545
 
516
546
  it "persists the changes" do
517
- person.reload.addresses.first.city.should eq("Berlin")
547
+ expect(person.reload.addresses.first.city).to eq("Berlin")
518
548
  end
519
549
  end
520
550
  end
@@ -546,23 +576,23 @@ describe Mongoid::Relations::Embedded::Many do
546
576
  end
547
577
 
548
578
  it "sets the new attributes on the address" do
549
- person.addresses.first.city.should eq("Berlin")
579
+ expect(person.addresses.first.city).to eq("Berlin")
550
580
  end
551
581
 
552
582
  it "sets the new attributes on the location" do
553
- person.addresses.first.locations.first.name.should eq("Home")
583
+ expect(person.addresses.first.locations.first.name).to eq("Home")
554
584
  end
555
585
 
556
586
  it "persists the changes to the address" do
557
- person.reload.addresses.first.city.should eq("Berlin")
587
+ expect(person.reload.addresses.first.city).to eq("Berlin")
558
588
  end
559
589
 
560
590
  it "persists the changes to the location" do
561
- person.reload.addresses.first.locations.first.name.should eq("Home")
591
+ expect(person.reload.addresses.first.locations.first.name).to eq("Home")
562
592
  end
563
593
 
564
594
  it "does not persist the locations collection to the person document" do
565
- person.reload[:locations].should be_nil
595
+ expect(person.reload[:locations]).to be_nil
566
596
  end
567
597
  end
568
598
  end
@@ -584,31 +614,31 @@ describe Mongoid::Relations::Embedded::Many do
584
614
  end
585
615
 
586
616
  it "sets the target of the relation" do
587
- parent_role.child_roles.should eq([ child_role ])
617
+ expect(parent_role.child_roles).to eq([ child_role ])
588
618
  end
589
619
 
590
620
  it "sets the base on the inverse relation" do
591
- child_role.parent_role.should eq(parent_role)
621
+ expect(child_role.parent_role).to eq(parent_role)
592
622
  end
593
623
 
594
624
  it "sets the same instance on the inverse relation" do
595
- child_role.parent_role.should eql(parent_role)
625
+ expect(child_role.parent_role).to eql(parent_role)
596
626
  end
597
627
 
598
628
  it "does not save the target" do
599
- child_role.should_not be_persisted
629
+ expect(child_role).to_not be_persisted
600
630
  end
601
631
 
602
632
  it "sets the parent on the child" do
603
- child_role._parent.should eq(parent_role)
633
+ expect(child_role._parent).to eq(parent_role)
604
634
  end
605
635
 
606
636
  it "sets the metadata on the child" do
607
- child_role.metadata.should_not be_nil
637
+ expect(child_role.__metadata).to_not be_nil
608
638
  end
609
639
 
610
640
  it "sets the index on the child" do
611
- child_role._index.should eq(0)
641
+ expect(child_role._index).to eq(0)
612
642
  end
613
643
  end
614
644
 
@@ -627,7 +657,7 @@ describe Mongoid::Relations::Embedded::Many do
627
657
  end
628
658
 
629
659
  it "saves the target" do
630
- child_role.should be_persisted
660
+ expect(child_role).to be_persisted
631
661
  end
632
662
  end
633
663
  end
@@ -653,15 +683,15 @@ describe Mongoid::Relations::Embedded::Many do
653
683
  end
654
684
 
655
685
  it "sets the relation to empty" do
656
- person.addresses.should be_empty
686
+ expect(person.addresses).to be_empty
657
687
  end
658
688
 
659
689
  it "sets the unscoped to empty" do
660
- person.addresses.send(:_unscoped).should be_empty
690
+ expect(person.addresses.send(:_unscoped)).to be_empty
661
691
  end
662
692
 
663
693
  it "removes the inverse relation" do
664
- address.addressable.should be_nil
694
+ expect(address.addressable).to be_nil
665
695
  end
666
696
  end
667
697
 
@@ -676,7 +706,7 @@ describe Mongoid::Relations::Embedded::Many do
676
706
  end
677
707
 
678
708
  it "sets the relation to empty" do
679
- person.addresses.should be_empty
709
+ expect(person.addresses).to be_empty
680
710
  end
681
711
  end
682
712
 
@@ -698,19 +728,19 @@ describe Mongoid::Relations::Embedded::Many do
698
728
  end
699
729
 
700
730
  it "sets the relation to empty" do
701
- person.addresses.should be_empty
731
+ expect(person.addresses).to be_empty
702
732
  end
703
733
 
704
734
  it "sets the relation to empty in the database" do
705
- person.reload.addresses.should be_empty
735
+ expect(person.reload.addresses).to be_empty
706
736
  end
707
737
 
708
738
  it "removed the inverse relation" do
709
- address.addressable.should be_nil
739
+ expect(address.addressable).to be_nil
710
740
  end
711
741
 
712
742
  it "deletes the child document" do
713
- address.should be_destroyed
743
+ expect(address).to be_destroyed
714
744
  end
715
745
  end
716
746
 
@@ -722,11 +752,11 @@ describe Mongoid::Relations::Embedded::Many do
722
752
  end
723
753
 
724
754
  it "sets the relation to empty" do
725
- person.addresses.should be_empty
755
+ expect(person.addresses).to be_empty
726
756
  end
727
757
 
728
758
  it "deletes the child document" do
729
- address.should be_destroyed
759
+ expect(address).to be_destroyed
730
760
  end
731
761
 
732
762
  context "when saving the parent" do
@@ -737,7 +767,7 @@ describe Mongoid::Relations::Embedded::Many do
737
767
  end
738
768
 
739
769
  it "persists the deletion" do
740
- person.addresses.should be_empty
770
+ expect(person.addresses).to be_empty
741
771
  end
742
772
  end
743
773
  end
@@ -763,11 +793,11 @@ describe Mongoid::Relations::Embedded::Many do
763
793
  end
764
794
 
765
795
  it "sets the relation to empty" do
766
- person.addresses.should be_empty
796
+ expect(person.addresses).to be_empty
767
797
  end
768
798
 
769
799
  it "sets the relation to empty in the database" do
770
- reloaded.addresses.should be_empty
800
+ expect(reloaded.addresses).to be_empty
771
801
  end
772
802
  end
773
803
  end
@@ -790,11 +820,11 @@ describe Mongoid::Relations::Embedded::Many do
790
820
  end
791
821
 
792
822
  it "sets the relation to empty" do
793
- parent_role.child_roles.should be_empty
823
+ expect(parent_role.child_roles).to be_empty
794
824
  end
795
825
 
796
826
  it "removes the inverse relation" do
797
- child_role.parent_role.should be_nil
827
+ expect(child_role.parent_role).to be_nil
798
828
  end
799
829
  end
800
830
 
@@ -809,7 +839,7 @@ describe Mongoid::Relations::Embedded::Many do
809
839
  end
810
840
 
811
841
  it "sets the relation to empty" do
812
- parent_role.child_roles.should be_empty
842
+ expect(parent_role.child_roles).to be_empty
813
843
  end
814
844
  end
815
845
 
@@ -829,15 +859,15 @@ describe Mongoid::Relations::Embedded::Many do
829
859
  end
830
860
 
831
861
  it "sets the relation to empty" do
832
- parent_role.child_roles.should be_empty
862
+ expect(parent_role.child_roles).to be_empty
833
863
  end
834
864
 
835
865
  it "removed the inverse relation" do
836
- child_role.parent_role.should be_nil
866
+ expect(child_role.parent_role).to be_nil
837
867
  end
838
868
 
839
869
  it "deletes the child document" do
840
- child_role.should be_destroyed
870
+ expect(child_role).to be_destroyed
841
871
  end
842
872
  end
843
873
  end
@@ -860,7 +890,7 @@ describe Mongoid::Relations::Embedded::Many do
860
890
  end
861
891
 
862
892
  it "returns the documents as an array of hashes" do
863
- document.should eq([ address.as_document ])
893
+ expect(document).to eq([ address.as_document ])
864
894
  end
865
895
  end
866
896
 
@@ -885,7 +915,7 @@ describe Mongoid::Relations::Embedded::Many do
885
915
  end
886
916
 
887
917
  it "returns the unscoped documents as an array of hashes" do
888
- document.should eq([ headache.as_document, cough.as_document ])
918
+ expect(document).to eq([ headache.as_document, cough.as_document ])
889
919
  end
890
920
  end
891
921
 
@@ -908,7 +938,7 @@ describe Mongoid::Relations::Embedded::Many do
908
938
  end
909
939
 
910
940
  it "returns the unscoped documents as an array of hashes" do
911
- document.should eq([ active.as_document, inactive.as_document ])
941
+ expect(document).to eq([ active.as_document, inactive.as_document ])
912
942
  end
913
943
  end
914
944
  end
@@ -918,28 +948,6 @@ describe Mongoid::Relations::Embedded::Many do
918
948
 
919
949
  describe "#build" do
920
950
 
921
- context "when providing scoped mass assignment" do
922
-
923
- let(:person) do
924
- Person.new
925
- end
926
-
927
- let(:video) do
928
- person.videos.send(
929
- method,
930
- { title: "Inception", year: 1999 }, as: :admin
931
- )
932
- end
933
-
934
- it "sets the attributes for the provided role" do
935
- video.title.should eq("Inception")
936
- end
937
-
938
- it "does not set the attributes for other roles" do
939
- video.year.should be_nil
940
- end
941
- end
942
-
943
951
  context "when the relation is not cyclic" do
944
952
 
945
953
  let(:person) do
@@ -953,39 +961,39 @@ describe Mongoid::Relations::Embedded::Many do
953
961
  end
954
962
 
955
963
  it "appends to the target" do
956
- person.addresses.should eq([ address ])
964
+ expect(person.addresses).to eq([ address ])
957
965
  end
958
966
 
959
967
  it "appends to the unscoped" do
960
- person.addresses.send(:_unscoped).should eq([ address ])
968
+ expect(person.addresses.send(:_unscoped)).to eq([ address ])
961
969
  end
962
970
 
963
971
  it "sets the base on the inverse relation" do
964
- address.addressable.should eq(person)
972
+ expect(address.addressable).to eq(person)
965
973
  end
966
974
 
967
975
  it "does not save the new document" do
968
- address.should_not be_persisted
976
+ expect(address).to_not be_persisted
969
977
  end
970
978
 
971
979
  it "sets the parent on the child" do
972
- address._parent.should eq(person)
980
+ expect(address._parent).to eq(person)
973
981
  end
974
982
 
975
983
  it "sets the metadata on the child" do
976
- address.metadata.should_not be_nil
984
+ expect(address.__metadata).to_not be_nil
977
985
  end
978
986
 
979
987
  it "sets the index on the child" do
980
- address._index.should eq(0)
988
+ expect(address._index).to eq(0)
981
989
  end
982
990
 
983
991
  it "writes to the attributes" do
984
- address.street.should eq("Bond")
992
+ expect(address.street).to eq("Bond")
985
993
  end
986
994
 
987
995
  it "calls the passed block" do
988
- address.state.should eq("CA")
996
+ expect(address.state).to eq("CA")
989
997
  end
990
998
  end
991
999
 
@@ -1000,31 +1008,31 @@ describe Mongoid::Relations::Embedded::Many do
1000
1008
  end
1001
1009
 
1002
1010
  it "appends to the target" do
1003
- parent_role.child_roles.should eq([ child_role ])
1011
+ expect(parent_role.child_roles).to eq([ child_role ])
1004
1012
  end
1005
1013
 
1006
1014
  it "sets the base on the inverse relation" do
1007
- child_role.parent_role.should eq(parent_role)
1015
+ expect(child_role.parent_role).to eq(parent_role)
1008
1016
  end
1009
1017
 
1010
1018
  it "does not save the new document" do
1011
- child_role.should_not be_persisted
1019
+ expect(child_role).to_not be_persisted
1012
1020
  end
1013
1021
 
1014
1022
  it "sets the parent on the child" do
1015
- child_role._parent.should eq(parent_role)
1023
+ expect(child_role._parent).to eq(parent_role)
1016
1024
  end
1017
1025
 
1018
1026
  it "sets the metadata on the child" do
1019
- child_role.metadata.should_not be_nil
1027
+ expect(child_role.__metadata).to_not be_nil
1020
1028
  end
1021
1029
 
1022
1030
  it "sets the index on the child" do
1023
- child_role._index.should eq(0)
1031
+ expect(child_role._index).to eq(0)
1024
1032
  end
1025
1033
 
1026
1034
  it "writes to the attributes" do
1027
- child_role.name.should eq("CTO")
1035
+ expect(child_role.name).to eq("CTO")
1028
1036
  end
1029
1037
  end
1030
1038
 
@@ -1053,7 +1061,7 @@ describe Mongoid::Relations::Embedded::Many do
1053
1061
  end
1054
1062
 
1055
1063
  it "persists the deeply embedded document" do
1056
- location.name.should eq("Home")
1064
+ expect(location.name).to eq("Home")
1057
1065
  end
1058
1066
  end
1059
1067
  end
@@ -1083,8 +1091,9 @@ describe Mongoid::Relations::Embedded::Many do
1083
1091
  end
1084
1092
 
1085
1093
  it "returns the many builder" do
1086
- described_class.builder(base, metadata, document).should
1087
- be_a(Mongoid::Relations::Builders::Embedded::Many)
1094
+ expect(
1095
+ described_class.builder(base, metadata, document)
1096
+ ).to be_a(Mongoid::Relations::Builders::Embedded::Many)
1088
1097
  end
1089
1098
  end
1090
1099
 
@@ -1107,23 +1116,23 @@ describe Mongoid::Relations::Embedded::Many do
1107
1116
  end
1108
1117
 
1109
1118
  it "clears out the relation" do
1110
- person.addresses.should be_empty
1119
+ expect(person.addresses).to be_empty
1111
1120
  end
1112
1121
 
1113
1122
  it "clears the unscoped" do
1114
- person.addresses.send(:_unscoped).should be_empty
1123
+ expect(person.addresses.send(:_unscoped)).to be_empty
1115
1124
  end
1116
1125
 
1117
1126
  it "marks the documents as deleted" do
1118
- address.should be_destroyed
1127
+ expect(address).to be_destroyed
1119
1128
  end
1120
1129
 
1121
1130
  it "deletes the documents from the db" do
1122
- person.reload.addresses.should be_empty
1131
+ expect(person.reload.addresses).to be_empty
1123
1132
  end
1124
1133
 
1125
1134
  it "returns the relation" do
1126
- relation.should be_empty
1135
+ expect(relation).to be_empty
1127
1136
  end
1128
1137
  end
1129
1138
 
@@ -1138,7 +1147,7 @@ describe Mongoid::Relations::Embedded::Many do
1138
1147
  end
1139
1148
 
1140
1149
  it "clears out the relation" do
1141
- person.addresses.should be_empty
1150
+ expect(person.addresses).to be_empty
1142
1151
  end
1143
1152
  end
1144
1153
  end
@@ -1158,7 +1167,7 @@ describe Mongoid::Relations::Embedded::Many do
1158
1167
  end
1159
1168
 
1160
1169
  it "clears out the relation" do
1161
- person.addresses.should be_empty
1170
+ expect(person.addresses).to be_empty
1162
1171
  end
1163
1172
  end
1164
1173
  end
@@ -1180,35 +1189,35 @@ describe Mongoid::Relations::Embedded::Many do
1180
1189
  end
1181
1190
 
1182
1191
  it "appends to the target" do
1183
- person.addresses.should eq([ address ])
1192
+ expect(person.addresses).to eq([ address ])
1184
1193
  end
1185
1194
 
1186
1195
  it "appends to the unscoped" do
1187
- person.addresses.send(:_unscoped).should eq([ address ])
1196
+ expect(person.addresses.send(:_unscoped)).to eq([ address ])
1188
1197
  end
1189
1198
 
1190
1199
  it "sets the base on the inverse relation" do
1191
- address.addressable.should eq(person)
1200
+ expect(address.addressable).to eq(person)
1192
1201
  end
1193
1202
 
1194
1203
  it "sets the same instance on the inverse relation" do
1195
- address.addressable.should eql(person)
1204
+ expect(address.addressable).to eql(person)
1196
1205
  end
1197
1206
 
1198
1207
  it "does not save the new document" do
1199
- address.should_not be_persisted
1208
+ expect(address).to_not be_persisted
1200
1209
  end
1201
1210
 
1202
1211
  it "sets the parent on the child" do
1203
- address._parent.should eq(person)
1212
+ expect(address._parent).to eq(person)
1204
1213
  end
1205
1214
 
1206
1215
  it "sets the metadata on the child" do
1207
- address.metadata.should_not be_nil
1216
+ expect(address.__metadata).to_not be_nil
1208
1217
  end
1209
1218
 
1210
1219
  it "sets the index on the child" do
1211
- address._index.should eq(0)
1220
+ expect(address._index).to eq(0)
1212
1221
  end
1213
1222
  end
1214
1223
 
@@ -1227,7 +1236,7 @@ describe Mongoid::Relations::Embedded::Many do
1227
1236
  end
1228
1237
 
1229
1238
  it "saves the new document" do
1230
- address.should be_persisted
1239
+ expect(address).to be_persisted
1231
1240
  end
1232
1241
  end
1233
1242
 
@@ -1238,12 +1247,12 @@ describe Mongoid::Relations::Embedded::Many do
1238
1247
  end
1239
1248
 
1240
1249
  before do
1241
- person.addresses.should_not_receive(:batch_insert)
1250
+ expect(person.addresses).to_not receive(:batch_insert)
1242
1251
  person.addresses.concat([])
1243
1252
  end
1244
1253
 
1245
1254
  it "doesn't update the target" do
1246
- person.addresses.should be_empty
1255
+ expect(person.addresses).to be_empty
1247
1256
  end
1248
1257
  end
1249
1258
 
@@ -1266,11 +1275,11 @@ describe Mongoid::Relations::Embedded::Many do
1266
1275
  end
1267
1276
 
1268
1277
  it "saves the first document" do
1269
- address_one.should be_persisted
1278
+ expect(address_one).to be_persisted
1270
1279
  end
1271
1280
 
1272
1281
  it "saves the second document" do
1273
- address_two.should be_persisted
1282
+ expect(address_two).to be_persisted
1274
1283
  end
1275
1284
  end
1276
1285
 
@@ -1291,31 +1300,31 @@ describe Mongoid::Relations::Embedded::Many do
1291
1300
  end
1292
1301
 
1293
1302
  it "appends to the target" do
1294
- parent_role.child_roles.should eq([ child_role ])
1303
+ expect(parent_role.child_roles).to eq([ child_role ])
1295
1304
  end
1296
1305
 
1297
1306
  it "sets the base on the inverse relation" do
1298
- child_role.parent_role.should eq(parent_role)
1307
+ expect(child_role.parent_role).to eq(parent_role)
1299
1308
  end
1300
1309
 
1301
1310
  it "sets the same instance on the inverse relation" do
1302
- child_role.parent_role.should eql(parent_role)
1311
+ expect(child_role.parent_role).to eql(parent_role)
1303
1312
  end
1304
1313
 
1305
1314
  it "does not save the new document" do
1306
- child_role.should_not be_persisted
1315
+ expect(child_role).to_not be_persisted
1307
1316
  end
1308
1317
 
1309
1318
  it "sets the parent on the child" do
1310
- child_role._parent.should eq(parent_role)
1319
+ expect(child_role._parent).to eq(parent_role)
1311
1320
  end
1312
1321
 
1313
1322
  it "sets the metadata on the child" do
1314
- child_role.metadata.should_not be_nil
1323
+ expect(child_role.__metadata).to_not be_nil
1315
1324
  end
1316
1325
 
1317
1326
  it "sets the index on the child" do
1318
- child_role._index.should eq(0)
1327
+ expect(child_role._index).to eq(0)
1319
1328
  end
1320
1329
  end
1321
1330
 
@@ -1334,7 +1343,7 @@ describe Mongoid::Relations::Embedded::Many do
1334
1343
  end
1335
1344
 
1336
1345
  it "saves the new document" do
1337
- child_role.should be_persisted
1346
+ expect(child_role).to be_persisted
1338
1347
  end
1339
1348
  end
1340
1349
  end
@@ -1352,30 +1361,36 @@ describe Mongoid::Relations::Embedded::Many do
1352
1361
  end
1353
1362
 
1354
1363
  it "returns the number of persisted documents" do
1355
- person.addresses.count.should eq(1)
1364
+ expect(person.addresses.count).to eq(1)
1356
1365
  end
1357
1366
  end
1358
1367
 
1359
1368
  describe "#create" do
1360
1369
 
1361
- context "when providing scoped mass assignment" do
1370
+ context "when providing multiple attributes" do
1362
1371
 
1363
1372
  let(:person) do
1364
1373
  Person.create
1365
1374
  end
1366
1375
 
1367
- let(:video) do
1368
- person.videos.create(
1369
- { title: "Inception", year: 1999 }, as: :admin
1370
- )
1376
+ let!(:addresses) do
1377
+ person.addresses.create([{ street: "Bond" }, { street: "Upper" }])
1378
+ end
1379
+
1380
+ it "creates multiple documents" do
1381
+ expect(addresses.size).to eq(2)
1382
+ end
1383
+
1384
+ it "sets the first attributes" do
1385
+ expect(addresses.first.street).to eq("Bond")
1371
1386
  end
1372
1387
 
1373
- it "sets the attributes for the provided role" do
1374
- video.title.should eq("Inception")
1388
+ it "sets the second attributes" do
1389
+ expect(addresses.last.street).to eq("Upper")
1375
1390
  end
1376
1391
 
1377
- it "does not set the attributes for other roles" do
1378
- video.year.should be_nil
1392
+ it "persists the children" do
1393
+ expect(person.addresses.count).to eq(2)
1379
1394
  end
1380
1395
  end
1381
1396
 
@@ -1392,39 +1407,39 @@ describe Mongoid::Relations::Embedded::Many do
1392
1407
  end
1393
1408
 
1394
1409
  it "appends to the target" do
1395
- person.reload.addresses.should eq([ address ])
1410
+ expect(person.reload.addresses).to eq([ address ])
1396
1411
  end
1397
1412
 
1398
1413
  it "appends to the unscoped" do
1399
- person.reload.addresses.send(:_unscoped).should eq([ address ])
1414
+ expect(person.reload.addresses.send(:_unscoped)).to eq([ address ])
1400
1415
  end
1401
1416
 
1402
1417
  it "sets the base on the inverse relation" do
1403
- address.addressable.should eq(person)
1418
+ expect(address.addressable).to eq(person)
1404
1419
  end
1405
1420
 
1406
1421
  it "saves the document" do
1407
- address.should be_persisted
1422
+ expect(address).to be_persisted
1408
1423
  end
1409
1424
 
1410
1425
  it "sets the parent on the child" do
1411
- address._parent.should eq(person)
1426
+ expect(address._parent).to eq(person)
1412
1427
  end
1413
1428
 
1414
1429
  it "sets the metadata on the child" do
1415
- address.metadata.should_not be_nil
1430
+ expect(address.__metadata).to_not be_nil
1416
1431
  end
1417
1432
 
1418
1433
  it "sets the index on the child" do
1419
- address._index.should eq(0)
1434
+ expect(address._index).to eq(0)
1420
1435
  end
1421
1436
 
1422
1437
  it "writes to the attributes" do
1423
- address.street.should eq("Bond")
1438
+ expect(address.street).to eq("Bond")
1424
1439
  end
1425
1440
 
1426
1441
  it "calls the passed block" do
1427
- address.state.should eq("CA")
1442
+ expect(address.state).to eq("CA")
1428
1443
  end
1429
1444
 
1430
1445
  context "when embedding a multi word named document" do
@@ -1434,7 +1449,7 @@ describe Mongoid::Relations::Embedded::Many do
1434
1449
  end
1435
1450
 
1436
1451
  it "saves the embedded document" do
1437
- person.reload.address_components.first.should eq(component)
1452
+ expect(person.reload.address_components.first).to eq(component)
1438
1453
  end
1439
1454
  end
1440
1455
  end
@@ -1450,7 +1465,7 @@ describe Mongoid::Relations::Embedded::Many do
1450
1465
  end
1451
1466
 
1452
1467
  it "creates a new child" do
1453
- child_entry.should be_persisted
1468
+ expect(child_entry).to be_persisted
1454
1469
  end
1455
1470
  end
1456
1471
  end
@@ -1461,20 +1476,26 @@ describe Mongoid::Relations::Embedded::Many do
1461
1476
  Person.create
1462
1477
  end
1463
1478
 
1464
- context "when providing scoped mass assignment" do
1479
+ context "when providing multiple attributes" do
1465
1480
 
1466
- let(:video) do
1467
- person.videos.create!(
1468
- { title: "Inception", year: 1999 }, as: :admin
1469
- )
1481
+ let!(:addresses) do
1482
+ person.addresses.create!([{ street: "Bond" }, { street: "Upper" }])
1483
+ end
1484
+
1485
+ it "creates multiple documents" do
1486
+ expect(addresses.size).to eq(2)
1487
+ end
1488
+
1489
+ it "sets the first attributes" do
1490
+ expect(addresses.first.street).to eq("Bond")
1470
1491
  end
1471
1492
 
1472
- it "sets the attributes for the provided role" do
1473
- video.title.should eq("Inception")
1493
+ it "sets the second attributes" do
1494
+ expect(addresses.last.street).to eq("Upper")
1474
1495
  end
1475
1496
 
1476
- it "does not set the attributes for other roles" do
1477
- video.year.should be_nil
1497
+ it "persists the children" do
1498
+ expect(person.addresses.count).to eq(2)
1478
1499
  end
1479
1500
  end
1480
1501
 
@@ -1485,35 +1506,35 @@ describe Mongoid::Relations::Embedded::Many do
1485
1506
  end
1486
1507
 
1487
1508
  it "appends to the target" do
1488
- person.addresses.should eq([ address ])
1509
+ expect(person.addresses).to eq([ address ])
1489
1510
  end
1490
1511
 
1491
1512
  it "appends to the unscoped" do
1492
- person.addresses.send(:_unscoped).should eq([ address ])
1513
+ expect(person.addresses.send(:_unscoped)).to eq([ address ])
1493
1514
  end
1494
1515
 
1495
1516
  it "sets the base on the inverse relation" do
1496
- address.addressable.should eq(person)
1517
+ expect(address.addressable).to eq(person)
1497
1518
  end
1498
1519
 
1499
1520
  it "saves the document" do
1500
- address.should be_persisted
1521
+ expect(address).to be_persisted
1501
1522
  end
1502
1523
 
1503
1524
  it "sets the parent on the child" do
1504
- address._parent.should eq(person)
1525
+ expect(address._parent).to eq(person)
1505
1526
  end
1506
1527
 
1507
1528
  it "sets the metadata on the child" do
1508
- address.metadata.should_not be_nil
1529
+ expect(address.__metadata).to_not be_nil
1509
1530
  end
1510
1531
 
1511
1532
  it "sets the index on the child" do
1512
- address._index.should eq(0)
1533
+ expect(address._index).to eq(0)
1513
1534
  end
1514
1535
 
1515
1536
  it "writes to the attributes" do
1516
- address.street.should eq("Bond")
1537
+ expect(address.street).to eq("Bond")
1517
1538
  end
1518
1539
  end
1519
1540
 
@@ -1552,26 +1573,26 @@ describe Mongoid::Relations::Embedded::Many do
1552
1573
  end
1553
1574
 
1554
1575
  it "deletes the document" do
1555
- person.addresses.should eq([ address_two ])
1576
+ expect(person.addresses).to eq([ address_two ])
1556
1577
  end
1557
1578
 
1558
1579
  it "deletes the document from the unscoped" do
1559
- person.addresses.send(:_unscoped).should eq([ address_two ])
1580
+ expect(person.addresses.send(:_unscoped)).to eq([ address_two ])
1560
1581
  end
1561
1582
 
1562
1583
  it "reindexes the relation" do
1563
- address_two._index.should eq(0)
1584
+ expect(address_two._index).to eq(0)
1564
1585
  end
1565
1586
 
1566
1587
  it "returns the document" do
1567
- deleted.should eq(address_one)
1588
+ expect(deleted).to eq(address_one)
1568
1589
  end
1569
1590
  end
1570
1591
 
1571
1592
  context "when the document does not exist" do
1572
1593
 
1573
1594
  it "returns nil" do
1574
- person.addresses.delete(Address.new).should be_nil
1595
+ expect(person.addresses.delete(Address.new)).to be_nil
1575
1596
  end
1576
1597
  end
1577
1598
  end
@@ -1601,15 +1622,15 @@ describe Mongoid::Relations::Embedded::Many do
1601
1622
  end
1602
1623
 
1603
1624
  it "removes the matching documents" do
1604
- person.addresses.size.should eq(1)
1625
+ expect(person.addresses.size).to eq(1)
1605
1626
  end
1606
1627
 
1607
1628
  it "removes from the unscoped" do
1608
- person.addresses.send(:_unscoped).size.should eq(1)
1629
+ expect(person.addresses.send(:_unscoped).size).to eq(1)
1609
1630
  end
1610
1631
 
1611
1632
  it "returns the relation" do
1612
- deleted.should eq(person.addresses)
1633
+ expect(deleted).to eq(person.addresses)
1613
1634
  end
1614
1635
  end
1615
1636
 
@@ -1620,7 +1641,7 @@ describe Mongoid::Relations::Embedded::Many do
1620
1641
  end
1621
1642
 
1622
1643
  it "returns an enumerator" do
1623
- deleted.should be_a(Enumerator)
1644
+ expect(deleted).to be_a(Enumerator)
1624
1645
  end
1625
1646
  end
1626
1647
  end
@@ -1644,15 +1665,15 @@ describe Mongoid::Relations::Embedded::Many do
1644
1665
  end
1645
1666
 
1646
1667
  it "deletes the matching documents" do
1647
- person.addresses.count.should eq(1)
1668
+ expect(person.addresses.count).to eq(1)
1648
1669
  end
1649
1670
 
1650
1671
  it "deletes the matching documents from the db" do
1651
- person.reload.addresses.count.should eq(1)
1672
+ expect(person.reload.addresses.count).to eq(1)
1652
1673
  end
1653
1674
 
1654
1675
  it "returns the relation" do
1655
- deleted.should eq(person.addresses)
1676
+ expect(deleted).to eq(person.addresses)
1656
1677
  end
1657
1678
  end
1658
1679
  end
@@ -1668,15 +1689,15 @@ describe Mongoid::Relations::Embedded::Many do
1668
1689
  end
1669
1690
 
1670
1691
  it "deletes the matching documents" do
1671
- person.addresses.count.should eq(0)
1692
+ expect(person.addresses.count).to eq(0)
1672
1693
  end
1673
1694
 
1674
1695
  it "deletes all the documents from the db" do
1675
- person.reload.addresses.count.should eq(0)
1696
+ expect(person.reload.addresses.count).to eq(0)
1676
1697
  end
1677
1698
 
1678
1699
  it "returns the relation" do
1679
- deleted.should eq(person.addresses)
1700
+ expect(deleted).to eq(person.addresses)
1680
1701
  end
1681
1702
  end
1682
1703
  end
@@ -1710,15 +1731,15 @@ describe Mongoid::Relations::Embedded::Many do
1710
1731
  end
1711
1732
 
1712
1733
  it "removes the matching documents" do
1713
- person.addresses.size.should eq(1)
1734
+ expect(person.addresses.size).to eq(1)
1714
1735
  end
1715
1736
 
1716
1737
  it "removes from the unscoped" do
1717
- person.addresses.send(:_unscoped).size.should eq(1)
1738
+ expect(person.addresses.send(:_unscoped).size).to eq(1)
1718
1739
  end
1719
1740
 
1720
1741
  it "returns the number deleted" do
1721
- deleted.should eq(1)
1742
+ expect(deleted).to eq(1)
1722
1743
  end
1723
1744
  end
1724
1745
 
@@ -1729,11 +1750,11 @@ describe Mongoid::Relations::Embedded::Many do
1729
1750
  end
1730
1751
 
1731
1752
  it "removes all documents" do
1732
- person.addresses.size.should eq(0)
1753
+ expect(person.addresses.size).to eq(0)
1733
1754
  end
1734
1755
 
1735
1756
  it "returns the number deleted" do
1736
- deleted.should eq(2)
1757
+ expect(deleted).to eq(2)
1737
1758
  end
1738
1759
  end
1739
1760
  end
@@ -1758,15 +1779,15 @@ describe Mongoid::Relations::Embedded::Many do
1758
1779
  end
1759
1780
 
1760
1781
  it "deletes the matching documents" do
1761
- person.addresses.count.should eq(1)
1782
+ expect(person.addresses.count).to eq(1)
1762
1783
  end
1763
1784
 
1764
1785
  it "deletes the matching documents from the db" do
1765
- person.reload.addresses.count.should eq(1)
1786
+ expect(person.reload.addresses.count).to eq(1)
1766
1787
  end
1767
1788
 
1768
1789
  it "returns the number deleted" do
1769
- deleted.should eq(1)
1790
+ expect(deleted).to eq(1)
1770
1791
  end
1771
1792
  end
1772
1793
 
@@ -1777,15 +1798,15 @@ describe Mongoid::Relations::Embedded::Many do
1777
1798
  end
1778
1799
 
1779
1800
  it "deletes all the documents" do
1780
- person.addresses.count.should eq(0)
1801
+ expect(person.addresses.count).to eq(0)
1781
1802
  end
1782
1803
 
1783
1804
  it "deletes all the documents from the db" do
1784
- person.reload.addresses.count.should eq(0)
1805
+ expect(person.reload.addresses.count).to eq(0)
1785
1806
  end
1786
1807
 
1787
1808
  it "returns the number deleted" do
1788
- deleted.should eq(2)
1809
+ expect(deleted).to eq(2)
1789
1810
  end
1790
1811
  end
1791
1812
 
@@ -1803,13 +1824,13 @@ describe Mongoid::Relations::Embedded::Many do
1803
1824
  end
1804
1825
 
1805
1826
  it "removes the documents" do
1806
- owner.pet.vet_visits.should be_empty
1827
+ expect(owner.pet.vet_visits).to be_empty
1807
1828
  end
1808
1829
 
1809
1830
  it "allows addition and a resave" do
1810
1831
  owner.pet.vet_visits << VetVisit.new(date: Date.today)
1811
1832
  owner.save!
1812
- owner.pet.vet_visits.first.should be_persisted
1833
+ expect(owner.pet.vet_visits.first).to be_persisted
1813
1834
  end
1814
1835
  end
1815
1836
  end
@@ -1822,15 +1843,15 @@ describe Mongoid::Relations::Embedded::Many do
1822
1843
  end
1823
1844
 
1824
1845
  it "deletes all the documents" do
1825
- person.addresses.count.should eq(0)
1846
+ expect(person.addresses.count).to eq(0)
1826
1847
  end
1827
1848
 
1828
1849
  it "deletes all the documents from the db" do
1829
- person.reload.addresses.count.should eq(0)
1850
+ expect(person.reload.addresses.count).to eq(0)
1830
1851
  end
1831
1852
 
1832
1853
  it "returns the number deleted" do
1833
- deleted.should eq(0)
1854
+ expect(deleted).to eq(0)
1834
1855
  end
1835
1856
  end
1836
1857
 
@@ -1844,15 +1865,15 @@ describe Mongoid::Relations::Embedded::Many do
1844
1865
  end
1845
1866
 
1846
1867
  it "deletes all the documents" do
1847
- person.addresses.count.should eq(0)
1868
+ expect(person.addresses.count).to eq(0)
1848
1869
  end
1849
1870
 
1850
1871
  it "deletes all the documents from the db" do
1851
- person.reload.addresses.count.should eq(0)
1872
+ expect(person.reload.addresses.count).to eq(0)
1852
1873
  end
1853
1874
 
1854
1875
  it "returns the number deleted" do
1855
- deleted.should eq(0)
1876
+ expect(deleted).to eq(0)
1856
1877
  end
1857
1878
  end
1858
1879
 
@@ -1863,15 +1884,15 @@ describe Mongoid::Relations::Embedded::Many do
1863
1884
  end
1864
1885
 
1865
1886
  it "deletes all the documents" do
1866
- person.addresses.count.should eq(0)
1887
+ expect(person.addresses.count).to eq(0)
1867
1888
  end
1868
1889
 
1869
1890
  it "deletes all the documents from the db" do
1870
- person.reload.addresses.count.should eq(0)
1891
+ expect(person.reload.addresses.count).to eq(0)
1871
1892
  end
1872
1893
 
1873
1894
  it "returns the number deleted" do
1874
- deleted.should eq(0)
1895
+ expect(deleted).to eq(0)
1875
1896
  end
1876
1897
  end
1877
1898
  end
@@ -1881,14 +1902,14 @@ describe Mongoid::Relations::Embedded::Many do
1881
1902
  describe ".embedded?" do
1882
1903
 
1883
1904
  it "returns true" do
1884
- described_class.should be_embedded
1905
+ expect(described_class).to be_embedded
1885
1906
  end
1886
1907
  end
1887
1908
 
1888
1909
  describe ".foreign_key_suffix" do
1889
1910
 
1890
1911
  it "returns nil" do
1891
- described_class.foreign_key_suffix.should be_nil
1912
+ expect(described_class.foreign_key_suffix).to be_nil
1892
1913
  end
1893
1914
  end
1894
1915
 
@@ -1905,7 +1926,7 @@ describe Mongoid::Relations::Embedded::Many do
1905
1926
  end
1906
1927
 
1907
1928
  it "returns true" do
1908
- person.addresses.exists?.should be_true
1929
+ expect(person.addresses.exists?).to be true
1909
1930
  end
1910
1931
  end
1911
1932
 
@@ -1916,7 +1937,7 @@ describe Mongoid::Relations::Embedded::Many do
1916
1937
  end
1917
1938
 
1918
1939
  it "returns false" do
1919
- person.addresses.exists?.should be_false
1940
+ expect(person.addresses.exists?).to be false
1920
1941
  end
1921
1942
  end
1922
1943
  end
@@ -1944,7 +1965,7 @@ describe Mongoid::Relations::Embedded::Many do
1944
1965
  end
1945
1966
 
1946
1967
  it "returns the matching document" do
1947
- address.should eq(address_one)
1968
+ expect(address).to eq(address_one)
1948
1969
  end
1949
1970
  end
1950
1971
 
@@ -1958,7 +1979,7 @@ describe Mongoid::Relations::Embedded::Many do
1958
1979
 
1959
1980
  it "raises an error" do
1960
1981
  expect {
1961
- person.addresses.find(Moped::BSON::ObjectId.new)
1982
+ person.addresses.find(BSON::ObjectId.new)
1962
1983
  }.to raise_error(Mongoid::Errors::DocumentNotFound)
1963
1984
  end
1964
1985
  end
@@ -1966,7 +1987,7 @@ describe Mongoid::Relations::Embedded::Many do
1966
1987
  context "when config set not to raise error" do
1967
1988
 
1968
1989
  let(:address) do
1969
- person.addresses.find(Moped::BSON::ObjectId.new)
1990
+ person.addresses.find(BSON::ObjectId.new)
1970
1991
  end
1971
1992
 
1972
1993
  before do
@@ -1978,7 +1999,7 @@ describe Mongoid::Relations::Embedded::Many do
1978
1999
  end
1979
2000
 
1980
2001
  it "returns nil" do
1981
- address.should be_nil
2002
+ expect(address).to be_nil
1982
2003
  end
1983
2004
  end
1984
2005
  end
@@ -1993,7 +2014,7 @@ describe Mongoid::Relations::Embedded::Many do
1993
2014
  end
1994
2015
 
1995
2016
  it "returns the matching documents" do
1996
- addresses.should eq([ address_one, address_two ])
2017
+ expect(addresses).to eq([ address_one, address_two ])
1997
2018
  end
1998
2019
  end
1999
2020
 
@@ -2007,7 +2028,7 @@ describe Mongoid::Relations::Embedded::Many do
2007
2028
 
2008
2029
  it "raises an error" do
2009
2030
  expect {
2010
- person.addresses.find([ Moped::BSON::ObjectId.new ])
2031
+ person.addresses.find([ BSON::ObjectId.new ])
2011
2032
  }.to raise_error(Mongoid::Errors::DocumentNotFound)
2012
2033
  end
2013
2034
  end
@@ -2015,7 +2036,7 @@ describe Mongoid::Relations::Embedded::Many do
2015
2036
  context "when config set not to raise error" do
2016
2037
 
2017
2038
  let(:addresses) do
2018
- person.addresses.find([ Moped::BSON::ObjectId.new ])
2039
+ person.addresses.find([ BSON::ObjectId.new ])
2019
2040
  end
2020
2041
 
2021
2042
  before do
@@ -2027,7 +2048,7 @@ describe Mongoid::Relations::Embedded::Many do
2027
2048
  end
2028
2049
 
2029
2050
  it "returns an empty array" do
2030
- addresses.should be_empty
2051
+ expect(addresses).to be_empty
2031
2052
  end
2032
2053
  end
2033
2054
  end
@@ -2051,7 +2072,7 @@ describe Mongoid::Relations::Embedded::Many do
2051
2072
  end
2052
2073
 
2053
2074
  it "returns the document" do
2054
- found.should eq(address)
2075
+ expect(found).to eq(address)
2055
2076
  end
2056
2077
  end
2057
2078
 
@@ -2064,15 +2085,15 @@ describe Mongoid::Relations::Embedded::Many do
2064
2085
  end
2065
2086
 
2066
2087
  it "sets the new document attributes" do
2067
- found.street.should eq("King")
2088
+ expect(found.street).to eq("King")
2068
2089
  end
2069
2090
 
2070
2091
  it "returns a newly persisted document" do
2071
- found.should be_persisted
2092
+ expect(found).to be_persisted
2072
2093
  end
2073
2094
 
2074
2095
  it "calls the passed block" do
2075
- found.state.should eq("CA")
2096
+ expect(found.state).to eq("CA")
2076
2097
  end
2077
2098
  end
2078
2099
 
@@ -2094,7 +2115,7 @@ describe Mongoid::Relations::Embedded::Many do
2094
2115
  end
2095
2116
 
2096
2117
  it "properly creates the document" do
2097
- line_item.product.should eq(product)
2118
+ expect(line_item.product).to eq(product)
2098
2119
  end
2099
2120
  end
2100
2121
  end
@@ -2116,7 +2137,7 @@ describe Mongoid::Relations::Embedded::Many do
2116
2137
  end
2117
2138
 
2118
2139
  it "returns the document" do
2119
- found.should eq(address)
2140
+ expect(found).to eq(address)
2120
2141
  end
2121
2142
  end
2122
2143
 
@@ -2129,15 +2150,15 @@ describe Mongoid::Relations::Embedded::Many do
2129
2150
  end
2130
2151
 
2131
2152
  it "sets the new document attributes" do
2132
- found.street.should eq("King")
2153
+ expect(found.street).to eq("King")
2133
2154
  end
2134
2155
 
2135
2156
  it "returns a non persisted document" do
2136
- found.should_not be_persisted
2157
+ expect(found).to_not be_persisted
2137
2158
  end
2138
2159
 
2139
2160
  it "calls the passed block" do
2140
- found.state.should eq("CA")
2161
+ expect(found.state).to eq("CA")
2141
2162
  end
2142
2163
  end
2143
2164
  end
@@ -2145,7 +2166,7 @@ describe Mongoid::Relations::Embedded::Many do
2145
2166
  describe ".macro" do
2146
2167
 
2147
2168
  it "returns embeds_many" do
2148
- described_class.macro.should eq(:embeds_many)
2169
+ expect(described_class.macro).to eq(:embeds_many)
2149
2170
  end
2150
2171
  end
2151
2172
 
@@ -2174,7 +2195,7 @@ describe Mongoid::Relations::Embedded::Many do
2174
2195
  end
2175
2196
 
2176
2197
  it "returns the document with the max value of the supplied field" do
2177
- max.should eq(address_two)
2198
+ expect(max).to eq(address_two)
2178
2199
  end
2179
2200
  end
2180
2201
 
@@ -2201,7 +2222,7 @@ describe Mongoid::Relations::Embedded::Many do
2201
2222
  end
2202
2223
 
2203
2224
  it "returns the document with the max value of the supplied field" do
2204
- max.should eq(address_two)
2225
+ expect(max).to eq(address_two)
2205
2226
  end
2206
2227
  end
2207
2228
 
@@ -2236,7 +2257,7 @@ describe Mongoid::Relations::Embedded::Many do
2236
2257
  end
2237
2258
 
2238
2259
  it "applies the criteria to the documents" do
2239
- addresses.should eq([ address_one ])
2260
+ expect(addresses).to eq([ address_one ])
2240
2261
  end
2241
2262
  end
2242
2263
 
@@ -2247,7 +2268,7 @@ describe Mongoid::Relations::Embedded::Many do
2247
2268
  end
2248
2269
 
2249
2270
  it "applies the criteria to the documents" do
2250
- addresses.should eq([ address_one, address_two ])
2271
+ expect(addresses).to eq([ address_one, address_two ])
2251
2272
  end
2252
2273
  end
2253
2274
 
@@ -2258,7 +2279,7 @@ describe Mongoid::Relations::Embedded::Many do
2258
2279
  end
2259
2280
 
2260
2281
  it "applies the criteria to the documents" do
2261
- addresses.should eq([ address_one, address_two ])
2282
+ expect(addresses).to eq([ address_one, address_two ])
2262
2283
  end
2263
2284
  end
2264
2285
  end
@@ -2270,7 +2291,7 @@ describe Mongoid::Relations::Embedded::Many do
2270
2291
  end
2271
2292
 
2272
2293
  it "applies the criteria to the documents" do
2273
- addresses.should eq([ address_one ])
2294
+ expect(addresses).to eq([ address_one ])
2274
2295
  end
2275
2296
  end
2276
2297
 
@@ -2281,7 +2302,7 @@ describe Mongoid::Relations::Embedded::Many do
2281
2302
  end
2282
2303
 
2283
2304
  it "applies the criteria to the documents" do
2284
- addresses.should eq([ address_one ])
2305
+ expect(addresses).to eq([ address_one ])
2285
2306
  end
2286
2307
  end
2287
2308
 
@@ -2290,8 +2311,7 @@ describe Mongoid::Relations::Embedded::Many do
2290
2311
  describe "#distinct" do
2291
2312
 
2292
2313
  it "returns the distinct values for the fields" do
2293
- person.addresses.distinct(:street).should =~
2294
- [ "Market", "Madison"]
2314
+ expect(person.addresses.distinct(:street)).to eq([ "Market", "Madison"])
2295
2315
  end
2296
2316
  end
2297
2317
  end
@@ -2322,7 +2342,7 @@ describe Mongoid::Relations::Embedded::Many do
2322
2342
  end
2323
2343
 
2324
2344
  it "returns the min value of the supplied field" do
2325
- min.should eq(address_one)
2345
+ expect(min).to eq(address_one)
2326
2346
  end
2327
2347
  end
2328
2348
 
@@ -2349,7 +2369,7 @@ describe Mongoid::Relations::Embedded::Many do
2349
2369
  end
2350
2370
 
2351
2371
  it "returns the min value of the supplied field" do
2352
- min.should eq(address_one)
2372
+ expect(min).to eq(address_one)
2353
2373
  end
2354
2374
  end
2355
2375
 
@@ -2360,8 +2380,9 @@ describe Mongoid::Relations::Embedded::Many do
2360
2380
  end
2361
2381
 
2362
2382
  it "returns the many nested builder class" do
2363
- described_class.nested_builder(metadata, {}, {}).should
2364
- be_a(Mongoid::Relations::Builders::NestedAttributes::Many)
2383
+ expect(
2384
+ described_class.nested_builder(metadata, {}, {})
2385
+ ).to be_a(Mongoid::Relations::Builders::NestedAttributes::Many)
2365
2386
  end
2366
2387
  end
2367
2388
 
@@ -2386,15 +2407,15 @@ describe Mongoid::Relations::Embedded::Many do
2386
2407
  end
2387
2408
 
2388
2409
  it "returns the popped document" do
2389
- popped.should eq(address_two)
2410
+ expect(popped).to eq(address_two)
2390
2411
  end
2391
2412
 
2392
2413
  it "removes the document from the relation" do
2393
- person.addresses.should eq([ address_one ])
2414
+ expect(person.addresses).to eq([ address_one ])
2394
2415
  end
2395
2416
 
2396
2417
  it "persists the pop" do
2397
- person.reload.addresses.should eq([ address_one ])
2418
+ expect(person.reload.addresses).to eq([ address_one ])
2398
2419
  end
2399
2420
  end
2400
2421
 
@@ -2415,15 +2436,15 @@ describe Mongoid::Relations::Embedded::Many do
2415
2436
  end
2416
2437
 
2417
2438
  it "returns the popped documents" do
2418
- popped.should eq([ address_one, address_two ])
2439
+ expect(popped).to eq([ address_one, address_two ])
2419
2440
  end
2420
2441
 
2421
2442
  it "removes the document from the relation" do
2422
- person.addresses.should be_empty
2443
+ expect(person.addresses).to be_empty
2423
2444
  end
2424
2445
 
2425
2446
  it "persists the pop" do
2426
- person.reload.addresses.should be_empty
2447
+ expect(person.reload.addresses).to be_empty
2427
2448
  end
2428
2449
  end
2429
2450
 
@@ -2434,15 +2455,15 @@ describe Mongoid::Relations::Embedded::Many do
2434
2455
  end
2435
2456
 
2436
2457
  it "returns the popped documents" do
2437
- popped.should eq([ address_one, address_two ])
2458
+ expect(popped).to eq([ address_one, address_two ])
2438
2459
  end
2439
2460
 
2440
2461
  it "removes the document from the relation" do
2441
- person.addresses.should be_empty
2462
+ expect(person.addresses).to be_empty
2442
2463
  end
2443
2464
 
2444
2465
  it "persists the pop" do
2445
- person.reload.addresses.should be_empty
2466
+ expect(person.reload.addresses).to be_empty
2446
2467
  end
2447
2468
  end
2448
2469
  end
@@ -2452,14 +2473,14 @@ describe Mongoid::Relations::Embedded::Many do
2452
2473
  context "when providing no number" do
2453
2474
 
2454
2475
  it "returns nil" do
2455
- person.addresses.pop.should be_nil
2476
+ expect(person.addresses.pop).to be_nil
2456
2477
  end
2457
2478
  end
2458
2479
 
2459
2480
  context "when providing a number" do
2460
2481
 
2461
2482
  it "returns nil" do
2462
- person.addresses.pop(2).should be_nil
2483
+ expect(person.addresses.pop(2)).to be_nil
2463
2484
  end
2464
2485
  end
2465
2486
  end
@@ -2476,11 +2497,11 @@ describe Mongoid::Relations::Embedded::Many do
2476
2497
  end
2477
2498
 
2478
2499
  it "returns the relation criteria" do
2479
- scoped.should be_a(Mongoid::Criteria)
2500
+ expect(scoped).to be_a(Mongoid::Criteria)
2480
2501
  end
2481
2502
 
2482
2503
  it "returns with an empty selector" do
2483
- scoped.selector.should be_empty
2504
+ expect(scoped.selector).to be_empty
2484
2505
  end
2485
2506
  end
2486
2507
 
@@ -2499,7 +2520,7 @@ describe Mongoid::Relations::Embedded::Many do
2499
2520
  context "when checking #{method}" do
2500
2521
 
2501
2522
  it "returns true" do
2502
- addresses.respond_to?(method).should be_true
2523
+ expect(addresses.respond_to?(method)).to be true
2503
2524
  end
2504
2525
  end
2505
2526
  end
@@ -2509,7 +2530,7 @@ describe Mongoid::Relations::Embedded::Many do
2509
2530
  context "when checking #{method}" do
2510
2531
 
2511
2532
  it "returns true" do
2512
- addresses.respond_to?(method).should be_true
2533
+ expect(addresses.respond_to?(method)).to be true
2513
2534
  end
2514
2535
  end
2515
2536
  end
@@ -2519,7 +2540,7 @@ describe Mongoid::Relations::Embedded::Many do
2519
2540
  context "when checking #{method}" do
2520
2541
 
2521
2542
  it "returns true" do
2522
- addresses.respond_to?(method).should be_true
2543
+ expect(addresses.respond_to?(method)).to be true
2523
2544
  end
2524
2545
  end
2525
2546
  end
@@ -2543,7 +2564,7 @@ describe Mongoid::Relations::Embedded::Many do
2543
2564
  end
2544
2565
 
2545
2566
  it "returns the number of persisted documents" do
2546
- person.addresses.send(method).should eq(2)
2567
+ expect(person.addresses.send(method)).to eq(2)
2547
2568
  end
2548
2569
  end
2549
2570
  end
@@ -2559,15 +2580,15 @@ describe Mongoid::Relations::Embedded::Many do
2559
2580
  end
2560
2581
 
2561
2582
  it "returns the relation criteria" do
2562
- unscoped.should be_a(Mongoid::Criteria)
2583
+ expect(unscoped).to be_a(Mongoid::Criteria)
2563
2584
  end
2564
2585
 
2565
2586
  it "returns with empty options" do
2566
- unscoped.options.should be_empty
2587
+ expect(unscoped.options).to be_empty
2567
2588
  end
2568
2589
 
2569
2590
  it "returns with an empty selector" do
2570
- unscoped.selector.should be_empty
2591
+ expect(unscoped.selector).to be_empty
2571
2592
  end
2572
2593
  end
2573
2594
 
@@ -2580,7 +2601,7 @@ describe Mongoid::Relations::Embedded::Many do
2580
2601
  end
2581
2602
 
2582
2603
  it "updates nothing" do
2583
- person.addresses.update_all(street: "test").should be_false
2604
+ expect(person.addresses.update_all(street: "test")).to be false
2584
2605
  end
2585
2606
  end
2586
2607
 
@@ -2603,19 +2624,19 @@ describe Mongoid::Relations::Embedded::Many do
2603
2624
  end
2604
2625
 
2605
2626
  it "resets the matching dirty flags" do
2606
- address.should_not be_changed
2627
+ expect(address).to_not be_changed
2607
2628
  end
2608
2629
 
2609
2630
  it "updates the first field" do
2610
- address.reload.number.should eq(26)
2631
+ expect(address.reload.number).to eq(26)
2611
2632
  end
2612
2633
 
2613
2634
  it "updates the second field" do
2614
- address.reload.post_code.should eq("12437")
2635
+ expect(address.reload.post_code).to eq("12437")
2615
2636
  end
2616
2637
 
2617
2638
  it "does not wipe out other fields" do
2618
- address.reload.street.should eq("Hobrecht")
2639
+ expect(address.reload.street).to eq("Hobrecht")
2619
2640
  end
2620
2641
  end
2621
2642
  end
@@ -2624,9 +2645,9 @@ describe Mongoid::Relations::Embedded::Many do
2624
2645
  describe ".valid_options" do
2625
2646
 
2626
2647
  it "returns the valid options" do
2627
- described_class.valid_options.should eq(
2648
+ expect(described_class.valid_options).to eq(
2628
2649
  [
2629
- :as, :cascade_callbacks, :cyclic, :order, :versioned,
2650
+ :as, :cascade_callbacks, :cyclic, :order,
2630
2651
  :store_as, :before_add, :after_add, :before_remove, :after_remove
2631
2652
  ]
2632
2653
  )
@@ -2636,7 +2657,7 @@ describe Mongoid::Relations::Embedded::Many do
2636
2657
  describe ".validation_default" do
2637
2658
 
2638
2659
  it "returns true" do
2639
- described_class.validation_default.should be_true
2660
+ expect(described_class.validation_default).to be true
2640
2661
  end
2641
2662
  end
2642
2663
 
@@ -2663,15 +2684,15 @@ describe Mongoid::Relations::Embedded::Many do
2663
2684
  end
2664
2685
 
2665
2686
  it "updates the attributes" do
2666
- address.locations.first.name.should eq("home")
2687
+ expect(address.locations.first.name).to eq("home")
2667
2688
  end
2668
2689
 
2669
2690
  it "overwrites the existing documents" do
2670
- address.locations.count.should eq(1)
2691
+ expect(address.locations.count).to eq(1)
2671
2692
  end
2672
2693
 
2673
2694
  it "persists the changes" do
2674
- address.reload.locations.count.should eq(1)
2695
+ expect(address.reload.locations.count).to eq(1)
2675
2696
  end
2676
2697
  end
2677
2698
  end
@@ -2701,15 +2722,15 @@ describe Mongoid::Relations::Embedded::Many do
2701
2722
  end
2702
2723
 
2703
2724
  it "sets up the hierarchy" do
2704
- animal.circus.should eq(circus)
2725
+ expect(animal.circus).to eq(circus)
2705
2726
  end
2706
2727
 
2707
2728
  it "assigns the attributes" do
2708
- animal.name.should eq(animal_name)
2729
+ expect(animal.name).to eq(animal_name)
2709
2730
  end
2710
2731
 
2711
2732
  it "uses custom writer methods" do
2712
- animal.tag_list.should eq(tag_list)
2733
+ expect(animal.tag_list).to eq(tag_list)
2713
2734
  end
2714
2735
  end
2715
2736
 
@@ -2720,15 +2741,15 @@ describe Mongoid::Relations::Embedded::Many do
2720
2741
  end
2721
2742
 
2722
2743
  it "sets up the hierarchy" do
2723
- animal.circus.should eq(circus)
2744
+ expect(animal.circus).to eq(circus)
2724
2745
  end
2725
2746
 
2726
2747
  it "assigns the attributes" do
2727
- animal.name.should eq(animal_name)
2748
+ expect(animal.name).to eq(animal_name)
2728
2749
  end
2729
2750
 
2730
2751
  it "uses custom writer methods" do
2731
- animal.tag_list.should eq(tag_list)
2752
+ expect(animal.tag_list).to eq(tag_list)
2732
2753
  end
2733
2754
  end
2734
2755
  end
@@ -2757,7 +2778,7 @@ describe Mongoid::Relations::Embedded::Many do
2757
2778
  end
2758
2779
 
2759
2780
  it "sets up the hierarchy" do
2760
- question.should eq(page_question)
2781
+ expect(question).to eq(page_question)
2761
2782
  end
2762
2783
  end
2763
2784
 
@@ -2780,7 +2801,7 @@ describe Mongoid::Relations::Embedded::Many do
2780
2801
  end
2781
2802
 
2782
2803
  it "sets up the hierarchy" do
2783
- question.should eq(page_question)
2804
+ expect(question).to eq(page_question)
2784
2805
  end
2785
2806
  end
2786
2807
 
@@ -2808,7 +2829,7 @@ describe Mongoid::Relations::Embedded::Many do
2808
2829
  end
2809
2830
 
2810
2831
  it "sets up the hierarchy" do
2811
- question.should eq(page_question)
2832
+ expect(question).to eq(page_question)
2812
2833
  end
2813
2834
 
2814
2835
  context "when reloading" do
@@ -2822,7 +2843,7 @@ describe Mongoid::Relations::Embedded::Many do
2822
2843
  end
2823
2844
 
2824
2845
  it "reloads the entire tree" do
2825
- reloaded_question.should eq(question)
2846
+ expect(reloaded_question).to eq(question)
2826
2847
  end
2827
2848
  end
2828
2849
  end
@@ -2856,11 +2877,11 @@ describe Mongoid::Relations::Embedded::Many do
2856
2877
  end
2857
2878
 
2858
2879
  it "persists the first level document" do
2859
- person.reload.addresses.first.should eq(address)
2880
+ expect(person.reload.addresses.first).to eq(address)
2860
2881
  end
2861
2882
 
2862
2883
  it "persists the second level document" do
2863
- person.reload.addresses[0].locations.should eq([ location ])
2884
+ expect(person.reload.addresses[0].locations).to eq([ location ])
2864
2885
  end
2865
2886
  end
2866
2887
  end
@@ -2895,7 +2916,7 @@ describe Mongoid::Relations::Embedded::Many do
2895
2916
 
2896
2917
  it "ignores the nil and persist the remaining items" do
2897
2918
  reloaded = Person.find(person.id)
2898
- reloaded.phone_numbers.should eq([ home_phone, office_phone ])
2919
+ expect(reloaded.phone_numbers).to eq([ home_phone, office_phone ])
2899
2920
  end
2900
2921
  end
2901
2922
 
@@ -2916,7 +2937,7 @@ describe Mongoid::Relations::Embedded::Many do
2916
2937
 
2917
2938
  it "ignores the nil and persist the remaining items" do
2918
2939
  reloaded = Person.find(person.id)
2919
- reloaded.phone_numbers.should eq([ home_phone, office_phone ])
2940
+ expect(reloaded.phone_numbers).to eq([ home_phone, office_phone ])
2920
2941
  end
2921
2942
  end
2922
2943
 
@@ -2937,7 +2958,7 @@ describe Mongoid::Relations::Embedded::Many do
2937
2958
 
2938
2959
  it "ignores the nil and persist the remaining items" do
2939
2960
  reloaded = Person.find(person.id)
2940
- reloaded.phone_numbers.should eq([ home_phone, office_phone ])
2961
+ expect(reloaded.phone_numbers).to eq([ home_phone, office_phone ])
2941
2962
  end
2942
2963
  end
2943
2964
  end
@@ -2959,7 +2980,7 @@ describe Mongoid::Relations::Embedded::Many do
2959
2980
 
2960
2981
  it "ignores the nil and persist the remaining items" do
2961
2982
  reloaded = Person.find(person.id)
2962
- reloaded.phone_numbers.should eq(person.phone_numbers)
2983
+ expect(reloaded.phone_numbers).to eq(person.phone_numbers)
2963
2984
  end
2964
2985
  end
2965
2986
 
@@ -2978,7 +2999,7 @@ describe Mongoid::Relations::Embedded::Many do
2978
2999
 
2979
3000
  it "ignores the nil and persist the remaining items" do
2980
3001
  reloaded = Person.find(person.id)
2981
- reloaded.phone_numbers.should eq(person.phone_numbers)
3002
+ expect(reloaded.phone_numbers).to eq(person.phone_numbers)
2982
3003
  end
2983
3004
  end
2984
3005
 
@@ -2997,7 +3018,7 @@ describe Mongoid::Relations::Embedded::Many do
2997
3018
 
2998
3019
  it "ignores the nil and persist the remaining items" do
2999
3020
  reloaded = Person.find(person.id)
3000
- reloaded.phone_numbers.should eq(person.phone_numbers)
3021
+ expect(reloaded.phone_numbers).to eq(person.phone_numbers)
3001
3022
  end
3002
3023
  end
3003
3024
  end
@@ -3018,7 +3039,7 @@ describe Mongoid::Relations::Embedded::Many do
3018
3039
  end
3019
3040
 
3020
3041
  it "retains the reference to the parent" do
3021
- league.name.should eq("Destroyed")
3042
+ expect(league.name).to eq("Destroyed")
3022
3043
  end
3023
3044
  end
3024
3045
 
@@ -3037,11 +3058,11 @@ describe Mongoid::Relations::Embedded::Many do
3037
3058
  end
3038
3059
 
3039
3060
  it "does not duplicate the embedded documents" do
3040
- person.addresses.should eq([ address ])
3061
+ expect(person.addresses).to eq([ address ])
3041
3062
  end
3042
3063
 
3043
3064
  it "does not persist duplicate embedded documents" do
3044
- person.reload.addresses.should eq([ address ])
3065
+ expect(person.reload.addresses).to eq([ address ])
3045
3066
  end
3046
3067
  end
3047
3068
 
@@ -3058,7 +3079,7 @@ describe Mongoid::Relations::Embedded::Many do
3058
3079
  end
3059
3080
 
3060
3081
  it "allows the operation" do
3061
- version.number.should eq(1)
3082
+ expect(version.number).to eq(1)
3062
3083
  end
3063
3084
 
3064
3085
  context "when reloading the parent" do
@@ -3068,7 +3089,7 @@ describe Mongoid::Relations::Embedded::Many do
3068
3089
  end
3069
3090
 
3070
3091
  it "saves the child versions" do
3071
- from_db.versions.should eq([ version ])
3092
+ expect(from_db.versions).to eq([ version ])
3072
3093
  end
3073
3094
  end
3074
3095
  end
@@ -3095,7 +3116,7 @@ describe Mongoid::Relations::Embedded::Many do
3095
3116
  end
3096
3117
 
3097
3118
  it "does not lose the parent reference" do
3098
- from_db.memberships.first.account.should eq(account)
3119
+ expect(from_db.memberships.first.account).to eq(account)
3099
3120
  end
3100
3121
  end
3101
3122
 
@@ -3106,7 +3127,7 @@ describe Mongoid::Relations::Embedded::Many do
3106
3127
  end
3107
3128
 
3108
3129
  it "does not lose the parent reference" do
3109
- from_db.memberships.first.account.should eq(account)
3130
+ expect(from_db.memberships.first.account).to eq(account)
3110
3131
  end
3111
3132
  end
3112
3133
  end
@@ -3130,11 +3151,11 @@ describe Mongoid::Relations::Embedded::Many do
3130
3151
  end
3131
3152
 
3132
3153
  it "adds the document to the new paarent" do
3133
- person_two.addresses.should eq([ address ])
3154
+ expect(person_two.addresses).to eq([ address ])
3134
3155
  end
3135
3156
 
3136
3157
  it "sets the new parent on the document" do
3137
- address._parent.should eq(person_two)
3158
+ expect(address._parent).to eq(person_two)
3138
3159
  end
3139
3160
 
3140
3161
  context "when reloading the documents" do
@@ -3145,11 +3166,11 @@ describe Mongoid::Relations::Embedded::Many do
3145
3166
  end
3146
3167
 
3147
3168
  it "persists the change to the new parent" do
3148
- person_two.addresses.should eq([ address ])
3169
+ expect(person_two.addresses).to eq([ address ])
3149
3170
  end
3150
3171
 
3151
3172
  it "keeps the address on the previous document" do
3152
- person_one.addresses.should eq([ address ])
3173
+ expect(person_one.addresses).to eq([ address ])
3153
3174
  end
3154
3175
  end
3155
3176
  end
@@ -3185,7 +3206,7 @@ describe Mongoid::Relations::Embedded::Many do
3185
3206
  end
3186
3207
 
3187
3208
  it "applies the default scope" do
3188
- symptoms.should eq([ cough, headache, nausea ])
3209
+ expect(symptoms).to eq([ cough, headache, nausea ])
3189
3210
  end
3190
3211
  end
3191
3212
 
@@ -3206,7 +3227,7 @@ describe Mongoid::Relations::Embedded::Many do
3206
3227
  end
3207
3228
 
3208
3229
  it "applies the default scope" do
3209
- symptoms.should eq([ constipation, cough, headache, nausea ])
3230
+ expect(symptoms).to eq([ constipation, cough, headache, nausea ])
3210
3231
  end
3211
3232
  end
3212
3233
  end
@@ -3218,7 +3239,7 @@ describe Mongoid::Relations::Embedded::Many do
3218
3239
  end
3219
3240
 
3220
3241
  it "removes the default scope" do
3221
- unscoped.should eq([ nausea, cough, headache ])
3242
+ expect(unscoped).to eq([ nausea, cough, headache ])
3222
3243
  end
3223
3244
  end
3224
3245
  end
@@ -3249,11 +3270,11 @@ describe Mongoid::Relations::Embedded::Many do
3249
3270
  end
3250
3271
 
3251
3272
  it "retains the unscoped index for the excluded document" do
3252
- relation.send(:_unscoped).first._index.should eq(0)
3273
+ expect(relation.send(:_unscoped).first._index).to eq(0)
3253
3274
  end
3254
3275
 
3255
3276
  it "retains the unscoped index for the included document" do
3256
- relation.first._index.should eq(1)
3277
+ expect(relation.first._index).to eq(1)
3257
3278
  end
3258
3279
 
3259
3280
  context "when a reindexing operation occurs" do
@@ -3263,11 +3284,11 @@ describe Mongoid::Relations::Embedded::Many do
3263
3284
  end
3264
3285
 
3265
3286
  it "retains the unscoped index for the excluded document" do
3266
- relation.send(:_unscoped).first._index.should eq(0)
3287
+ expect(relation.send(:_unscoped).first._index).to eq(0)
3267
3288
  end
3268
3289
 
3269
3290
  it "retains the unscoped index for the included document" do
3270
- relation.first._index.should eq(1)
3291
+ expect(relation.first._index).to eq(1)
3271
3292
  end
3272
3293
  end
3273
3294
  end
@@ -3291,11 +3312,11 @@ describe Mongoid::Relations::Embedded::Many do
3291
3312
  end
3292
3313
 
3293
3314
  it "sets the value" do
3294
- video.genres.should eq([ "horror", "scifi" ])
3315
+ expect(video.genres).to eq([ "horror", "scifi" ])
3295
3316
  end
3296
3317
 
3297
3318
  it "persists the value" do
3298
- video.reload.genres.should eq([ "horror", "scifi" ])
3319
+ expect(video.reload.genres).to eq([ "horror", "scifi" ])
3299
3320
  end
3300
3321
 
3301
3322
  context "when reloading the parent" do
@@ -3316,11 +3337,11 @@ describe Mongoid::Relations::Embedded::Many do
3316
3337
  end
3317
3338
 
3318
3339
  it "sets the new value" do
3319
- loaded_video.genres.should eq([ "comedy" ])
3340
+ expect(loaded_video.genres).to eq([ "comedy" ])
3320
3341
  end
3321
3342
 
3322
3343
  it "persists the new value" do
3323
- loaded_video.reload.genres.should eq([ "comedy" ])
3344
+ expect(loaded_video.reload.genres).to eq([ "comedy" ])
3324
3345
  end
3325
3346
  end
3326
3347
  end
@@ -3346,15 +3367,15 @@ describe Mongoid::Relations::Embedded::Many do
3346
3367
  end
3347
3368
 
3348
3369
  it "destroys the document" do
3349
- address_one.should be_destroyed
3370
+ expect(address_one).to be_destroyed
3350
3371
  end
3351
3372
 
3352
3373
  it "reindexes the relation" do
3353
- address_two._index.should eq(0)
3374
+ expect(address_two._index).to eq(0)
3354
3375
  end
3355
3376
 
3356
3377
  it "removes the document from the unscoped" do
3357
- person.addresses.send(:_unscoped).should_not include(address_one)
3378
+ expect(person.addresses.send(:_unscoped)).to_not include(address_one)
3358
3379
  end
3359
3380
 
3360
3381
  context "when subsequently updating the next document" do
@@ -3368,11 +3389,11 @@ describe Mongoid::Relations::Embedded::Many do
3368
3389
  end
3369
3390
 
3370
3391
  it "updates the correct document" do
3371
- addresses.first.number.should eq(10)
3392
+ expect(addresses.first.number).to eq(10)
3372
3393
  end
3373
3394
 
3374
3395
  it "does not add additional documents" do
3375
- addresses.count.should eq(1)
3396
+ expect(addresses.count).to eq(1)
3376
3397
  end
3377
3398
  end
3378
3399
  end
@@ -3402,7 +3423,7 @@ describe Mongoid::Relations::Embedded::Many do
3402
3423
  end
3403
3424
 
3404
3425
  it "adds both documents" do
3405
- result.should eq([ address_one, address_two ])
3426
+ expect(result).to eq([ address_one, address_two ])
3406
3427
  end
3407
3428
  end
3408
3429
  end
@@ -3426,7 +3447,7 @@ describe Mongoid::Relations::Embedded::Many do
3426
3447
  end
3427
3448
 
3428
3449
  it "allows the dot notation criteria" do
3429
- criteria.should eq([ address ])
3450
+ expect(criteria).to eq([ address ])
3430
3451
  end
3431
3452
  end
3432
3453
 
@@ -3459,7 +3480,7 @@ describe Mongoid::Relations::Embedded::Many do
3459
3480
  end
3460
3481
 
3461
3482
  it "updates the nested document" do
3462
- updated.name.should eq("work")
3483
+ expect(updated.name).to eq("work")
3463
3484
  end
3464
3485
  end
3465
3486
  end
@@ -3479,7 +3500,7 @@ describe Mongoid::Relations::Embedded::Many do
3479
3500
  end
3480
3501
 
3481
3502
  it "orders properly with the boolean" do
3482
- circuit.reload.buses.should eq([ bus_two, bus_one ])
3503
+ expect(circuit.reload.buses).to eq([ bus_two, bus_one ])
3483
3504
  end
3484
3505
  end
3485
3506
 
@@ -3517,11 +3538,11 @@ describe Mongoid::Relations::Embedded::Many do
3517
3538
  end
3518
3539
 
3519
3540
  it "does not duplicate the first relation" do
3520
- person.reload.symptoms.count.should eq(2)
3541
+ expect(person.reload.symptoms.count).to eq(2)
3521
3542
  end
3522
3543
 
3523
3544
  it "does not duplicate the second relation" do
3524
- person.reload.appointments.count.should eq(2)
3545
+ expect(person.reload.appointments.count).to eq(2)
3525
3546
  end
3526
3547
  end
3527
3548
 
@@ -3542,29 +3563,29 @@ describe Mongoid::Relations::Embedded::Many do
3542
3563
  end
3543
3564
 
3544
3565
  it "executes the callback" do
3545
- artist.before_add_called.should be_true
3566
+ expect(artist.before_add_called).to be true
3546
3567
  end
3547
3568
 
3548
3569
  it "executes the callback as proc" do
3549
- song.before_add_called.should be_true
3570
+ expect(song.before_add_called).to be true
3550
3571
  end
3551
3572
 
3552
3573
  it "adds the document to the relation" do
3553
- artist.songs.should eq([song])
3574
+ expect(artist.songs).to eq([song])
3554
3575
  end
3555
3576
  end
3556
3577
 
3557
3578
  context "with errors" do
3558
3579
 
3559
3580
  before do
3560
- artist.should_receive(:before_add_song).and_raise
3581
+ expect(artist).to receive(:before_add_song).and_raise
3561
3582
  end
3562
3583
 
3563
3584
  it "does not add the document to the relation" do
3564
3585
  expect {
3565
3586
  artist.songs << song
3566
3587
  }.to raise_error
3567
- artist.songs.should be_empty
3588
+ expect(artist.songs).to be_empty
3568
3589
  end
3569
3590
  end
3570
3591
  end
@@ -3581,20 +3602,20 @@ describe Mongoid::Relations::Embedded::Many do
3581
3602
 
3582
3603
  it "executes the callback" do
3583
3604
  artist.labels << label
3584
- artist.after_add_called.should be_true
3605
+ expect(artist.after_add_called).to be true
3585
3606
  end
3586
3607
 
3587
3608
  context "when errors are raised" do
3588
3609
 
3589
3610
  before do
3590
- artist.should_receive(:after_add_label).and_raise
3611
+ expect(artist).to receive(:after_add_label).and_raise
3591
3612
  end
3592
3613
 
3593
3614
  it "adds the document to the relation" do
3594
3615
  expect {
3595
3616
  artist.labels << label
3596
3617
  }.to raise_error
3597
- artist.labels.should eq([ label ])
3618
+ expect(artist.labels).to eq([ label ])
3598
3619
  end
3599
3620
  end
3600
3621
  end
@@ -3622,11 +3643,11 @@ describe Mongoid::Relations::Embedded::Many do
3622
3643
  end
3623
3644
 
3624
3645
  it "executes the callback" do
3625
- artist.before_remove_embedded_called.should be_true
3646
+ expect(artist.before_remove_embedded_called).to be true
3626
3647
  end
3627
3648
 
3628
3649
  it "removes the document from the relation" do
3629
- artist.songs.should be_empty
3650
+ expect(artist.songs).to be_empty
3630
3651
  end
3631
3652
  end
3632
3653
 
@@ -3637,18 +3658,18 @@ describe Mongoid::Relations::Embedded::Many do
3637
3658
  end
3638
3659
 
3639
3660
  it "executes the callback" do
3640
- artist.before_remove_embedded_called.should be_true
3661
+ expect(artist.before_remove_embedded_called).to be true
3641
3662
  end
3642
3663
 
3643
3664
  it "shoud clear the relation" do
3644
- artist.songs.should be_empty
3665
+ expect(artist.songs).to be_empty
3645
3666
  end
3646
3667
  end
3647
3668
 
3648
3669
  context "when errors are raised" do
3649
3670
 
3650
3671
  before do
3651
- artist.should_receive(:before_remove_song).and_raise
3672
+ expect(artist).to receive(:before_remove_song).and_raise
3652
3673
  end
3653
3674
 
3654
3675
  describe "#delete" do
@@ -3657,7 +3678,7 @@ describe Mongoid::Relations::Embedded::Many do
3657
3678
  expect {
3658
3679
  artist.songs.delete(song)
3659
3680
  }.to raise_error
3660
- artist.songs.should eq([ song ])
3681
+ expect(artist.songs).to eq([ song ])
3661
3682
  end
3662
3683
  end
3663
3684
 
@@ -3667,7 +3688,7 @@ describe Mongoid::Relations::Embedded::Many do
3667
3688
  expect {
3668
3689
  artist.songs.clear
3669
3690
  }.to raise_error
3670
- artist.songs.should eq([ song ])
3691
+ expect(artist.songs).to eq([ song ])
3671
3692
  end
3672
3693
  end
3673
3694
  end
@@ -3696,7 +3717,7 @@ describe Mongoid::Relations::Embedded::Many do
3696
3717
  end
3697
3718
 
3698
3719
  it "executes the callback" do
3699
- artist.after_remove_embedded_called.should be_true
3720
+ expect(artist.after_remove_embedded_called).to be true
3700
3721
  end
3701
3722
  end
3702
3723
 
@@ -3708,7 +3729,7 @@ describe Mongoid::Relations::Embedded::Many do
3708
3729
 
3709
3730
  it "executes the callback" do
3710
3731
  artist.labels.clear
3711
- artist.after_remove_embedded_called.should be_true
3732
+ expect(artist.after_remove_embedded_called).to be true
3712
3733
  end
3713
3734
  end
3714
3735
  end
@@ -3716,7 +3737,7 @@ describe Mongoid::Relations::Embedded::Many do
3716
3737
  context "when errors are raised" do
3717
3738
 
3718
3739
  before do
3719
- artist.should_receive(:after_remove_label).and_raise
3740
+ expect(artist).to receive(:after_remove_label).and_raise
3720
3741
  end
3721
3742
 
3722
3743
  describe "#delete" do
@@ -3728,7 +3749,7 @@ describe Mongoid::Relations::Embedded::Many do
3728
3749
  end
3729
3750
 
3730
3751
  it "removes the document from the relation" do
3731
- artist.labels.should be_empty
3752
+ expect(artist.labels).to be_empty
3732
3753
  end
3733
3754
  end
3734
3755
 
@@ -3741,7 +3762,7 @@ describe Mongoid::Relations::Embedded::Many do
3741
3762
  end
3742
3763
 
3743
3764
  it "should remove from collection" do
3744
- artist.labels.should be_empty
3765
+ expect(artist.labels).to be_empty
3745
3766
  end
3746
3767
  end
3747
3768
  end
@@ -3764,7 +3785,7 @@ describe Mongoid::Relations::Embedded::Many do
3764
3785
  end
3765
3786
 
3766
3787
  it "does not push the embedded documents twice" do
3767
- server.reload.filesystems.count.should eq(1)
3788
+ expect(server.reload.filesystems.count).to eq(1)
3768
3789
  end
3769
3790
  end
3770
3791
  end
@@ -3792,11 +3813,11 @@ describe Mongoid::Relations::Embedded::Many do
3792
3813
  end
3793
3814
 
3794
3815
  it "creates proper documents from the db" do
3795
- record.name.should eq("Moderat")
3816
+ expect(record.name).to eq("Moderat")
3796
3817
  end
3797
3818
 
3798
3819
  it "assigns ids to the documents" do
3799
- record.id.should_not be_nil
3820
+ expect(record.id).to_not be_nil
3800
3821
  end
3801
3822
 
3802
3823
  context "when subsequently updating the documents" do
@@ -3806,11 +3827,11 @@ describe Mongoid::Relations::Embedded::Many do
3806
3827
  end
3807
3828
 
3808
3829
  it "updates the document" do
3809
- record.name.should eq("Apparat")
3830
+ expect(record.name).to eq("Apparat")
3810
3831
  end
3811
3832
 
3812
3833
  it "persists the change" do
3813
- record.reload.name.should eq("Apparat")
3834
+ expect(record.reload.name).to eq("Apparat")
3814
3835
  end
3815
3836
  end
3816
3837
  end
@@ -3835,7 +3856,7 @@ describe Mongoid::Relations::Embedded::Many do
3835
3856
  end
3836
3857
 
3837
3858
  it "keeps the proxy extensions when remarshalling" do
3838
- loaded.extension.should eq("Testing")
3859
+ expect(loaded.extension).to eq("Testing")
3839
3860
  end
3840
3861
  end
3841
3862
  end