mongoid 3.1.7 → 4.0.0.alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (521) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +317 -11
  3. data/README.md +4 -5
  4. data/lib/config/locales/en.yml +9 -12
  5. data/lib/mongoid.rb +6 -75
  6. data/lib/mongoid/atomic.rb +0 -11
  7. data/lib/mongoid/atomic/paths/embedded.rb +0 -30
  8. data/lib/mongoid/atomic/paths/root.rb +0 -13
  9. data/lib/mongoid/attributes.rb +30 -108
  10. data/lib/mongoid/attributes/dynamic.rb +154 -0
  11. data/lib/mongoid/attributes/nested.rb +82 -0
  12. data/lib/mongoid/attributes/processing.rb +13 -66
  13. data/lib/mongoid/{dirty.rb → changeable.rb} +5 -2
  14. data/lib/mongoid/composable.rb +104 -0
  15. data/lib/mongoid/config.rb +3 -9
  16. data/lib/mongoid/config/options.rb +1 -1
  17. data/lib/mongoid/contextual/aggregable/mongo.rb +5 -9
  18. data/lib/mongoid/contextual/atomic.rb +53 -53
  19. data/lib/mongoid/contextual/command.rb +26 -0
  20. data/lib/mongoid/contextual/map_reduce.rb +1 -1
  21. data/lib/mongoid/contextual/memory.rb +6 -5
  22. data/lib/mongoid/contextual/mongo.rb +59 -28
  23. data/lib/mongoid/contextual/text_search.rb +180 -0
  24. data/lib/mongoid/copyable.rb +2 -3
  25. data/lib/mongoid/criteria.rb +13 -33
  26. data/lib/mongoid/criteria/{#findable.rb# → findable.rb} +0 -2
  27. data/lib/mongoid/{criterion/inspection.rb → criteria/inspectable.rb} +2 -2
  28. data/lib/mongoid/{criterion → criteria}/marshalable.rb +3 -1
  29. data/lib/mongoid/{criterion → criteria}/modifiable.rb +1 -1
  30. data/lib/mongoid/{criterion/scoping.rb → criteria/scopable.rb} +2 -2
  31. data/lib/mongoid/document.rb +28 -12
  32. data/lib/mongoid/errors.rb +1 -1
  33. data/lib/mongoid/errors/document_not_found.rb +2 -1
  34. data/lib/mongoid/errors/invalid_value.rb +16 -0
  35. data/lib/mongoid/errors/mongoid_error.rb +1 -1
  36. data/lib/mongoid/extensions.rb +2 -7
  37. data/lib/mongoid/extensions/array.rb +2 -2
  38. data/lib/mongoid/extensions/boolean.rb +14 -17
  39. data/lib/mongoid/extensions/float.rb +1 -0
  40. data/lib/mongoid/extensions/hash.rb +1 -1
  41. data/lib/mongoid/extensions/object.rb +4 -4
  42. data/lib/mongoid/extensions/object_id.rb +5 -5
  43. data/lib/mongoid/extensions/range.rb +8 -2
  44. data/lib/mongoid/extensions/string.rb +5 -17
  45. data/lib/mongoid/extensions/time.rb +2 -2
  46. data/lib/mongoid/factory.rb +3 -3
  47. data/lib/mongoid/fields.rb +9 -8
  48. data/lib/mongoid/fields/foreign_key.rb +3 -3
  49. data/lib/mongoid/fields/standard.rb +4 -16
  50. data/lib/mongoid/fields/validators/macro.rb +11 -3
  51. data/lib/mongoid/{finders.rb → findable.rb} +6 -2
  52. data/lib/mongoid/{indexes.rb → indexable.rb} +50 -55
  53. data/lib/mongoid/indexable/specification.rb +104 -0
  54. data/lib/mongoid/{indexes → indexable}/validators/options.rb +2 -1
  55. data/lib/mongoid/{inspection.rb → inspectable.rb} +15 -11
  56. data/lib/mongoid/{callbacks.rb → interceptable.rb} +3 -52
  57. data/lib/mongoid/log_subscriber.rb +22 -0
  58. data/lib/mongoid/matchable.rb +152 -0
  59. data/lib/mongoid/{matchers → matchable}/all.rb +1 -1
  60. data/lib/mongoid/{matchers → matchable}/and.rb +2 -2
  61. data/lib/mongoid/{matchers → matchable}/default.rb +1 -1
  62. data/lib/mongoid/{matchers → matchable}/exists.rb +1 -1
  63. data/lib/mongoid/{matchers → matchable}/gt.rb +1 -1
  64. data/lib/mongoid/{matchers → matchable}/gte.rb +1 -1
  65. data/lib/mongoid/{matchers → matchable}/in.rb +2 -2
  66. data/lib/mongoid/{matchers → matchable}/lt.rb +1 -1
  67. data/lib/mongoid/{matchers → matchable}/lte.rb +1 -1
  68. data/lib/mongoid/{matchers → matchable}/ne.rb +1 -1
  69. data/lib/mongoid/{matchers → matchable}/nin.rb +3 -2
  70. data/lib/mongoid/{matchers → matchable}/or.rb +2 -2
  71. data/lib/mongoid/{matchers → matchable}/size.rb +1 -1
  72. data/lib/mongoid/persistable.rb +212 -0
  73. data/lib/mongoid/persistable/creatable.rb +188 -0
  74. data/lib/mongoid/persistable/deletable.rb +148 -0
  75. data/lib/mongoid/persistable/destroyable.rb +55 -0
  76. data/lib/mongoid/persistable/incrementable.rb +36 -0
  77. data/lib/mongoid/persistable/logical.rb +38 -0
  78. data/lib/mongoid/persistable/poppable.rb +39 -0
  79. data/lib/mongoid/persistable/pullable.rb +55 -0
  80. data/lib/mongoid/persistable/pushable.rb +62 -0
  81. data/lib/mongoid/persistable/renamable.rb +35 -0
  82. data/lib/mongoid/persistable/savable.rb +52 -0
  83. data/lib/mongoid/persistable/settable.rb +33 -0
  84. data/lib/mongoid/persistable/unsettable.rb +36 -0
  85. data/lib/mongoid/persistable/updatable.rb +151 -0
  86. data/lib/mongoid/persistable/upsertable.rb +55 -0
  87. data/lib/mongoid/positional.rb +71 -0
  88. data/lib/mongoid/railtie.rb +32 -45
  89. data/lib/mongoid/railties/database.rake +12 -6
  90. data/lib/mongoid/relations.rb +3 -3
  91. data/lib/mongoid/relations/accessors.rb +13 -46
  92. data/lib/mongoid/relations/auto_save.rb +15 -36
  93. data/lib/mongoid/relations/binding.rb +0 -23
  94. data/lib/mongoid/relations/bindings/embedded/many.rb +1 -3
  95. data/lib/mongoid/relations/bindings/referenced/in.rb +3 -8
  96. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +3 -1
  97. data/lib/mongoid/relations/builder.rb +1 -1
  98. data/lib/mongoid/relations/builders.rb +2 -2
  99. data/lib/mongoid/relations/builders/nested_attributes/many.rb +10 -13
  100. data/lib/mongoid/relations/builders/nested_attributes/one.rb +4 -5
  101. data/lib/mongoid/relations/builders/referenced/in.rb +1 -1
  102. data/lib/mongoid/relations/builders/referenced/many.rb +1 -2
  103. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +1 -2
  104. data/lib/mongoid/relations/builders/referenced/one.rb +1 -1
  105. data/lib/mongoid/relations/cascading.rb +3 -5
  106. data/lib/mongoid/relations/constraint.rb +1 -1
  107. data/lib/mongoid/relations/conversions.rb +1 -1
  108. data/lib/mongoid/relations/counter_cache.rb +39 -15
  109. data/lib/mongoid/relations/eager.rb +47 -0
  110. data/lib/mongoid/relations/eager/base.rb +57 -0
  111. data/lib/mongoid/relations/eager/belongs_to.rb +30 -0
  112. data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +40 -0
  113. data/lib/mongoid/relations/eager/has_many.rb +37 -0
  114. data/lib/mongoid/relations/eager/has_one.rb +29 -0
  115. data/lib/mongoid/relations/embedded/batchable.rb +3 -4
  116. data/lib/mongoid/relations/embedded/many.rb +7 -27
  117. data/lib/mongoid/relations/macros.rb +2 -4
  118. data/lib/mongoid/relations/many.rb +30 -31
  119. data/lib/mongoid/relations/metadata.rb +6 -75
  120. data/lib/mongoid/relations/nested_builder.rb +2 -2
  121. data/lib/mongoid/relations/options.rb +1 -0
  122. data/lib/mongoid/relations/polymorphic.rb +0 -1
  123. data/lib/mongoid/relations/proxy.rb +10 -32
  124. data/lib/mongoid/relations/referenced/in.rb +2 -18
  125. data/lib/mongoid/relations/referenced/many.rb +9 -22
  126. data/lib/mongoid/relations/referenced/many_to_many.rb +10 -33
  127. data/lib/mongoid/relations/referenced/one.rb +2 -21
  128. data/lib/mongoid/relations/synchronization.rb +3 -3
  129. data/lib/mongoid/relations/touchable.rb +33 -0
  130. data/lib/mongoid/{reloading.rb → reloadable.rb} +6 -4
  131. data/lib/mongoid/{scoping.rb → scopable.rb} +26 -3
  132. data/lib/mongoid/selectable.rb +59 -0
  133. data/lib/mongoid/{serialization.rb → serializable.rb} +10 -1
  134. data/lib/mongoid/sessions.rb +37 -345
  135. data/lib/mongoid/sessions/factory.rb +2 -0
  136. data/lib/mongoid/sessions/options.rb +176 -0
  137. data/lib/mongoid/sessions/storage_options.rb +140 -0
  138. data/lib/mongoid/sessions/thread_options.rb +19 -0
  139. data/lib/mongoid/sessions/validators/storage.rb +15 -1
  140. data/lib/mongoid/{sharding.rb → shardable.rb} +5 -1
  141. data/lib/mongoid/support/query_counter.rb +23 -0
  142. data/lib/mongoid/threaded.rb +0 -110
  143. data/lib/mongoid/threaded/lifecycle.rb +0 -28
  144. data/lib/mongoid/timestamps/updated/short.rb +2 -2
  145. data/lib/mongoid/{hierarchy.rb → traversable.rb} +9 -5
  146. data/lib/mongoid/{validations.rb → validatable.rb} +23 -9
  147. data/lib/mongoid/{validations → validatable}/associated.rb +3 -1
  148. data/lib/mongoid/{validations → validatable}/format.rb +1 -1
  149. data/lib/mongoid/{validations → validatable}/length.rb +1 -1
  150. data/lib/mongoid/{validations → validatable}/localizable.rb +1 -1
  151. data/lib/mongoid/{validations → validatable}/macros.rb +4 -3
  152. data/lib/mongoid/{validations → validatable}/presence.rb +1 -1
  153. data/lib/mongoid/{validations → validatable}/queryable.rb +1 -2
  154. data/lib/mongoid/{validations → validatable}/uniqueness.rb +3 -3
  155. data/lib/mongoid/version.rb +1 -1
  156. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +9 -13
  157. data/lib/rails/generators/mongoid/model/model_generator.rb +0 -1
  158. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +0 -3
  159. data/lib/rails/generators/mongoid_generator.rb +3 -40
  160. data/lib/rails/mongoid.rb +59 -57
  161. data/lib/support/ruby_version.rb +1 -1
  162. data/spec/app/models/account.rb +2 -6
  163. data/spec/app/models/acolyte.rb +1 -0
  164. data/spec/app/models/actor.rb +0 -1
  165. data/spec/app/models/address.rb +6 -1
  166. data/spec/app/models/animal.rb +1 -1
  167. data/spec/app/models/appointment.rb +2 -2
  168. data/spec/app/models/article.rb +1 -4
  169. data/spec/app/models/audio.rb +5 -0
  170. data/spec/app/models/author.rb +0 -2
  171. data/spec/app/models/band.rb +3 -2
  172. data/spec/app/models/bar.rb +1 -0
  173. data/spec/app/models/book.rb +1 -0
  174. data/spec/app/models/building.rb +0 -2
  175. data/spec/app/models/building_address.rb +0 -2
  176. data/spec/app/models/bus.rb +1 -1
  177. data/spec/app/models/canvas.rb +1 -1
  178. data/spec/app/models/contractor.rb +0 -2
  179. data/spec/app/models/country_code.rb +1 -1
  180. data/spec/app/models/definition.rb +2 -2
  181. data/spec/app/models/dragon.rb +4 -0
  182. data/spec/app/models/drug.rb +1 -3
  183. data/spec/app/models/dungeon.rb +4 -0
  184. data/spec/app/models/filesystem.rb +1 -0
  185. data/spec/app/models/fish.rb +0 -1
  186. data/spec/app/models/fruits.rb +6 -0
  187. data/spec/app/models/game.rb +0 -2
  188. data/spec/app/models/house.rb +0 -2
  189. data/spec/app/models/item.rb +1 -5
  190. data/spec/app/models/jar.rb +1 -1
  191. data/spec/app/models/label.rb +4 -4
  192. data/spec/app/models/login.rb +1 -1
  193. data/spec/app/models/movie.rb +1 -0
  194. data/spec/app/models/name.rb +3 -3
  195. data/spec/app/models/note.rb +1 -1
  196. data/spec/app/models/oscar.rb +1 -1
  197. data/spec/app/models/parent_doc.rb +1 -1
  198. data/spec/app/models/person.rb +13 -8
  199. data/spec/app/models/phone.rb +1 -3
  200. data/spec/app/models/player.rb +1 -1
  201. data/spec/app/models/post.rb +2 -1
  202. data/spec/app/models/quiz.rb +0 -3
  203. data/spec/app/models/record.rb +5 -5
  204. data/spec/app/models/registry.rb +1 -1
  205. data/spec/app/models/server.rb +1 -1
  206. data/spec/app/models/service.rb +3 -3
  207. data/spec/app/models/sound.rb +5 -0
  208. data/spec/app/models/template.rb +1 -1
  209. data/spec/app/models/title.rb +0 -1
  210. data/spec/app/models/track.rb +5 -5
  211. data/spec/app/models/tree.rb +1 -1
  212. data/spec/app/models/video.rb +0 -4
  213. data/spec/app/models/wiki_page.rb +1 -4
  214. data/spec/app/models/word.rb +3 -0
  215. data/spec/app/models/word_origin.rb +1 -1
  216. data/spec/config/mongoid.yml +7 -8
  217. data/spec/helpers.rb +18 -0
  218. data/spec/mongoid/atomic/modifiers_spec.rb +22 -22
  219. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +8 -49
  220. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +7 -49
  221. data/spec/mongoid/atomic/paths/root_spec.rb +3 -61
  222. data/spec/mongoid/atomic/paths_spec.rb +19 -19
  223. data/spec/mongoid/atomic_spec.rb +19 -19
  224. data/spec/mongoid/{nested_attributes_spec.rb → attributes/nested_spec.rb} +335 -448
  225. data/spec/mongoid/attributes/readonly_spec.rb +16 -16
  226. data/spec/mongoid/attributes_spec.rb +188 -434
  227. data/spec/mongoid/{dirty_spec.rb → changeable_spec.rb} +117 -148
  228. data/spec/mongoid/{components_spec.rb → composable_spec.rb} +3 -3
  229. data/spec/mongoid/config/environment_spec.rb +3 -3
  230. data/spec/mongoid/config/options_spec.rb +6 -6
  231. data/spec/mongoid/config_spec.rb +24 -48
  232. data/spec/mongoid/contextual/aggregable/memory_spec.rb +12 -12
  233. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +46 -38
  234. data/spec/mongoid/contextual/atomic_spec.rb +60 -56
  235. data/spec/mongoid/contextual/find_and_modify_spec.rb +14 -14
  236. data/spec/mongoid/contextual/geo_near_spec.rb +22 -22
  237. data/spec/mongoid/contextual/map_reduce_spec.rb +27 -27
  238. data/spec/mongoid/contextual/memory_spec.rb +94 -94
  239. data/spec/mongoid/contextual/mongo_spec.rb +225 -139
  240. data/spec/mongoid/contextual/text_search_spec.rb +207 -0
  241. data/spec/mongoid/copyable_spec.rb +56 -68
  242. data/spec/mongoid/criteria/findable_spec.rb +991 -0
  243. data/spec/mongoid/{criterion/inspection_spec.rb → criteria/inspectable_spec.rb} +5 -5
  244. data/spec/mongoid/{criterion → criteria}/marshalable_spec.rb +2 -2
  245. data/spec/mongoid/criteria/modifiable_spec.rb +1063 -0
  246. data/spec/mongoid/{criterion/scoping_spec.rb → criteria/scopable_spec.rb} +31 -31
  247. data/spec/mongoid/criteria_spec.rb +530 -2207
  248. data/spec/mongoid/document_spec.rb +166 -120
  249. data/spec/mongoid/equality_spec.rb +22 -22
  250. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +3 -3
  251. data/spec/mongoid/errors/callback_spec.rb +3 -3
  252. data/spec/mongoid/errors/delete_restriction_spec.rb +3 -3
  253. data/spec/mongoid/errors/document_not_found_spec.rb +11 -11
  254. data/spec/mongoid/errors/eager_load_spec.rb +3 -3
  255. data/spec/mongoid/errors/invalid_collection_spec.rb +3 -3
  256. data/spec/mongoid/errors/invalid_config_option_spec.rb +3 -3
  257. data/spec/mongoid/errors/invalid_field_option_spec.rb +3 -3
  258. data/spec/mongoid/errors/invalid_field_spec.rb +3 -3
  259. data/spec/mongoid/errors/invalid_find_spec.rb +3 -3
  260. data/spec/mongoid/errors/invalid_includes_spec.rb +3 -3
  261. data/spec/mongoid/errors/invalid_index_spec.rb +3 -3
  262. data/spec/mongoid/errors/invalid_options_spec.rb +3 -3
  263. data/spec/mongoid/errors/invalid_path_spec.rb +3 -3
  264. data/spec/mongoid/errors/invalid_scope_spec.rb +3 -3
  265. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -3
  266. data/spec/mongoid/errors/invalid_storage_options_spec.rb +3 -3
  267. data/spec/mongoid/errors/invalid_time_spec.rb +3 -3
  268. data/spec/mongoid/errors/inverse_not_found_spec.rb +3 -3
  269. data/spec/mongoid/errors/mixed_relations_spec.rb +3 -3
  270. data/spec/mongoid/errors/mixed_session_configuration_spec.rb +3 -3
  271. data/spec/mongoid/errors/mongoid_error_spec.rb +7 -7
  272. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +3 -3
  273. data/spec/mongoid/errors/no_environment_spec.rb +3 -3
  274. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +3 -3
  275. data/spec/mongoid/errors/no_metadata_spec.rb +3 -3
  276. data/spec/mongoid/errors/no_parent_spec.rb +3 -3
  277. data/spec/mongoid/errors/no_session_config_spec.rb +3 -3
  278. data/spec/mongoid/errors/no_session_database_spec.rb +3 -3
  279. data/spec/mongoid/errors/no_session_hosts_spec.rb +3 -3
  280. data/spec/mongoid/errors/no_sessions_config_spec.rb +3 -3
  281. data/spec/mongoid/errors/readonly_attribute_spec.rb +3 -3
  282. data/spec/mongoid/errors/scope_overwrite_spec.rb +3 -3
  283. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +3 -3
  284. data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -5
  285. data/spec/mongoid/errors/unsaved_document_spec.rb +3 -3
  286. data/spec/mongoid/errors/unsupported_javascript_spec.rb +3 -3
  287. data/spec/mongoid/errors/validations_spec.rb +7 -7
  288. data/spec/mongoid/extensions/array_spec.rb +61 -61
  289. data/spec/mongoid/extensions/big_decimal_spec.rb +11 -11
  290. data/spec/mongoid/extensions/binary_spec.rb +12 -12
  291. data/spec/mongoid/extensions/boolean_spec.rb +18 -18
  292. data/spec/mongoid/extensions/date_spec.rb +13 -13
  293. data/spec/mongoid/extensions/date_time_spec.rb +9 -9
  294. data/spec/mongoid/extensions/false_class_spec.rb +5 -5
  295. data/spec/mongoid/extensions/float_spec.rb +29 -15
  296. data/spec/mongoid/extensions/hash_spec.rb +29 -29
  297. data/spec/mongoid/extensions/integer_spec.rb +15 -15
  298. data/spec/mongoid/extensions/module_spec.rb +2 -2
  299. data/spec/mongoid/extensions/nil_class_spec.rb +1 -1
  300. data/spec/mongoid/extensions/object_id_spec.rb +134 -134
  301. data/spec/mongoid/extensions/object_spec.rb +26 -26
  302. data/spec/mongoid/extensions/range_spec.rb +61 -12
  303. data/spec/mongoid/extensions/regexp_spec.rb +4 -4
  304. data/spec/mongoid/extensions/set_spec.rb +4 -4
  305. data/spec/mongoid/extensions/string_spec.rb +35 -46
  306. data/spec/mongoid/extensions/symbol_spec.rb +9 -9
  307. data/spec/mongoid/extensions/time_spec.rb +49 -49
  308. data/spec/mongoid/extensions/time_with_zone_spec.rb +34 -34
  309. data/spec/mongoid/extensions/true_class_spec.rb +5 -5
  310. data/spec/mongoid/extensions_spec.rb +15 -0
  311. data/spec/mongoid/factory_spec.rb +15 -15
  312. data/spec/mongoid/fields/foreign_key_spec.rb +73 -66
  313. data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +15 -15
  314. data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +22 -22
  315. data/spec/mongoid/fields/localized_spec.rb +23 -23
  316. data/spec/mongoid/fields/standard_spec.rb +12 -12
  317. data/spec/mongoid/fields_spec.rb +168 -209
  318. data/spec/mongoid/{finders_spec.rb → findable_spec.rb} +62 -27
  319. data/spec/mongoid/indexable/specification_spec.rb +102 -0
  320. data/spec/mongoid/{indexes_spec.rb → indexable_spec.rb} +171 -51
  321. data/spec/mongoid/{inspection_spec.rb → inspectable_spec.rb} +6 -14
  322. data/spec/mongoid/{callbacks_spec.rb → interceptable_spec.rb} +105 -105
  323. data/spec/mongoid/log_subscriber_spec.rb +74 -0
  324. data/spec/mongoid/loggable_spec.rb +1 -1
  325. data/spec/mongoid/{matchers → matchable}/all_spec.rb +4 -4
  326. data/spec/mongoid/{matchers → matchable}/and_spec.rb +11 -11
  327. data/spec/mongoid/{matchers → matchable}/default_spec.rb +15 -15
  328. data/spec/mongoid/{matchers → matchable}/exists_spec.rb +5 -5
  329. data/spec/mongoid/{matchers → matchable}/gt_spec.rb +9 -8
  330. data/spec/mongoid/{matchers → matchable}/gte_spec.rb +7 -7
  331. data/spec/mongoid/matchable/in_spec.rb +49 -0
  332. data/spec/mongoid/{matchers → matchable}/lt_spec.rb +7 -7
  333. data/spec/mongoid/{matchers → matchable}/lte_spec.rb +7 -7
  334. data/spec/mongoid/{matchers → matchable}/ne_spec.rb +3 -3
  335. data/spec/mongoid/matchable/nin_spec.rb +48 -0
  336. data/spec/mongoid/{matchers → matchable}/or_spec.rb +6 -6
  337. data/spec/mongoid/{matchers → matchable}/size_spec.rb +3 -3
  338. data/spec/mongoid/{matchers_spec.rb → matchable_spec.rb} +41 -41
  339. data/spec/mongoid/persistable/creatable_spec.rb +512 -0
  340. data/spec/mongoid/persistable/deletable_spec.rb +205 -0
  341. data/spec/mongoid/persistable/destroyable_spec.rb +148 -0
  342. data/spec/mongoid/persistable/incrementable_spec.rb +173 -0
  343. data/spec/mongoid/persistable/logical_spec.rb +143 -0
  344. data/spec/mongoid/persistable/poppable_spec.rb +115 -0
  345. data/spec/mongoid/persistable/pullable_spec.rb +228 -0
  346. data/spec/mongoid/persistable/pushable_spec.rb +258 -0
  347. data/spec/mongoid/persistable/renamable_spec.rb +135 -0
  348. data/spec/mongoid/persistable/savable_spec.rb +432 -0
  349. data/spec/mongoid/persistable/settable_spec.rb +139 -0
  350. data/spec/mongoid/persistable/unsettable_spec.rb +155 -0
  351. data/spec/mongoid/persistable/updatable_spec.rb +558 -0
  352. data/spec/mongoid/persistable/upsertable_spec.rb +106 -0
  353. data/spec/mongoid/persistable_spec.rb +206 -0
  354. data/spec/mongoid/{atomic/positionable_spec.rb → positional_spec.rb} +19 -14
  355. data/spec/mongoid/railties/document_spec.rb +2 -2
  356. data/spec/mongoid/relations/accessors_spec.rb +53 -145
  357. data/spec/mongoid/relations/auto_save_spec.rb +36 -16
  358. data/spec/mongoid/relations/bindings/embedded/in_spec.rb +6 -6
  359. data/spec/mongoid/relations/bindings/embedded/many_spec.rb +2 -2
  360. data/spec/mongoid/relations/bindings/embedded/one_spec.rb +3 -3
  361. data/spec/mongoid/relations/bindings/referenced/in_spec.rb +12 -12
  362. data/spec/mongoid/relations/bindings/referenced/many_spec.rb +6 -6
  363. data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +9 -9
  364. data/spec/mongoid/relations/bindings/referenced/one_spec.rb +6 -6
  365. data/spec/mongoid/relations/builders/embedded/in_spec.rb +4 -4
  366. data/spec/mongoid/relations/builders/embedded/many_spec.rb +18 -18
  367. data/spec/mongoid/relations/builders/embedded/one_spec.rb +11 -11
  368. data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +12 -13
  369. data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +14 -14
  370. data/spec/mongoid/relations/builders/referenced/in_spec.rb +22 -33
  371. data/spec/mongoid/relations/builders/referenced/many_spec.rb +15 -15
  372. data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +18 -18
  373. data/spec/mongoid/relations/builders/referenced/one_spec.rb +11 -24
  374. data/spec/mongoid/relations/builders_spec.rb +21 -21
  375. data/spec/mongoid/relations/cascading/delete_spec.rb +7 -7
  376. data/spec/mongoid/relations/cascading/destroy_spec.rb +2 -2
  377. data/spec/mongoid/relations/cascading/nullify_spec.rb +2 -2
  378. data/spec/mongoid/relations/cascading/restrict_spec.rb +3 -3
  379. data/spec/mongoid/relations/cascading_spec.rb +16 -16
  380. data/spec/mongoid/relations/constraint_spec.rb +8 -7
  381. data/spec/mongoid/relations/conversions_spec.rb +16 -14
  382. data/spec/mongoid/relations/counter_cache_spec.rb +85 -0
  383. data/spec/mongoid/relations/cyclic_spec.rb +18 -18
  384. data/spec/mongoid/relations/eager/belongs_to_spec.rb +154 -0
  385. data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +143 -0
  386. data/spec/mongoid/relations/eager/has_many_spec.rb +207 -0
  387. data/spec/mongoid/relations/eager/has_one_spec.rb +163 -0
  388. data/spec/mongoid/relations/eager_spec.rb +228 -0
  389. data/spec/mongoid/relations/embedded/dirty_spec.rb +8 -8
  390. data/spec/mongoid/relations/embedded/in_spec.rb +55 -56
  391. data/spec/mongoid/relations/embedded/many_spec.rb +357 -367
  392. data/spec/mongoid/relations/embedded/one_spec.rb +98 -139
  393. data/spec/mongoid/relations/macros_spec.rb +108 -102
  394. data/spec/mongoid/relations/metadata_spec.rb +147 -241
  395. data/spec/mongoid/relations/options_spec.rb +1 -1
  396. data/spec/mongoid/relations/polymorphic_spec.rb +13 -17
  397. data/spec/mongoid/relations/proxy_spec.rb +2 -2
  398. data/spec/mongoid/relations/referenced/in_spec.rb +128 -303
  399. data/spec/mongoid/relations/referenced/many_spec.rb +379 -522
  400. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +345 -417
  401. data/spec/mongoid/relations/referenced/one_spec.rb +148 -263
  402. data/spec/mongoid/relations/reflections_spec.rb +6 -6
  403. data/spec/mongoid/relations/synchronization_spec.rb +46 -50
  404. data/spec/mongoid/relations/targets/enumerable_spec.rb +116 -116
  405. data/spec/mongoid/relations/touchable_spec.rb +296 -0
  406. data/spec/mongoid/relations_spec.rb +16 -15
  407. data/spec/mongoid/{reloading_spec.rb → reloadable_spec.rb} +20 -60
  408. data/spec/mongoid/{scoping_spec.rb → scopable_spec.rb} +74 -126
  409. data/spec/mongoid/selectable_spec.rb +134 -0
  410. data/spec/mongoid/{serialization_spec.rb → serializable_spec.rb} +111 -82
  411. data/spec/mongoid/sessions/factory_spec.rb +49 -28
  412. data/spec/mongoid/sessions/mongo_uri_spec.rb +7 -7
  413. data/spec/mongoid/sessions/options_spec.rb +92 -0
  414. data/spec/mongoid/sessions_spec.rb +288 -177
  415. data/spec/mongoid/{sharding_spec.rb → shardable_spec.rb} +8 -8
  416. data/spec/mongoid/state_spec.rb +10 -10
  417. data/spec/mongoid/threaded_spec.rb +17 -70
  418. data/spec/mongoid/timestamps/created/short_spec.rb +6 -6
  419. data/spec/mongoid/timestamps/created_spec.rb +5 -5
  420. data/spec/mongoid/timestamps/updated/short_spec.rb +10 -10
  421. data/spec/mongoid/timestamps/updated_spec.rb +8 -12
  422. data/spec/mongoid/timestamps_spec.rb +7 -11
  423. data/spec/mongoid/{hierarchy_spec.rb → traversable_spec.rb} +19 -19
  424. data/spec/mongoid/{validations → validatable}/associated_spec.rb +18 -18
  425. data/spec/mongoid/{validations → validatable}/format_spec.rb +6 -6
  426. data/spec/mongoid/{validations → validatable}/length_spec.rb +7 -7
  427. data/spec/mongoid/{validations → validatable}/numericality_spec.rb +1 -1
  428. data/spec/mongoid/{validations → validatable}/presence_spec.rb +31 -38
  429. data/spec/mongoid/{validations → validatable}/uniqueness_spec.rb +126 -183
  430. data/spec/mongoid/{validations_spec.rb → validatable_spec.rb} +28 -28
  431. data/spec/mongoid_spec.rb +8 -8
  432. data/spec/rails/mongoid_spec.rb +72 -87
  433. data/spec/spec_helper.rb +19 -17
  434. metadata +261 -283
  435. data/lib/mongoid/atomic/positionable.rb +0 -73
  436. data/lib/mongoid/components.rb +0 -92
  437. data/lib/mongoid/config/inflections.rb +0 -6
  438. data/lib/mongoid/contextual/eager.rb +0 -158
  439. data/lib/mongoid/criterion/findable.rb +0 -179
  440. data/lib/mongoid/errors/versioning_not_on_root.rb +0 -23
  441. data/lib/mongoid/identity_map.rb +0 -163
  442. data/lib/mongoid/json.rb +0 -16
  443. data/lib/mongoid/matchers.rb +0 -32
  444. data/lib/mongoid/matchers/strategies.rb +0 -97
  445. data/lib/mongoid/multi_parameter_attributes.rb +0 -105
  446. data/lib/mongoid/nested_attributes.rb +0 -78
  447. data/lib/mongoid/observer.rb +0 -192
  448. data/lib/mongoid/paranoia.rb +0 -136
  449. data/lib/mongoid/persistence.rb +0 -357
  450. data/lib/mongoid/persistence/atomic.rb +0 -231
  451. data/lib/mongoid/persistence/atomic/add_to_set.rb +0 -47
  452. data/lib/mongoid/persistence/atomic/bit.rb +0 -35
  453. data/lib/mongoid/persistence/atomic/inc.rb +0 -45
  454. data/lib/mongoid/persistence/atomic/operation.rb +0 -154
  455. data/lib/mongoid/persistence/atomic/pop.rb +0 -32
  456. data/lib/mongoid/persistence/atomic/pull.rb +0 -32
  457. data/lib/mongoid/persistence/atomic/pull_all.rb +0 -32
  458. data/lib/mongoid/persistence/atomic/push.rb +0 -25
  459. data/lib/mongoid/persistence/atomic/push_all.rb +0 -25
  460. data/lib/mongoid/persistence/atomic/rename.rb +0 -30
  461. data/lib/mongoid/persistence/atomic/sets.rb +0 -28
  462. data/lib/mongoid/persistence/atomic/unset.rb +0 -27
  463. data/lib/mongoid/persistence/deletion.rb +0 -31
  464. data/lib/mongoid/persistence/insertion.rb +0 -38
  465. data/lib/mongoid/persistence/modification.rb +0 -35
  466. data/lib/mongoid/persistence/operations.rb +0 -214
  467. data/lib/mongoid/persistence/operations/embedded/insert.rb +0 -46
  468. data/lib/mongoid/persistence/operations/embedded/remove.rb +0 -43
  469. data/lib/mongoid/persistence/operations/insert.rb +0 -34
  470. data/lib/mongoid/persistence/operations/remove.rb +0 -33
  471. data/lib/mongoid/persistence/operations/update.rb +0 -59
  472. data/lib/mongoid/persistence/operations/upsert.rb +0 -28
  473. data/lib/mongoid/persistence/upsertion.rb +0 -31
  474. data/lib/mongoid/unit_of_work.rb +0 -61
  475. data/lib/mongoid/versioning.rb +0 -217
  476. data/lib/rack/mongoid.rb +0 -2
  477. data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
  478. data/lib/rails/generators/mongoid/observer/observer_generator.rb +0 -17
  479. data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +0 -4
  480. data/spec/app/models/actor_observer.rb +0 -15
  481. data/spec/app/models/callback_recorder.rb +0 -25
  482. data/spec/app/models/draft.rb +0 -9
  483. data/spec/app/models/paranoid_phone.rb +0 -25
  484. data/spec/app/models/paranoid_post.rb +0 -36
  485. data/spec/app/models/phone_observer.rb +0 -6
  486. data/spec/mongoid/#atomic_spec.rb# +0 -365
  487. data/spec/mongoid/attributes/processing_spec.rb +0 -149
  488. data/spec/mongoid/criterion/destructive_spec.rb +0 -101
  489. data/spec/mongoid/criterion/modifiable_spec.rb +0 -409
  490. data/spec/mongoid/criterion/modification_spec.rb +0 -402
  491. data/spec/mongoid/errors/versioning_not_on_root_spec.rb +0 -29
  492. data/spec/mongoid/identity_map_spec.rb +0 -564
  493. data/spec/mongoid/json_spec.rb +0 -33
  494. data/spec/mongoid/matchers/in_spec.rb +0 -25
  495. data/spec/mongoid/matchers/nin_spec.rb +0 -25
  496. data/spec/mongoid/multi_parameter_attributes_spec.rb +0 -128
  497. data/spec/mongoid/observer_spec.rb +0 -290
  498. data/spec/mongoid/paranoia_spec.rb +0 -759
  499. data/spec/mongoid/persistence/atomic/add_to_set_spec.rb +0 -262
  500. data/spec/mongoid/persistence/atomic/bit_spec.rb +0 -88
  501. data/spec/mongoid/persistence/atomic/inc_spec.rb +0 -133
  502. data/spec/mongoid/persistence/atomic/pop_spec.rb +0 -111
  503. data/spec/mongoid/persistence/atomic/pull_all_spec.rb +0 -77
  504. data/spec/mongoid/persistence/atomic/pull_spec.rb +0 -80
  505. data/spec/mongoid/persistence/atomic/push_all_spec.rb +0 -77
  506. data/spec/mongoid/persistence/atomic/push_spec.rb +0 -77
  507. data/spec/mongoid/persistence/atomic/rename_spec.rb +0 -42
  508. data/spec/mongoid/persistence/atomic/sets_spec.rb +0 -154
  509. data/spec/mongoid/persistence/atomic/unset_spec.rb +0 -65
  510. data/spec/mongoid/persistence/atomic_spec.rb +0 -216
  511. data/spec/mongoid/persistence/operations/embedded/insert_spec.rb +0 -191
  512. data/spec/mongoid/persistence/operations/embedded/remove_spec.rb +0 -8
  513. data/spec/mongoid/persistence/operations/insert_spec.rb +0 -149
  514. data/spec/mongoid/persistence/operations/remove_spec.rb +0 -113
  515. data/spec/mongoid/persistence/operations/update_spec.rb +0 -141
  516. data/spec/mongoid/persistence/operations/upsert_spec.rb +0 -59
  517. data/spec/mongoid/persistence/operations_spec.rb +0 -313
  518. data/spec/mongoid/persistence_spec.rb +0 -2279
  519. data/spec/mongoid/unit_of_work_spec.rb +0 -196
  520. data/spec/mongoid/versioning_spec.rb +0 -540
  521. data/spec/rack/mongoid/middleware/identity_map_spec.rb +0 -72
@@ -15,7 +15,7 @@ describe Mongoid::Attributes::Readonly do
15
15
  end
16
16
 
17
17
  it "adds the field to readonly attributes" do
18
- Person.readonly_attributes.to_a.should eq([ "title" ])
18
+ expect(Person.readonly_attributes.to_a).to eq([ "title" ])
19
19
  end
20
20
  end
21
21
 
@@ -26,7 +26,7 @@ describe Mongoid::Attributes::Readonly do
26
26
  end
27
27
 
28
28
  it "adds the fields to readonly attributes" do
29
- Person.readonly_attributes.to_a.should eq([ "title", "terms" ])
29
+ expect(Person.readonly_attributes.to_a).to eq([ "title", "terms" ])
30
30
  end
31
31
  end
32
32
 
@@ -41,19 +41,19 @@ describe Mongoid::Attributes::Readonly do
41
41
  end
42
42
 
43
43
  it "sets the first readonly value" do
44
- person.title.should eq("sir")
44
+ expect(person.title).to eq("sir")
45
45
  end
46
46
 
47
47
  it "sets subsequent readonly values" do
48
- person.terms.should be_true
48
+ expect(person.terms).to be true
49
49
  end
50
50
 
51
51
  it "persists the first readonly value" do
52
- person.reload.title.should eq("sir")
52
+ expect(person.reload.title).to eq("sir")
53
53
  end
54
54
 
55
55
  it "persists subsequent readonly values" do
56
- person.reload.terms.should be_true
56
+ expect(person.reload.terms).to be true
57
57
  end
58
58
  end
59
59
 
@@ -75,11 +75,11 @@ describe Mongoid::Attributes::Readonly do
75
75
  end
76
76
 
77
77
  it "does not update the field" do
78
- person.title.should eq("sir")
78
+ expect(person.title).to eq("sir")
79
79
  end
80
80
 
81
81
  it "does not persist the changes" do
82
- person.reload.title.should eq("sir")
82
+ expect(person.reload.title).to eq("sir")
83
83
  end
84
84
  end
85
85
 
@@ -91,11 +91,11 @@ describe Mongoid::Attributes::Readonly do
91
91
  end
92
92
 
93
93
  it "does not update the field" do
94
- person.title.should eq("sir")
94
+ expect(person.title).to eq("sir")
95
95
  end
96
96
 
97
97
  it "does not persist the changes" do
98
- person.reload.title.should eq("sir")
98
+ expect(person.reload.title).to eq("sir")
99
99
  end
100
100
  end
101
101
 
@@ -107,11 +107,11 @@ describe Mongoid::Attributes::Readonly do
107
107
  end
108
108
 
109
109
  it "does not update the field" do
110
- person.title.should eq("sir")
110
+ expect(person.title).to eq("sir")
111
111
  end
112
112
 
113
113
  it "does not persist the changes" do
114
- person.reload.title.should eq("sir")
114
+ expect(person.reload.title).to eq("sir")
115
115
  end
116
116
  end
117
117
 
@@ -123,11 +123,11 @@ describe Mongoid::Attributes::Readonly do
123
123
  end
124
124
 
125
125
  it "does not update the field" do
126
- person.title.should eq("sir")
126
+ expect(person.title).to eq("sir")
127
127
  end
128
128
 
129
129
  it "does not persist the changes" do
130
- person.reload.title.should eq("sir")
130
+ expect(person.reload.title).to eq("sir")
131
131
  end
132
132
  end
133
133
 
@@ -139,11 +139,11 @@ describe Mongoid::Attributes::Readonly do
139
139
  end
140
140
 
141
141
  it "does not update the field" do
142
- person.title.should eq("sir")
142
+ expect(person.title).to eq("sir")
143
143
  end
144
144
 
145
145
  it "does not persist the changes" do
146
- person.reload.title.should eq("sir")
146
+ expect(person.reload.title).to eq("sir")
147
147
  end
148
148
  end
149
149
 
@@ -11,7 +11,7 @@ describe Mongoid::Attributes do
11
11
  end
12
12
 
13
13
  it "does not cause an infinite loop" do
14
- account.overridden.should eq("not recommended")
14
+ expect(account.overridden).to eq("not recommended")
15
15
  end
16
16
  end
17
17
  end
@@ -33,14 +33,14 @@ describe Mongoid::Attributes do
33
33
  context "when passing just the name" do
34
34
 
35
35
  it "returns the full value" do
36
- person[:desc].should eq("en" => "testing")
36
+ expect(person[:desc]).to eq("en" => "testing")
37
37
  end
38
38
  end
39
39
 
40
40
  context "when passing the name with locale" do
41
41
 
42
42
  it "returns the value for the locale" do
43
- person["desc.en"].should eq("testing")
43
+ expect(person["desc.en"]).to eq("testing")
44
44
  end
45
45
  end
46
46
  end
@@ -48,7 +48,7 @@ describe Mongoid::Attributes do
48
48
  context "when attribute does not exist" do
49
49
 
50
50
  it "returns the default value" do
51
- person[:age].should eq(100)
51
+ expect(person[:age]).to eq(100)
52
52
  end
53
53
  end
54
54
 
@@ -59,7 +59,7 @@ describe Mongoid::Attributes do
59
59
  end
60
60
 
61
61
  it "returns the value" do
62
- person[:owner_id].should eq(5)
62
+ expect(person[:owner_id]).to eq(5)
63
63
  end
64
64
  end
65
65
  end
@@ -85,7 +85,7 @@ describe Mongoid::Attributes do
85
85
  end
86
86
 
87
87
  it "returns the default value" do
88
- found[:age].should eq(100)
88
+ expect(found[:age]).to eq(100)
89
89
  end
90
90
  end
91
91
 
@@ -98,7 +98,7 @@ describe Mongoid::Attributes do
98
98
  end
99
99
 
100
100
  it "returns the default value" do
101
- person[:age].should eq(100)
101
+ expect(person[:age]).to eq(100)
102
102
  end
103
103
  end
104
104
  end
@@ -113,270 +113,31 @@ describe Mongoid::Attributes do
113
113
 
114
114
  context "when setting the attribute to nil" do
115
115
 
116
- before do
116
+ let!(:age) do
117
117
  person[:age] = nil
118
118
  end
119
119
 
120
120
  it "does not use the default value" do
121
- person.age.should be_nil
121
+ expect(person.age).to be_nil
122
+ end
123
+
124
+ it "returns the set value" do
125
+ expect(age).to be_nil
122
126
  end
123
127
  end
124
128
 
125
129
  context "when field has a default value" do
126
130
 
127
- before do
131
+ let!(:terms) do
128
132
  person[:terms] = true
129
133
  end
130
134
 
131
135
  it "allows overwriting of the default value" do
132
- person.terms.should be_true
133
- end
134
- end
135
- end
136
-
137
- describe ".attr_accessible" do
138
-
139
- context "when the field is not _id" do
140
-
141
- let(:account) do
142
- Account.new(number: 999999)
143
- end
144
-
145
- it "prevents setting via mass assignment" do
146
- account.number.should be_nil
147
- end
148
- end
149
-
150
- context "when the field is _id" do
151
-
152
- let(:account) do
153
- Account.new(_id: "ABBA")
154
- end
155
-
156
- it "prevents setting via mass assignment" do
157
- account._id.should_not eq("ABBA")
158
- end
159
- end
160
-
161
- context "when using instantiate" do
162
-
163
- let(:account) do
164
- Account.instantiate("_id" => "1", "balance" => "ABBA")
165
- end
166
-
167
- it "ignores any protected attribute" do
168
- account.balance.should eq("ABBA")
169
- end
170
- end
171
-
172
- context "when using override" do
173
-
174
- let(:account) do
175
- Account.new
176
- end
177
-
178
- it "ignores any protected attribute" do
179
- account.write_attributes({balance: "ABBA"}, false)
180
- account.balance.should eq("ABBA")
181
- end
182
- end
183
-
184
- context "when mass assignment role is indicated" do
185
-
186
- context "when attributes assigned from default role" do
187
-
188
- let(:article) do
189
- Article.new(
190
- title: "Some Title",
191
- is_rss: true,
192
- user_login: "SomeLogin"
193
- )
194
- end
195
-
196
- it "sets the title field for default role" do
197
- article.title.should eq("Some Title")
198
- end
199
-
200
- it "sets the user login field for the default role" do
201
- article.user_login.should eq("SomeLogin")
202
- end
203
-
204
- it "sets the rss field for the default role" do
205
- article.is_rss.should be_false
206
- end
207
- end
208
-
209
- context "when attributes assigned from parser role" do
210
-
211
- let(:article) do
212
- Article.new({
213
- title: "Some Title",
214
- is_rss: true,
215
- user_login: "SomeLogin"
216
- }, as: :parser
217
- )
218
- end
219
-
220
- it "sets the title field" do
221
- article.title.should eq("Some Title")
222
- end
223
-
224
- it "sets the rss field" do
225
- article.is_rss.should be_true
226
- end
227
-
228
- it "does not set the user login field" do
229
- article.user_login.should be_nil
230
- end
136
+ expect(person.terms).to be true
231
137
  end
232
138
 
233
- context "when attributes assigned without protection" do
234
-
235
- let(:article) do
236
- Article.new(
237
- { title: "Some Title",
238
- is_rss: true,
239
- user_login: "SomeLogin"
240
- }, without_protection: true
241
- )
242
- end
243
-
244
- it "sets the title field" do
245
- article.title.should eq("Some Title")
246
- end
247
-
248
- it "sets the user login field" do
249
- article.user_login.should eq("SomeLogin")
250
- end
251
-
252
- it "sets the rss field" do
253
- article.is_rss.should be_true
254
- end
255
- end
256
- end
257
- end
258
-
259
- describe ".attr_protected" do
260
-
261
- context "when the field is not _id" do
262
-
263
- let(:person) do
264
- Person.new(security_code: "ABBA")
265
- end
266
-
267
- it "prevents setting via mass assignment" do
268
- person.security_code.should be_nil
269
- end
270
- end
271
-
272
- context "when the field is _id" do
273
-
274
- let(:game) do
275
- Game.new(_id: "ABBA")
276
- end
277
-
278
- it "prevents setting via mass assignment" do
279
- game._id.should_not eq("ABBA")
280
- end
281
- end
282
-
283
- context "when using instantiate" do
284
-
285
- let(:person) do
286
- Person.instantiate("_id" => "1", "security_code" => "ABBA")
287
- end
288
-
289
- it "ignores any protected attribute" do
290
- person.security_code.should eq("ABBA")
291
- end
292
- end
293
-
294
- context "when using override" do
295
-
296
- let(:person) do
297
- Person.new
298
- end
299
-
300
- it "ignores any protected attribute" do
301
- person.write_attributes({security_code: "ABBA"}, false)
302
- person.security_code.should eq("ABBA")
303
- end
304
- end
305
-
306
- context "when mass assignment role is indicated" do
307
-
308
- let(:item) do
309
- Item.new
310
- end
311
-
312
- context "when attributes assigned from default role" do
313
-
314
- before do
315
- item.assign_attributes(
316
- title: "Some Title",
317
- is_rss: true,
318
- user_login: "SomeLogin"
319
- )
320
- end
321
-
322
- it "sets the field for the default role" do
323
- item.is_rss.should be_true
324
- end
325
-
326
- it "does not set the field for non default role title" do
327
- item.title.should be_nil
328
- end
329
-
330
- it "does not set the field for non default role user login" do
331
- item.user_login.should be_nil
332
- end
333
- end
334
-
335
- context "when attributes assigned from parser role" do
336
-
337
- before do
338
- item.assign_attributes(
339
- { title: "Some Title",
340
- is_rss: true,
341
- user_login: "SomeLogin" }, as: :parser
342
- )
343
- end
344
-
345
- it "sets the user login field for parser role" do
346
- item.user_login.should eq("SomeLogin")
347
- end
348
-
349
- it "sets the is rss field for parse role" do
350
- item.is_rss.should be_false
351
- end
352
-
353
- it "does not set the title field" do
354
- item.title.should be_nil
355
- end
356
- end
357
-
358
- context "when attributes assigned without protection" do
359
-
360
- before do
361
- item.assign_attributes(
362
- { title: "Some Title",
363
- is_rss: true,
364
- user_login: "SomeLogin"
365
- }, without_protection: true
366
- )
367
- end
368
-
369
- it "sets the title attribute" do
370
- item.title.should eq("Some Title")
371
- end
372
-
373
- it "sets the user login attribute" do
374
- item.user_login.should eq("SomeLogin")
375
- end
376
-
377
- it "sets the rss attribute" do
378
- item.is_rss.should be_true
379
- end
139
+ it "returns the set value" do
140
+ expect(terms).to eq(true)
380
141
  end
381
142
  end
382
143
  end
@@ -388,7 +149,7 @@ describe Mongoid::Attributes do
388
149
  end
389
150
 
390
151
  it "delegates to #id" do
391
- person._id.should eq(person.id)
152
+ expect(person._id).to eq(person.id)
392
153
  end
393
154
  end
394
155
 
@@ -397,9 +158,10 @@ describe Mongoid::Attributes do
397
158
  after(:all) do
398
159
  Person.field(
399
160
  :_id,
400
- type: Moped::BSON::ObjectId,
161
+ type: BSON::ObjectId,
401
162
  pre_processed: true,
402
- default: ->{ Moped::BSON::ObjectId.new }
163
+ default: ->{ BSON::ObjectId.new },
164
+ overwrite: true
403
165
  )
404
166
  end
405
167
 
@@ -408,9 +170,10 @@ describe Mongoid::Attributes do
408
170
  before(:all) do
409
171
  Person.field(
410
172
  :_id,
411
- type: Moped::BSON::ObjectId,
173
+ type: BSON::ObjectId,
412
174
  pre_processed: true,
413
- default: ->{ Moped::BSON::ObjectId.new }
175
+ default: ->{ BSON::ObjectId.new },
176
+ overwrite: true
414
177
  )
415
178
  end
416
179
 
@@ -419,7 +182,7 @@ describe Mongoid::Attributes do
419
182
  end
420
183
 
421
184
  let(:bson_id) do
422
- Moped::BSON::ObjectId.new
185
+ BSON::ObjectId.new
423
186
  end
424
187
 
425
188
  context "when providing an object id" do
@@ -429,7 +192,7 @@ describe Mongoid::Attributes do
429
192
  end
430
193
 
431
194
  it "sets the id as the object id" do
432
- person.id.should eq(bson_id)
195
+ expect(person.id).to eq(bson_id)
433
196
  end
434
197
  end
435
198
 
@@ -440,7 +203,7 @@ describe Mongoid::Attributes do
440
203
  end
441
204
 
442
205
  it "sets the id as the object id" do
443
- person.id.should eq(bson_id)
206
+ expect(person.id).to eq(bson_id)
444
207
  end
445
208
  end
446
209
 
@@ -451,7 +214,7 @@ describe Mongoid::Attributes do
451
214
  end
452
215
 
453
216
  it "sets the id as the supplied value to_s" do
454
- person.id.should eq(2)
217
+ expect(person.id).to eq(2)
455
218
  end
456
219
  end
457
220
  end
@@ -463,7 +226,8 @@ describe Mongoid::Attributes do
463
226
  :_id,
464
227
  type: String,
465
228
  pre_processed: true,
466
- default: ->{ Moped::BSON::ObjectId.new.to_s }
229
+ default: ->{ BSON::ObjectId.new.to_s },
230
+ overwrite: true
467
231
  )
