mongoid 3.1.6 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (571) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +479 -8
  3. data/README.md +10 -7
  4. data/lib/config/locales/en.yml +34 -20
  5. data/lib/mongoid.rb +10 -76
  6. data/lib/mongoid/atomic.rb +3 -14
  7. data/lib/mongoid/atomic/paths/embedded.rb +0 -30
  8. data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
  9. data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
  10. data/lib/mongoid/atomic/paths/root.rb +0 -13
  11. data/lib/mongoid/attributes.rb +65 -101
  12. data/lib/mongoid/attributes/dynamic.rb +154 -0
  13. data/lib/mongoid/attributes/nested.rb +82 -0
  14. data/lib/mongoid/attributes/processing.rb +13 -66
  15. data/lib/mongoid/{dirty.rb → changeable.rb} +32 -2
  16. data/lib/mongoid/composable.rb +105 -0
  17. data/lib/mongoid/config.rb +3 -9
  18. data/lib/mongoid/config/options.rb +1 -1
  19. data/lib/mongoid/contextual.rb +2 -0
  20. data/lib/mongoid/contextual/aggregable/memory.rb +2 -2
  21. data/lib/mongoid/contextual/aggregable/mongo.rb +7 -9
  22. data/lib/mongoid/contextual/atomic.rb +53 -53
  23. data/lib/mongoid/contextual/geo_near.rb +1 -1
  24. data/lib/mongoid/contextual/map_reduce.rb +4 -2
  25. data/lib/mongoid/contextual/memory.rb +23 -11
  26. data/lib/mongoid/contextual/mongo.rb +75 -57
  27. data/lib/mongoid/contextual/none.rb +90 -0
  28. data/lib/mongoid/contextual/text_search.rb +178 -0
  29. data/lib/mongoid/copyable.rb +2 -3
  30. data/lib/mongoid/criteria.rb +39 -34
  31. data/lib/mongoid/criteria/#findable.rb# +141 -0
  32. data/lib/mongoid/{criterion → criteria}/findable.rb +7 -47
  33. data/lib/mongoid/{criterion/inspection.rb → criteria/inspectable.rb} +2 -2
  34. data/lib/mongoid/{criterion → criteria}/marshalable.rb +3 -1
  35. data/lib/mongoid/{criterion → criteria}/modifiable.rb +28 -8
  36. data/lib/mongoid/criteria/permission.rb +70 -0
  37. data/lib/mongoid/{criterion/scoping.rb → criteria/scopable.rb} +2 -2
  38. data/lib/mongoid/document.rb +39 -24
  39. data/lib/mongoid/errors.rb +4 -1
  40. data/lib/mongoid/errors/document_not_destroyed.rb +25 -0
  41. data/lib/mongoid/errors/document_not_found.rb +2 -1
  42. data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
  43. data/lib/mongoid/errors/invalid_storage_parent.rb +26 -0
  44. data/lib/mongoid/errors/invalid_value.rb +16 -0
  45. data/lib/mongoid/errors/mongoid_error.rb +1 -1
  46. data/lib/mongoid/errors/readonly_document.rb +24 -0
  47. data/lib/mongoid/extensions.rb +15 -7
  48. data/lib/mongoid/extensions/array.rb +3 -3
  49. data/lib/mongoid/extensions/big_decimal.rb +1 -1
  50. data/lib/mongoid/extensions/boolean.rb +15 -17
  51. data/lib/mongoid/extensions/date.rb +1 -1
  52. data/lib/mongoid/extensions/date_time.rb +3 -3
  53. data/lib/mongoid/extensions/float.rb +2 -1
  54. data/lib/mongoid/extensions/hash.rb +3 -3
  55. data/lib/mongoid/extensions/integer.rb +1 -1
  56. data/lib/mongoid/extensions/object.rb +7 -7
  57. data/lib/mongoid/extensions/object_id.rb +5 -5
  58. data/lib/mongoid/extensions/range.rb +9 -3
  59. data/lib/mongoid/extensions/regexp.rb +1 -1
  60. data/lib/mongoid/extensions/set.rb +1 -1
  61. data/lib/mongoid/extensions/string.rb +6 -18
  62. data/lib/mongoid/extensions/symbol.rb +1 -1
  63. data/lib/mongoid/extensions/time.rb +3 -3
  64. data/lib/mongoid/extensions/time_with_zone.rb +1 -1
  65. data/lib/mongoid/factory.rb +8 -6
  66. data/lib/mongoid/fields.rb +41 -8
  67. data/lib/mongoid/fields/foreign_key.rb +3 -3
  68. data/lib/mongoid/fields/localized.rb +1 -1
  69. data/lib/mongoid/fields/standard.rb +5 -17
  70. data/lib/mongoid/fields/validators/macro.rb +15 -5
  71. data/lib/mongoid/{finders.rb → findable.rb} +35 -7
  72. data/lib/mongoid/{indexes.rb → indexable.rb} +50 -55
  73. data/lib/mongoid/indexable/specification.rb +104 -0
  74. data/lib/mongoid/{indexes → indexable}/validators/options.rb +2 -1
  75. data/lib/mongoid/{inspection.rb → inspectable.rb} +15 -11
  76. data/lib/mongoid/{callbacks.rb → interceptable.rb} +30 -62
  77. data/lib/mongoid/log_subscriber.rb +55 -0
  78. data/lib/mongoid/matchable.rb +152 -0
  79. data/lib/mongoid/{matchers → matchable}/all.rb +1 -1
  80. data/lib/mongoid/{matchers → matchable}/and.rb +2 -2
  81. data/lib/mongoid/{matchers → matchable}/default.rb +1 -1
  82. data/lib/mongoid/{matchers → matchable}/exists.rb +1 -1
  83. data/lib/mongoid/{matchers → matchable}/gt.rb +1 -1
  84. data/lib/mongoid/{matchers → matchable}/gte.rb +1 -1
  85. data/lib/mongoid/{matchers → matchable}/in.rb +2 -2
  86. data/lib/mongoid/{matchers → matchable}/lt.rb +1 -1
  87. data/lib/mongoid/{matchers → matchable}/lte.rb +1 -1
  88. data/lib/mongoid/{matchers → matchable}/ne.rb +2 -2
  89. data/lib/mongoid/{matchers → matchable}/nin.rb +3 -2
  90. data/lib/mongoid/{matchers → matchable}/or.rb +2 -2
  91. data/lib/mongoid/{matchers → matchable}/size.rb +1 -1
  92. data/lib/mongoid/persistable.rb +216 -0
  93. data/lib/mongoid/persistable/creatable.rb +189 -0
  94. data/lib/mongoid/persistable/deletable.rb +149 -0
  95. data/lib/mongoid/persistable/destroyable.rb +60 -0
  96. data/lib/mongoid/persistable/incrementable.rb +36 -0
  97. data/lib/mongoid/persistable/logical.rb +38 -0
  98. data/lib/mongoid/persistable/poppable.rb +39 -0
  99. data/lib/mongoid/persistable/pullable.rb +55 -0
  100. data/lib/mongoid/persistable/pushable.rb +62 -0
  101. data/lib/mongoid/persistable/renamable.rb +35 -0
  102. data/lib/mongoid/persistable/savable.rb +52 -0
  103. data/lib/mongoid/persistable/settable.rb +33 -0
  104. data/lib/mongoid/persistable/unsettable.rb +36 -0
  105. data/lib/mongoid/persistable/updatable.rb +153 -0
  106. data/lib/mongoid/persistable/upsertable.rb +55 -0
  107. data/lib/mongoid/positional.rb +71 -0
  108. data/lib/mongoid/query_cache.rb +255 -0
  109. data/lib/mongoid/railtie.rb +34 -60
  110. data/lib/mongoid/railties/database.rake +9 -25
  111. data/lib/mongoid/relations.rb +11 -25
  112. data/lib/mongoid/relations/accessors.rb +15 -51
  113. data/lib/mongoid/relations/auto_save.rb +15 -36
  114. data/lib/mongoid/relations/binding.rb +2 -25
  115. data/lib/mongoid/relations/bindings/embedded/in.rb +1 -1
  116. data/lib/mongoid/relations/bindings/embedded/many.rb +1 -3
  117. data/lib/mongoid/relations/bindings/referenced/in.rb +3 -8
  118. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -2
  119. data/lib/mongoid/relations/builder.rb +1 -1
  120. data/lib/mongoid/relations/builders.rb +2 -2
  121. data/lib/mongoid/relations/builders/embedded/one.rb +1 -1
  122. data/lib/mongoid/relations/builders/nested_attributes/many.rb +10 -13
  123. data/lib/mongoid/relations/builders/nested_attributes/one.rb +5 -6
  124. data/lib/mongoid/relations/builders/referenced/in.rb +1 -1
  125. data/lib/mongoid/relations/builders/referenced/many.rb +1 -2
  126. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +1 -2
  127. data/lib/mongoid/relations/builders/referenced/one.rb +1 -1
  128. data/lib/mongoid/relations/cascading.rb +3 -5
  129. data/lib/mongoid/relations/constraint.rb +1 -1
  130. data/lib/mongoid/relations/conversions.rb +1 -1
  131. data/lib/mongoid/relations/counter_cache.rb +39 -15
  132. data/lib/mongoid/relations/eager.rb +46 -0
  133. data/lib/mongoid/relations/eager/base.rb +149 -0
  134. data/lib/mongoid/relations/eager/belongs_to.rb +31 -0
  135. data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +47 -0
  136. data/lib/mongoid/relations/eager/has_many.rb +38 -0
  137. data/lib/mongoid/relations/eager/has_one.rb +30 -0
  138. data/lib/mongoid/relations/embedded/batchable.rb +4 -5
  139. data/lib/mongoid/relations/embedded/in.rb +4 -4
  140. data/lib/mongoid/relations/embedded/many.rb +14 -32
  141. data/lib/mongoid/relations/embedded/one.rb +1 -1
  142. data/lib/mongoid/relations/macros.rb +3 -4
  143. data/lib/mongoid/relations/many.rb +51 -31
  144. data/lib/mongoid/relations/marshalable.rb +3 -3
  145. data/lib/mongoid/relations/metadata.rb +14 -79
  146. data/lib/mongoid/relations/nested_builder.rb +2 -2
  147. data/lib/mongoid/relations/one.rb +1 -1
  148. data/lib/mongoid/relations/options.rb +1 -0
  149. data/lib/mongoid/relations/polymorphic.rb +0 -1
  150. data/lib/mongoid/relations/proxy.rb +21 -41
  151. data/lib/mongoid/relations/referenced/in.rb +4 -20
  152. data/lib/mongoid/relations/referenced/many.rb +22 -35
  153. data/lib/mongoid/relations/referenced/many_to_many.rb +19 -42
  154. data/lib/mongoid/relations/referenced/one.rb +6 -25
  155. data/lib/mongoid/relations/synchronization.rb +4 -4
  156. data/lib/mongoid/relations/targets/enumerable.rb +10 -10
  157. data/lib/mongoid/relations/touchable.rb +34 -1
  158. data/lib/mongoid/{reloading.rb → reloadable.rb} +7 -5
  159. data/lib/mongoid/{scoping.rb → scopable.rb} +36 -36
  160. data/lib/mongoid/selectable.rb +59 -0
  161. data/lib/mongoid/{serialization.rb → serializable.rb} +11 -2
  162. data/lib/mongoid/sessions.rb +37 -345
  163. data/lib/mongoid/sessions/factory.rb +2 -0
  164. data/lib/mongoid/sessions/options.rb +185 -0
  165. data/lib/mongoid/sessions/storage_options.rb +140 -0
  166. data/lib/mongoid/sessions/thread_options.rb +19 -0
  167. data/lib/mongoid/sessions/validators/storage.rb +16 -3
  168. data/lib/mongoid/{sharding.rb → shardable.rb} +5 -1
  169. data/lib/mongoid/{state.rb → stateful.rb} +13 -1
  170. data/lib/mongoid/support/query_counter.rb +23 -0
  171. data/lib/mongoid/tasks/database.rake +31 -0
  172. data/lib/mongoid/tasks/database.rb +107 -0
  173. data/lib/mongoid/threaded.rb +26 -172
  174. data/lib/mongoid/threaded/lifecycle.rb +0 -28
  175. data/lib/mongoid/timestamps/updated/short.rb +2 -2
  176. data/lib/mongoid/{hierarchy.rb → traversable.rb} +15 -7
  177. data/lib/mongoid/{validations.rb → validatable.rb} +23 -10
  178. data/lib/mongoid/{validations → validatable}/associated.rb +4 -2
  179. data/lib/mongoid/{validations → validatable}/format.rb +1 -1
  180. data/lib/mongoid/{validations → validatable}/length.rb +1 -1
  181. data/lib/mongoid/{validations → validatable}/localizable.rb +1 -1
  182. data/lib/mongoid/{validations → validatable}/macros.rb +4 -3
  183. data/lib/mongoid/{validations → validatable}/presence.rb +1 -1
  184. data/lib/mongoid/{validations → validatable}/queryable.rb +1 -2
  185. data/lib/mongoid/{validations → validatable}/uniqueness.rb +25 -21
  186. data/lib/mongoid/version.rb +1 -1
  187. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +46 -25
  188. data/lib/rails/generators/mongoid/model/model_generator.rb +0 -1
  189. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +0 -3
  190. data/lib/rails/generators/mongoid_generator.rb +3 -40
  191. data/lib/rails/mongoid.rb +0 -122
  192. data/lib/support/ruby_version.rb +1 -1
  193. data/spec/app/models/account.rb +2 -6
  194. data/spec/app/models/acolyte.rb +2 -1
  195. data/spec/app/models/actor.rb +0 -1
  196. data/spec/app/models/address.rb +8 -3
  197. data/spec/app/models/animal.rb +1 -1
  198. data/spec/app/models/appointment.rb +3 -3
  199. data/spec/app/models/article.rb +1 -4
  200. data/spec/app/models/audio.rb +5 -0
  201. data/spec/app/models/author.rb +0 -2
  202. data/spec/app/models/band.rb +3 -2
  203. data/spec/app/models/bar.rb +1 -0
  204. data/spec/app/models/book.rb +1 -0
  205. data/spec/app/models/building.rb +0 -2
  206. data/spec/app/models/building_address.rb +0 -2
  207. data/spec/app/models/bus.rb +1 -1
  208. data/spec/app/models/canvas.rb +1 -1
  209. data/spec/app/models/contextable_item.rb +5 -0
  210. data/spec/app/models/contractor.rb +0 -2
  211. data/spec/app/models/country_code.rb +1 -1
  212. data/spec/app/models/definition.rb +2 -2
  213. data/spec/app/models/dog.rb +1 -1
  214. data/spec/app/models/draft.rb +9 -0
  215. data/spec/app/models/dragon.rb +4 -0
  216. data/spec/app/models/drug.rb +1 -3
  217. data/spec/app/models/dungeon.rb +4 -0
  218. data/spec/app/models/edit.rb +5 -0
  219. data/spec/app/models/even.rb +7 -0
  220. data/spec/app/models/event.rb +1 -1
  221. data/spec/app/models/filesystem.rb +1 -0
  222. data/spec/app/models/fish.rb +0 -1
  223. data/spec/app/models/fruits.rb +6 -0
  224. data/spec/app/models/game.rb +0 -2
  225. data/spec/app/models/house.rb +1 -3
  226. data/spec/app/models/id_key.rb +6 -0
  227. data/spec/app/models/item.rb +1 -5
  228. data/spec/app/models/jar.rb +1 -1
  229. data/spec/app/models/label.rb +4 -4
  230. data/spec/app/models/line_item.rb +1 -1
  231. data/spec/app/models/login.rb +1 -1
  232. data/spec/app/models/message.rb +8 -0
  233. data/spec/app/models/movie.rb +1 -0
  234. data/spec/app/models/name.rb +3 -3
  235. data/spec/app/models/note.rb +3 -1
  236. data/spec/app/models/odd.rb +7 -0
  237. data/spec/app/models/oscar.rb +1 -1
  238. data/spec/app/models/parent_doc.rb +1 -1
  239. data/spec/app/models/person.rb +16 -10
  240. data/spec/app/models/phone.rb +1 -3
  241. data/spec/app/models/player.rb +3 -3
  242. data/spec/app/models/post.rb +5 -3
  243. data/spec/app/models/preference.rb +1 -1
  244. data/spec/app/models/quiz.rb +0 -3
  245. data/spec/app/models/record.rb +10 -5
  246. data/spec/app/models/registry.rb +1 -1
  247. data/spec/app/models/server.rb +1 -1
  248. data/spec/app/models/service.rb +3 -3
  249. data/spec/app/models/sound.rb +5 -0
  250. data/spec/app/models/symptom.rb +1 -1
  251. data/spec/app/models/template.rb +1 -1
  252. data/spec/app/models/title.rb +0 -1
  253. data/spec/app/models/track.rb +5 -5
  254. data/spec/app/models/tree.rb +3 -3
  255. data/spec/app/models/video.rb +1 -5
  256. data/spec/app/models/wiki_page.rb +2 -5
  257. data/spec/app/models/word.rb +3 -0
  258. data/spec/app/models/word_origin.rb +1 -1
  259. data/spec/config/mongoid.yml +7 -8
  260. data/spec/helpers.rb +18 -0
  261. data/spec/mongoid/#atomic_spec.rb# +365 -0
  262. data/spec/mongoid/atomic/modifiers_spec.rb +22 -22
  263. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +8 -49
  264. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +7 -49
  265. data/spec/mongoid/atomic/paths/root_spec.rb +3 -61
  266. data/spec/mongoid/atomic/paths_spec.rb +19 -19
  267. data/spec/mongoid/atomic_spec.rb +19 -19
  268. data/spec/mongoid/{nested_attributes_spec.rb → attributes/nested_spec.rb} +474 -592
  269. data/spec/mongoid/attributes/readonly_spec.rb +58 -18
  270. data/spec/mongoid/attributes_spec.rb +349 -434
  271. data/spec/mongoid/{dirty_spec.rb → changeable_spec.rb} +203 -153
  272. data/spec/mongoid/{components_spec.rb → composable_spec.rb} +3 -3
  273. data/spec/mongoid/config/environment_spec.rb +3 -3
  274. data/spec/mongoid/config/options_spec.rb +6 -6
  275. data/spec/mongoid/config_spec.rb +24 -48
  276. data/spec/mongoid/contextual/aggregable/memory_spec.rb +12 -12
  277. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +78 -38
  278. data/spec/mongoid/contextual/atomic_spec.rb +60 -56
  279. data/spec/mongoid/contextual/find_and_modify_spec.rb +14 -14
  280. data/spec/mongoid/contextual/geo_near_spec.rb +22 -22
  281. data/spec/mongoid/contextual/map_reduce_spec.rb +27 -27
  282. data/spec/mongoid/contextual/memory_spec.rb +156 -94
  283. data/spec/mongoid/contextual/mongo_spec.rb +238 -150
  284. data/spec/mongoid/contextual/none_spec.rb +127 -0
  285. data/spec/mongoid/contextual/text_search_spec.rb +209 -0
  286. data/spec/mongoid/copyable_spec.rb +56 -68
  287. data/spec/mongoid/criteria/findable_spec.rb +991 -0
  288. data/spec/mongoid/{criterion/inspection_spec.rb → criteria/inspectable_spec.rb} +5 -5
  289. data/spec/mongoid/{criterion → criteria}/marshalable_spec.rb +2 -2
  290. data/spec/mongoid/criteria/modifiable_spec.rb +1252 -0
  291. data/spec/mongoid/{criterion/scoping_spec.rb → criteria/scopable_spec.rb} +37 -37
  292. data/spec/mongoid/criteria_spec.rb +715 -2421
  293. data/spec/mongoid/document_spec.rb +171 -121
  294. data/spec/mongoid/equality_spec.rb +22 -22
  295. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +3 -3
  296. data/spec/mongoid/errors/callback_spec.rb +3 -3
  297. data/spec/mongoid/errors/delete_restriction_spec.rb +3 -3
  298. data/spec/mongoid/errors/document_not_destroyed_spec.rb +33 -0
  299. data/spec/mongoid/errors/document_not_found_spec.rb +11 -11
  300. data/spec/mongoid/errors/eager_load_spec.rb +3 -3
  301. data/spec/mongoid/errors/invalid_collection_spec.rb +3 -3
  302. data/spec/mongoid/errors/invalid_config_option_spec.rb +3 -3
  303. data/spec/mongoid/errors/invalid_field_option_spec.rb +3 -3
  304. data/spec/mongoid/errors/invalid_field_spec.rb +3 -3
  305. data/spec/mongoid/errors/invalid_find_spec.rb +3 -3
  306. data/spec/mongoid/errors/invalid_includes_spec.rb +3 -3
  307. data/spec/mongoid/errors/invalid_index_spec.rb +3 -3
  308. data/spec/mongoid/errors/invalid_options_spec.rb +3 -3
  309. data/spec/mongoid/errors/invalid_path_spec.rb +3 -3
  310. data/spec/mongoid/errors/invalid_scope_spec.rb +5 -5
  311. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -3
  312. data/spec/mongoid/errors/invalid_storage_options_spec.rb +3 -3
  313. data/spec/mongoid/errors/invalid_time_spec.rb +3 -3
  314. data/spec/mongoid/errors/inverse_not_found_spec.rb +3 -3
  315. data/spec/mongoid/errors/mixed_relations_spec.rb +3 -3
  316. data/spec/mongoid/errors/mixed_session_configuration_spec.rb +3 -3
  317. data/spec/mongoid/errors/mongoid_error_spec.rb +8 -8
  318. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +3 -3
  319. data/spec/mongoid/errors/no_environment_spec.rb +3 -3
  320. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +3 -3
  321. data/spec/mongoid/errors/no_metadata_spec.rb +3 -3
  322. data/spec/mongoid/errors/no_parent_spec.rb +3 -3
  323. data/spec/mongoid/errors/no_session_config_spec.rb +3 -3
  324. data/spec/mongoid/errors/no_session_database_spec.rb +3 -3
  325. data/spec/mongoid/errors/no_session_hosts_spec.rb +3 -3
  326. data/spec/mongoid/errors/no_sessions_config_spec.rb +3 -3
  327. data/spec/mongoid/errors/readonly_attribute_spec.rb +3 -3
  328. data/spec/mongoid/errors/readonly_document_spec.rb +29 -0
  329. data/spec/mongoid/errors/scope_overwrite_spec.rb +3 -3
  330. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +3 -3
  331. data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -5
  332. data/spec/mongoid/errors/unsaved_document_spec.rb +3 -3
  333. data/spec/mongoid/errors/unsupported_javascript_spec.rb +3 -3
  334. data/spec/mongoid/errors/validations_spec.rb +7 -7
  335. data/spec/mongoid/extensions/array_spec.rb +61 -61
  336. data/spec/mongoid/extensions/big_decimal_spec.rb +11 -11
  337. data/spec/mongoid/extensions/binary_spec.rb +12 -12
  338. data/spec/mongoid/extensions/boolean_spec.rb +18 -18
  339. data/spec/mongoid/extensions/date_spec.rb +13 -13
  340. data/spec/mongoid/extensions/date_time_spec.rb +8 -8
  341. data/spec/mongoid/extensions/false_class_spec.rb +5 -5
  342. data/spec/mongoid/extensions/float_spec.rb +29 -15
  343. data/spec/mongoid/extensions/hash_spec.rb +29 -29
  344. data/spec/mongoid/extensions/integer_spec.rb +15 -15
  345. data/spec/mongoid/extensions/module_spec.rb +2 -2
  346. data/spec/mongoid/extensions/nil_class_spec.rb +1 -1
  347. data/spec/mongoid/extensions/object_id_spec.rb +134 -134
  348. data/spec/mongoid/extensions/object_spec.rb +26 -26
  349. data/spec/mongoid/extensions/range_spec.rb +61 -12
  350. data/spec/mongoid/extensions/regexp_spec.rb +4 -4
  351. data/spec/mongoid/extensions/set_spec.rb +4 -4
  352. data/spec/mongoid/extensions/string_spec.rb +35 -46
  353. data/spec/mongoid/extensions/symbol_spec.rb +9 -9
  354. data/spec/mongoid/extensions/time_spec.rb +49 -49
  355. data/spec/mongoid/extensions/time_with_zone_spec.rb +34 -34
  356. data/spec/mongoid/extensions/true_class_spec.rb +5 -5
  357. data/spec/mongoid/extensions_spec.rb +29 -0
  358. data/spec/mongoid/factory_spec.rb +15 -15
  359. data/spec/mongoid/fields/foreign_key_spec.rb +73 -66
  360. data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +15 -15
  361. data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +22 -22
  362. data/spec/mongoid/fields/localized_spec.rb +38 -23
  363. data/spec/mongoid/fields/standard_spec.rb +12 -12
  364. data/spec/mongoid/fields_spec.rb +263 -217
  365. data/spec/mongoid/findable_spec.rb +509 -0
  366. data/spec/mongoid/indexable/specification_spec.rb +102 -0
  367. data/spec/mongoid/{indexes_spec.rb → indexable_spec.rb} +171 -51
  368. data/spec/mongoid/{inspection_spec.rb → inspectable_spec.rb} +6 -14
  369. data/spec/mongoid/{callbacks_spec.rb → interceptable_spec.rb} +117 -116
  370. data/spec/mongoid/log_subscriber_spec.rb +75 -0
  371. data/spec/mongoid/loggable_spec.rb +1 -1
  372. data/spec/mongoid/{matchers → matchable}/all_spec.rb +4 -4
  373. data/spec/mongoid/{matchers → matchable}/and_spec.rb +11 -11
  374. data/spec/mongoid/{matchers → matchable}/default_spec.rb +15 -15
  375. data/spec/mongoid/{matchers → matchable}/exists_spec.rb +5 -5
  376. data/spec/mongoid/{matchers → matchable}/gt_spec.rb +9 -8
  377. data/spec/mongoid/{matchers → matchable}/gte_spec.rb +7 -7
  378. data/spec/mongoid/matchable/in_spec.rb +49 -0
  379. data/spec/mongoid/{matchers → matchable}/lt_spec.rb +7 -7
  380. data/spec/mongoid/{matchers → matchable}/lte_spec.rb +7 -7
  381. data/spec/mongoid/matchable/ne_spec.rb +46 -0
  382. data/spec/mongoid/matchable/nin_spec.rb +48 -0
  383. data/spec/mongoid/{matchers → matchable}/or_spec.rb +6 -6
  384. data/spec/mongoid/{matchers → matchable}/size_spec.rb +3 -3
  385. data/spec/mongoid/{matchers_spec.rb → matchable_spec.rb} +41 -41
  386. data/spec/mongoid/persistable/creatable_spec.rb +553 -0
  387. data/spec/mongoid/persistable/deletable_spec.rb +218 -0
  388. data/spec/mongoid/persistable/destroyable_spec.rb +192 -0
  389. data/spec/mongoid/persistable/incrementable_spec.rb +173 -0
  390. data/spec/mongoid/persistable/logical_spec.rb +143 -0
  391. data/spec/mongoid/persistable/poppable_spec.rb +115 -0
  392. data/spec/mongoid/persistable/pullable_spec.rb +228 -0
  393. data/spec/mongoid/persistable/pushable_spec.rb +258 -0
  394. data/spec/mongoid/persistable/renamable_spec.rb +135 -0
  395. data/spec/mongoid/persistable/savable_spec.rb +498 -0
  396. data/spec/mongoid/persistable/settable_spec.rb +162 -0
  397. data/spec/mongoid/persistable/unsettable_spec.rb +155 -0
  398. data/spec/mongoid/persistable/updatable_spec.rb +558 -0
  399. data/spec/mongoid/persistable/upsertable_spec.rb +106 -0
  400. data/spec/mongoid/persistable_spec.rb +206 -0
  401. data/spec/mongoid/{atomic/positionable_spec.rb → positional_spec.rb} +14 -19
  402. data/spec/mongoid/query_cache_spec.rb +263 -0
  403. data/spec/mongoid/railties/document_spec.rb +2 -2
  404. data/spec/mongoid/relations/accessors_spec.rb +53 -145
  405. data/spec/mongoid/relations/auto_save_spec.rb +37 -17
  406. data/spec/mongoid/relations/bindings/embedded/in_spec.rb +12 -12
  407. data/spec/mongoid/relations/bindings/embedded/many_spec.rb +3 -3
  408. data/spec/mongoid/relations/bindings/embedded/one_spec.rb +5 -5
  409. data/spec/mongoid/relations/bindings/referenced/in_spec.rb +26 -26
  410. data/spec/mongoid/relations/bindings/referenced/many_spec.rb +10 -10
  411. data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +19 -19
  412. data/spec/mongoid/relations/bindings/referenced/one_spec.rb +12 -12
  413. data/spec/mongoid/relations/builders/embedded/in_spec.rb +4 -4
  414. data/spec/mongoid/relations/builders/embedded/many_spec.rb +18 -18
  415. data/spec/mongoid/relations/builders/embedded/one_spec.rb +11 -11
  416. data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +12 -13
  417. data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +14 -14
  418. data/spec/mongoid/relations/builders/referenced/in_spec.rb +24 -35
  419. data/spec/mongoid/relations/builders/referenced/many_spec.rb +15 -15
  420. data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +18 -18
  421. data/spec/mongoid/relations/builders/referenced/one_spec.rb +12 -25
  422. data/spec/mongoid/relations/builders_spec.rb +21 -21
  423. data/spec/mongoid/relations/cascading/delete_spec.rb +9 -9
  424. data/spec/mongoid/relations/cascading/destroy_spec.rb +6 -6
  425. data/spec/mongoid/relations/cascading/nullify_spec.rb +4 -4
  426. data/spec/mongoid/relations/cascading/restrict_spec.rb +7 -7
  427. data/spec/mongoid/relations/cascading_spec.rb +16 -16
  428. data/spec/mongoid/relations/constraint_spec.rb +8 -7
  429. data/spec/mongoid/relations/conversions_spec.rb +16 -14
  430. data/spec/mongoid/relations/counter_cache_spec.rb +85 -0
  431. data/spec/mongoid/relations/cyclic_spec.rb +18 -18
  432. data/spec/mongoid/relations/eager/belongs_to_spec.rb +154 -0
  433. data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +117 -0
  434. data/spec/mongoid/relations/eager/has_many_spec.rb +207 -0
  435. data/spec/mongoid/relations/eager/has_one_spec.rb +163 -0
  436. data/spec/mongoid/relations/eager_spec.rb +228 -0
  437. data/spec/mongoid/relations/embedded/dirty_spec.rb +8 -8
  438. data/spec/mongoid/relations/embedded/in_spec.rb +56 -57
  439. data/spec/mongoid/relations/embedded/many_spec.rb +467 -372
  440. data/spec/mongoid/relations/embedded/one_spec.rb +108 -141
  441. data/spec/mongoid/relations/macros_spec.rb +108 -102
  442. data/spec/mongoid/relations/metadata_spec.rb +180 -255
  443. data/spec/mongoid/relations/options_spec.rb +1 -1
  444. data/spec/mongoid/relations/polymorphic_spec.rb +13 -17
  445. data/spec/mongoid/relations/proxy_spec.rb +2 -2
  446. data/spec/mongoid/relations/referenced/in_spec.rb +128 -303
  447. data/spec/mongoid/relations/referenced/many_spec.rb +587 -527
  448. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +401 -424
  449. data/spec/mongoid/relations/referenced/one_spec.rb +149 -264
  450. data/spec/mongoid/relations/reflections_spec.rb +6 -6
  451. data/spec/mongoid/relations/synchronization_spec.rb +46 -50
  452. data/spec/mongoid/relations/targets/enumerable_spec.rb +118 -118
  453. data/spec/mongoid/relations/touchable_spec.rb +333 -0
  454. data/spec/mongoid/relations_spec.rb +16 -15
  455. data/spec/mongoid/{reloading_spec.rb → reloadable_spec.rb} +38 -55
  456. data/spec/mongoid/{scoping_spec.rb → scopable_spec.rb} +89 -164
  457. data/spec/mongoid/selectable_spec.rb +134 -0
  458. data/spec/mongoid/{serialization_spec.rb → serializable_spec.rb} +129 -82
  459. data/spec/mongoid/sessions/factory_spec.rb +49 -28
  460. data/spec/mongoid/sessions/mongo_uri_spec.rb +7 -7
  461. data/spec/mongoid/sessions/options_spec.rb +108 -0
  462. data/spec/mongoid/sessions_spec.rb +319 -178
  463. data/spec/mongoid/{sharding_spec.rb → shardable_spec.rb} +8 -8
  464. data/spec/mongoid/{state_spec.rb → stateful_spec.rb} +36 -11
  465. data/spec/mongoid/tasks/database_rake_spec.rb +285 -0
  466. data/spec/mongoid/tasks/database_spec.rb +160 -0
  467. data/spec/mongoid/threaded_spec.rb +17 -70
  468. data/spec/mongoid/timestamps/created/short_spec.rb +6 -6
  469. data/spec/mongoid/timestamps/created_spec.rb +5 -5
  470. data/spec/mongoid/timestamps/timeless_spec.rb +6 -6
  471. data/spec/mongoid/timestamps/updated/short_spec.rb +11 -11
  472. data/spec/mongoid/timestamps/updated_spec.rb +9 -13
  473. data/spec/mongoid/timestamps_spec.rb +9 -13
  474. data/spec/mongoid/{hierarchy_spec.rb → traversable_spec.rb} +19 -19
  475. data/spec/mongoid/{validations → validatable}/associated_spec.rb +45 -22
  476. data/spec/mongoid/{validations → validatable}/format_spec.rb +6 -6
  477. data/spec/mongoid/{validations → validatable}/length_spec.rb +14 -14
  478. data/spec/mongoid/{validations → validatable}/numericality_spec.rb +1 -1
  479. data/spec/mongoid/{validations → validatable}/presence_spec.rb +37 -44
  480. data/spec/mongoid/{validations → validatable}/uniqueness_spec.rb +184 -192
  481. data/spec/mongoid/{validations_spec.rb → validatable_spec.rb} +28 -28
  482. data/spec/mongoid_spec.rb +8 -8
  483. data/spec/rails/mongoid_spec.rb +19 -335
  484. data/spec/spec_helper.rb +31 -13
  485. metadata +303 -283
  486. data/lib/mongoid/atomic/positionable.rb +0 -73
  487. data/lib/mongoid/components.rb +0 -92
  488. data/lib/mongoid/config/inflections.rb +0 -6
  489. data/lib/mongoid/contextual/eager.rb +0 -158
  490. data/lib/mongoid/errors/versioning_not_on_root.rb +0 -23
  491. data/lib/mongoid/identity_map.rb +0 -163
  492. data/lib/mongoid/json.rb +0 -16
  493. data/lib/mongoid/matchers.rb +0 -32
  494. data/lib/mongoid/matchers/strategies.rb +0 -97
  495. data/lib/mongoid/multi_parameter_attributes.rb +0 -105
  496. data/lib/mongoid/nested_attributes.rb +0 -78
  497. data/lib/mongoid/observer.rb +0 -192
  498. data/lib/mongoid/paranoia.rb +0 -136
  499. data/lib/mongoid/persistence.rb +0 -357
  500. data/lib/mongoid/persistence/atomic.rb +0 -231
  501. data/lib/mongoid/persistence/atomic/add_to_set.rb +0 -47
  502. data/lib/mongoid/persistence/atomic/bit.rb +0 -35
  503. data/lib/mongoid/persistence/atomic/inc.rb +0 -45
  504. data/lib/mongoid/persistence/atomic/operation.rb +0 -154
  505. data/lib/mongoid/persistence/atomic/pop.rb +0 -32
  506. data/lib/mongoid/persistence/atomic/pull.rb +0 -32
  507. data/lib/mongoid/persistence/atomic/pull_all.rb +0 -32
  508. data/lib/mongoid/persistence/atomic/push.rb +0 -25
  509. data/lib/mongoid/persistence/atomic/push_all.rb +0 -25
  510. data/lib/mongoid/persistence/atomic/rename.rb +0 -30
  511. data/lib/mongoid/persistence/atomic/sets.rb +0 -28
  512. data/lib/mongoid/persistence/atomic/unset.rb +0 -27
  513. data/lib/mongoid/persistence/deletion.rb +0 -31
  514. data/lib/mongoid/persistence/insertion.rb +0 -38
  515. data/lib/mongoid/persistence/modification.rb +0 -35
  516. data/lib/mongoid/persistence/operations.rb +0 -214
  517. data/lib/mongoid/persistence/operations/embedded/insert.rb +0 -46
  518. data/lib/mongoid/persistence/operations/embedded/remove.rb +0 -43
  519. data/lib/mongoid/persistence/operations/insert.rb +0 -34
  520. data/lib/mongoid/persistence/operations/remove.rb +0 -33
  521. data/lib/mongoid/persistence/operations/update.rb +0 -59
  522. data/lib/mongoid/persistence/operations/upsert.rb +0 -28
  523. data/lib/mongoid/persistence/upsertion.rb +0 -31
  524. data/lib/mongoid/unit_of_work.rb +0 -61
  525. data/lib/mongoid/versioning.rb +0 -217
  526. data/lib/rack/mongoid.rb +0 -2
  527. data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
  528. data/lib/rails/generators/mongoid/observer/observer_generator.rb +0 -17
  529. data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +0 -4
  530. data/spec/app/models/actor_observer.rb +0 -15
  531. data/spec/app/models/callback_recorder.rb +0 -25
  532. data/spec/app/models/paranoid_phone.rb +0 -25
  533. data/spec/app/models/paranoid_post.rb +0 -36
  534. data/spec/app/models/phone_observer.rb +0 -6
  535. data/spec/mongoid/attributes/processing_spec.rb +0 -149
  536. data/spec/mongoid/criterion/destructive_spec.rb +0 -101
  537. data/spec/mongoid/criterion/modifiable_spec.rb +0 -409
  538. data/spec/mongoid/criterion/modification_spec.rb +0 -402
  539. data/spec/mongoid/errors/versioning_not_on_root_spec.rb +0 -29
  540. data/spec/mongoid/finders_spec.rb +0 -321
  541. data/spec/mongoid/identity_map_spec.rb +0 -564
  542. data/spec/mongoid/json_spec.rb +0 -33
  543. data/spec/mongoid/matchers/in_spec.rb +0 -25
  544. data/spec/mongoid/matchers/ne_spec.rb +0 -25
  545. data/spec/mongoid/matchers/nin_spec.rb +0 -25
  546. data/spec/mongoid/multi_parameter_attributes_spec.rb +0 -128
  547. data/spec/mongoid/observer_spec.rb +0 -290
  548. data/spec/mongoid/paranoia_spec.rb +0 -759
  549. data/spec/mongoid/persistence/atomic/add_to_set_spec.rb +0 -262
  550. data/spec/mongoid/persistence/atomic/bit_spec.rb +0 -88
  551. data/spec/mongoid/persistence/atomic/inc_spec.rb +0 -133
  552. data/spec/mongoid/persistence/atomic/pop_spec.rb +0 -111
  553. data/spec/mongoid/persistence/atomic/pull_all_spec.rb +0 -77
  554. data/spec/mongoid/persistence/atomic/pull_spec.rb +0 -80
  555. data/spec/mongoid/persistence/atomic/push_all_spec.rb +0 -77
  556. data/spec/mongoid/persistence/atomic/push_spec.rb +0 -77
  557. data/spec/mongoid/persistence/atomic/rename_spec.rb +0 -42
  558. data/spec/mongoid/persistence/atomic/sets_spec.rb +0 -154
  559. data/spec/mongoid/persistence/atomic/unset_spec.rb +0 -65
  560. data/spec/mongoid/persistence/atomic_spec.rb +0 -216
  561. data/spec/mongoid/persistence/operations/embedded/insert_spec.rb +0 -191
  562. data/spec/mongoid/persistence/operations/embedded/remove_spec.rb +0 -8
  563. data/spec/mongoid/persistence/operations/insert_spec.rb +0 -149
  564. data/spec/mongoid/persistence/operations/remove_spec.rb +0 -113
  565. data/spec/mongoid/persistence/operations/update_spec.rb +0 -141
  566. data/spec/mongoid/persistence/operations/upsert_spec.rb +0 -59
  567. data/spec/mongoid/persistence/operations_spec.rb +0 -313
  568. data/spec/mongoid/persistence_spec.rb +0 -2279
  569. data/spec/mongoid/unit_of_work_spec.rb +0 -196
  570. data/spec/mongoid/versioning_spec.rb +0 -540
  571. data/spec/rack/mongoid/middleware/identity_map_spec.rb +0 -72
