mongoid 7.5.4 → 8.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (298) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +3 -3
  4. data/Rakefile +0 -25
  5. data/lib/config/locales/en.yml +46 -30
  6. data/lib/mongoid/association/accessors.rb +32 -3
  7. data/lib/mongoid/association/bindable.rb +48 -0
  8. data/lib/mongoid/association/builders.rb +4 -2
  9. data/lib/mongoid/association/eager_loadable.rb +29 -7
  10. data/lib/mongoid/association/embedded/batchable.rb +28 -5
  11. data/lib/mongoid/association/embedded/embedded_in/binding.rb +24 -2
  12. data/lib/mongoid/association/embedded/embedded_in.rb +2 -1
  13. data/lib/mongoid/association/embedded/embeds_many/binding.rb +1 -0
  14. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +1 -1
  15. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +40 -18
  16. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +18 -4
  17. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +21 -2
  18. data/lib/mongoid/association/macros.rb +2 -1
  19. data/lib/mongoid/association/many.rb +5 -0
  20. data/lib/mongoid/association/nested/many.rb +2 -1
  21. data/lib/mongoid/association/proxy.rb +12 -0
  22. data/lib/mongoid/association/referenced/auto_save.rb +3 -2
  23. data/lib/mongoid/association/referenced/belongs_to/binding.rb +1 -0
  24. data/lib/mongoid/association/referenced/belongs_to/buildable.rb +1 -1
  25. data/lib/mongoid/association/referenced/belongs_to.rb +1 -1
  26. data/lib/mongoid/association/referenced/counter_cache.rb +8 -8
  27. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +64 -11
  28. data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +4 -1
  29. data/lib/mongoid/association/referenced/has_many/enumerable.rb +10 -18
  30. data/lib/mongoid/association/referenced/has_many/proxy.rb +12 -9
  31. data/lib/mongoid/association/referenced/has_one/buildable.rb +1 -1
  32. data/lib/mongoid/association/referenced/has_one/proxy.rb +8 -11
  33. data/lib/mongoid/association/referenced/syncable.rb +2 -2
  34. data/lib/mongoid/association/relatable.rb +38 -4
  35. data/lib/mongoid/attributes/processing.rb +9 -2
  36. data/lib/mongoid/attributes.rb +30 -27
  37. data/lib/mongoid/cacheable.rb +2 -2
  38. data/lib/mongoid/changeable.rb +37 -2
  39. data/lib/mongoid/clients/options.rb +4 -0
  40. data/lib/mongoid/clients/sessions.rb +2 -14
  41. data/lib/mongoid/config.rb +15 -11
  42. data/lib/mongoid/contextual/aggregable/memory.rb +23 -15
  43. data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
  44. data/lib/mongoid/contextual/map_reduce.rb +2 -2
  45. data/lib/mongoid/contextual/memory.rb +55 -28
  46. data/lib/mongoid/contextual/mongo.rb +173 -262
  47. data/lib/mongoid/contextual/none.rb +33 -15
  48. data/lib/mongoid/copyable.rb +32 -8
  49. data/lib/mongoid/criteria/includable.rb +24 -20
  50. data/lib/mongoid/criteria/marshalable.rb +10 -2
  51. data/lib/mongoid/criteria/queryable/extensions/array.rb +2 -15
  52. data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +25 -4
  53. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
  54. data/lib/mongoid/criteria/queryable/extensions/date.rb +6 -1
  55. data/lib/mongoid/criteria/queryable/extensions/date_time.rb +6 -1
  56. data/lib/mongoid/criteria/queryable/extensions/hash.rb +0 -16
  57. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
  58. data/lib/mongoid/criteria/queryable/extensions/object.rb +2 -1
  59. data/lib/mongoid/criteria/queryable/extensions/range.rb +13 -5
  60. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +1 -1
  61. data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -1
  62. data/lib/mongoid/criteria/queryable/extensions/time.rb +6 -1
  63. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +6 -1
  64. data/lib/mongoid/criteria/queryable/optional.rb +3 -9
  65. data/lib/mongoid/criteria/queryable/options.rb +1 -1
  66. data/lib/mongoid/criteria/queryable/selectable.rb +2 -24
  67. data/lib/mongoid/criteria/queryable/selector.rb +90 -5
  68. data/lib/mongoid/criteria/queryable/smash.rb +39 -6
  69. data/lib/mongoid/criteria/queryable/storable.rb +1 -1
  70. data/lib/mongoid/criteria/queryable.rb +11 -6
  71. data/lib/mongoid/criteria.rb +1 -28
  72. data/lib/mongoid/deprecable.rb +36 -0
  73. data/lib/mongoid/deprecation.rb +25 -0
  74. data/lib/mongoid/document.rb +88 -33
  75. data/lib/mongoid/equality.rb +4 -4
  76. data/lib/mongoid/errors/document_not_found.rb +6 -2
  77. data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +23 -0
  78. data/lib/mongoid/errors/invalid_field.rb +5 -1
  79. data/lib/mongoid/errors/invalid_field_type.rb +26 -0
  80. data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -1
  81. data/lib/mongoid/errors.rb +2 -2
  82. data/lib/mongoid/extensions/array.rb +8 -6
  83. data/lib/mongoid/extensions/big_decimal.rb +29 -10
  84. data/lib/mongoid/extensions/binary.rb +42 -0
  85. data/lib/mongoid/extensions/boolean.rb +8 -2
  86. data/lib/mongoid/extensions/date.rb +26 -20
  87. data/lib/mongoid/extensions/date_time.rb +1 -1
  88. data/lib/mongoid/extensions/float.rb +4 -5
  89. data/lib/mongoid/extensions/hash.rb +12 -5
  90. data/lib/mongoid/extensions/integer.rb +4 -5
  91. data/lib/mongoid/extensions/object.rb +2 -0
  92. data/lib/mongoid/extensions/range.rb +41 -10
  93. data/lib/mongoid/extensions/regexp.rb +11 -4
  94. data/lib/mongoid/extensions/set.rb +11 -4
  95. data/lib/mongoid/extensions/string.rb +2 -13
  96. data/lib/mongoid/extensions/symbol.rb +3 -14
  97. data/lib/mongoid/extensions/time.rb +27 -16
  98. data/lib/mongoid/extensions/time_with_zone.rb +1 -2
  99. data/lib/mongoid/extensions.rb +1 -0
  100. data/lib/mongoid/factory.rb +42 -7
  101. data/lib/mongoid/fields/foreign_key.rb +7 -0
  102. data/lib/mongoid/fields/validators/macro.rb +3 -9
  103. data/lib/mongoid/fields.rb +49 -7
  104. data/lib/mongoid/findable.rb +21 -16
  105. data/lib/mongoid/indexable/specification.rb +1 -1
  106. data/lib/mongoid/indexable/validators/options.rb +4 -1
  107. data/lib/mongoid/interceptable.rb +69 -9
  108. data/lib/mongoid/persistable/creatable.rb +14 -5
  109. data/lib/mongoid/persistable/updatable.rb +12 -5
  110. data/lib/mongoid/persistence_context.rb +8 -42
  111. data/lib/mongoid/query_cache.rb +6 -258
  112. data/lib/mongoid/railties/controller_runtime.rb +1 -1
  113. data/lib/mongoid/reloadable.rb +7 -3
  114. data/lib/mongoid/scopable.rb +9 -11
  115. data/lib/mongoid/selectable.rb +1 -2
  116. data/lib/mongoid/shardable.rb +11 -35
  117. data/lib/mongoid/stateful.rb +27 -1
  118. data/lib/mongoid/timestamps/created.rb +1 -1
  119. data/lib/mongoid/timestamps/updated.rb +1 -1
  120. data/lib/mongoid/touchable.rb +2 -3
  121. data/lib/mongoid/traversable.rb +1 -0
  122. data/lib/mongoid/validatable/uniqueness.rb +2 -1
  123. data/lib/mongoid/version.rb +1 -1
  124. data/lib/mongoid/warnings.rb +3 -4
  125. data/lib/mongoid.rb +1 -0
  126. data/spec/config/mongoid.yml +16 -0
  127. data/spec/integration/app_spec.rb +8 -12
  128. data/spec/integration/associations/belongs_to_spec.rb +18 -0
  129. data/spec/integration/associations/embedded_spec.rb +15 -0
  130. data/spec/integration/associations/embeds_many_spec.rb +15 -2
  131. data/spec/integration/associations/embeds_one_spec.rb +18 -0
  132. data/spec/integration/associations/foreign_key_spec.rb +9 -0
  133. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +21 -0
  134. data/spec/integration/associations/has_one_spec.rb +97 -1
  135. data/spec/integration/associations/scope_option_spec.rb +1 -1
  136. data/spec/integration/callbacks_models.rb +95 -1
  137. data/spec/integration/callbacks_spec.rb +226 -4
  138. data/spec/integration/criteria/range_spec.rb +95 -1
  139. data/spec/integration/discriminator_key_spec.rb +115 -76
  140. data/spec/integration/dots_and_dollars_spec.rb +277 -0
  141. data/spec/integration/i18n_fallbacks_spec.rb +1 -15
  142. data/spec/integration/matcher_examples_spec.rb +20 -13
  143. data/spec/integration/matcher_operator_data/type_decimal.yml +3 -2
  144. data/spec/integration/matcher_operator_spec.rb +3 -5
  145. data/spec/integration/persistence/range_field_spec.rb +350 -0
  146. data/spec/mongoid/association/counter_cache_spec.rb +1 -1
  147. data/spec/mongoid/association/depending_spec.rb +9 -9
  148. data/spec/mongoid/association/eager_spec.rb +2 -1
  149. data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +2 -1
  150. data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +54 -0
  151. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +69 -9
  152. data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +112 -0
  153. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +198 -8
  154. data/spec/mongoid/association/embedded/embeds_many_models.rb +36 -0
  155. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +12 -0
  156. data/spec/mongoid/association/embedded/embeds_many_spec.rb +68 -0
  157. data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +25 -0
  158. data/spec/mongoid/association/embedded/embeds_one_models.rb +19 -0
  159. data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -0
  160. data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +2 -1
  161. data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +54 -0
  162. data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +15 -0
  163. data/spec/mongoid/association/referenced/belongs_to_models.rb +11 -0
  164. data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -2
  165. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +38 -5
  166. data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +25 -0
  167. data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +35 -2
  168. data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +109 -0
  169. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +2 -56
  170. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +62 -13
  171. data/spec/mongoid/association/referenced/has_many_models.rb +3 -1
  172. data/spec/mongoid/association/referenced/has_many_spec.rb +25 -0
  173. data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +2 -2
  174. data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +107 -1
  175. data/spec/mongoid/association/referenced/has_one_models.rb +16 -0
  176. data/spec/mongoid/association/syncable_spec.rb +14 -0
  177. data/spec/mongoid/atomic/paths_spec.rb +0 -14
  178. data/spec/mongoid/attributes/nested_spec.rb +80 -11
  179. data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
  180. data/spec/mongoid/attributes/projector_spec.rb +1 -5
  181. data/spec/mongoid/attributes_spec.rb +480 -27
  182. data/spec/mongoid/cacheable_spec.rb +3 -3
  183. data/spec/mongoid/changeable_spec.rb +130 -13
  184. data/spec/mongoid/clients/factory_spec.rb +23 -30
  185. data/spec/mongoid/clients/sessions_spec.rb +0 -38
  186. data/spec/mongoid/clients_spec.rb +2 -2
  187. data/spec/mongoid/config_spec.rb +52 -14
  188. data/spec/mongoid/contextual/aggregable/memory_spec.rb +396 -158
  189. data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
  190. data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +62 -0
  191. data/spec/mongoid/contextual/map_reduce_spec.rb +2 -16
  192. data/spec/mongoid/contextual/memory_spec.rb +521 -14
  193. data/spec/mongoid/contextual/mongo_spec.rb +566 -416
  194. data/spec/mongoid/contextual/none_spec.rb +11 -19
  195. data/spec/mongoid/copyable_spec.rb +451 -1
  196. data/spec/mongoid/criteria/findable_spec.rb +86 -210
  197. data/spec/mongoid/criteria/includable_spec.rb +1492 -0
  198. data/spec/mongoid/criteria/includable_spec_models.rb +54 -0
  199. data/spec/mongoid/criteria/marshalable_spec.rb +18 -1
  200. data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +7 -19
  201. data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +134 -26
  202. data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +11 -0
  203. data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +11 -0
  204. data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +0 -15
  205. data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +73 -7
  206. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +11 -0
  207. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +11 -0
  208. data/spec/mongoid/criteria/queryable/optional_spec.rb +0 -484
  209. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +50 -0
  210. data/spec/mongoid/criteria/queryable/selectable_spec.rb +77 -85
  211. data/spec/mongoid/criteria/queryable/selector_spec.rb +16 -77
  212. data/spec/mongoid/criteria/queryable/storable_spec.rb +0 -72
  213. data/spec/mongoid/criteria_spec.rb +469 -1201
  214. data/spec/mongoid/document_fields_spec.rb +173 -24
  215. data/spec/mongoid/document_spec.rb +32 -41
  216. data/spec/mongoid/equality_spec.rb +12 -12
  217. data/spec/mongoid/errors/document_not_found_spec.rb +29 -2
  218. data/spec/mongoid/errors/invalid_field_spec.rb +1 -1
  219. data/spec/mongoid/errors/invalid_field_type_spec.rb +55 -0
  220. data/spec/mongoid/errors/mongoid_error_spec.rb +3 -1
  221. data/spec/mongoid/errors/no_environment_spec.rb +3 -3
  222. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +1 -1
  223. data/spec/mongoid/extensions/array_spec.rb +16 -2
  224. data/spec/mongoid/extensions/big_decimal_spec.rb +697 -212
  225. data/spec/mongoid/extensions/binary_spec.rb +44 -9
  226. data/spec/mongoid/extensions/boolean_spec.rb +68 -82
  227. data/spec/mongoid/extensions/date_class_mongoize_spec.rb +7 -3
  228. data/spec/mongoid/extensions/date_spec.rb +71 -1
  229. data/spec/mongoid/extensions/date_time_spec.rb +15 -9
  230. data/spec/mongoid/extensions/float_spec.rb +48 -76
  231. data/spec/mongoid/extensions/hash_spec.rb +30 -0
  232. data/spec/mongoid/extensions/integer_spec.rb +45 -66
  233. data/spec/mongoid/extensions/range_spec.rb +255 -54
  234. data/spec/mongoid/extensions/regexp_spec.rb +58 -33
  235. data/spec/mongoid/extensions/set_spec.rb +106 -0
  236. data/spec/mongoid/extensions/string_spec.rb +53 -25
  237. data/spec/mongoid/extensions/symbol_spec.rb +18 -25
  238. data/spec/mongoid/extensions/time_spec.rb +634 -66
  239. data/spec/mongoid/extensions/time_with_zone_spec.rb +17 -31
  240. data/spec/mongoid/factory_spec.rb +61 -1
  241. data/spec/mongoid/fields_spec.rb +321 -50
  242. data/spec/mongoid/findable_spec.rb +64 -29
  243. data/spec/mongoid/indexable/specification_spec.rb +2 -2
  244. data/spec/mongoid/indexable_spec.rb +16 -19
  245. data/spec/mongoid/interceptable_spec.rb +584 -5
  246. data/spec/mongoid/interceptable_spec_models.rb +235 -4
  247. data/spec/mongoid/matcher/extract_attribute_spec.rb +1 -5
  248. data/spec/mongoid/mongoizable_spec.rb +285 -0
  249. data/spec/mongoid/persistable/creatable_spec.rb +2 -2
  250. data/spec/mongoid/persistable/deletable_spec.rb +2 -2
  251. data/spec/mongoid/persistable/destroyable_spec.rb +2 -2
  252. data/spec/mongoid/persistable/upsertable_spec.rb +14 -0
  253. data/spec/mongoid/persistence_context_spec.rb +24 -0
  254. data/spec/mongoid/query_cache_middleware_spec.rb +0 -18
  255. data/spec/mongoid/query_cache_spec.rb +0 -154
  256. data/spec/mongoid/reloadable_spec.rb +35 -2
  257. data/spec/mongoid/scopable_spec.rb +36 -34
  258. data/spec/mongoid/shardable_models.rb +0 -14
  259. data/spec/mongoid/shardable_spec.rb +61 -153
  260. data/spec/mongoid/stateful_spec.rb +28 -0
  261. data/spec/mongoid/timestamps_spec.rb +390 -0
  262. data/spec/mongoid/timestamps_spec_models.rb +67 -0
  263. data/spec/mongoid/touchable_spec.rb +116 -0
  264. data/spec/mongoid/touchable_spec_models.rb +12 -8
  265. data/spec/mongoid/traversable_spec.rb +4 -11
  266. data/spec/mongoid/validatable/presence_spec.rb +1 -1
  267. data/spec/mongoid/validatable/uniqueness_spec.rb +60 -31
  268. data/spec/mongoid/warnings_spec.rb +35 -0
  269. data/spec/mongoid_spec.rb +1 -7
  270. data/spec/rails/controller_extension/controller_runtime_spec.rb +2 -2
  271. data/spec/rails/mongoid_spec.rb +4 -16
  272. data/spec/shared/lib/mrss/event_subscriber.rb +5 -15
  273. data/spec/shared/lib/mrss/lite_constraints.rb +0 -8
  274. data/spec/shared/shlib/server.sh +5 -5
  275. data/spec/support/constraints.rb +24 -0
  276. data/spec/support/macros.rb +30 -0
  277. data/spec/support/models/augmentation.rb +12 -0
  278. data/spec/support/models/band.rb +3 -0
  279. data/spec/support/models/catalog.rb +24 -0
  280. data/spec/support/models/circus.rb +3 -0
  281. data/spec/support/models/fanatic.rb +8 -0
  282. data/spec/support/models/implant.rb +9 -0
  283. data/spec/support/models/label.rb +2 -0
  284. data/spec/support/models/passport.rb +9 -0
  285. data/spec/support/models/person.rb +1 -0
  286. data/spec/support/models/player.rb +2 -0
  287. data/spec/support/models/powerup.rb +12 -0
  288. data/spec/support/models/registry.rb +1 -0
  289. data/spec/support/models/school.rb +14 -0
  290. data/spec/support/models/shield.rb +18 -0
  291. data/spec/support/models/student.rb +14 -0
  292. data/spec/support/models/weapon.rb +12 -0
  293. data.tar.gz.sig +0 -0
  294. metadata +689 -657
  295. metadata.gz.sig +0 -0
  296. data/lib/mongoid/errors/eager_load.rb +0 -23
  297. data/lib/mongoid/errors/invalid_value.rb +0 -17
  298. data/spec/mongoid/errors/eager_load_spec.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce7f228fdc033dc1142f46f4771395d36acafc97e0c144599cd063af537c7ae3