468
232
  end
469
233
 
@@ -472,7 +236,7 @@ describe Mongoid::Attributes do
472
236
  end
473
237
 
474
238
  let(:bson_id) do
475
- Moped::BSON::ObjectId.new
239
+ BSON::ObjectId.new
476
240
  end
477
241
 
478
242
  context "when providing an object id" do
@@ -482,7 +246,7 @@ describe Mongoid::Attributes do
482
246
  end
483
247
 
484
248
  it "sets the id as the string of the object id" do
485
- person.id.should eq(bson_id.to_s)
249
+ expect(person.id).to eq(bson_id.to_s)
486
250
  end
487
251
  end
488
252
 
@@ -493,7 +257,7 @@ describe Mongoid::Attributes do
493
257
  end
494
258
 
495
259
  it "sets the id as the string" do
496
- person.id.should eq(bson_id.to_s)
260
+ expect(person.id).to eq(bson_id.to_s)
497
261
  end
498
262
  end
499
263
 
@@ -504,7 +268,7 @@ describe Mongoid::Attributes do
504
268
  end
505
269
 
506
270
  it "sets the id as the supplied value to_s" do
507
- person.id.should eq("2")
271
+ expect(person.id).to eq("2")
508
272
  end
509
273
  end
510
274
  end
@@ -512,7 +276,7 @@ describe Mongoid::Attributes do
512
276
  context "when using integer ids" do