@@ -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)
1371
1382
  end
1372
1383
 
1373
- it "sets the attributes for the provided role" do
1374
- video.title.should eq("Inception")
1384
+ it "sets the first attributes" do
1385
+ expect(addresses.first.street).to eq("Bond")
1375
1386
  end
1376
1387
 
1377
- it "does not set the attributes for other roles" do
1378
- video.year.should be_nil
1388
+ it "sets the second attributes" do
1389
+ expect(addresses.last.street).to eq("Upper")
1390
+ end
1391
+
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" }])
1470
1483
  end
1471
1484
 
1472
- it "sets the attributes for the provided role" do
1473
- video.title.should eq("Inception")
1485
+ it "creates multiple documents" do
1486
+ expect(addresses.size).to eq(2)
1474
1487
  end
1475
1488
 
1476
- it "does not set the attributes for other roles" do
1477
- video.year.should be_nil
1489
+ it "sets the first attributes" do
1490
+ expect(addresses.first.street).to eq("Bond")
1491
+ end
1492
+
1493
+ it "sets the second attributes" do
1494
+ expect(addresses.last.street).to eq("Upper")
1495
+ end
1496
+
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,81 @@ 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)
2119
+ end
2120
+ end
2121
+ end
2122
+
2123
+ describe "#find_or_create_by!" do
2124
+
2125
+ let(:person) do
2126
+ Person.create
2127
+ end
2128
+
2129
+ let!(:address) do
2130
+ person.addresses.build(street: "Bourke", city: "Melbourne")
2131
+ end
2132
+
2133
+ context "when the document exists" do
2134
+
2135
+ let(:found) do
2136
+ person.addresses.find_or_create_by!(street: "Bourke")
2137
+ end
2138
+
2139
+ it "returns the document" do
2140
+ expect(found).to eq(address)
2141
+ end
2142
+ end
2143
+
2144
+ context "when the document does not exist" do
2145
+
2146
+ let(:found) do
2147
+ person.addresses.find_or_create_by!(street: "King") do |address|
2148
+ address.state = "CA"
2149
+ end
2150
+ end
2151
+
2152
+ it "sets the new document attributes" do
2153
+ expect(found.street).to eq("King")
2154
+ end
2155
+
2156
+ it "returns a newly persisted document" do
2157
+ expect(found).to be_persisted
2158
+ end
2159
+
2160
+ it "calls the passed block" do
2161
+ expect(found.state).to eq("CA")
2162
+ end
2163
+
2164
+ context "when validation fails" do
2165
+
2166
+ it "raises an error" do
2167
+ expect {
2168
+ person.addresses.find_or_create_by!(street: "1")
2169
+ }.to raise_error(Mongoid::Errors::Validations)
2170
+ end
2171
+ end
2172
+ end
2173
+
2174
+ context "when the child belongs to another document" do
2175
+
2176
+ let(:product) do
2177
+ Product.create
2178
+ end
2179
+
2180
+ let(:purchase) do
2181
+ Purchase.create
2182
+ end
2183
+
2184
+ let(:line_item) do
2185
+ purchase.line_items.find_or_create_by(
2186
+ product_id: product.id,
2187
+ product_type: product.class.name
2188
+ )
2189
+ end
2190
+
2191
+ it "properly creates the document" do
2192
+ expect(line_item.product).to eq(product)
2098
2193
  end
