mongoid 8.0.10 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +3 -3
  4. data/README.md +3 -3
  5. data/Rakefile +18 -67
  6. data/lib/config/locales/en.yml +46 -14
  7. data/lib/mongoid/association/accessors.rb +3 -7
  8. data/lib/mongoid/association/builders.rb +1 -1
  9. data/lib/mongoid/association/eager_loadable.rb +0 -3
  10. data/lib/mongoid/association/embedded/batchable.rb +2 -2
  11. data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -2
  12. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -1
  13. data/lib/mongoid/association/embedded/embeds_many/buildable.rb +3 -2
  14. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +6 -6
  15. data/lib/mongoid/association/embedded/embeds_one/buildable.rb +1 -1
  16. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +1 -1
  17. data/lib/mongoid/association/macros.rb +0 -6
  18. data/lib/mongoid/association/nested/one.rb +40 -2
  19. data/lib/mongoid/association/proxy.rb +1 -1
  20. data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
  21. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +1 -1
  22. data/lib/mongoid/association/referenced/has_many/enumerable.rb +6 -23
  23. data/lib/mongoid/association/referenced/has_many/proxy.rb +3 -3
  24. data/lib/mongoid/association/reflections.rb +2 -2
  25. data/lib/mongoid/atomic.rb +7 -16
  26. data/lib/mongoid/attributes/dynamic.rb +1 -1
  27. data/lib/mongoid/attributes/nested.rb +2 -2
  28. data/lib/mongoid/attributes/processing.rb +5 -29
  29. data/lib/mongoid/attributes/projector.rb +1 -1
  30. data/lib/mongoid/attributes/readonly.rb +1 -1
  31. data/lib/mongoid/attributes.rb +8 -2
  32. data/lib/mongoid/changeable.rb +107 -5
  33. data/lib/mongoid/clients/storage_options.rb +2 -5
  34. data/lib/mongoid/clients/validators/storage.rb +1 -13
  35. data/lib/mongoid/collection_configurable.rb +58 -0
  36. data/lib/mongoid/composable.rb +2 -0
  37. data/lib/mongoid/config/defaults.rb +60 -0
  38. data/lib/mongoid/config/options.rb +0 -3
  39. data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
  40. data/lib/mongoid/config/validators.rb +1 -0
  41. data/lib/mongoid/config.rb +88 -27
  42. data/lib/mongoid/contextual/atomic.rb +1 -1
  43. data/lib/mongoid/contextual/memory.rb +233 -33
  44. data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
  45. data/lib/mongoid/contextual/mongo.rb +370 -133
  46. data/lib/mongoid/contextual/none.rb +162 -7
  47. data/lib/mongoid/contextual.rb +12 -0
  48. data/lib/mongoid/criteria/findable.rb +2 -2
  49. data/lib/mongoid/criteria/includable.rb +4 -3
  50. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -15
  51. data/lib/mongoid/criteria/queryable/key.rb +1 -1
  52. data/lib/mongoid/criteria/queryable/mergeable.rb +1 -1
  53. data/lib/mongoid/criteria/queryable/optional.rb +8 -8
  54. data/lib/mongoid/criteria/queryable/selectable.rb +43 -12
  55. data/lib/mongoid/criteria/queryable/selector.rb +1 -1
  56. data/lib/mongoid/criteria/queryable/storable.rb +1 -1
  57. data/lib/mongoid/criteria.rb +6 -5
  58. data/lib/mongoid/deprecable.rb +1 -2
  59. data/lib/mongoid/deprecation.rb +3 -3
  60. data/lib/mongoid/document.rb +1 -8
  61. data/lib/mongoid/errors/create_collection_failure.rb +33 -0
  62. data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
  63. data/lib/mongoid/errors/immutable_attribute.rb +26 -0
  64. data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
  65. data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
  66. data/lib/mongoid/errors/invalid_storage_parent.rb +2 -0
  67. data/lib/mongoid/errors.rb +4 -1
  68. data/lib/mongoid/extensions/hash.rb +2 -24
  69. data/lib/mongoid/extensions/object.rb +2 -2
  70. data/lib/mongoid/extensions/time.rb +2 -0
  71. data/lib/mongoid/fields/localized.rb +10 -0
  72. data/lib/mongoid/fields/standard.rb +10 -0
  73. data/lib/mongoid/fields.rb +59 -35
  74. data/lib/mongoid/findable.rb +27 -3
  75. data/lib/mongoid/interceptable.rb +6 -116
  76. data/lib/mongoid/matcher/eq_impl.rb +1 -1
  77. data/lib/mongoid/matcher/type.rb +1 -1
  78. data/lib/mongoid/persistable/creatable.rb +1 -0
  79. data/lib/mongoid/persistable/deletable.rb +1 -1
  80. data/lib/mongoid/persistable/savable.rb +13 -1
  81. data/lib/mongoid/persistable/unsettable.rb +2 -2
  82. data/lib/mongoid/persistable/updatable.rb +51 -1
  83. data/lib/mongoid/persistable/upsertable.rb +20 -1
  84. data/lib/mongoid/persistable.rb +3 -0
  85. data/lib/mongoid/query_cache.rb +5 -1
  86. data/lib/mongoid/railties/database.rake +7 -2
  87. data/lib/mongoid/reloadable.rb +5 -3
  88. data/lib/mongoid/stateful.rb +22 -1
  89. data/lib/mongoid/tasks/database.rake +12 -0
  90. data/lib/mongoid/tasks/database.rb +20 -0
  91. data/lib/mongoid/timestamps/created.rb +1 -8
  92. data/lib/mongoid/traversable.rb +0 -12
  93. data/lib/mongoid/utils.rb +22 -0
  94. data/lib/mongoid/validatable/associated.rb +17 -98
  95. data/lib/mongoid/validatable/macros.rb +5 -5
  96. data/lib/mongoid/validatable.rb +4 -9
  97. data/lib/mongoid/version.rb +1 -1
  98. data/lib/mongoid/warnings.rb +17 -1
  99. data/lib/mongoid.rb +16 -3
  100. data/spec/integration/app_spec.rb +2 -6
  101. data/spec/integration/associations/has_and_belongs_to_many_spec.rb +0 -40
  102. data/spec/integration/callbacks_spec.rb +99 -12
  103. data/spec/integration/discriminator_key_spec.rb +4 -5
  104. data/spec/integration/i18n_fallbacks_spec.rb +3 -2
  105. data/spec/mongoid/association/eager_spec.rb +2 -24
  106. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +27 -0
  107. data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +20 -25
  108. data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
  109. data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +0 -4
  110. data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +15 -2
  111. data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -18
  112. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +42 -55
  113. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +9 -50
  114. data/spec/mongoid/association/syncable_spec.rb +1 -1
  115. data/spec/mongoid/association_spec.rb +0 -60
  116. data/spec/mongoid/attributes_spec.rb +3 -33
  117. data/spec/mongoid/changeable_spec.rb +299 -24
  118. data/spec/mongoid/clients_spec.rb +122 -13
  119. data/spec/mongoid/collection_configurable_spec.rb +158 -0
  120. data/spec/mongoid/config/defaults_spec.rb +160 -0
  121. data/spec/mongoid/config_spec.rb +154 -27
  122. data/spec/mongoid/contextual/memory_spec.rb +332 -76
  123. data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
  124. data/spec/mongoid/contextual/mongo_spec.rb +1009 -125
  125. data/spec/mongoid/contextual/none_spec.rb +49 -2
  126. data/spec/mongoid/copyable_spec.rb +2 -10
  127. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +4 -10
  128. data/spec/mongoid/criteria/queryable/options_spec.rb +1 -1
  129. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +419 -0
  130. data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -1
  131. data/spec/mongoid/criteria/queryable/selector_spec.rb +3 -76
  132. data/spec/mongoid/criteria/queryable/storable_spec.rb +0 -72
  133. data/spec/mongoid/criteria_projection_spec.rb +1 -4
  134. data/spec/mongoid/criteria_spec.rb +5 -9
  135. data/spec/mongoid/document_spec.rb +0 -27
  136. data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
  137. data/spec/mongoid/extensions/hash_spec.rb +3 -3
  138. data/spec/mongoid/extensions/time_spec.rb +8 -43
  139. data/spec/mongoid/extensions/time_with_zone_spec.rb +7 -52
  140. data/spec/mongoid/fields/localized_spec.rb +46 -28
  141. data/spec/mongoid/fields_spec.rb +136 -77
  142. data/spec/mongoid/findable_spec.rb +391 -34
  143. data/spec/mongoid/indexable_spec.rb +16 -10
  144. data/spec/mongoid/interceptable_spec.rb +153 -442
  145. data/spec/mongoid/interceptable_spec_models.rb +111 -51
  146. data/spec/mongoid/persistable/deletable_spec.rb +26 -6
  147. data/spec/mongoid/persistable/destroyable_spec.rb +26 -6
  148. data/spec/mongoid/persistable/incrementable_spec.rb +37 -0
  149. data/spec/mongoid/persistable/logical_spec.rb +37 -0
  150. data/spec/mongoid/persistable/poppable_spec.rb +36 -0
  151. data/spec/mongoid/persistable/pullable_spec.rb +72 -0
  152. data/spec/mongoid/persistable/pushable_spec.rb +72 -0
  153. data/spec/mongoid/persistable/renamable_spec.rb +36 -0
  154. data/spec/mongoid/persistable/savable_spec.rb +96 -0
  155. data/spec/mongoid/persistable/settable_spec.rb +37 -0
  156. data/spec/mongoid/persistable/unsettable_spec.rb +36 -0
  157. data/spec/mongoid/persistable/updatable_spec.rb +20 -28
  158. data/spec/mongoid/persistable/upsertable_spec.rb +80 -6
  159. data/spec/mongoid/persistence_context_spec.rb +7 -57
  160. data/spec/mongoid/query_cache_spec.rb +56 -61
  161. data/spec/mongoid/reloadable_spec.rb +24 -28
  162. data/spec/mongoid/scopable_spec.rb +70 -0
  163. data/spec/mongoid/serializable_spec.rb +23 -44
  164. data/spec/mongoid/stateful_spec.rb +122 -8
  165. data/spec/mongoid/tasks/database_rake_spec.rb +74 -0
  166. data/spec/mongoid/tasks/database_spec.rb +127 -0
  167. data/spec/mongoid/timestamps/created_spec.rb +0 -23
  168. data/spec/mongoid/timestamps_spec.rb +9 -11
  169. data/spec/mongoid/touchable_spec.rb +277 -5
  170. data/spec/mongoid/touchable_spec_models.rb +3 -1
  171. data/spec/mongoid/traversable_spec.rb +9 -24
  172. data/spec/mongoid/validatable/associated_spec.rb +34 -27
  173. data/spec/mongoid/validatable/uniqueness_spec.rb +2 -3
  174. data/spec/mongoid_spec.rb +36 -10
  175. data/spec/shared/LICENSE +20 -0
  176. data/spec/shared/bin/get-mongodb-download-url +17 -0
  177. data/spec/shared/bin/s3-copy +45 -0
  178. data/spec/shared/bin/s3-upload +69 -0
  179. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  180. data/spec/shared/lib/mrss/cluster_config.rb +231 -0
  181. data/spec/shared/lib/mrss/constraints.rb +378 -0
  182. data/spec/shared/lib/mrss/docker_runner.rb +298 -0
  183. data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
  184. data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
  185. data/spec/shared/lib/mrss/lite_constraints.rb +238 -0
  186. data/spec/shared/lib/mrss/server_version_registry.rb +113 -0
  187. data/spec/shared/lib/mrss/session_registry.rb +69 -0
  188. data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
  189. data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
  190. data/spec/shared/lib/mrss/utils.rb +37 -0
  191. data/spec/shared/share/Dockerfile.erb +321 -0
  192. data/spec/shared/share/haproxy-1.conf +16 -0
  193. data/spec/shared/share/haproxy-2.conf +17 -0
  194. data/spec/shared/shlib/config.sh +27 -0
  195. data/spec/shared/shlib/distro.sh +74 -0
  196. data/spec/shared/shlib/server.sh +416 -0
  197. data/spec/shared/shlib/set_env.sh +169 -0
  198. data/spec/spec_helper.rb +5 -0
  199. data/spec/support/immutable_ids.rb +118 -0
  200. data/spec/support/macros.rb +47 -15
  201. data/spec/support/models/artist.rb +0 -1
  202. data/spec/support/models/band.rb +1 -0
  203. data/spec/support/models/building.rb +2 -0
  204. data/spec/support/models/name.rb +0 -10
  205. data/spec/support/models/person.rb +0 -1
  206. data/spec/support/models/product.rb +1 -0
  207. data.tar.gz.sig +0 -0
  208. metadata +745 -637
  209. metadata.gz.sig +2 -0
  210. data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -60
  211. data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -60
  212. data/spec/support/models/purse.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d5d57d80bf503ada4f229db360fee76b689f1224292a05ce8b9e2e1f2768f17