513
277
 
514
278
  before(:all) do
515
- Person.field(:_id, type: Integer)
279
+ Person.field(:_id, type: Integer, overwrite: true)
516
280
  end
517
281
 
518
282
  let(:person) do
@@ -526,7 +290,7 @@ describe Mongoid::Attributes do
526
290
  end
527
291
 
528
292
  it "sets the id as the integer" do
529
- person.id.should eq(1)
293
+ expect(person.id).to eq(1)
530
294
  end
531
295
  end
532
296
 
@@ -537,7 +301,7 @@ describe Mongoid::Attributes do
537
301
  end
538
302
 
539
303
  it "sets the id as the supplied value" do
540
- person.id.should eq(2)
304
+ expect(person.id).to eq(2)
541
305
  end
542
306
  end
543
307
  end
@@ -553,27 +317,23 @@ describe Mongoid::Attributes do
553
317
  Person.new(attributes)
554
318
  end
555
319
 
556
- before do
557
- Mongoid.configure.allow_dynamic_fields = true
558
- end
559
-
560
320
  context "when an attribute exists" do
561
321
 
562
322
  it "allows the getter" do
563
- person.testing.should eq("Testing")
323
+ expect(person.testing).to eq("Testing")
564
324
  end
565
325
 
566
326
  it "allows the setter" do