2099
2194
  end
2100
2195
  end
@@ -2116,7 +2211,7 @@ describe Mongoid::Relations::Embedded::Many do
2116
2211
  end
2117
2212
 
2118
2213
  it "returns the document" do
2119
- found.should eq(address)
2214
+ expect(found).to eq(address)
2120
2215
  end
2121
2216
  end
2122
2217
 
@@ -2129,15 +2224,15 @@ describe Mongoid::Relations::Embedded::Many do
2129
2224
  end
2130
2225
 
2131
2226
  it "sets the new document attributes" do
2132
- found.street.should eq("King")
2227
+ expect(found.street).to eq("King")
2133
2228
  end
2134
2229
 
2135
2230
  it "returns a non persisted document" do
2136
- found.should_not be_persisted
2231
+ expect(found).to_not be_persisted
2137
2232
  end
2138
2233
 
2139
2234
  it "calls the passed block" do
2140
- found.state.should eq("CA")
2235
+ expect(found.state).to eq("CA")
2141
2236
  end
2142
2237
  end
2143
2238
  end
@@ -2145,7 +2240,7 @@ describe Mongoid::Relations::Embedded::Many do
2145
2240
  describe ".macro" do
2146
2241
 
2147
2242
  it "returns embeds_many" do
2148
- described_class.macro.should eq(:embeds_many)
2243
+ expect(described_class.macro).to eq(:embeds_many)
2149
2244
  end