4
- data.tar.gz: 409bfdfa5c3f91cfc75429569148cbff7bc19716193ac2af3d101f91647b7ea8
3
+ metadata.gz: 1f5f0b81e26dba41d786804bd1213f2c05c4594ca9e05d0f62417fc15da6532e
4
+ data.tar.gz: c44f03a981d2fc648822718522e2ee7e8db6fa3fec01764eb09d77a4183a3559
5
5
  SHA512:
6
- metadata.gz: 2aa57a75a92f7a03d872f28a0be8cfdd800d2917a9893b2cb4101cedcc1196c02c2e9591e3de67580b00b06626ea16bdf8aa742cc5752a806581e88a186410de
7
- data.tar.gz: 725b89395a8d8126c196bd3ed42f02dc44c9e019247364f4fcc2d5587cf742a2ba3e9c27cafface3ea13712e2f17ea0fab081a8177b52299ed36b74b35a49347
6
+ metadata.gz: bafd2e708f204e23b0e277df74f897d19a83f059eb34bff3b636231f6e76a83176a45ea1b49586bff52c44bc3a526bd0d988cec3441bc469514035ad0acc7272
7
+ data.tar.gz: 59e6b77e3e03d94cb82fd2aad20c3951cbcc9f0872138ae76f6837986aad641cce339d5d51b8122047b5732266883708f847a7bd23c0ed2fe7bf8e19e834e045
checksums.yaml.gz.sig ADDED
Binary file
data/CHANGELOG.md CHANGED
@@ -63,7 +63,7 @@ For instructions on upgrading to newer versions, visit
63
63
 