567
327
  person.testing = "Test"
568
- person.testing.should eq("Test")
328
+ expect(person.testing).to eq("Test")
569
329
  end
570
330
 
571
331
  it "allows the getter before_type_cast" do
572
- person.testing_before_type_cast.should eq("Testing")
332
+ expect(person.testing_before_type_cast).to eq("Testing")
573
333
  end
574
334
 
575
335
  it "returns true for respond_to?" do
576
- person.respond_to?(:testing).should be_true
336
+ expect(person.respond_to?(:testing)).to be true
577
337
  end
578
338
  end
579
339
 
@@ -588,28 +348,17 @@ describe Mongoid::Attributes do
588
348
  end
589
349
 
590
350
  it "mongoizes the dynamic field" do
591
- person.new_years.should be_a(Time)
351
+ expect(person.new_years).to be_a(Time)
592
352
  end
593
353
 
594
354
  it "keeps the same value" do
595
- person.new_years.should eq(new_years)
355
+ expect(person.new_years).to eq(new_years)
596
356
  end
597
357
  end
598
358
  end
599
359
 
600
360
  describe "#process" do
601
361
 
602
- context "when passing non accessible fields" do
603
-
604
- let(:person) do
605
- Person.new(owner_id: 6)
606
- end
607
-
608
- it "does not set the value" do
609
- person.owner_id.should be_nil
610
- end
611
- end
612
-
613
362
  context "when attributes dont have fields defined" do