4
- data.tar.gz: 15f8f0efbb076eb03f25f23898cbe27d044e7441e4a7ae4bc8d22f036838bb98
3
+ metadata.gz: f4aba01720c23aaef7cb2c1ca3045e351a3499bb80758f4ddbdf2cc15baa9cd4
4
+ data.tar.gz: '082d09a7a072d85b8a19f884efc7805107732a32f0e90fe953785eabfae25bb7'
5
5
  SHA512:
6
- metadata.gz: 91f40b7136ae729e6831c5033c60c0a1e2207cd98d80bf5caaef50844230d6830efe555748571d9bdef62a101f75ffd21d2a7942278f84b68e2a51fc6a8f20df
7
- data.tar.gz: 3555b90da32865e1faadb9efccc6db0262adea620b4dd473d5dc1ee533b00451039dfaacd982ef5c8f6be4009ccff589119b2f512971a1b5ac509bb7ae4aa96e
6
+ metadata.gz: 35fedeedf4ad08f7f250600101eab0af7460e2b1c727448d0e880e418b195a18c33c8b672f2472e8291d2984d13e0781f271d8b034fab0753a80a7a76e62e6fd
7
+ data.tar.gz: f5da886e2b77b820c4d8928edc3c9f19d090712e17fd2efc484af0e13cd1e659dbf6f19270e4c53462779536e8b924b9cc65da3aeeed65cd98a1a5fbcb1e1649
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -19,9 +19,9 @@ Compatibility
19
19
 