2150
2245
  end
2151
2246
 
@@ -2174,7 +2269,7 @@ describe Mongoid::Relations::Embedded::Many do
2174
2269
  end
2175
2270
 
2176
2271
  it "returns the document with the max value of the supplied field" do
2177
- max.should eq(address_two)
2272
+ expect(max).to eq(address_two)
2178
2273
  end
2179
2274
  end
2180
2275
 
@@ -2201,7 +2296,7 @@ describe Mongoid::Relations::Embedded::Many do
2201
2296
  end
2202
2297
 
2203
2298
  it "returns the document with the max value of the supplied field" do
2204
- max.should eq(address_two)
2299
+ expect(max).to eq(address_two)
2205
2300
  end
2206
2301
  end
2207
2302
 
@@ -2236,7 +2331,7 @@ describe Mongoid::Relations::Embedded::Many do
2236
2331
  end
2237
2332
 
2238
2333
  it "applies the criteria to the documents" do
2239
- addresses.should eq([ address_one ])
2334
+ expect(addresses).to eq([ address_one ])
2240
2335
  end
2241
2336
  end
2242
2337
 
@@ -2247,7 +2342,7 @@ describe Mongoid::Relations::Embedded::Many do
2247
2342
  end
2248
2343
 
2249
2344
  it "applies the criteria to the documents" do