614
363
 
615
364
  let(:attributes) do
@@ -626,43 +375,26 @@ describe Mongoid::Attributes do
626
375
  Person.new(attributes)
627
376
  end
628
377
 
629
- before do
630
- Mongoid.configure.allow_dynamic_fields = true
631
- end
632
-
633
378
  context "when attribute is a string" do
634
379
 
635
380
  it "adds the string to the attributes" do
636
- person.attributes["nofieldstring"].should eq("Testing")
381
+ expect(person.attributes["nofieldstring"]).to eq("Testing")
637
382
  end
638
383
  end
639
384
 
640
385
  context "when attribute is not a string" do
641
386
 
642
387
  it "adds a cast value to the attributes" do
643
- person.attributes["nofieldint"].should eq(5)
388
+ expect(person.attributes["nofieldint"]).to eq(5)
644
389
  end
645
390
  end
646
391
  end
647
392
 
648
393
  context "when not allowing dynamic fields" do
649
394
 
650
- let!(:attributes) do
651
- { nofieldstring: "Testing" }
652
- end
653
-
654
- before do
655
- Mongoid.configure.allow_dynamic_fields = false
656
- Person.fields.delete(:nofieldstring)
657
- end
658
-
659
- after do
660
- Mongoid.configure.allow_dynamic_fields = true
661
- end
662
-
663
- it "raises an unknown attribute error" do
395
+ it "raises an unknown attribute error on instantiation" do
664
396
  expect {
665
- Person.new({ anothernew: "Test" })
397
+ Account.new({ anothernew: "Test" })
666
398
  }.to raise_error(Mongoid::Errors::UnknownAttribute)