20
20
  Mongoid supports and is tested against:
21
21
 
22
- - MRI 2.5 - 3.1
23
- - JRuby 9.2
24
- - MongoDB server 2.6 - 6.0
22
+ - MRI 2.6 - 3.1
23
+ - JRuby 9.3
24
+ - MongoDB server 3.6 - 6.0
25
25
 
26
26
  Issues
27
27
  ------
data/Rakefile CHANGED
@@ -11,15 +11,6 @@ $: << File.join(ROOT, 'spec/shared/lib')
11
11
  require "rake"
12
12
  require "rspec/core/rake_task"
13
13
  require 'mrss/spec_organizer'
14
- require 'rubygems/package'
15
- require 'rubygems/security/policies'
16
-
17
- def signed_gem?(path_to_gem)
18
- Gem::Package.new(path_to_gem, Gem::Security::HighSecurity).verify
19
- true
20
- rescue Gem::Security::Exception => e
21
- false
22
- end
23
14
 
24
15
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
25
16
  require "mongoid/version"
@@ -112,19 +103,3 @@ namespace :release do
112
103
  end
113
104
  end
114
105
  end
115
-
116
- desc 'Verifies that all built gems in pkg/ are valid'
117
- task :verify do
118
- gems = Dir['pkg/*.gem']
119
- if gems.empty?
120
- puts 'There are no gems in pkg/ to verify'
121
- else
122
- gems.each do |gem|
123
- if signed_gem?(gem)
124
- puts "#{gem} is signed"
125
- else
126
- abort "#{gem} is not signed"
127
- end
128
- end
129
- end
130
- end
@@ -1,4 +1,8 @@
1
1
  en:
2
+ errors:
3
+ messages:
4
+ taken: "has already been taken"
5
+
2
6
  mongoid:
3
7
  errors:
4
8
  messages:
@@ -61,7 +65,7 @@ en:
61
65
  and the following ids were not found: %{missing}."
62
66
  resolution: "Search for an id that is in the database or set
63
67
  the Mongoid.raise_not_found_error configuration option to false,
64
- which will cause a nil to be returned instead of raising this error when
68
+ which will cause nil to be returned instead of raising this error when
65
69
  searching for a single id, or only the matched documents when searching
66
70
  for multiples."
67
71
  document_with_attributes_not_found:
@@ -71,15 +75,17 @@ en:
71
75
  will be raised."
72
76
  resolution: "Search for attributes that are in the database or set
73
77
  the Mongoid.raise_not_found_error configuration option to false,
74
- which will cause a nil to be returned instead of raising this error."
75
- eager_load:
76
- message: "Eager loading :%{name} is not supported since it is a
77
- polymorphic belongs_to association."
78
- summary: "Mongoid cannot currently determine the classes it needs to
79
- eager load when the association is polymorphic. The parents reside in
80
- different collections so a simple id lookup is not sufficient enough."
81
- resolution: "Don't attempt to perform this action and have patience,
82
- maybe this will be supported in the future."
78
+ which will cause nil to be returned instead of raising this error."
79
+ document_with_shard_key_not_found:
80
+ message: "Document not found for class %{klass} with id %{missing} and
81
+ shard key %{shard_key}."
82
+ summary: "When calling %{klass}.find with an id and a shard key, each
83
+ parameter must match a document in the database or this error will
84
+ be raised. The search was for the id: %{missing} with
85
+ shard_key: %{shard_key} and it was not found."
86
+ resolution: "Search for an id/shard key that is in the database or set
87
+ the Mongoid.raise_not_found_error configuration option to false,
88
+ which will cause nil to be returned instead of raising this error."
83
89
  empty_config_file:
84
90
  message: "Empty configuration file: %{path}."
85
91
  summary: "Your mongoid.yml configuration file appears to be empty."
@@ -126,6 +132,17 @@ en:
126
132
  allowed."
127
133
  resolution: "Try setting the discriminator key on %{superclass} or one of %{class_name}'s
128
134
  ancestors."
135
+ invalid_dot_dollar_assignment:
136
+ message: "Cannot set the %{attr} attribute on the %{klass} class."
137
+ summary: "Calling the setters for fields that start with a dollar
138
+ sign ($) or contain a dot/period (.) is prohibited. See the
139
+ Mongoid documentation on Field Names with Dots/Periods (.) and
140
+ Dollar Signs ($) for more information."
141
+ resolution: "In order to set fields that start with a dollar
142
+ sign ($) or contain a dot/period (.), the aggregation pipeline can
143
+ be used. MongoDB provides specific operators for working with these
144
+ fields. Refer to the MongoDB documentation here:
145
+ https://www.mongodb.com/docs/manual/core/dot-dollar-considerations/"
129
146
  invalid_elem_match_operator:
130
147
  message: "Invalid $elemMatch operator '%{operator}'."
131
148
  summary: "You misspelled an operator or are using an operator that
@@ -146,7 +163,7 @@ en:
146
163
  resolution: "Valid expression operators are: %{valid_operators}.
147
164
  Ensure you are using one of these operators."
148
165
  invalid_field:
149
- message: "Defining a field named '%{name}' is not allowed."
166
+ message: "Defining a field named '%{field}' is not allowed."
150
167
  summary: "Defining this field would override the method '%{name}',
151
168
  which would cause issues with expectations around the original
152
169
  method and cause extremely hard to debug issues. The original
@@ -181,6 +198,13 @@ en:
181
198
  \_\_end\n\n
182
199
  Refer to:
183
200
  https://docs.mongodb.com/mongoid/current/reference/fields/#custom-field-options"
201
+ invalid_field_type:
202
+ message: "Invalid field type %{type_inspection} for field '%{field}' on model '%{klass}'."
203
+ summary: "Model '%{klass}' defines a field '%{field}' with an unknown type value
204
+ %{type_inspection}."
205
+ resolution: "Please provide a valid type value for the field.
206
+ Refer to:
207
+ https://docs.mongodb.com/mongoid/current/reference/fields/#using-symbols-or-strings-instead-of-classes"
184
208
  invalid_includes:
185
209
  message: "Invalid includes directive: %{klass}.includes(%{args})"
186
210
  summary: "Eager loading in Mongoid only supports providing arguments
@@ -196,7 +220,6 @@ en:
196
220
  Valid options are:\n
197
221
  \_\_background: true|false\n
198
222
  \_\_database: 'database_name'\n
199
- \_\_drop_dups: true|false\n
200
223
  \_\_name: 'index_name'\n
201
224
  \_\_sparse: true|false\n
202
225
  \_\_unique: true|false\n