64
64
  * Mongoid now uses the official Mongo Ruby Driver 2.x instead of Moped.
65
65
 
66
- * Most driver specific configuration options have changed, please see [here](http://docs.mongodb.org/ecosystem/tutorial/ruby-driver-tutorial/#ruby-options) for the new options.
66
+ * Most driver specific configuration options have changed, please see [here](https://www.mongodb.com/docs/ecosystem/tutorial/ruby-driver-tutorial/#ruby-options) for the new options.
67
67
 
68
68
  * All references to `session` are now replaced with `client`. This includes the mongoid.yml configuration, `store_in` options, and all exceptions and modules with `Session` in the name.
69
69
 
@@ -872,8 +872,8 @@ child elements.
872
872
  handling of validations. (Gerad Suyderhoud)
873
873
 
874
874
  * \#2443 `expire_after_seconds` is now a valid index option
875
- (http://docs.mongodb.org/manual/core/indexes/#ttl-indexes,
876
- http://docs.mongodb.org/manual/tutorial/expire-data/).
875
+ (https://www.mongodb.com/docs/manual/core/indexes/#ttl-indexes,
876
+ https://www.mongodb.com/docs/manual/tutorial/expire-data/).
877
877
 
878
878
  class Event
879
879
  include Mongoid::Document
data/README.md CHANGED
@@ -8,11 +8,11 @@ Mongoid is an ODM (Object-Document Mapper) framework for MongoDB in Ruby.
8
8
  Documentation
9
9
  -------------
10
10
 
11
- Mongoid has [extensive user documentation](https://docs.mongodb.com/mongoid/current/).
12
- [API documentation](https://docs.mongodb.com/mongoid/current/api/) is also available.
11
+ Mongoid has [extensive user documentation](https://www.mongodb.com/docs/mongoid/current/).
12
+ [API documentation](https://www.mongodb.com/docs/mongoid/current/api/) is also available.
13
13
 
14
14
  Mongoid is built on top of the MongoDB Ruby driver which has
15
- [its own user documentation](https://docs.mongodb.com/ruby-driver/current/).
15
+ [its own user documentation](https://www.mongodb.com/docs/ruby-driver/current/).
16
16
 
17
17
  Compatibility
18
18
  -------------
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler"
4
+ require "bundler/gem_tasks"
4
5
  Bundler.setup
5
6
 
6
7
  ROOT = File.expand_path(File.join(File.dirname(__FILE__)))
@@ -9,53 +10,25 @@ $: << File.join(ROOT, 'spec/shared/lib')
9
10
 
10
11
  require "rake"
11
12
  require "rspec/core/rake_task"
13
+ require 'mrss/spec_organizer'
12
14
 
13
- # stands in for the Bundler-provided `build` task, which builds the
14
- # gem for this project. Our release process builds the gems in a
15
- # particular way, in a GitHub action. This task is just to help remind
16
- # developers of that fact.
15
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
16
+ require "mongoid/version"
17
+
18
+ tasks = Rake.application.instance_variable_get('@tasks')
19
+ tasks['release:do'] = tasks.delete('release')
20
+
21
+ task :gem => :build
17
22
  task :build do
18
- abort <<~WARNING
19
- `rake build` does nothing in this project. The gem must be built via
20
- the `Mongoid Release` action on GitHub, which is triggered manually when
21
- a new release is ready.
22
- WARNING
23
+ system "gem build mongoid.gemspec"
23
24
  end
24
25
 
25
- # `rake version` is used by the deployment system so get the release version
26
- # of the product beng deployed. It must do nothing more than just print the
27
- # product version number.
28
- #
29
- # See the mongodb-labs/driver-github-tools/ruby/publish Github action.
30
- desc "Print the current value of Mongoid::VERSION"
31
- task :version do
32
- require 'mongoid/version'
33
-
34
- puts Mongoid::VERSION
26
+ task :install => :build do
27
+ system "sudo gem install mongoid-#{Mongoid::VERSION}.gem"
35
28
  end
36
29
 
37
- # overrides the default Bundler-provided `release` task, which also
38
- # builds the gem. Our release process assumes the gem has already
39
- # been built (and signed via GPG), so we just need `rake release` to
40
- # push the gem to rubygems.
41
30
  task :release do
42
- require 'mongoid/version'
43
-
44
- if ENV['GITHUB_ACTION'].nil?
45
- abort <<~WARNING
46
- `rake release` must be invoked from the `Mongoid Release` GitHub action,
47
- and must not be invoked locally. This ensures the gem is properly signed
48
- and distributed by the appropriate user.
49
-
50
- Note that it is the `rubygems/release-gem@v1` step in the `Mongoid Release`
51
- action that invokes this task. Do not rename or remove this task, or the
52
- release-gem step will fail. Reimplement this task with caution.
53
-
54
- mongoid-#{Mongoid::VERSION}.gem was NOT pushed to RubyGems.
55
- WARNING
56
- end
57
-
58
- system 'gem', 'push', "mongoid-#{Mongoid::VERSION}.gem"
31
+ raise "Please use ./release.sh to release"
59
32
  end
60
33
 
61
34
  RSpec::Core::RakeTask.new("spec") do |spec|
@@ -82,8 +55,6 @@ RUN_PRIORITY = %i(
82
55
  )
83
56
 
84
57
  def spec_organizer
85
- require 'mrss/spec_organizer'
86
-
87
58
  Mrss::SpecOrganizer.new(
88
59
  root: ROOT,
89
60
  classifiers: CLASSIFIERS,
@@ -119,36 +90,16 @@ task :docs => 'docs:yard'
119
90
  namespace :docs do
120
91
  desc "Generate yard documention"
121
92
  task :yard do
122
- require "mongoid/version"
123
-
124
93
  out = File.join('yard-docs', Mongoid::VERSION)
125
94
  FileUtils.rm_rf(out)
126
95
  system "yardoc -o #{out} --title mongoid-#{Mongoid::VERSION}"
127
96
  end
128
97
  end
129
98
 
130
- desc 'Build and validate the evergreen config'
131
- task eg: %w[ eg:build eg:validate ]
132
-
133
- # 'eg' == 'evergreen', but evergreen is too many letters for convenience
134
- namespace :eg do
135
- desc 'Builds the .evergreen/config.yml file from the templates'
136
- task :build do
137
- ruby '.evergreen/update-evergreen-configs'
138
- end
139
-
140
- desc 'Validates the .evergreen/config.yml file'
141
- task :validate do
142
- system 'evergreen validate --project mongoid .evergreen/config.yml'
143
- end
144
-
145
- desc 'Updates the evergreen executable to the latest available version'
146
- task :update do
147
- system 'evergreen get-update --install'
148
- end
149
-
150
- desc 'Runs the current branch as an evergreen patch'
151
- task :patch do
152
- system 'evergreen patch --uncommitted --project mongoid --browse --auto-description --yes'
99
+ namespace :release do
100
+ task :check_private_key do
101
+ unless File.exist?('gem-private_key.pem')
102
+ raise "No private key present, cannot release"
103
+ end
153
104
  end
154
105
  end
@@ -31,6 +31,17 @@ en:
31
31
  since the document did not actually get saved."
32
32
  resolution: "Double check all before callbacks to make sure they are
33
33
  not unintentionally returning false."
34
+ create_collection_failure:
35
+ message: "Cannot create collection %{collection_name}
36
+ with options %{collection_options}. The following error was raised:
37
+ %{error}."
38
+ summary: "The server rejected createCollection command with given collection
39
+ options. This may happen when some of the options are invalid, or not
40
+ supported by your version of the server."
41
+ resolution: "Double check that collection options for the collection
42
+ %{collection_name} are valid. Consult with Ruby driver documentation
43
+ and MongoDB documentation if the desired options are supported by
44
+ your version of the server."
34
45
  criteria_argument_required:
35
46
  message: "Calling Criteria methods with nil arguments is not allowed."
36
47
  summary: "Arguments to Criteria methods cannot be nil, and most
@@ -86,11 +97,24 @@ en:
86
97
  resolution: "Search for an id/shard key that is in the database or set
87
98
  the Mongoid.raise_not_found_error configuration option to false,
88
99
  which will cause nil to be returned instead of raising this error."
100
+ drop_collection_failure:
101
+ message: "Cannot drop collection %{collection_name}."
102
+ summary: "Mongoid tried to drop collection %{collection_name}, but the
103
+ collection still exists in the database."
104
+ resolution: "Try to drop the collection manually using Ruby driver or
105
+ mongo shell."
89
106
  empty_config_file:
90
107
  message: "Empty configuration file: %{path}."
91
108
  summary: "Your mongoid.yml configuration file appears to be empty."
92
109
  resolution: "Ensure your configuration file contains the correct contents.
93
- Refer to: https://docs.mongodb.com/mongoid/current/reference/configuration/"
110
+ Refer to: https://www.mongodb.com/docs/mongoid/current/reference/configuration/"
111
+ immutable_attribute:
112
+ message: "Attempted to change the immutable attribute '%{name}' with
113
+ the value: %{value}."
114
+ summary: "Immutable attributes can only have values set when the
115
+ document is a new record."
116
+ resolution: "Do not attempt to update the value of '%{name}' after
117
+ the document is persisted."
94
118
  invalid_collection:
95
119
  message: "Access to the collection for %{klass} is not allowed."
96
120
  summary: "%{klass}.collection was called, and %{klass} is an embedded
@@ -105,12 +129,20 @@ en:
105
129
  A collation option is only supported if the query is executed on a MongoDB server
106
130
  with version >= 3.4."
107
131
  resolution: "Remove the collation option from the query."
132
+ invalid_async_query_executor:
133
+ message: "Invalid async_query_executor option: %{executor}."
134
+ summary: "A invalid async query executor was specified.
135
+ The valid options are: %{options}."
136
+ resolution: "Pick an allowed option or fix the typo. If you were
137
+ expecting the option to be there, please consult the following page
138
+ with respect to Mongoid's configuration:\n\n
139
+ \_\_https://www.mongodb.com/docs/mongoid/current/reference/configuration/#mongoid-configuration-options"
108
140
  invalid_config_file:
109
141
  message: "Invalid configuration file: %{path}."
110
142
  summary: "Your mongoid.yml configuration file does not contain the
111
143
  correct file structure."
112
144
  resolution: "Ensure your configuration file contains the correct contents.
113
- Refer to: https://docs.mongodb.com/mongoid/current/reference/configuration/"
145
+ Refer to: https://www.mongodb.com/docs/mongoid/current/reference/configuration/"
114
146
  invalid_config_option:
115
147
  message: "Invalid configuration option: %{name}."
116
148
  summary: "A invalid configuration option was provided in your
@@ -197,14 +229,21 @@ en:
197
229
  \_\_\_\_field :%{name}, %{option}: true\n
198
230
  \_\_end\n\n
199
231
  Refer to:
200
- https://docs.mongodb.com/mongoid/current/reference/fields/#custom-field-options"
232
+ https://www.mongodb.com/docs/mongoid/current/reference/fields/#custom-field-options"
201
233
  invalid_field_type:
202
234
  message: "Invalid field type %{type_inspection} for field '%{field}' on model '%{klass}'."
203
235
  summary: "Model '%{klass}' defines a field '%{field}' with an unknown type value
204
236
  %{type_inspection}."
205
237
  resolution: "Please provide a valid type value for the field.
206
238
  Refer to:
207
- https://docs.mongodb.com/mongoid/current/reference/fields/#using-symbols-or-strings-instead-of-classes"
239
+ https://www.mongodb.com/docs/mongoid/current/reference/fields/#using-symbols-or-strings-instead-of-classes"
240
+ invalid_global_executor_concurrency:
241
+ message: "Invalid global_executor_concurrency option."
242
+ summary: "You set global_executor_concurrency while async_query_executor
243
+ option is not set to :global_thread_pool. The global_executor_concurrency is
244
+ allowed only for the global thread pool executor."
245
+ resolution: "Set global_executor_concurrency option to :global_thread_pool
246
+ or remove global_executor_concurrency option."
208
247
  invalid_includes:
209
248
  message: "Invalid includes directive: %{klass}.includes(%{args})"
210
249
  summary: "Eager loading in Mongoid only supports providing arguments
@@ -315,7 +354,7 @@ en:
315
354
  invalid_storage_options:
316
355
  message: "Invalid options passed to %{klass}.store_in: %{options}."
317
356
  summary: "The :store_in macro takes only a hash of parameters with
318
- the keys :database, :collection, or :client."
357
+ the keys :database, :collection, :collection_options, or :client."
319
358
  resolution: "Change the options passed to store_in to match the
320
359
  documented API, and ensure all keys in the options hash are
321
360
  symbols.\n\n
@@ -324,12 +363,6 @@ en:
324
363
  \_\_\_\_include Mongoid::Document\n
325
364
  \_\_\_\_store_in collection: 'artists', database: 'music'\n
326
365
  \_\_end\n\n"
327
- invalid_storage_parent:
328
- message: "Invalid store_in call on class %{klass}."
329
- summary: "The :store_in macro can only be called on a base Mongoid Document"
330
- resolution: "Remove the store_in call on class %{klass}, as it will use its
331
- parent store configuration. Or remove the hierarchy extension for this
332
- class."
333
366
  invalid_time:
334
367
  message: "'%{value}' is not a valid Time."
335
368
  summary: "Mongoid tries to serialize the values for Date, DateTime, and
@@ -545,9 +578,8 @@ en:
545
578
  resolution: "Don't define '%{name}' as readonly, or do not attempt
546
579
  to update its value after the document is persisted."
547
580
  readonly_document:
548
- message: "Attempted to persist the readonly document '%{klass}'."
549
- summary: "Documents loaded from the database using #only
550
- cannot be persisted."
581
+ message: "Attempted to persist a readonly document of class '%{klass}'."
582
+ summary: "Documents that are marked readonly cannot be persisted."
551
583
  resolution: "Don't attempt to persist documents that are flagged as
552
584
  readonly."
553
585
  scope_overwrite:
@@ -115,11 +115,7 @@ module Mongoid
115
115
  # during binding or when cascading callbacks. Whenever we retrieve
116
116
  # associations within the codebase, we use without_autobuild.
117
117
  if !without_autobuild? && association.embedded? && attribute_missing?(field_name)
118
- # We always allow accessing the parent document of an embedded one.
119
- try_get_parent = association.is_a?(
120
- Mongoid::Association::Embedded::EmbeddedIn
121
- ) && field_name == association.key
122
- raise ActiveModel::MissingAttributeError, "Missing attribute: '#{field_name}'" unless try_get_parent
118
+ raise ActiveModel::MissingAttributeError, "Missing attribute: '#{field_name}'"
123
119
  end
124
120
 
125
121
  if !reload && (value = ivar(name)) != false
@@ -210,7 +206,7 @@ module Mongoid
210
206
 
211
207
  # Positional projection is specified as "foo.$". In this case the
212
208
  # document that the $ is referring to should be retrieved with all
213
- # fields. See https://docs.mongodb.com/manual/reference/operator/projection/positional/
209
+ # fields. See https://www.mongodb.com/docs/manual/reference/operator/projection/positional/
214
210
  # and https://jira.mongodb.org/browse/MONGOID-4769.
215
211
  if filtered.keys == %w($)
216
212
  filtered = nil
@@ -255,7 +251,7 @@ module Mongoid
255
251
  # @example Parse the args.
256
252
  # doc.parse_args(:name => "Joe")
257
253
  #
258
- # @param [ Array ] args The arguments.
254
+ # @param [ Hash... ] *args The arguments.
259
255
  #
260
256
  # @return [ Array<Hash> ] The attributes and options.
261
257
  def parse_args(*args)
@@ -27,7 +27,7 @@ module Mongoid
27
27
  # @example Parse the args.
28
28
  # doc.parse_args(:name => "Joe")
29
29
  #
30
- # @param [ Array ] args The arguments.
30
+ # @param [ Hash... ] *args The arguments.
31
31
  #
32
32
  # @return [ Array<Hash> ] The attributes and options.
33
33
  def parse_args(*args)
@@ -31,9 +31,6 @@ module Mongoid
31
31
  docs_map = {}
32
32
  queue = [ klass.to_s ]
33
33
 
34
- # account for single-collection inheritance
35
- queue.push(klass.root_class.to_s) if klass != klass.root_class
36
-
37
34
  while klass = queue.shift
38
35
  if as = assoc_map.delete(klass)
39
36
  as.each do |assoc|
@@ -97,7 +97,7 @@ module Mongoid
97
97
  # @example Batch replace the documents.
98
98
  # batchable.batch_replace([ doc_one, doc_two ])
99
99
  #
100
- # @param [ Array<Document> ] docs The docs to replace with.
100
+ # @param [ Array<Document> | Array<Hash> ] docs The docs to replace with.
101
101
  #
102
102
  # @return [ Array<Hash> ] The inserts.
103
103
  def batch_replace(docs)
@@ -235,7 +235,7 @@ module Mongoid
235
235
  # @example Normalize the docs.
236
236
  # batchable.normalize_docs(docs)
237
237
  #
238
- # @param [ Array<Hash | Document> ] docs The docs to normalize.
238
+ # @param [ Array<Document> | Array<Hash> ] docs The docs to normalize.
239
239
  #
240
240
  # @return [ Array<Document> ] The docs.
241
241
  def normalize_docs(docs)
@@ -15,8 +15,8 @@ module Mongoid
15
15
  # @example Build the document.
16
16
  # Builder.new(meta, attrs).build
17
17
  #
18
- # @param [ Object ] base The object.
19
- # @param [ Object ] object The parent hash or document.
18
+ # @param [ Document ] base The object.
19
+ # @param [ Document | Hash ] object The parent hash or document.
20
20
  # @param [ String ] type Not used in this context.
21
21
  # @param [ Hash ] selected_fields Fields which were retrieved via
22
22
  # #only. If selected_fields are specified, fields not listed in it
@@ -30,7 +30,7 @@ module Mongoid
30
30
  # @example Substitute the new document.
31
31
  # person.name.substitute(new_name)
32
32
  #
33
- # @param [ Document ] replacement A document to replace the target.
33
+ # @param [ Document | Hash ] replacement A document to replace the target.
34
34
  #
35
35
  # @return [ Document | nil ] The association or nil.
36
36
  def substitute(replacement)
@@ -40,6 +40,7 @@ module Mongoid
40
40
  return nil
41
41
  end
42
42
  _base.new_record = true
43
+ replacement = Factory.build(klass, replacement) if replacement.is_a?(::Hash)
43
44
  self._target = replacement
44
45
  bind_one
45
46
  self
@@ -17,8 +17,9 @@ module Mongoid
17
17
  # @example Build the documents.
18
18
  # Builder.new(meta, attrs).build
19
19
  #
20
- # @param [ Object ] base The base object.
21
- # @param [ Object ] object The object to use to build the association.
20
+ # @param [ Document ] base The base object.
21
+ # @param [ Array<Document> | Array<Hash> ] object The object to use
22
+ # to build the association.
22
23
  # @param [ String ] type Not used in this context.
23
24
  # @param [ Hash ] selected_fields Fields which were retrieved via
24
25
  # #only. If selected_fields are specified, fields not listed in it
@@ -19,7 +19,7 @@ module Mongoid
19
19
  # @example Push a document.
20
20
  # person.addresses.push(address)
21
21
  #
22
- # @param [ Document | Array<Document> ] args Any number of documents.
22
+ # @param [ Document... ] *args Any number of documents.
23
23
  def <<(*args)
24
24
  docs = args.flatten
25
25
  return concat(docs) if docs.size > 1
@@ -117,7 +117,7 @@ module Mongoid
117
117
  # @example Use #persisted? inside block to count persisted documents.
118
118
  # person.addresses.count { |a| a.persisted? && a.country == "FR" }
119
119
  #
120
- # @param [ Object | Array<Object> ] args Args to delegate to the target.
120
+ # @param [ Object... ] *args Args to delegate to the target.
121
121
  #
122
122
  # @return [ Integer ] The total number of persisted embedded docs, as
123
123
  # flagged by the #persisted? method.
@@ -252,7 +252,7 @@ module Mongoid
252
252
  # @example Finds the first matching document using a block.
253
253
  # person.addresses.find { |addr| addr.state == 'CA' }
254
254
  #
255
- # @param [ Array<Object> ] args Various arguments.
255
+ # @param [ Object... ] *args Various arguments.
256
256
  # @param [ Proc ] block Optional block to pass.
257
257
  #
258
258
  # @return [ Document | Array<Document> | nil ] A document or matching documents.
@@ -348,7 +348,7 @@ module Mongoid
348
348
  # @example Substitute the association's target.
349
349
  # person.addresses.substitute([ address ])
350
350
  #
351
- # @param [ Array<Document> ] docs The replacement docs.
351
+ # @param [ Array<Document> | Array<Hash> ] docs The replacement docs.
352
352
  #
353
353
  # @return [ Many ] The proxied association.
354
354
  def substitute(docs)
@@ -432,10 +432,10 @@ module Mongoid
432
432
  # If the method exists on the array, use the default proxy behavior.
433
433
  #
434
434
  # @param [ Symbol | String ] name The name of the method.
435
- # @param [ Array ] args The method args
435
+ # @param [ Object... ] *args The method args.
436
436
  # @param [ Proc ] block Optional block to pass.
437
437
  #
438
- # @return [ Criteria, Object ] A Criteria or return value from the target.
438
+ # @return [ Criteria | Object ] A Criteria or return value from the target.
439
439
  ruby2_keywords def method_missing(name, *args, &block)
440
440
  return super if _target.respond_to?(name)
441
441
  klass.send(:with_scope, criteria) do
@@ -17,7 +17,7 @@ module Mongoid
17
17
  # Builder.new(meta, attrs).build
18
18
  #
19
19
  # @param [ Document ] base The document this association hangs off of.
20
- # @param [ Document ] object The related document.
20
+ # @param [ Document | Hash ] object The related document.
21
21
  # @param [ String ] _type Not used in this context.
22
22
  # @param [ Hash ] selected_fields Fields which were retrieved via
23
23
  # #only. If selected_fields are specified, fields not listed in it
@@ -43,7 +43,7 @@ module Mongoid
43
43
  # @example Substitute the new document.
44
44
  # person.name.substitute(new_name)
45
45
  #
46
- # @param [ Document ] replacement A document to replace the target.
46
+ # @param [ Document | Hash ] replacement A document to replace the target.
47
47
  #
48
48
  # @return [ Document | nil ] The association or nil.
49
49
  def substitute(replacement)
@@ -35,15 +35,10 @@ module Mongoid
35
35
  # @api private
36
36
  class_attribute :aliased_associations
37
37
 
38
- # @return [ Set<String> ] The set of associations that are configured
39
- # with :store_as parameter.
40
- class_attribute :stored_as_associations
41
-
42
38
  self.embedded = false
43
39
  self.embedded_relations = BSON::Document.new
44
40
  self.relations = BSON::Document.new
45
41
  self.aliased_associations = {}
46
- self.stored_as_associations = Set.new
47
42
  end
48
43
 
49
44
  # This is convenience for libraries still on the old API.
@@ -224,7 +219,6 @@ module Mongoid
224
219
  self.relations = self.relations.merge(name => assoc)
225
220
  if assoc.embedded? && assoc.respond_to?(:store_as) && assoc.store_as != name
226
221
  self.aliased_associations[assoc.store_as] = name
227
- self.stored_as_associations << assoc.store_as
228
222
  end
229
223
  end
230
224
  end
@@ -32,6 +32,8 @@ module Mongoid
32
32
  parent.send(association.setter, Factory.build(@class_name, attributes))
33
33
  elsif delete?
34
34
  parent.send(association.setter, nil)
35
+ else
36
+ check_for_id_violation!
35
37
  end
36
38
  end
37
39
 
@@ -54,6 +56,17 @@ module Mongoid
54
56
 
55
57
  private
56
58
 
59
+ # Extracts and converts the id to the expected type.
60
+ #
61
+ # @return [ BSON::ObjectId | String | Object | nil ] The converted id,
62
+ # or nil if no id is present in the attributes hash.
63
+ def extracted_id
64
+ @extracted_id ||= begin
65
+ id = association.klass.extract_id_field(attributes)
66
+ convert_id(existing.class, id)
67
+ end
68
+ end
69
+
57
70
  # Is the id in the attributes acceptable for allowing an update to
58
71
  # the existing association?
59
72
  #
@@ -64,8 +77,7 @@ module Mongoid
64
77
  #
65
78
  # @return [ true | false ] If the id part of the logic will allow an update.
66
79
  def acceptable_id?
67
- id = association.klass.extract_id_field(attributes)
68
- id = convert_id(existing.class, id)
80
+ id = extracted_id
69
81
  existing._id == id || id.nil? || (existing._id != id && update_only?)
70
82
  end
71
83
 
@@ -110,6 +122,32 @@ module Mongoid
110
122
  def update?
111
123
  existing && !destroyable? && acceptable_id?
112
124
  end
125
+
126
+ # Checks to see if the _id attribute (which is supposed to be
127
+ # immutable) is being asked to change. If so, raise an exception.
128
+ #
129
+ # If Mongoid::Config.immutable_ids is false, this will do nothing,
130
+ # and the update operation will fail silently.
131
+ #
132
+ # @raise [ Errors::ImmutableAttribute ] if _id has changed, and
133
+ # the document has been persisted.
134
+ def check_for_id_violation!
135
+ # look for the basic criteria of an update (see #update?)
136
+ return unless existing&.persisted? && !destroyable?
137
+
138
+ # if the id is either absent, or if it equals the existing record's
139
+ # id, there is no immutability violation.
140
+ id = extracted_id
141
+ return if existing._id == id || id.nil?
142
+
143
+ # otherwise, an attempt has been made to set the _id of an existing,
144
+ # persisted document.
145
+ if Mongoid::Config.immutable_ids
146
+ raise Errors::ImmutableAttribute.new(:_id, id)
147
+ else
148
+ Mongoid::Warnings.warn_mutable_ids
149
+ end
150
+ end
113
151
  end
114
152
  end
115
153
  end
@@ -118,7 +118,7 @@ module Mongoid
118
118
  # to the target of the proxy. This can be overridden in special cases.
119
119
  #
120
120
  # @param [ String | Symbol ] name The name of the method.
121
- # @param [ Array ] args The arguments passed to the method.
121
+ # @param [ Object... ] *args The arguments passed to the method.
122
122
  ruby2_keywords def method_missing(name, *args, &block)
123
123
  _target.send(name, *args, &block)
124
124
  end
@@ -13,7 +13,7 @@ module Mongoid
13
13
  # @example Reset the given counter cache
14
14
  # post.reset_counters(:comments)
15
15
  #
16
- # @param [ Symbol | Array ] counters One or more counter caches to reset
16
+ # @param [ Symbol... ] *counters One or more counter caches to reset.
17
17
  def reset_counters(*counters)
18
18
  self.class.with(persistence_context) do |_class|
19
19
  _class.reset_counters(self, *counters)
@@ -30,7 +30,7 @@ module Mongoid
30
30
  # Post.reset_counters('50e0edd97c71c17ea9000001', :comments)
31
31
  #
32
32
  # @param [ String ] id The id of the object that will be reset.
33
- # @param [ Symbol | Array ] counters One or more counter caches to reset
33
+ # @param [ Symbol... ] *counters One or more counter caches to reset.
34
34
  def reset_counters(id, *counters)
35
35
  document = id.is_a?(Document) ? id : find(id)
36
36
  counters.each do |name|
@@ -21,7 +21,7 @@ module Mongoid
21
21
  # @example Concat with other documents.
22
22
  # person.posts.concat([ post_one, post_two ])
23
23
  #
24
- # @param [ Document | Array<Document> ] args Any number of documents.
24
+ # @param [ Document... ] *args Any number of documents.
25
25
  #
26
26
  # @return [ Array<Document> ] The loaded docs.
27
27
  def <<(*args)