667
399
  end
668
400
  end
@@ -671,7 +403,7 @@ describe Mongoid::Attributes do
671
403
  context "when supplied hash has string values" do
672
404
 
673
405
  let(:bson_id) do
674
- Moped::BSON::ObjectId.new
406
+ BSON::ObjectId.new
675
407
  end
676
408
 
677
409
  let!(:attributes) do
@@ -695,15 +427,15 @@ describe Mongoid::Attributes do
695
427
  end
696
428
 
697
429
  it "casts integers" do
698
- person[:age].should eq(30)
430
+ expect(person[:age]).to eq(30)
699
431
  end
700
432
 
701
433
  it "casts booleans" do
702
- person[:terms].should be_true
434
+ expect(person[:terms]).to be true
703
435
  end
704
436
 
705
437
  it "sets empty strings to nil" do
706
- person[:score].should be_nil
438
+ expect(person[:score]).to be_nil
707
439
  end
708
440
  end
709
441
 
@@ -724,7 +456,7 @@ describe Mongoid::Attributes do
724
456
  end
725
457
 
726
458
  it "sets the associations" do
727
- person.name.should eq(name)
459
+ expect(person.name).to eq(name)
728
460
  end
729
461
  end
730
462
 
@@ -743,11 +475,11 @@ describe Mongoid::Attributes do
743
475
  end
744
476
 
745
477
  it "sets the parent association" do
746
- person.game.should eq(game)
478
+ expect(person.game).to eq(game)
747
479
  end
748
480
 
749
481
  it "sets the inverse association" do
750
- game.person.should eq(person)
482
+ expect(game.person).to eq(person)
751
483
  end
752
484
  end
753
485
 
@@ -762,7 +494,7 @@ describe Mongoid::Attributes do
762
494
  end
763
495
 
764
496
  it "sets the association" do
765
- name.person.should eq(person)
497
+ expect(name.person).to eq(person)
766
498
  end
767
499
  end
768
500
  end
@@ -782,7 +514,7 @@ describe Mongoid::Attributes do
782
514
  end
783
515
 
784
516
  it "calls the setter for the association" do
785
- person.employer_id.should eq("1")
517
+ expect(person.employer_id).to eq("1")
786
518
  end
787
519
  end
788
520
 
@@ -797,7 +529,7 @@ describe Mongoid::Attributes do
797
529
  end
798
530
 
799
531
  it "sets the empty array" do
800
- person.aliases.should be_empty
532
+ expect(person.aliases).to be_empty
801
533
  end
802
534
  end
803
535
 
@@ -812,7 +544,7 @@ describe Mongoid::Attributes do
812
544
  end
813
545
 
814
546
  it "sets the empty hash" do
815
- person.map.should eq({})
547
+ expect(person.map).to eq({})
816
548
  end
817
549
  end
818
550
  end
@@ -832,7 +564,7 @@ describe Mongoid::Attributes do
832
564
  end
833
565
 
834
566
  it "only overwrites supplied attributes" do
835
- person.title.should eq("Sir")
567
+ expect(person.title).to eq("Sir")
836
568
  end
837
569
  end
838
570
 
@@ -847,8 +579,8 @@ describe Mongoid::Attributes do
847
579
  context "when attribute does not exist" do
848
580
 
849
581
  it "returns the default value" do
850
- person.age.should eq(100)
851
- person.pets.should be_false
582
+ expect(person.age).to eq(100)
583
+ expect(person.pets).to be false
852
584
  end
853
585
 
854
586
  end
@@ -860,7 +592,7 @@ describe Mongoid::Attributes do
860
592
  end
861
593
 
862
594
  it "returns the value" do
863
- person.read_attribute(:owner_id).should eq(5)
595
+ expect(person.read_attribute(:owner_id)).to eq(5)
864
596
  end
865
597
  end
866
598
  end
@@ -883,7 +615,7 @@ describe Mongoid::Attributes do
883
615
  end
884
616
 
885
617
  it "returns the default value" do
886
- person.age.should eq(100)
618
+ expect(person.age).to eq(100)
887
619
  end
888
620
  end
889
621
  end
@@ -912,7 +644,7 @@ describe Mongoid::Attributes do
912
644
  context "when the attribute has not yet been assigned" do
913
645
 
914
646
  it "returns the default value" do
915
- person.age_before_type_cast.should eq(100)
647
+ expect(person.age_before_type_cast).to eq(100)
916
648
  end
917
649
  end
918
650
 
@@ -920,7 +652,7 @@ describe Mongoid::Attributes do
920
652
 
921
653
  it "returns the default value" do
922
654
  person.age = "old"
923
- person.age_before_type_cast.should eq("old")
655
+ expect(person.age_before_type_cast).to eq("old")
924
656
  end
925
657
  end
926
658
  end
@@ -937,7 +669,7 @@ describe Mongoid::Attributes do
937
669
  context "when attribute does not exist" do
938
670
 
939
671
  it "returns false" do
940
- person.attribute_present?(:owner_id).should be_false
672
+ expect(person.attribute_present?(:owner_id)).to be false
941
673
  end
942
674
  end
943
675
 
@@ -947,7 +679,7 @@ describe Mongoid::Attributes do
947
679
  end
948
680
 
949
681
  it "returns true" do