@@ -215,7 +238,7 @@ en:
215
238
  \_\_language_override\n
216
239
  \_\_default_language\n
217
240
  \_\_collation\n
218
- Valid types are: 1, -1, '2d', '2dsphere', 'geoHaystack', 'text', 'hashed'\n\n
241
+ Valid types are: 1, -1, '2d', '2dsphere', 'geoHaystack (deprecated)', 'text', 'hashed'\n\n
219
242
  Example:\n
220
243
  \_\_class Band\n
221
244
  \_\_\_\_include Mongoid::Document\n
@@ -349,10 +372,6 @@ en:
349
372
  from the child side which association to go in."
350
373
  resolution: "Set the values from the parent, or redefine the association
351
374
  with only a single definition in the parent."
352
- invalid_value:
353
- message: "Value of type %{value_class} cannot be written to a field of type %{field_class}"
354
- summary: "Tried to set a value of type %{value_class} to a field of type %{field_class}"
355
- resolution: "Verify if the value to be set correspond to field definition"
356
375
  mixed_relations:
357
376
  message: "Referencing a(n) %{embedded} document from the %{root}
358
377
  document via a non-embedded association is not allowed since the
@@ -409,19 +428,18 @@ en:
409
428
  summary: "Mongoid attempted to find a document of the class %{klass}
410
429
  but none exist."
411
430
  resolution: "Create a document of class %{klass} or use a finder
412
- method that returns nil when no documents are found instead of
413
- raising an exception."
431
+ method that does not raise an exception when no documents are
432
+ found."
414
433
  no_environment:
415
434
  message: "Could not load the configuration since no environment
416
435
  was defined."