2250
- addresses.should eq([ address_one, address_two ])
2345
+ expect(addresses).to eq([ address_one, address_two ])
2251
2346
  end
2252
2347
  end
2253
2348
 
@@ -2258,7 +2353,7 @@ describe Mongoid::Relations::Embedded::Many do
2258
2353
  end
2259
2354
 
2260
2355
  it "applies the criteria to the documents" do
2261
- addresses.should eq([ address_one, address_two ])
2356
+ expect(addresses).to eq([ address_one, address_two ])
2262
2357
  end
2263
2358
  end
2264
2359
  end
@@ -2270,7 +2365,7 @@ describe Mongoid::Relations::Embedded::Many do
2270
2365
  end
2271
2366
 
2272
2367
  it "applies the criteria to the documents" do
2273
- addresses.should eq([ address_one ])
2368
+ expect(addresses).to eq([ address_one ])
2274
2369
  end
2275
2370
  end
2276
2371
 
@@ -2281,7 +2376,7 @@ describe Mongoid::Relations::Embedded::Many do
2281
2376
  end
2282
2377
 
2283
2378
  it "applies the criteria to the documents" do
2284
- addresses.should eq([ address_one ])
2379
+ expect(addresses).to eq([ address_one ])
2285
2380
  end
2286
2381
  end
2287
2382
 
@@ -2290,8 +2385,7 @@ describe Mongoid::Relations::Embedded::Many do
2290
2385
  describe "#distinct" do
2291
2386
 
2292
2387
  it "returns the distinct values for the fields" do
2293
- person.addresses.distinct(:street).should =~
2294
- [ "Market", "Madison"]
2388
+ expect(person.addresses.distinct(:street)).to eq([ "Market", "Madison"])
2295
2389
  end
2296
2390
  end
2297
2391
  end
@@ -2322,7 +2416,7 @@ describe Mongoid::Relations::Embedded::Many do
2322
2416
  end
2323
2417
 
2324
2418
  it "returns the min value of the supplied field" do
2325
- min.should eq(address_one)
2419
+ expect(min).to eq(address_one)
2326
2420
  end
2327
2421
  end
2328
2422
 
@@ -2349,7 +2443,7 @@ describe Mongoid::Relations::Embedded::Many do
2349
2443
  end
2350
2444
 
2351
2445
  it "returns the min value of the supplied field" do
2352
- min.should eq(address_one)
2446
+ expect(min).to eq(address_one)
2353
2447
  end
2354
2448
  end
2355
2449
 
@@ -2360,8 +2454,9 @@ describe Mongoid::Relations::Embedded::Many do
2360
2454
  end
2361
2455
 
2362
2456
  it "returns the many nested builder class" do
2363
- described_class.nested_builder(metadata, {}, {}).should
2364
- be_a(Mongoid::Relations::Builders::NestedAttributes::Many)
2457
+ expect(
2458
+ described_class.nested_builder(metadata, {}, {})
2459
+ ).to be_a(Mongoid::Relations::Builders::NestedAttributes::Many)
2365
2460
  end
2366
2461
  end
2367
2462
 
@@ -2386,15 +2481,15 @@ describe Mongoid::Relations::Embedded::Many do
2386
2481
  end
2387
2482
 
2388
2483
  it "returns the popped document" do
2389
- popped.should eq(address_two)
2484
+ expect(popped).to eq(address_two)
2390
2485
  end
2391
2486
 
2392
2487
  it "removes the document from the relation" do
2393
- person.addresses.should eq([ address_one ])
2488
+ expect(person.addresses).to eq([ address_one ])
2394
2489
  end
2395
2490
 
2396
2491
  it "persists the pop" do
2397
- person.reload.addresses.should eq([ address_one ])
2492
+ expect(person.reload.addresses).to eq([ address_one ])
2398
2493
  end
2399
2494
  end
2400
2495
 
@@ -2415,15 +2510,15 @@ describe Mongoid::Relations::Embedded::Many do
2415
2510
  end
2416
2511
 
2417
2512
  it "returns the popped documents" do
2418
- popped.should eq([ address_one, address_two ])
2513
+ expect(popped).to eq([ address_one, address_two ])
2419
2514
  end
2420
2515
 
2421
2516
  it "removes the document from the relation" do
2422
- person.addresses.should be_empty
2517
+ expect(person.addresses).to be_empty
2423
2518
  end
2424
2519
 
2425
2520
  it "persists the pop" do
2426
- person.reload.addresses.should be_empty
2521
+ expect(person.reload.addresses).to be_empty
2427
2522
  end
2428
2523
  end
2429
2524
 
@@ -2434,15 +2529,15 @@ describe Mongoid::Relations::Embedded::Many do
2434
2529
  end
2435
2530
 
2436
2531
  it "returns the popped documents" do
2437
- popped.should eq([ address_one, address_two ])
2532
+ expect(popped).to eq([ address_one, address_two ])
2438
2533
  end
2439
2534
 
2440
2535
  it "removes the document from the relation" do
2441
- person.addresses.should be_empty
2536
+ expect(person.addresses).to be_empty
2442
2537
  end
2443
2538
 
2444
2539
  it "persists the pop" do
2445
- person.reload.addresses.should be_empty
2540
+ expect(person.reload.addresses).to be_empty
2446
2541
  end
2447
2542
  end
2448
2543
  end