950
- person.attribute_present?(:owner_id).should be_true
682
+ expect(person.attribute_present?(:owner_id)).to be true
951
683
  end
952
684
  end
953
685
  end
@@ -970,7 +702,7 @@ describe Mongoid::Attributes do
970
702
  end
971
703
 
972
704
  it "returns true" do
973
- person.attribute_present?(:age).should be_true
705
+ expect(person.attribute_present?(:age)).to be true
974
706
  end
975
707
  end
976
708
  end
@@ -987,7 +719,7 @@ describe Mongoid::Attributes do
987
719
 
988
720
  it "return true" do
989
721
  person.terms = false
990
- person.attribute_present?(:terms).should be_true
722
+ expect(person.attribute_present?(:terms)).to be true
991
723
  end
992
724
  end
993
725
 
@@ -995,7 +727,7 @@ describe Mongoid::Attributes do
995
727
 
996
728
  it "return true" do
997
729
  person.terms = false
998
- person.attribute_present?(:terms).should be_true
730
+ expect(person.attribute_present?(:terms)).to be true
999
731
  end
1000
732
  end
1001
733
  end
@@ -1008,7 +740,7 @@ describe Mongoid::Attributes do
1008
740
  end
1009
741
 
1010
742
  it "return false" do
1011
- person.attribute_present?(:title).should be_false
743
+ expect(person.attribute_present?(:title)).to be false
1012
744
  end
1013
745
  end
1014
746
  end
@@ -1024,14 +756,14 @@ describe Mongoid::Attributes do
1024
756
  context "when provided a symbol" do
1025
757
 
1026
758
  it "returns true" do
1027
- person.has_attribute?(:title).should be_true
759
+ expect(person.has_attribute?(:title)).to be true
1028
760
  end
1029
761
  end
1030
762
 
1031
763
  context "when provided a string" do
1032
764
 
1033
765
  it "returns true" do
1034
- person.has_attribute?("title").should be_true
766
+ expect(person.has_attribute?("title")).to be true
1035
767
  end
1036
768
  end
1037
769
  end
@@ -1039,7 +771,7 @@ describe Mongoid::Attributes do
1039
771
  context "when the key is not in the attributes" do
1040
772
 
1041
773
  it "returns false" do
1042
- person.has_attribute?(:employer_id).should be_false
774
+ expect(person.has_attribute?(:employer_id)).to be false
1043
775
  end
1044
776
  end
1045
777
  end
@@ -1053,7 +785,7 @@ describe Mongoid::Attributes do
1053
785
  context "before the attribute has been assigned" do
1054
786
 
1055
787
  it "returns false" do
1056
- person.has_attribute_before_type_cast?(:age).should be_false
788
+ expect(person.has_attribute_before_type_cast?(:age)).to be false
1057
789
  end
1058
790
  end
1059
791
 
@@ -1061,7 +793,7 @@ describe Mongoid::Attributes do
1061
793
 
1062
794
  it "returns true" do
1063
795
  person.age = 'old'
1064
- person.has_attribute_before_type_cast?(:age).should be_true
796
+ expect(person.has_attribute_before_type_cast?(:age)).to be true
1065
797
  end
1066
798
  end
1067
799
  end
@@ -1079,11 +811,11 @@ describe Mongoid::Attributes do
1079
811
  end
1080
812
 
1081
813
  it "removes the attribute" do
1082
- person.title.should be_nil
814
+ expect(person.title).to be_nil
1083
815
  end
1084
816
 
1085
817
  it "removes the key from the attributes hash" do
1086
- person.has_attribute?(:title).should be_false
818
+ expect(person.has_attribute?(:title)).to be false
1087
819
  end
1088
820
 
1089
821
  context "when saving after the removal" do
@@ -1093,7 +825,7 @@ describe Mongoid::Attributes do
1093
825
  end
1094
826
 
1095
827
  it "persists the removal" do
1096
- person.reload.has_attribute?(:title).should be_false
828
+ expect(person.reload.has_attribute?(:title)).to be false
1097
829
  end
1098
830
  end
1099
831
  end
@@ -1114,11 +846,11 @@ describe Mongoid::Attributes do
1114
846
  end
1115
847
 
1116
848
  it "removes the attribute" do
1117
- person.pet.name.should be_nil
849
+ expect(person.pet.name).to be_nil
1118
850
  end
1119
851
 
1120
852
  it "removes the key from the attributes hash" do
1121
- person.pet.has_attribute?(:name).should be_false
853
+ expect(person.pet.has_attribute?(:name)).to be false
1122
854
  end
1123
855
 
1124
856
  context "when saving after the removal" do
@@ -1128,7 +860,7 @@ describe Mongoid::Attributes do
1128
860
  end
1129
861
 
1130
862
  it "persists the removal" do
1131
- person.reload.pet.has_attribute?(:name).should be_false
863
+ expect(person.reload.pet.has_attribute?(:name)).to be false
1132
864
  end
1133
865
  end
1134
866
 
@@ -1145,7 +877,7 @@ describe Mongoid::Attributes do
1145
877
  end
1146
878
 
1147
879
  it "does not fail" do
1148
- person.title.should be_nil
880
+ expect(person.title).to be_nil
1149
881
  end
1150
882
  end
1151
883
 
@@ -1160,7 +892,7 @@ describe Mongoid::Attributes do
1160
892
  end
1161
893
 
1162
894
  it "does not add a delayed unset operation" do
1163
- person.delayed_atomic_unsets.should be_empty
895
+ expect(person.delayed_atomic_unsets).to be_empty
1164
896
  end
1165
897
  end
1166
898
  end
@@ -1173,10 +905,6 @@ describe Mongoid::Attributes do
1173
905
  Person.new
1174
906
  end
1175
907
 
1176
- before(:all) do
1177
- Mongoid.allow_dynamic_fields = true
1178
- end
1179
-
1180
908
  context "when asking for the getter" do
1181
909
 
1182
910
  context "when the attribute exists" do
@@ -1186,14 +914,14 @@ describe Mongoid::Attributes do
1186
914
  end
1187
915
 
1188
916
  it "returns true" do
1189
- person.should respond_to(:attr)
917
+ expect(person).to respond_to(:attr)
1190
918
  end
1191
919
  end
1192
920
 
1193
921
  context "when the attribute does not exist" do
1194
922
 
1195
923
  it "returns false" do
1196
- person.should_not respond_to(:attr)
924
+ expect(person).to_not respond_to(:attr)
1197
925
  end
1198
926
  end
1199
927
  end
@@ -1207,14 +935,14 @@ describe Mongoid::Attributes do
1207
935
  end
1208
936
 
1209
937
  it "returns true" do
1210
- person.should respond_to(:attr=)
938
+ expect(person).to respond_to(:attr=)
1211
939
  end
1212
940
  end
1213
941
 
1214
942
  context "when the attribute does not exist" do
1215
943
 
1216
944
  it "returns false" do
1217
- person.should_not respond_to(:attr=)
945
+ expect(person).to_not respond_to(:attr=)
1218
946
  end
1219
947
  end
1220
948
  end
@@ -1222,29 +950,21 @@ describe Mongoid::Attributes do
1222
950
 
1223
951
  context "when not allowing dynamic fields" do
1224
952
 
1225
- let(:person) do
1226
- Person.new
1227
- end
1228
-
1229
- before(:all) do
1230
- Mongoid.allow_dynamic_fields = false
1231
- end
1232
-
1233
- after(:all) do
1234
- Mongoid.allow_dynamic_fields = true
953
+ let(:bar) do
954
+ Bar.new
1235
955
  end
1236
956
 
1237
957
  context "when asking for the getter" do
1238
958
 
1239
959
  it "returns false" do
1240
- person.should_not respond_to(:attr)
960
+ expect(bar).to_not respond_to(:attr)
1241
961
  end
1242
962
  end
1243
963
 
1244
964
  context "when asking for the setter" do
1245
965
 
1246
966
  it "returns false" do
1247
- person.should_not respond_to(:attr=)
967
+ expect(bar).to_not respond_to(:attr=)
1248
968
  end
1249
969
  end
1250
970
  end
@@ -1259,7 +979,7 @@ describe Mongoid::Attributes do
1259
979
  end
1260
980
 
1261
981
  it "returns the default value" do
1262
- person.age.should eq(100)
982
+ expect(person.age).to eq(100)
1263
983
  end
1264
984
  end
1265
985
 
@@ -1269,7 +989,7 @@ describe Mongoid::Attributes do
1269
989
  end
1270
990
 
1271
991
  it "should store the attribute before type cast" do
1272
- person.age_before_type_cast.should eq("old")
992
+ expect(person.age_before_type_cast).to eq("old")
1273
993
  end
1274
994
  end
1275
995
 
@@ -1280,7 +1000,7 @@ describe Mongoid::Attributes do
1280
1000
  end
1281
1001
 
1282
1002
  it "does not use the default value" do
1283
- person.age.should be_nil
1003
+ expect(person.age).to be_nil
1284
1004
  end
1285
1005
  end
1286
1006
 
@@ -1295,7 +1015,7 @@ describe Mongoid::Attributes do
1295
1015
  end
1296
1016
 
1297
1017
  it "allows overwriting of the default value" do
1298
- person.terms.should be_true
1018
+ expect(person.terms).to be true
1299
1019
  end
1300
1020
  end
1301
1021
 
@@ -1310,7 +1030,35 @@ describe Mongoid::Attributes do
1310
1030
  end
1311
1031
 
1312
1032
  it "allows the field name to be udpated" do
1313
- person.t.should eq("aliased field to test")
1033
+ expect(person.t).to eq("aliased field to test")
1034
+ end
1035
+ end
1036
+
1037
+ context "when attribute is a Hash" do
1038
+ let(:person) { Person.new map: { somekey: "somevalue" } }
1039
+
1040
+ it "raises an error when try to set an invalid value" do
1041
+ expect {
1042
+ person.map = []
1043
+ }.to raise_error(Mongoid::Errors::InvalidValue)
1044
+ end
1045
+
1046
+ it "can set a Hash value" do
1047
+ person.map.should eq( { somekey: "somevalue" } )
1048
+ end
1049
+ end
1050
+
1051
+ context "when attribute is an Array" do
1052
+ let(:person) { Person.new aliases: [ :alias_1 ] }
1053
+
1054
+ it "can set an Array Value" do
1055
+ person.aliases.should eq [ :alias_1 ]
1056
+ end
1057
+
1058
+ it "raises an error when try to set an invalid value" do
1059
+ expect {
1060
+ person.aliases = {}
1061
+ }.to raise_error(Mongoid::Errors::InvalidValue)
1314
1062
  end
1315
1063
  end
1316
1064
  end
@@ -1335,7 +1083,7 @@ describe Mongoid::Attributes do
1335
1083
  end