417
- summary: "Mongoid attempted to find the appropriate environment
418
- but no Rails.env, Sinatra::Base.environment, RACK_ENV, or
419
- MONGOID_ENV could be found."
420
- resolution: "Make sure some environment is set from the mentioned
421
- options. Mongoid cannot load configuration from the yaml without
422
- knowing which environment it is in, and we have considered
423
- defaulting to development an undesirable side effect of this not
424
- being defined."
436
+ summary: "Mongoid could not determine the environment to use because
437
+ it was not specified in any of the following locations:
438
+ Rails.env, Sinatra::Base.environment,
439
+ ENV[\"RACK_ENV\"], ENV[\"MONGOID_ENV\"]. Without knowing the
440
+ environment, Mongoid cannot load its configuration."
441
+ resolution: "Please ensure an environment is set in one of the
442
+ listed locations. The environment must be explicitly set."
425
443
  no_map_reduce_output:
426
444
  message: "No output location was specified for the map/reduce
427
445
  operation."
@@ -548,11 +566,9 @@ en:
548
566
  server versions 3.6 and higher."
549
567
  resolution: "Verify that all servers in your deployment are at least
550
568
  version 3.6 or don't attempt to use sessions with older server versions."
551
- taken:
552
- "is already taken"
553
569
  too_many_nested_attribute_records:
554
570
  message: "Accepting nested attributes for %{association} is limited
555
- to %{limit} records."
571
+ to %{limit} documents."
556
572
  summary: "More documents were sent to be processed than the allowed
557
573
  limit."
558
574
  resolution: "The limit is set as an option to the macro, for example:
@@ -42,8 +42,23 @@ module Mongoid
42
42
  # @return [ Proxy ] The association.
43
43
  def create_relation(object, association, selected_fields = nil)
44
44
  type = @attributes[association.inverse_type]
45
- target = association.build(self, object, type, selected_fields)
46
- target ? association.create_relation(self, target) : nil
45
+ target = if t = association.build(self, object, type, selected_fields)
46
+ association.create_relation(self, t)
47
+ else
48
+ nil
49
+ end
50
+
51
+ # Only need to do this on embedded associations. The pending callbacks
52
+ # are only added when materializing the documents, which only happens
53
+ # on embedded associations. There is no call to the database in the
54
+ # construction of a referenced association.
55
+ if association.embedded?
56
+ Array(target).each do |doc|
57
+ doc.try(:run_pending_callbacks)
58
+ end
59
+ end
60
+
61
+ target
47
62
  end
48
63
 
49
64
  # Resets the criteria inside the association proxy. Used by many-to-many
@@ -90,6 +105,19 @@ module Mongoid
90
105
  #
91
106
  # @return [ Proxy ] The association.
92
107
  def get_relation(name, association, object, reload = false)
108
+ field_name = database_field_name(name)
109
+
110
+ # As per the comments under MONGOID-5034, I've decided to only raise on
111
+ # embedded associations for a missing attribute. Rails does not raise
112
+ # for a missing attribute on referenced associations.
113
+ # We also don't want to raise if we're retrieving an association within
114
+ # the codebase. This is often done when retrieving the inverse association
115
+ # during binding or when cascading callbacks. Whenever we retrieve
116
+ # associations within the codebase, we use without_autobuild.
117
+ if !without_autobuild? && association.embedded? && attribute_missing?(field_name)
118
+ raise ActiveModel::MissingAttributeError, "Missing attribute: '#{field_name}'"
119
+ end
120
+
93
121
  if !reload && (value = ivar(name)) != false
94
122
  value
95
123
  else
@@ -291,7 +319,7 @@ module Mongoid
291
319
  ids_method = "#{association.name.to_s.singularize}_ids"
292
320
  association.inverse_class.tap do |klass|
293
321
  klass.re_define_method(ids_method) do
294
- send(association.name).only(:_id).map(&:_id)
322
+ send(association.name).pluck(:_id)
295
323
  end
296
324
  end
297
325
  end
@@ -341,6 +369,7 @@ module Mongoid
341
369
  # @return [ Class ] The class being set up.
342
370
  def self.define_ids_setter!(association)
343
371
  ids_method = "#{association.name.to_s.singularize}_ids="
372
+ association.inverse_class.aliased_associations[ids_method.chop] = association.name.to_s
344
373
  association.inverse_class.tap do |klass|
345
374
  klass.re_define_method(ids_method) do |ids|
346
375
  send(association.setter, association.relation_class.find(ids.reject(&:blank?)))
@@ -60,6 +60,53 @@ module Mongoid
60
60
  end
61
61
  end
62
62
 
63
+ # Remove the associated document from the inverse's association.
64
+ #
65
+ # @param [ Document ] doc The document to remove.
66
+ def remove_associated(doc)
67
+ if inverse = _association.inverse(doc)
68
+ if _association.many?
69
+ remove_associated_many(doc, inverse)
70
+ elsif _association.in_to?
71
+ remove_associated_in_to(doc, inverse)
72
+ end
73
+ end
74
+ end
75
+
76
+ # Remove the associated document from the inverse's association.
77
+ #
78
+ # This method removes the associated on *_many relationships.
79
+ #
80
+ # @param [ Document ] doc The document to remove.
81
+ # @param [ Symbol ] inverse The name of the inverse.
82
+ def remove_associated_many(doc, inverse)
83
+ # We only want to remove the inverse association when the inverse
84
+ # document is in memory.
85
+ if inv = doc.ivar(inverse)
86
+ # This first condition is needed because when assigning the
87
+ # embeds_many association using the same embeds_many
88
+ # association, we delete from the array we are about to assign.
89
+ if _base != inv && (associated = inv.ivar(_association.name))
90
+ associated.delete(doc)
91
+ end
92
+ end
93
+ end
94
+
95
+ # Remove the associated document from the inverse's association.
96
+ #
97
+ # This method removes associated on belongs_to and embedded_in
98
+ # associations.
99
+ #
100
+ # @param [ Document ] doc The document to remove.
101
+ # @param [ Symbol ] inverse The name of the inverse.
102
+ def remove_associated_in_to(doc, inverse)
103
+ # We only want to remove the inverse association when the inverse
104
+ # document is in memory.
105
+ if associated = doc.ivar(inverse)
106
+ associated.send(_association.setter, nil)
107
+ end
108
+ end
109
+
63
110
  # Set the id of the related document in the foreign key field on the
64
111
  # keyed document.
65
112
  #
@@ -134,6 +181,7 @@ module Mongoid
134
181
  # @param [ Document ] doc The document to bind.
135
182
  def bind_from_relational_parent(doc)
136
183
  check_inverse!(doc)
184
+ remove_associated(doc)
137
185
  bind_foreign_key(doc, record_id(_base))
138
186
  bind_polymorphic_type(doc, _base.class.name)
139
187
  bind_inverse(doc, _base)
@@ -46,9 +46,10 @@ module Mongoid
46
46
  association.inverse_class.tap do |klass|
47
47
  klass.re_define_method("build_#{association.name}") do |*args|
48
48
  attributes, _options = parse_args(*args)
49
- document = Factory.build(association.relation_class, attributes)
49
+ document = Factory.execute_build(association.relation_class, attributes, execute_callbacks: false)
50
50
  _building do
51
51
  child = send("#{association.name}=", document)
52
+ child.run_pending_callbacks
52
53
  child.run_callbacks(:build)
53
54
  child
54
55
  end
@@ -69,10 +70,11 @@ module Mongoid
69
70
  association.inverse_class.tap do |klass|
70
71
  klass.re_define_method("create_#{association.name}") do |*args|
71
72
  attributes, _options = parse_args(*args)
72
- document = Factory.build(association.relation_class, attributes)
73
+ document = Factory.execute_build(association.relation_class, attributes, execute_callbacks: false)
73
74
  doc = _assigning do
74
75
  send("#{association.name}=", document)
75
76
  end
77
+ doc.run_pending_callbacks
76
78
  doc.save
77
79
  save if new_record? && association.stores_foreign_key?
78
80
  doc
@@ -20,13 +20,35 @@ module Mongoid
20
20
  end
21
21
  end
22
22
 
23
- def preload(relations, docs)
24
- relations.group_by(&:inverse_class_name)
25
- .values
26
- .each do |associations|
27
- associations.group_by(&:relation)
28
- .each do |relation, association|
29
- relation.eager_loader(association, docs).run
23
+ # Load the associations for the given documents. This will be done
24
+ # recursively to load the associations of the given documents'
25
+ # subdocuments.
26
+ #
27
+ # @param [ Array<Association> ] associations The associations to load.
28
+ # @param [ Array<Document> ] document The documents.
29
+ def preload(associations, docs)
30
+ assoc_map = associations.group_by(&:inverse_class_name)
31
+ docs_map = {}
32
+ queue = [ klass.to_s ]
33
+
34
+ while klass = queue.shift
35
+ if as = assoc_map.delete(klass)
36
+ as.each do |assoc|
37
+ queue << assoc.class_name
38
+
39
+ # If this class is nested in the inclusion tree, only load documents
40
+ # for the association above it. If there is no parent association,
41
+ # we will include documents from the documents passed to this method.
42
+ ds = docs
43
+ if assoc.parent_inclusions.length > 0
44
+ ds = assoc.parent_inclusions.map{ |p| docs_map[p].to_a }.flatten
45
+ end
46
+
47
+ res = assoc.relation.eager_loader([assoc], ds).run
48
+
49
+ docs_map[assoc.name] ||= [].to_set
50
+ docs_map[assoc.name].merge(res)
51
+ end
30
52
  end
31
53
  end
32
54
  end
@@ -50,7 +50,7 @@ module Mongoid
50
50
  _unscoped.clear
51
51
  end
52
52
 
53
- # Batch remove the provided documents as a $pullAll.
53
+ # Batch remove the provided documents as a $pullAll or $pull.
54
54
  #
55
55
  # @example Batch remove the documents.
56
56
  # batchable.batch_remove([ doc_one, doc_two ])
@@ -58,13 +58,36 @@ module Mongoid
58
58
  # @param [ Array<Document> ] docs The docs to remove.
59
59
  # @param [ Symbol ] method Delete or destroy.
60
60
  def batch_remove(docs, method = :delete)
61
+ # If the _id is nil, we cannot use $pull and delete by searching for
62
+ # the id. Therefore we have to use pullAll with the documents'
63
+ # attributes.
61
64
  removals = pre_process_batch_remove(docs, method)
65
+ pulls, pull_alls = removals.partition { |o| !o["_id"].nil? }
66
+
67
+ if !_base.persisted?
68
+ post_process_batch_remove(docs, method) unless docs.empty?
69
+ return reindex
70
+ end
71
+
62
72
  if !docs.empty?
63
- collection.find(selector).update_one(
64
- positionally(selector, "$pullAll" => { path => removals }),
73
+ if !pulls.empty?
74
+ collection.find(selector).update_one(
75
+ positionally(selector, "$pull" => { path => { "_id" => { "$in" => pulls.pluck("_id") } } }),
65
76
  session: _session
66
- )
77
+ )
78
+ end
79
+ if !pull_alls.empty?
80
+ collection.find(selector).update_one(
81
+ positionally(selector, "$pullAll" => { path => pull_alls }),
82
+ session: _session
83
+ )
84
+ end
67
85
  post_process_batch_remove(docs, method)
86
+ else
87
+ collection.find(selector).update_one(
88
+ positionally(selector, "$set" => { path => [] }),
89
+ session: _session
90
+ )
68
91
  end
69
92
  reindex
70
93
  end
@@ -90,7 +113,7 @@ module Mongoid
90
113
  batch_remove(_target.dup)
91
114
  end
92
115
  elsif _target != docs
93
- _base.delayed_atomic_sets.clear unless _assigning?
116
+ _base.delayed_atomic_sets.delete(path) unless _assigning?
94
117
  docs = normalize_docs(docs).compact
95
118
  _target.clear and _unscoped.clear
96
119
  _base.delayed_atomic_unsets.delete(path)
@@ -19,12 +19,14 @@ module Mongoid
19
19
  # name.person.bind(:continue => true)
20
20
  # name.person = Person.new
21
21
  def bind_one
22
- _base._association = _association.inverse_association(_target) unless _base._association
23
- _base.parentize(_target)
24
22
  binding do
23
+ check_polymorphic_inverses!(_target)
24
+ _base._association = _association.inverse_association(_target) unless _base._association
25
+ _base.parentize(_target)
25
26
  if _base.embedded_many?
26
27
  _target.do_or_do_not(_association.inverse(_target)).push(_base)
27
28
  else
29
+ remove_associated(_target)
28
30
  _target.do_or_do_not(_association.inverse_setter(_target), _base)
29
31
  end
30
32
  end
@@ -45,6 +47,26 @@ module Mongoid
45
47
  end
46
48
  end
47
49
  end
50
+
51
+ private
52
+
53
+ # Check for problems with multiple inverse definitions.
54
+ #
55
+ # @api private
56
+ #
57
+ # @example Check for inverses errors.
58
+ # binding.check_inverses!(doc)
59
+ #
60
+ # @param [ Document ] doc The document to check.
61
+ def check_polymorphic_inverses!(doc)
62
+ if inverses = _association.inverses(doc)
63
+ if inverses.length > 1
64
+ raise Errors::InvalidSetPolymorphicRelation.new(
65
+ _association.name, _base.class.name, _target.class.name
66
+ )
67
+ end
68
+ end
69
+ end
48
70
  end
49
71
  end
50
72
  end
@@ -114,7 +114,8 @@ module Mongoid
114
114
  rel.as == name &&
115
115
  rel.relation_class_name == inverse_class_name
116
116
  end
117
- matches.collect { |m| m.name }
117
+
118
+ matches.map { |m| m.name }
118
119
  end
119
120
  end
120
121
 
@@ -19,6 +19,7 @@ module Mongoid
19
19
  def bind_one(doc)
20
20
  doc.parentize(_base)
21
21
  binding do
22
+ remove_associated(doc)
22
23
  doc.do_or_do_not(_association.inverse_setter(_target), _base)
23
24
  end
24
25
  end
@@ -31,7 +31,7 @@ module Mongoid
31
31
  docs = []
32
32
  object.each do |attrs|
33
33
  if _loading? && base.persisted?
34
- docs.push(Factory.from_db(klass, attrs, nil, selected_fields))
34
+ docs.push(Factory.execute_from_db(klass, attrs, nil, selected_fields, execute_callbacks: false))
35
35
  else
36
36
  docs.push(Factory.build(klass, attrs))
37
37
  end