@@ -2452,14 +2547,14 @@ describe Mongoid::Relations::Embedded::Many do
2452
2547
  context "when providing no number" do
2453
2548
 
2454
2549
  it "returns nil" do
2455
- person.addresses.pop.should be_nil
2550
+ expect(person.addresses.pop).to be_nil
2456
2551
  end
2457
2552
  end
2458
2553
 
2459
2554
  context "when providing a number" do
2460
2555
 
2461
2556
  it "returns nil" do
2462
- person.addresses.pop(2).should be_nil
2557
+ expect(person.addresses.pop(2)).to be_nil
2463
2558
  end
2464
2559
  end
2465
2560
  end
@@ -2476,11 +2571,11 @@ describe Mongoid::Relations::Embedded::Many do
2476
2571
  end
2477
2572
 
2478
2573
  it "returns the relation criteria" do
2479
- scoped.should be_a(Mongoid::Criteria)
2574
+ expect(scoped).to be_a(Mongoid::Criteria)
2480
2575
  end
2481
2576
 
2482
2577
  it "returns with an empty selector" do
2483
- scoped.selector.should be_empty
2578
+ expect(scoped.selector).to be_empty
2484
2579
  end
2485
2580
  end
2486
2581
 
@@ -2499,7 +2594,7 @@ describe Mongoid::Relations::Embedded::Many do
2499
2594
  context "when checking #{method}" do
2500
2595
 
2501
2596
  it "returns true" do
2502
- addresses.respond_to?(method).should be_true
2597
+ expect(addresses.respond_to?(method)).to be true
2503
2598
  end
2504
2599
  end
2505
2600
  end
@@ -2509,7 +2604,7 @@ describe Mongoid::Relations::Embedded::Many do
2509
2604
  context "when checking #{method}" do
2510
2605
 
2511
2606
  it "returns true" do
2512
- addresses.respond_to?(method).should be_true
2607
+ expect(addresses.respond_to?(method)).to be true
2513
2608
  end
2514
2609
  end
2515
2610
  end
@@ -2519,7 +2614,7 @@ describe Mongoid::Relations::Embedded::Many do
2519
2614
  context "when checking #{method}" do
2520
2615
 
2521
2616
  it "returns true" do
2522
- addresses.respond_to?(method).should be_true
2617
+ expect(addresses.respond_to?(method)).to be true
2523
2618
  end
2524
2619
  end
2525
2620
  end
@@ -2543,7 +2638,7 @@ describe Mongoid::Relations::Embedded::Many do
2543
2638
  end
2544
2639
 
2545
2640
  it "returns the number of persisted documents" do
2546
- person.addresses.send(method).should eq(2)
2641
+ expect(person.addresses.send(method)).to eq(2)
2547
2642
  end
2548
2643
  end
2549
2644
  end
@@ -2559,15 +2654,15 @@ describe Mongoid::Relations::Embedded::Many do
2559
2654
  end
2560
2655
 
2561
2656
  it "returns the relation criteria" do
2562
- unscoped.should be_a(Mongoid::Criteria)
2657
+ expect(unscoped).to be_a(Mongoid::Criteria)
2563
2658
  end
2564
2659
 
2565
2660
  it "returns with empty options" do
2566
- unscoped.options.should be_empty
2661
+ expect(unscoped.options).to be_empty
2567
2662
  end
2568
2663
 
2569
2664
  it "returns with an empty selector" do
2570
- unscoped.selector.should be_empty
2665
+ expect(unscoped.selector).to be_empty
2571
2666
  end
2572
2667
  end
2573
2668
 
@@ -2580,7 +2675,7 @@ describe Mongoid::Relations::Embedded::Many do
2580
2675
  end
2581
2676
 
2582
2677
  it "updates nothing" do
2583
- person.addresses.update_all(street: "test").should be_false
2678
+ expect(person.addresses.update_all(street: "test")).to be false
2584
2679
  end
2585
2680
  end
2586
2681
 
@@ -2603,19 +2698,19 @@ describe Mongoid::Relations::Embedded::Many do
2603
2698
  end
2604
2699
 
2605
2700
  it "resets the matching dirty flags" do
2606
- address.should_not be_changed
2701
+ expect(address).to_not be_changed
2607
2702
  end
2608
2703
 
2609
2704
  it "updates the first field" do
2610
- address.reload.number.should eq(26)
2705
+ expect(address.reload.number).to eq(26)
2611
2706
  end
2612
2707
 
2613
2708
  it "updates the second field" do
2614
- address.reload.post_code.should eq("12437")
2709
+ expect(address.reload.post_code).to eq("12437")
2615
2710
  end
2616
2711
 
2617
2712
  it "does not wipe out other fields" do
2618
- address.reload.street.should eq("Hobrecht")
2713
+ expect(address.reload.street).to eq("Hobrecht")
2619
2714
  end
2620
2715
  end
2621
2716
  end
@@ -2624,9 +2719,9 @@ describe Mongoid::Relations::Embedded::Many do
2624
2719
  describe ".valid_options" do
2625
2720
 
2626
2721
  it "returns the valid options" do