1336
1084
 
1337
1085
  it "returns the value" do
1338
- person.send(:typed_value_for, "age", "51").should eq("51")
1086
+ person.send(:typed_value_for, "age", expect("51")).to eq("51")
1339
1087
  end
1340
1088
  end
1341
1089
  end
@@ -1347,7 +1095,7 @@ describe Mongoid::Attributes do
1347
1095
  end
1348
1096
 
1349
1097
  it "typecasts proc values" do
1350
- person.age.should eq(100)
1098
+ expect(person.age).to eq(100)
1351
1099
  end
1352
1100
  end
1353
1101
 
@@ -1366,7 +1114,7 @@ describe Mongoid::Attributes do
1366
1114
  end
1367
1115
 
1368
1116
  it "sets nested documents" do
1369
- person.videos.first.title.should eq("Fight Club")
1117
+ expect(person.videos.first.title).to eq("Fight Club")
1370
1118
  end
1371
1119
  end
1372
1120
 
@@ -1387,7 +1135,7 @@ describe Mongoid::Attributes do
1387
1135
  end
1388
1136
 
1389
1137
  it "properly casts values" do
1390
- person.age.should eq(50)
1138
+ expect(person.age).to eq(50)
1391
1139
  end
1392
1140
  end
1393
1141
 
@@ -1398,11 +1146,38 @@ describe Mongoid::Attributes do
1398
1146
  end
1399
1147
 
1400
1148
  it "does not set anything" do
1401
- person.age.should eq(100)
1149
+ expect(person.age).to eq(100)
1402
1150
  end
1403
1151
  end
1404
1152
  end
1405
1153
 
1154
+ context "copying from instance" do
1155
+
1156
+ let(:person) do
1157
+ Person.new
1158
+ end
1159
+
1160
+ let(:instance) do
1161
+ Person.new(attributes)
1162
+ end
1163
+
1164
+ let(:attributes) do
1165
+ { age: 50, range: 1..100 }
1166
+ end
1167
+
1168
+ before do
1169
+ person.send(method, instance.attributes)
1170
+ end
1171
+
1172
+ it "properly copies values" do
1173
+ expect(person.age).to eq(50)
1174
+ end
1175
+
1176
+ it "properly copies ranges" do
1177
+ expect(person.range).to eq(1..100)
1178
+ end
1179
+ end
1180
+
1406
1181
  context "on a parent document" do
1407
1182
 
1408
1183
  context "when the parent has a has many through a has one" do
@@ -1426,8 +1201,8 @@ describe Mongoid::Attributes do
1426
1201
  end
1427
1202
 
1428
1203
  it "does not overwrite child attributes if not in the hash" do
1429
- owner.pet.name.should eq("Bingo")
1430
- owner.pet.vet_visits.size.should eq(1)
1204
+ expect(owner.pet.name).to eq("Bingo")
1205
+ expect(owner.pet.vet_visits.size).to eq(1)
1431
1206
  end
1432
1207
  end
1433
1208
 
@@ -1451,11 +1226,11 @@ describe Mongoid::Attributes do
1451
1226
  end
1452
1227
 
1453
1228
  it "has 3 new entries" do
1454
- pet.vet_visits.count.should eq(3)
1229
+ expect(pet.vet_visits.count).to eq(3)
1455
1230
  end
1456
1231
 
1457
1232
  it "persists the changes" do
1458
- pet.reload.vet_visits.count.should eq(3)
1233
+ expect(pet.reload.vet_visits.count).to eq(3)
1459
1234
  end
1460
1235
  end
1461
1236
 
@@ -1493,7 +1268,7 @@ describe Mongoid::Attributes do
1493
1268
  end
1494
1269
 
1495
1270
  it "sets the child attributes on the parent" do
1496
- name.attributes.should eq(
1271
+ expect(name.attributes).to eq(
1497
1272
  { "_id" => "Test-User", "first_name" => "Test2", "last_name" => "User2" }
1498
1273
  )
1499
1274
  end
@@ -1515,7 +1290,7 @@ describe Mongoid::Attributes do
1515
1290
  end
1516
1291
 
1517
1292
  it "updates the child attributes on the parent" do
1518
- address.attributes.should eq(
1293
+ expect(address.attributes).to eq(
1519
1294
  { "_id" => "test", "street" => "Test2" }
1520
1295
  )
1521
1296
  end
@@ -1536,38 +1311,42 @@ describe Mongoid::Attributes do
1536
1311
  product.cost = 500
1537
1312
  end
1538
1313
 
1314
+ it "adds the alias for criteria" do
1315
+ expect(Product.where(cost: 500).selector).to eq("price" => 500)
1316
+ end
1317
+
1539
1318
  it "aliases the getter" do
1540
- product.cost.should eq(500)
1319
+ expect(product.cost).to eq(500)
1541
1320
  end
1542
1321
 
1543
1322
  it "aliases the existance check" do
1544
- product.cost?.should be_true
1323
+ expect(product.cost?).to be true
1545
1324
  end
1546
1325
 
1547
1326
  it "aliases *_changed?" do
1548
- product.cost_changed?.should be_true
1327
+ expect(product.cost_changed?).to be true
1549
1328
  end
1550
1329
 
1551
1330
  it "aliases *_change" do
1552
- product.cost_change.should eq([ nil, 500 ])
1331
+ expect(product.cost_change).to eq([ nil, 500 ])
1553
1332
  end
1554
1333
 
1555
1334
  it "aliases *_will_change!" do
1556
- product.should respond_to(:cost_will_change!)
1335
+ expect(product).to respond_to(:cost_will_change!)
1557
1336
  end
1558
1337
 
1559
1338
  it "aliases *_was" do
1560
- product.cost_was.should be_nil
1339
+ expect(product.cost_was).to be_nil
1561
1340
  end
1562
1341
 
1563
1342
  it "aliases reset_*!" do
1564
1343
  product.reset_cost!
1565
- product.cost.should be_nil
1344
+ expect(product.cost).to be_nil
1566
1345
  end
1567
1346
 
1568
1347
  it "aliases *_before_type_cast" do
1569
1348
  product.cost = "expensive"
1570
- product.cost_before_type_cast.should eq("expensive")
1349
+ expect(product.cost_before_type_cast).to eq("expensive")
1571
1350
  end
1572
1351
  end
1573
1352
 
@@ -1578,32 +1357,32 @@ describe Mongoid::Attributes do
1578
1357
  end
1579
1358
 
1580
1359
  it "aliases the getter" do
1581
- product.price.should eq(500)
1360
+ expect(product.price).to eq(500)
1582
1361
  end
1583
1362
 
1584
1363
  it "aliases the existance check" do
1585
- product.price?.should be_true
1364
+ expect(product.price?).to be true
1586
1365
  end
1587
1366
 
1588
1367
  it "aliases *_changed?" do
1589
- product.price_changed?.should be_true
1368
+ expect(product.price_changed?).to be true
1590
1369
  end
1591
1370
 
1592
1371
  it "aliases *_change" do
1593
- product.price_change.should eq([ nil, 500 ])
1372
+ expect(product.price_change).to eq([ nil, 500 ])
1594
1373
  end
1595
1374
 
1596
1375
  it "aliases *_will_change!" do
1597
- product.should respond_to(:price_will_change!)
1376
+ expect(product).to respond_to(:price_will_change!)
1598
1377
  end
1599
1378
 
1600
1379
  it "aliases *_was" do
1601
- product.price_was.should be_nil
1380
+ expect(product.price_was).to be_nil
1602
1381
  end
1603
1382
 
1604
1383
  it "aliases reset_*!" do
1605
1384
  product.reset_price!
1606
- product.price.should be_nil
1385
+ expect(product.price).to be_nil
1607
1386
  end
1608
1387
  end
1609
1388
  end
@@ -1615,7 +1394,7 @@ describe Mongoid::Attributes do
1615
1394
  end
1616
1395
 
1617
1396
  it "has an entry in the attributes" do
1618
- person.reload.attributes.should have_key("score")
1397
+ expect(person.reload.attributes).to have_key("score")
1619
1398
  end
1620
1399
  end
1621
1400
 
@@ -1627,7 +1406,7 @@ describe Mongoid::Attributes do
1627
1406
 
1628
1407
  it "saves the default" do
1629
1408
  expect { person.save }.to_not raise_error
1630
- person.last_drink_taken_at.should eq(1.day.ago.in_time_zone("Alaska").to_date)
1409
+ expect(person.last_drink_taken_at).to eq(1.day.ago.in_time_zone("Alaska").to_date)
1631
1410
  end
1632
1411
  end
1633
1412
 
@@ -1640,7 +1419,7 @@ describe Mongoid::Attributes do
1640
1419
  end
1641
1420
 
1642
1421
  it "applies the default value" do
1643
- person.last_drink_taken_at.should eq(1.day.ago.in_time_zone("Alaska").to_date)
1422
+ expect(person.last_drink_taken_at).to eq(1.day.ago.in_time_zone("Alaska").to_date)
1644
1423
  end
1645
1424
  end
1646
1425
 
@@ -1657,7 +1436,7 @@ describe Mongoid::Attributes do
1657
1436
  end
1658
1437
 
1659
1438
  it "does not set the default" do
1660
- from_db.age.should eq(50)
1439
+ expect(from_db.age).to eq(50)
1661
1440
  end
1662
1441
  end
1663
1442
 
@@ -1672,7 +1451,7 @@ describe Mongoid::Attributes do
1672
1451
  end
1673
1452
 
1674
1453
  it "does not set the default" do
1675
- from_db.age.should be_nil
1454
+ expect(from_db.age).to be_nil
1676
1455
  end
1677
1456
  end
1678
1457
 
@@ -1687,32 +1466,7 @@ describe Mongoid::Attributes do
1687
1466
  end
1688
1467
 
1689
1468
  it "applies the defaults after all attributes are set" do
1690
- from_db.should be_balanced
1691
- end
1692
- end
1693
- end
1694
- end
1695
-
1696
- context "when dynamic fields are not allowed" do
1697
-
1698
- before do
1699
- Mongoid.configure.allow_dynamic_fields = false
1700
- end
1701
-
1702
- after do
1703
- Mongoid.configure.allow_dynamic_fields = true
1704
- end
1705
-
1706
- context "when an embedded document has been persisted" do
1707
-
1708
- context "when the field is no longer recognized" do
1709
-
1710
- before do
1711
- Person.collection.insert 'pet' => { 'unrecognized_field' => true }
1712
- end
1713
-
1714
- it "allows access to the legacy data" do
1715
- Person.first.pet.read_attribute(:unrecognized_field).should be_true
1469
+ expect(from_db).to be_balanced
1716
1470
  end
1717
1471
  end
1718
1472
  end