2627
- described_class.valid_options.should eq(
2722
+ expect(described_class.valid_options).to eq(
2628
2723
  [
2629
- :as, :cascade_callbacks, :cyclic, :order, :versioned,
2724
+ :as, :cascade_callbacks, :cyclic, :order,
2630
2725
  :store_as, :before_add, :after_add, :before_remove, :after_remove
2631
2726
  ]
2632
2727
  )
@@ -2636,7 +2731,7 @@ describe Mongoid::Relations::Embedded::Many do
2636
2731
  describe ".validation_default" do
2637
2732
 
2638
2733
  it "returns true" do
2639
- described_class.validation_default.should be_true
2734
+ expect(described_class.validation_default).to be true
2640
2735
  end
2641
2736
  end
2642
2737
 
@@ -2663,15 +2758,15 @@ describe Mongoid::Relations::Embedded::Many do
2663
2758
  end
2664
2759
 
2665
2760
  it "updates the attributes" do
2666
- address.locations.first.name.should eq("home")
2761
+ expect(address.locations.first.name).to eq("home")
2667
2762
  end
2668
2763
 
2669
2764
  it "overwrites the existing documents" do
2670
- address.locations.count.should eq(1)
2765
+ expect(address.locations.count).to eq(1)
2671
2766
  end
2672
2767
 
2673
2768
  it "persists the changes" do
2674
- address.reload.locations.count.should eq(1)
2769
+ expect(address.reload.locations.count).to eq(1)
2675
2770
  end
2676
2771
  end
2677
2772
  end
@@ -2701,15 +2796,15 @@ describe Mongoid::Relations::Embedded::Many do
2701
2796
  end
2702
2797
 
2703
2798
  it "sets up the hierarchy" do
2704
- animal.circus.should eq(circus)
2799
+ expect(animal.circus).to eq(circus)
2705
2800
  end
2706
2801
 
2707
2802
  it "assigns the attributes" do
2708
- animal.name.should eq(animal_name)
2803
+ expect(animal.name).to eq(animal_name)
2709
2804
  end
2710
2805
 
2711
2806
  it "uses custom writer methods" do
2712
- animal.tag_list.should eq(tag_list)
2807
+ expect(animal.tag_list).to eq(tag_list)
2713
2808
  end
2714
2809
  end
2715
2810
 
@@ -2720,15 +2815,15 @@ describe Mongoid::Relations::Embedded::Many do
2720
2815
  end
2721
2816
 
2722
2817
  it "sets up the hierarchy" do
2723
- animal.circus.should eq(circus)
2818
+ expect(animal.circus).to eq(circus)
2724
2819
  end
2725
2820
 
2726
2821
  it "assigns the attributes" do
2727
- animal.name.should eq(animal_name)
2822
+ expect(animal.name).to eq(animal_name)
2728
2823
  end
2729
2824
 
2730
2825
  it "uses custom writer methods" do
2731
- animal.tag_list.should eq(tag_list)
2826
+ expect(animal.tag_list).to eq(tag_list)
2732
2827
  end
2733
2828
  end
2734
2829
  end
@@ -2757,7 +2852,7 @@ describe Mongoid::Relations::Embedded::Many do
2757
2852
  end
2758
2853
 
2759
2854
  it "sets up the hierarchy" do
2760
- question.should eq(page_question)
2855
+ expect(question).to eq(page_question)
2761
2856
  end
2762
2857
  end
2763
2858
 
@@ -2780,7 +2875,7 @@ describe Mongoid::Relations::Embedded::Many do
2780
2875
  end
2781
2876
 
2782
2877
  it "sets up the hierarchy" do
2783
- question.should eq(page_question)
2878
+ expect(question).to eq(page_question)
2784
2879
  end
2785
2880
  end
2786
2881
 
@@ -2808,7 +2903,7 @@ describe Mongoid::Relations::Embedded::Many do
2808
2903
  end
2809
2904
 
2810
2905
  it "sets up the hierarchy" do
2811
- question.should eq(page_question)
2906
+ expect(question).to eq(page_question)
2812
2907
  end
2813
2908
 
2814
2909
  context "when reloading" do
@@ -2822,7 +2917,7 @@ describe Mongoid::Relations::Embedded::Many do
2822
2917
  end
2823
2918
 
2824
2919
  it "reloads the entire tree" do
2825
- reloaded_question.should eq(question)
2920
+ expect(reloaded_question).to eq(question)
2826
2921
  end
2827
2922
  end
2828
2923
  end
@@ -2856,11 +2951,11 @@ describe Mongoid::Relations::Embedded::Many do
2856
2951
  end
2857
2952
 
2858
2953
  it "persists the first level document" do
2859
- person.reload.addresses.first.should eq(address)
2954
+ expect(person.reload.addresses.first).to eq(address)
2860
2955
  end
2861
2956
 
2862
2957
  it "persists the second level document" do
2863
- person.reload.addresses[0].locations.should eq([ location ])
2958
+ expect(person.reload.addresses[0].locations).to eq([ location ])
2864
2959
  end
2865
2960
  end
2866
2961
  end
@@ -2895,7 +2990,7 @@ describe Mongoid::Relations::Embedded::Many do
2895
2990
 
2896
2991
  it "ignores the nil and persist the remaining items" do
2897
2992
  reloaded = Person.find(person.id)
2898
- reloaded.phone_numbers.should eq([ home_phone, office_phone ])
2993
+ expect(reloaded.phone_numbers).to eq([ home_phone, office_phone ])
2899
2994
  end
2900
2995
  end
2901
2996
 
@@ -2916,7 +3011,7 @@ describe Mongoid::Relations::Embedded::Many do
2916
3011
 
2917
3012
  it "ignores the nil and persist the remaining items" do
2918
3013
  reloaded = Person.find(person.id)
2919
- reloaded.phone_numbers.should eq([ home_phone, office_phone ])
3014
+ expect(reloaded.phone_numbers).to eq([ home_phone, office_phone ])
2920
3015
  end
2921
3016
  end
2922
3017
 
@@ -2937,7 +3032,7 @@ describe Mongoid::Relations::Embedded::Many do
2937
3032
 
2938
3033
  it "ignores the nil and persist the remaining items" do
2939
3034
  reloaded = Person.find(person.id)
2940
- reloaded.phone_numbers.should eq([ home_phone, office_phone ])
3035
+ expect(reloaded.phone_numbers).to eq([ home_phone, office_phone ])
2941
3036
  end
2942
3037
  end
2943
3038
  end
@@ -2959,7 +3054,7 @@ describe Mongoid::Relations::Embedded::Many do
2959
3054
 
2960
3055
  it "ignores the nil and persist the remaining items" do
2961
3056
  reloaded = Person.find(person.id)
2962
- reloaded.phone_numbers.should eq(person.phone_numbers)
3057
+ expect(reloaded.phone_numbers).to eq(person.phone_numbers)
2963
3058
  end
2964
3059
  end
2965
3060
 
@@ -2978,7 +3073,7 @@ describe Mongoid::Relations::Embedded::Many do
2978
3073
 
2979
3074
  it "ignores the nil and persist the remaining items" do
2980
3075
  reloaded = Person.find(person.id)
2981
- reloaded.phone_numbers.should eq(person.phone_numbers)
3076
+ expect(reloaded.phone_numbers).to eq(person.phone_numbers)
2982
3077
  end
2983
3078
  end
2984
3079
 
@@ -2997,7 +3092,7 @@ describe Mongoid::Relations::Embedded::Many do
2997
3092
 
2998
3093
  it "ignores the nil and persist the remaining items" do
2999
3094
  reloaded = Person.find(person.id)
3000
- reloaded.phone_numbers.should eq(person.phone_numbers)
3095
+ expect(reloaded.phone_numbers).to eq(person.phone_numbers)
3001
3096
  end
3002
3097
  end
3003
3098
  end
@@ -3018,7 +3113,7 @@ describe Mongoid::Relations::Embedded::Many do
3018
3113
  end
3019
3114
 
3020
3115
  it "retains the reference to the parent" do
3021
- league.name.should eq("Destroyed")
3116
+ expect(league.name).to eq("Destroyed")
3022
3117
  end
3023
3118
  end
3024
3119
 
@@ -3037,11 +3132,11 @@ describe Mongoid::Relations::Embedded::Many do
3037
3132
  end
3038
3133
 
3039
3134
  it "does not duplicate the embedded documents" do
3040
- person.addresses.should eq([ address ])
3135
+ expect(person.addresses).to eq([ address ])
3041
3136
  end
3042
3137
 
3043
3138
  it "does not persist duplicate embedded documents" do
3044
- person.reload.addresses.should eq([ address ])
3139
+ expect(person.reload.addresses).to eq([ address ])
3045
3140
  end
3046
3141
  end
3047
3142
 
@@ -3058,7 +3153,7 @@ describe Mongoid::Relations::Embedded::Many do
3058
3153
  end
3059
3154
 
3060
3155
  it "allows the operation" do
3061
- version.number.should eq(1)
3156
+ expect(version.number).to eq(1)
3062
3157
  end
3063
3158
 
3064
3159
  context "when reloading the parent" do
@@ -3068,7 +3163,7 @@ describe Mongoid::Relations::Embedded::Many do
3068
3163
  end
3069
3164
 
3070
3165
  it "saves the child versions" do
3071
- from_db.versions.should eq([ version ])
3166
+ expect(from_db.versions).to eq([ version ])
3072
3167
  end
3073
3168
  end
3074
3169
  end
@@ -3095,7 +3190,7 @@ describe Mongoid::Relations::Embedded::Many do
3095
3190
  end
3096
3191
 
3097
3192
  it "does not lose the parent reference" do
3098
- from_db.memberships.first.account.should eq(account)
3193
+ expect(from_db.memberships.first.account).to eq(account)
3099
3194
  end
3100
3195
  end
3101
3196
 
@@ -3106,7 +3201,7 @@ describe Mongoid::Relations::Embedded::Many do
3106
3201
  end
3107
3202
 
3108
3203
  it "does not lose the parent reference" do
3109
- from_db.memberships.first.account.should eq(account)
3204
+ expect(from_db.memberships.first.account).to eq(account)
3110
3205
  end
3111
3206
  end
3112
3207
  end
@@ -3130,11 +3225,11 @@ describe Mongoid::Relations::Embedded::Many do
3130
3225
  end
3131
3226
 
3132
3227
  it "adds the document to the new paarent" do
3133
- person_two.addresses.should eq([ address ])
3228
+ expect(person_two.addresses).to eq([ address ])
3134
3229
  end
3135
3230
 
3136
3231
  it "sets the new parent on the document" do
3137
- address._parent.should eq(person_two)
3232
+ expect(address._parent).to eq(person_two)
3138
3233
  end
3139
3234
 
3140
3235
  context "when reloading the documents" do
@@ -3145,11 +3240,11 @@ describe Mongoid::Relations::Embedded::Many do
3145
3240
  end
3146
3241
 
3147
3242
  it "persists the change to the new parent" do
3148
- person_two.addresses.should eq([ address ])
3243
+ expect(person_two.addresses).to eq([ address ])
3149
3244
  end
3150
3245
 
3151
3246
  it "keeps the address on the previous document" do
3152
- person_one.addresses.should eq([ address ])
3247
+ expect(person_one.addresses).to eq([ address ])
3153
3248
  end
3154
3249
  end
3155
3250
  end
@@ -3185,7 +3280,7 @@ describe Mongoid::Relations::Embedded::Many do
3185
3280
  end
3186
3281
 
3187
3282
  it "applies the default scope" do
3188
- symptoms.should eq([ cough, headache, nausea ])
3283
+ expect(symptoms).to eq([ cough, headache, nausea ])
3189
3284
  end
3190
3285
  end
3191
3286
 
@@ -3206,7 +3301,7 @@ describe Mongoid::Relations::Embedded::Many do
3206
3301
  end
3207
3302
 
3208
3303
  it "applies the default scope" do
3209
- symptoms.should eq([ constipation, cough, headache, nausea ])
3304
+ expect(symptoms).to eq([ constipation, cough, headache, nausea ])
3210
3305
  end
3211
3306
  end
3212
3307
  end
@@ -3218,7 +3313,7 @@ describe Mongoid::Relations::Embedded::Many do
3218
3313
  end
3219
3314
 
3220
3315
  it "removes the default scope" do
3221
- unscoped.should eq([ nausea, cough, headache ])
3316
+ expect(unscoped).to eq([ nausea, cough, headache ])
3222
3317
  end
3223
3318
  end
3224
3319
  end
@@ -3249,11 +3344,11 @@ describe Mongoid::Relations::Embedded::Many do
3249
3344
  end
3250
3345
 
3251
3346
  it "retains the unscoped index for the excluded document" do
3252
- relation.send(:_unscoped).first._index.should eq(0)
3347
+ expect(relation.send(:_unscoped).first._index).to eq(0)
3253
3348
  end
3254
3349
 
3255
3350
  it "retains the unscoped index for the included document" do
3256
- relation.first._index.should eq(1)
3351
+ expect(relation.first._index).to eq(1)
3257
3352
  end
3258
3353
 
3259
3354
  context "when a reindexing operation occurs" do
@@ -3263,11 +3358,11 @@ describe Mongoid::Relations::Embedded::Many do
3263
3358
  end
3264
3359
 
3265
3360
  it "retains the unscoped index for the excluded document" do
3266
- relation.send(:_unscoped).first._index.should eq(0)
3361
+ expect(relation.send(:_unscoped).first._index).to eq(0)
3267
3362
  end
3268
3363
 
3269
3364
  it "retains the unscoped index for the included document" do
3270
- relation.first._index.should eq(1)
3365
+ expect(relation.first._index).to eq(1)
3271
3366
  end
3272
3367
  end
3273
3368
  end
@@ -3291,11 +3386,11 @@ describe Mongoid::Relations::Embedded::Many do
3291
3386
  end
3292
3387
 
3293
3388
  it "sets the value" do
3294
- video.genres.should eq([ "horror", "scifi" ])
3389
+ expect(video.genres).to eq([ "horror", "scifi" ])
3295
3390
  end
3296
3391
 
3297
3392
  it "persists the value" do
3298
- video.reload.genres.should eq([ "horror", "scifi" ])
3393
+ expect(video.reload.genres).to eq([ "horror", "scifi" ])
3299
3394
  end
3300
3395
 
3301
3396
  context "when reloading the parent" do
@@ -3316,11 +3411,11 @@ describe Mongoid::Relations::Embedded::Many do
3316
3411
  end
3317
3412
 
3318
3413
  it "sets the new value" do
3319
- loaded_video.genres.should eq([ "comedy" ])
3414
+ expect(loaded_video.genres).to eq([ "comedy" ])
3320
3415
  end
3321
3416
 
3322
3417
  it "persists the new value" do
3323
- loaded_video.reload.genres.should eq([ "comedy" ])
3418
+ expect(loaded_video.reload.genres).to eq([ "comedy" ])
3324
3419
  end
3325
3420
  end
3326
3421
  end
@@ -3346,15 +3441,15 @@ describe Mongoid::Relations::Embedded::Many do
3346
3441
  end
3347
3442
 
3348
3443
  it "destroys the document" do
3349
- address_one.should be_destroyed
3444
+ expect(address_one).to be_destroyed
3350
3445
  end
3351
3446
 
3352
3447
  it "reindexes the relation" do
3353
- address_two._index.should eq(0)
3448
+ expect(address_two._index).to eq(0)
3354
3449
  end
3355
3450
 
3356
3451
  it "removes the document from the unscoped" do
3357
- person.addresses.send(:_unscoped).should_not include(address_one)
3452
+ expect(person.addresses.send(:_unscoped)).to_not include(address_one)
3358
3453
  end
3359
3454
 
3360
3455
  context "when subsequently updating the next document" do
@@ -3368,11 +3463,11 @@ describe Mongoid::Relations::Embedded::Many do
3368
3463
  end
3369
3464
 
3370
3465
  it "updates the correct document" do
3371
- addresses.first.number.should eq(10)
3466
+ expect(addresses.first.number).to eq(10)
3372
3467
  end
3373
3468
 
3374
3469
  it "does not add additional documents" do
3375
- addresses.count.should eq(1)
3470
+ expect(addresses.count).to eq(1)
3376
3471
  end
3377
3472
  end
3378
3473
  end
@@ -3402,7 +3497,7 @@ describe Mongoid::Relations::Embedded::Many do
3402
3497
  end
3403
3498
 
3404
3499
  it "adds both documents" do
3405
- result.should eq([ address_one, address_two ])
3500
+ expect(result).to eq([ address_one, address_two ])
3406
3501
  end
3407
3502
  end
3408
3503
  end
@@ -3426,7 +3521,7 @@ describe Mongoid::Relations::Embedded::Many do
3426
3521
  end
3427
3522
 
3428
3523
  it "allows the dot notation criteria" do
3429
- criteria.should eq([ address ])
3524
+ expect(criteria).to eq([ address ])
3430
3525
  end
3431
3526
  end
3432
3527
 
@@ -3459,7 +3554,7 @@ describe Mongoid::Relations::Embedded::Many do
3459
3554
  end
3460
3555
 
3461
3556
  it "updates the nested document" do
3462
- updated.name.should eq("work")
3557
+ expect(updated.name).to eq("work")
3463
3558
  end
3464
3559
  end
3465
3560
  end
@@ -3479,7 +3574,7 @@ describe Mongoid::Relations::Embedded::Many do
3479
3574
  end
3480
3575
 
3481
3576
  it "orders properly with the boolean" do
3482
- circuit.reload.buses.should eq([ bus_two, bus_one ])
3577
+ expect(circuit.reload.buses).to eq([ bus_two, bus_one ])
3483
3578
  end
3484
3579
  end
3485
3580
 
@@ -3517,11 +3612,11 @@ describe Mongoid::Relations::Embedded::Many do
3517
3612
  end
3518
3613
 
3519
3614
  it "does not duplicate the first relation" do
3520
- person.reload.symptoms.count.should eq(2)
3615
+ expect(person.reload.symptoms.count).to eq(2)
3521
3616
  end
3522
3617
 
3523
3618
  it "does not duplicate the second relation" do
3524
- person.reload.appointments.count.should eq(2)
3619
+ expect(person.reload.appointments.count).to eq(2)
3525
3620
  end
3526
3621
  end
3527
3622
 
@@ -3542,29 +3637,29 @@ describe Mongoid::Relations::Embedded::Many do
3542
3637
  end
3543
3638
 
3544
3639
  it "executes the callback" do
3545
- artist.before_add_called.should be_true
3640
+ expect(artist.before_add_called).to be true
3546
3641
  end
3547
3642
 
3548
3643
  it "executes the callback as proc" do
3549
- song.before_add_called.should be_true
3644
+ expect(song.before_add_called).to be true
3550
3645
  end
3551
3646
 
3552
3647
  it "adds the document to the relation" do
3553
- artist.songs.should eq([song])
3648
+ expect(artist.songs).to eq([song])
3554
3649
  end
3555
3650
  end
3556
3651
 
3557
3652
  context "with errors" do
3558
3653
 
3559
3654
  before do
3560
- artist.should_receive(:before_add_song).and_raise
3655
+ expect(artist).to receive(:before_add_song).and_raise
3561
3656
  end
3562
3657
 
3563
3658
  it "does not add the document to the relation" do
3564
3659
  expect {
3565
3660
  artist.songs << song
3566
3661
  }.to raise_error
3567
- artist.songs.should be_empty
3662
+ expect(artist.songs).to be_empty
3568
3663
  end
3569
3664
  end
3570
3665
  end
@@ -3581,20 +3676,20 @@ describe Mongoid::Relations::Embedded::Many do
3581
3676
 
3582
3677
  it "executes the callback" do
3583
3678
  artist.labels << label
3584
- artist.after_add_called.should be_true
3679
+ expect(artist.after_add_called).to be true
3585
3680
  end
3586
3681
 
3587
3682
  context "when errors are raised" do
3588
3683
 
3589
3684
  before do
3590
- artist.should_receive(:after_add_label).and_raise
3685
+ expect(artist).to receive(:after_add_label).and_raise
3591
3686
  end
3592
3687
 
3593
3688
  it "adds the document to the relation" do
3594
3689
  expect {
3595
3690
  artist.labels << label
3596
3691
  }.to raise_error
3597
- artist.labels.should eq([ label ])
3692
+ expect(artist.labels).to eq([ label ])
3598
3693
  end
3599
3694
  end
3600
3695
  end
@@ -3622,11 +3717,11 @@ describe Mongoid::Relations::Embedded::Many do
3622
3717
  end
3623
3718
 
3624
3719
  it "executes the callback" do
3625
- artist.before_remove_embedded_called.should be_true
3720
+ expect(artist.before_remove_embedded_called).to be true
3626
3721
  end
3627
3722
 
3628
3723
  it "removes the document from the relation" do
3629
- artist.songs.should be_empty
3724
+ expect(artist.songs).to be_empty
3630
3725
  end
3631
3726
  end
3632
3727
 
@@ -3637,18 +3732,18 @@ describe Mongoid::Relations::Embedded::Many do
3637
3732
  end
3638
3733
 
3639
3734
  it "executes the callback" do
3640
- artist.before_remove_embedded_called.should be_true
3735
+ expect(artist.before_remove_embedded_called).to be true
3641
3736
  end
3642
3737
 
3643
3738
  it "shoud clear the relation" do
3644
- artist.songs.should be_empty
3739
+ expect(artist.songs).to be_empty
3645
3740
  end
3646
3741
  end
3647
3742
 
3648
3743
  context "when errors are raised" do
3649
3744
 
3650
3745
  before do
3651
- artist.should_receive(:before_remove_song).and_raise
3746
+ expect(artist).to receive(:before_remove_song).and_raise
3652
3747
  end
3653
3748
 
3654
3749
  describe "#delete" do
@@ -3657,7 +3752,7 @@ describe Mongoid::Relations::Embedded::Many do
3657
3752
  expect {
3658
3753
  artist.songs.delete(song)
3659
3754
  }.to raise_error
3660
- artist.songs.should eq([ song ])
3755
+ expect(artist.songs).to eq([ song ])
3661
3756
  end
3662
3757
  end
3663
3758
 
@@ -3667,7 +3762,7 @@ describe Mongoid::Relations::Embedded::Many do
3667
3762
  expect {
3668
3763
  artist.songs.clear
3669
3764
  }.to raise_error
3670
- artist.songs.should eq([ song ])
3765
+ expect(artist.songs).to eq([ song ])
3671
3766
  end
3672
3767
  end
3673
3768
  end
@@ -3696,7 +3791,7 @@ describe Mongoid::Relations::Embedded::Many do
3696
3791
  end
3697
3792
 
3698
3793
  it "executes the callback" do
3699
- artist.after_remove_embedded_called.should be_true
3794
+ expect(artist.after_remove_embedded_called).to be true
3700
3795
  end
3701
3796
  end
3702
3797
 
@@ -3708,7 +3803,7 @@ describe Mongoid::Relations::Embedded::Many do
3708
3803
 
3709
3804
  it "executes the callback" do
3710
3805
  artist.labels.clear
3711
- artist.after_remove_embedded_called.should be_true
3806
+ expect(artist.after_remove_embedded_called).to be true
3712
3807
  end
3713
3808
  end
3714
3809
  end
@@ -3716,7 +3811,7 @@ describe Mongoid::Relations::Embedded::Many do
3716
3811
  context "when errors are raised" do
3717
3812
 
3718
3813
  before do
3719
- artist.should_receive(:after_remove_label).and_raise
3814
+ expect(artist).to receive(:after_remove_label).and_raise
3720
3815
  end
3721
3816
 
3722
3817
  describe "#delete" do
@@ -3728,7 +3823,7 @@ describe Mongoid::Relations::Embedded::Many do
3728
3823
  end
3729
3824
 
3730
3825
  it "removes the document from the relation" do
3731
- artist.labels.should be_empty
3826
+ expect(artist.labels).to be_empty
3732
3827
  end
3733
3828
  end
3734
3829
 
@@ -3741,7 +3836,7 @@ describe Mongoid::Relations::Embedded::Many do
3741
3836
  end
3742
3837
 
3743
3838
  it "should remove from collection" do
3744
- artist.labels.should be_empty
3839
+ expect(artist.labels).to be_empty
3745
3840
  end
3746
3841
  end
3747
3842
  end
@@ -3764,7 +3859,7 @@ describe Mongoid::Relations::Embedded::Many do
3764
3859
  end
3765
3860
 
3766
3861
  it "does not push the embedded documents twice" do
3767
- server.reload.filesystems.count.should eq(1)
3862
+ expect(server.reload.filesystems.count).to eq(1)
3768
3863
  end
3769
3864
  end
3770
3865
  end
@@ -3792,11 +3887,11 @@ describe Mongoid::Relations::Embedded::Many do
3792
3887
  end
3793
3888
 
3794
3889
  it "creates proper documents from the db" do
3795
- record.name.should eq("Moderat")
3890
+ expect(record.name).to eq("Moderat")
3796
3891
  end
3797
3892
 
3798
3893
  it "assigns ids to the documents" do
3799
- record.id.should_not be_nil
3894
+ expect(record.id).to_not be_nil
3800
3895
  end
3801
3896
 
3802
3897
  context "when subsequently updating the documents" do
@@ -3806,11 +3901,11 @@ describe Mongoid::Relations::Embedded::Many do
3806
3901
  end
3807
3902
 
3808
3903
  it "updates the document" do
3809
- record.name.should eq("Apparat")
3904
+ expect(record.name).to eq("Apparat")
3810
3905
  end
3811
3906
 
3812
3907
  it "persists the change" do
3813
- record.reload.name.should eq("Apparat")
3908
+ expect(record.reload.name).to eq("Apparat")
3814
3909
  end
3815
3910
  end
3816
3911
  end
@@ -3835,7 +3930,7 @@ describe Mongoid::Relations::Embedded::Many do
3835
3930
  end
3836
3931
 
3837
3932
  it "keeps the proxy extensions when remarshalling" do
3838
- loaded.extension.should eq("Testing")
3933
+ expect(loaded.extension).to eq("Testing")
3839
3934
  end
3840
3935
  end
3841
3936
  end