mongoid 7.0.7 → 7.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +45 -5
  5. data/lib/mongoid.rb +1 -1
  6. data/lib/mongoid/association/embedded/embeds_many.rb +2 -1
  7. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +9 -9
  8. data/lib/mongoid/association/embedded/embeds_one.rb +2 -1
  9. data/lib/mongoid/association/proxy.rb +15 -2
  10. data/lib/mongoid/atomic.rb +13 -3
  11. data/lib/mongoid/attributes.rb +8 -1
  12. data/lib/mongoid/clients/sessions.rb +20 -4
  13. data/lib/mongoid/criteria.rb +7 -1
  14. data/lib/mongoid/criteria/modifiable.rb +2 -1
  15. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
  16. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +3 -3
  17. data/lib/mongoid/criteria/queryable/extensions/time.rb +1 -1
  18. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +12 -0
  19. data/lib/mongoid/document.rb +3 -2
  20. data/lib/mongoid/extensions/hash.rb +4 -2
  21. data/lib/mongoid/extensions/regexp.rb +1 -1
  22. data/lib/mongoid/fields.rb +2 -1
  23. data/lib/mongoid/interceptable.rb +3 -1
  24. data/lib/mongoid/matchable/regexp.rb +2 -2
  25. data/lib/mongoid/persistable/pushable.rb +4 -1
  26. data/lib/mongoid/persistence_context.rb +6 -6
  27. data/lib/mongoid/query_cache.rb +61 -18
  28. data/lib/mongoid/validatable/uniqueness.rb +1 -1
  29. data/lib/mongoid/version.rb +1 -1
  30. data/lib/rails/generators/mongoid/config/config_generator.rb +8 -1
  31. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
  32. data/spec/app/models/customer.rb +11 -0
  33. data/spec/app/models/customer_address.rb +12 -0
  34. data/spec/app/models/delegating_patient.rb +16 -0
  35. data/spec/integration/app_spec.rb +341 -0
  36. data/spec/integration/associations/embedded_spec.rb +176 -0
  37. data/spec/integration/callbacks_models.rb +49 -0
  38. data/spec/integration/callbacks_spec.rb +216 -0
  39. data/spec/integration/criteria/date_field_spec.rb +41 -0
  40. data/spec/integration/document_spec.rb +22 -0
  41. data/spec/lite_spec_helper.rb +17 -5
  42. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +50 -0
  43. data/spec/mongoid/association/embedded/embeds_many_models.rb +53 -0
  44. data/spec/mongoid/association/embedded/embeds_many_spec.rb +10 -0
  45. data/spec/mongoid/association/embedded/embeds_one_spec.rb +0 -2
  46. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +140 -1
  47. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +105 -0
  48. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +2 -1
  49. data/spec/mongoid/atomic/paths_spec.rb +41 -0
  50. data/spec/mongoid/attributes_spec.rb +241 -0
  51. data/spec/mongoid/clients/options_spec.rb +4 -4
  52. data/spec/mongoid/clients/sessions_spec.rb +8 -4
  53. data/spec/mongoid/clients/transactions_spec.rb +20 -8
  54. data/spec/mongoid/clients_spec.rb +2 -2
  55. data/spec/mongoid/contextual/atomic_spec.rb +37 -14
  56. data/spec/mongoid/contextual/geo_near_spec.rb +11 -2
  57. data/spec/mongoid/contextual/map_reduce_spec.rb +20 -5
  58. data/spec/mongoid/contextual/mongo_spec.rb +76 -53
  59. data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -7
  60. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +1 -1
  61. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +19 -7
  62. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +28 -1
  63. data/spec/mongoid/criteria_spec.rb +4 -2
  64. data/spec/mongoid/document_persistence_context_spec.rb +33 -0
  65. data/spec/mongoid/factory_spec.rb +2 -2
  66. data/spec/mongoid/indexable_spec.rb +6 -4
  67. data/spec/mongoid/matchable/default_spec.rb +1 -1
  68. data/spec/mongoid/matchable/regexp_spec.rb +2 -2
  69. data/spec/mongoid/matchable_spec.rb +2 -2
  70. data/spec/mongoid/persistable/savable_spec.rb +4 -4
  71. data/spec/mongoid/persistable/settable_spec.rb +30 -0
  72. data/spec/mongoid/query_cache_spec.rb +77 -9
  73. data/spec/mongoid/relations/proxy_spec.rb +1 -1
  74. data/spec/mongoid/scopable_spec.rb +2 -1
  75. data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
  76. data/spec/mongoid/tasks/database_spec.rb +1 -1
  77. data/spec/shared/LICENSE +20 -0
  78. data/spec/shared/bin/get-mongodb-download-url +17 -0
  79. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  80. data/spec/shared/lib/mrss/cluster_config.rb +221 -0
  81. data/spec/shared/lib/mrss/constraints.rb +354 -0
  82. data/spec/shared/lib/mrss/docker_runner.rb +265 -0
  83. data/spec/shared/lib/mrss/lite_constraints.rb +191 -0
  84. data/spec/shared/lib/mrss/server_version_registry.rb +115 -0
  85. data/spec/shared/lib/mrss/spec_organizer.rb +162 -0
  86. data/spec/shared/lib/mrss/utils.rb +15 -0
  87. data/spec/shared/share/Dockerfile.erb +231 -0
  88. data/spec/shared/shlib/distro.sh +73 -0
  89. data/spec/shared/shlib/server.sh +290 -0
  90. data/spec/shared/shlib/set_env.sh +128 -0
  91. data/spec/spec_helper.rb +2 -31
  92. data/spec/support/cluster_config.rb +3 -3
  93. data/spec/support/constraints.rb +21 -76
  94. data/spec/support/session_registry.rb +50 -0
  95. data/spec/support/spec_config.rb +20 -4
  96. metadata +513 -460
  97. metadata.gz.sig +1 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82df1754cb3984ed07b2a5c83b17d489d4d5c3b00d5613d0294406fa818408a4
4
- data.tar.gz: 6d9b8693eecd837d139340eebcc08b340296da68bc7ffd5af84428e61ab83e08
3
+ metadata.gz: c687add0cd3bcd3001781fcb3011966fb5617848c1b1096c9ecf08a6a8d3e123
4
+ data.tar.gz: 242b9126fc96c4719aa23e96a25f9ff590c063020b8d8806315cbd887316fd24
5
5
  SHA512:
6
- metadata.gz: 2dba026ded69def250670ef96bdbbc9363237a3885002760918fe4aaed1d2e06755793383220b94fbdf57268770964f91ac30d62641b4ec74394ac98c0b332e5
7
- data.tar.gz: 227afb604eb0da1c058aa4f22d69bcaeccaf920c389dd3d5001776d688a2a1b72b030aa4a238c8d4ad0dc33e2394679e51a8560204ad9da041430c4d6f5becc9
6
+ metadata.gz: 13f8de150ffbc721206b56d8b532525bd66d380454d3ae53e202159da26d39db48a0c70f15ae0f10278adaa97ec3380c6565c2c97993f7953920b1ab89ea02a4
7
+ data.tar.gz: 2e5a35a8935add506b7a514ca392ce1f9f9e3d6440b0152a154d56bce2b9f5e12dabf7ce1ca9c99f6f424d7efcdeb1ddd3e05dad17849b91b7b76fd3b5cb543d
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -1,12 +1,21 @@
1
1
  require "bundler"
2
+ require "bundler/gem_tasks"
2
3
  Bundler.setup
3
4
 
5
+ ROOT = File.expand_path(File.join(File.dirname(__FILE__)))
6
+
7
+ $: << File.join(ROOT, 'spec/shared/lib')
8
+
4
9
  require "rake"
5
10
  require "rspec/core/rake_task"
11
+ require 'mrss/spec_organizer'
6
12
 
7
13
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
8
14
  require "mongoid/version"
9
15
 
16
+ tasks = Rake.application.instance_variable_get('@tasks')
17
+ tasks['release:do'] = tasks.delete('release')
18
+
10
19
  task :gem => :build
11
20
  task :build do
12
21
  system "gem build mongoid.gemspec"
@@ -16,11 +25,8 @@ task :install => :build do
16
25
  system "sudo gem install mongoid-#{Mongoid::VERSION}.gem"
17
26
  end
18
27
 
19
- task :release => :build do
20
- system "git tag -a v#{Mongoid::VERSION} -m 'Tagging #{Mongoid::VERSION}'"
21
- system "git push --tags"
22
- system "gem push mongoid-#{Mongoid::VERSION}.gem"
23
- system "rm mongoid-#{Mongoid::VERSION}.gem"
28
+ task :release do
29
+ raise "Please use ./release.sh to release"
24
30
  end
25
31
 
26
32
  RSpec::Core::RakeTask.new("spec") do |spec|
@@ -32,6 +38,32 @@ RSpec::Core::RakeTask.new('spec:progress') do |spec|
32
38
  spec.pattern = "spec/**/*_spec.rb"
33
39
  end
34
40
 
41
+ CLASSIFIERS = [
42
+ [%r,^mongoid/attribute,, :attributes],
43
+ [%r,^mongoid/association/[or],, :associations_referenced],
44
+ [%r,^mongoid/association,, :associations],
45
+ [%r,^mongoid,, :unit],
46
+ [%r,^integration,, :integration],
47
+ [%r,^rails,, :rails],
48
+ ]
49
+
50
+ RUN_PRIORITY = %i(
51
+ unit attributes associations_referenced associations
52
+ integration rails
53
+ )
54
+
55
+ def spec_organizer
56
+ Mrss::SpecOrganizer.new(
57
+ root: ROOT,
58
+ classifiers: CLASSIFIERS,
59
+ priority_order: RUN_PRIORITY,
60
+ )
61
+ end
62
+
63
+ task :ci do
64
+ spec_organizer.run
65
+ end
66
+
35
67
  task :default => :spec
36
68
 
37
69
  desc "Generate all documentation"
@@ -45,3 +77,11 @@ namespace :docs do
45
77
  system "yardoc -o #{out} --title mongoid-#{Mongoid::VERSION}"
46
78
  end
47
79
  end
80
+
81
+ namespace :release do
82
+ task :check_private_key do
83
+ unless File.exist?('gem-private_key.pem')
84
+ raise "No private key present, cannot release"
85
+ end
86
+ end
87
+ end
data/lib/mongoid.rb CHANGED
@@ -102,5 +102,5 @@ module Mongoid
102
102
  # Mongoid.database = Mongo::Connection.new.db("test")
103
103
  #
104
104
  # @since 1.0.0
105
- delegate(*(Config.public_instance_methods(false) - [ :logger=, :logger ] << { to: Config }))
105
+ delegate(*(Config.public_instance_methods(false) - [ :logger=, :logger ]), to: Config)
106
106
  end
@@ -197,7 +197,8 @@ module Mongoid
197
197
  def determine_inverses(other)
198
198
  matches = relation_class.relations.values.select do |rel|
199
199
  relation_complements.include?(rel.class) &&
200
- rel.relation_class_name == inverse_class_name
200
+ # https://jira.mongodb.org/browse/MONGOID-4882
201
+ rel.relation_class_name.sub(/\A::/, '') == inverse_class_name
201
202
  end
202
203
  if matches.size > 1
203
204
  raise Errors::AmbiguousRelationship.new(relation_class, @owner_class, name, matches)
@@ -364,15 +364,12 @@ module Mongoid
364
364
  Binding.new(_base, _target, _association)
365
365
  end
366
366
 
367
- # Returns the "#{criteria}"# object for the target class with its documents set
368
- # to target.
369
- #
370
- # @example Get a criteria for the relation.
371
- # relation.criteria
367
+ # Returns the +Criteria+ object for the target class with its
368
+ # documents set to the list of target documents in the association.
372
369
  #
373
370
  # @return [ Criteria ] A new criteria.
374
371
  def criteria
375
- @criteria ||= _association.criteria(_base, _target)
372
+ _association.criteria(_base, _target)
376
373
  end
377
374
 
378
375
  # Deletes one document from the target and unscoped.
@@ -448,8 +445,8 @@ module Mongoid
448
445
  end
449
446
  end
450
447
 
451
- # Apply the association ordering or the default scoping to the provided
452
- # documents.
448
+ # Apply the association ordering and default scoping (defined on
449
+ # association's target class) to the provided documents.
453
450
  #
454
451
  # @example Apply scoping.
455
452
  # person.addresses.scope(target)
@@ -460,7 +457,10 @@ module Mongoid
460
457
  #
461
458
  # @since 2.4.0
462
459
  def scope(docs)
463
- return docs unless _association.order || _association.klass.default_scoping?
460
+ unless _association.order || _association.klass.default_scoping?
461
+ return docs
462
+ end
463
+
464
464
  crit = _association.klass.order_by(_association.order)
465
465
  crit.embedded = true
466
466
  crit.documents = docs
@@ -159,7 +159,8 @@ module Mongoid
159
159
  def determine_inverses(other)
160
160
  matches = relation_class.relations.values.select do |rel|
161
161
  relation_complements.include?(rel.class) &&
162
- rel.relation_class_name == inverse_class_name
162
+ # https://jira.mongodb.org/browse/MONGOID-4882
163
+ rel.relation_class_name.sub(/\A::/, '') == inverse_class_name
163
164
 
164
165
  end
165
166
  if matches.size > 1
@@ -12,13 +12,26 @@ module Mongoid
12
12
  # We undefine most methods to get them sent through to the target.
13
13
  instance_methods.each do |method|
14
14
  undef_method(method) unless
15
- method =~ /^(__.*|send|object_id|equal\?|respond_to\?|tap|public_send|extend_proxy|extend_proxies)$/
15
+ method =~ /\A(__.*|send|object_id|equal\?|respond_to\?|tap|public_send|extend_proxy|extend_proxies)\z/
16
16
  end
17
17
 
18
18
  include Threaded::Lifecycle
19
19
  include Marshalable
20
20
 
21
- attr_accessor :_base, :_association, :_target
21
+ # Model instance for the base of the association.
22
+ #
23
+ # For example, if a Post embeds_many Comments, _base is a particular
24
+ # instance of the Post model.
25
+ attr_accessor :_base
26
+
27
+ attr_accessor :_association
28
+
29
+ # Model instance for one to one associations, or array of model instances
30
+ # for one to many associations, for the target of the association.
31
+ #
32
+ # For example, if a Post embeds_many Comments, _target is an array of
33
+ # Comment models embedded in a particular Post.
34
+ attr_accessor :_target
22
35
 
23
36
  # Backwards compatibility with Mongoid beta releases.
24
37
  delegate :foreign_key, :inverse_foreign_key, to: :_association
@@ -36,7 +36,9 @@ module Mongoid
36
36
  # @since 2.2.0
37
37
  def add_atomic_pull(document)
38
38
  document.flagged_for_destroy = true
39
- (delayed_atomic_pulls[document.association_name.to_s] ||= []).push(document)
39
+ key = document.association_name.to_s
40
+ delayed_atomic_pulls[key] ||= []
41
+ delayed_atomic_pulls[key] << document
40
42
  end
41
43
 
42
44
  # Add an atomic unset for the document.
@@ -51,7 +53,9 @@ module Mongoid
51
53
  # @since 3.0.0
52
54
  def add_atomic_unset(document)
53
55
  document.flagged_for_destroy = true
54
- (delayed_atomic_unsets[document.association_name.to_s] ||= []).push(document)
56
+ key = document.association_name.to_s
57
+ delayed_atomic_unsets[key] ||= []
58
+ delayed_atomic_unsets[key] << document
55
59
  end
56
60
 
57
61
  # Returns path of the attribute for modification
@@ -189,7 +193,13 @@ module Mongoid
189
193
  #
190
194
  # @since 2.1.0
191
195
  def atomic_paths
192
- @atomic_paths ||= _association ? _association.path(self) : Atomic::Paths::Root.new(self)
196
+ @atomic_paths ||= begin
197
+ if _association
198
+ _association.path(self)
199
+ else
200
+ Atomic::Paths::Root.new(self)
201
+ end
202
+ end
193
203
  end
194
204
 
195
205
  # Get all the attributes that need to be pulled.
@@ -158,6 +158,11 @@ module Mongoid
158
158
  # @since 1.0.0
159
159
  def write_attribute(name, value)
160
160
  field_name = database_field_name(name)
161
+
162
+ if attribute_missing?(field_name)
163
+ raise ActiveModel::MissingAttributeError, "Missing attribute: '#{name}'"
164
+ end
165
+
161
166
  if attribute_writable?(field_name)
162
167
  _assigning do
163
168
  validate_attribute_value(field_name, value)
@@ -175,6 +180,8 @@ module Mongoid
175
180
  end
176
181
  typed_value
177
182
  end
183
+ else
184
+ # TODO: MONGOID-5072
178
185
  end
179
186
  end
180
187
  alias :[]= :write_attribute
@@ -292,7 +299,7 @@ module Mongoid
292
299
  def read_raw_attribute(name)
293
300
  normalized = database_field_name(name.to_s)
294
301
  if attribute_missing?(normalized)
295
- raise ActiveModel::MissingAttributeError, "Missing attribute: '#{name}'."
302
+ raise ActiveModel::MissingAttributeError, "Missing attribute: '#{name}'"
296
303
  end
297
304
  if hash_dot_syntax?(normalized)
298
305
  attributes.__nested__(normalized)
@@ -38,12 +38,20 @@ module Mongoid
38
38
  #
39
39
  # @since 6.4.0
40
40
  def with_session(options = {})
41
- raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_nesting) if Threaded.get_session
41
+ if Threaded.get_session
42
+ raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_nesting)
43
+ end
42
44
  session = persistence_context.client.start_session(options)
43
45
  Threaded.set_session(session)
44
46
  yield(session)
45
47
  rescue Mongo::Error::InvalidSession => ex
46
- if ex.message == Mongo::Session::SESSIONS_NOT_SUPPORTED
48
+ if
49
+ # Driver 2.13.0+
50
+ defined?(Mongo::Error::SessionsNotSupported) &&
51
+ Mongo::Error::SessionsNotSupported === ex ||
52
+ # Legacy drivers
53
+ ex.message == Mongo::Session::SESSIONS_NOT_SUPPORTED
54
+ then
47
55
  raise Mongoid::Errors::InvalidSessionUse.new(:sessions_not_supported)
48
56
  end
49
57
  raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_use)
@@ -89,12 +97,20 @@ module Mongoid
89
97
  #
90
98
  # @since 6.4.0
91
99
  def with_session(options = {})
92
- raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_nesting) if Threaded.get_session
100
+ if Threaded.get_session
101
+ raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_nesting)
102
+ end
93
103
  session = persistence_context.client.start_session(options)
94
104
  Threaded.set_session(session)
95
105
  yield(session)
96
106
  rescue Mongo::Error::InvalidSession => ex
97
- if ex.message == Mongo::Session::SESSIONS_NOT_SUPPORTED
107
+ if
108
+ # Driver 2.13.0+
109
+ defined?(Mongo::Error::SessionsNotSupported) &&
110
+ Mongo::Error::SessionsNotSupported === ex ||
111
+ # Legacy drivers
112
+ ex.message == Mongo::Session::SESSIONS_NOT_SUPPORTED
113
+ then
98
114
  raise Mongoid::Errors::InvalidSessionUse.new(:sessions_not_supported)
99
115
  end
100
116
  raise Mongoid::Errors::InvalidSessionUse.new(:invalid_session_use)
@@ -435,7 +435,13 @@ module Mongoid
435
435
  #
436
436
  # @since 3.1.0
437
437
  def for_js(javascript, scope = {})
438
- js_query(BSON::CodeWithScope.new(javascript, scope))
438
+ code = if scope.empty?
439
+ # CodeWithScope is not supported for $where as of MongoDB 4.4
440
+ BSON::Code.new(javascript)
441
+ else
442
+ BSON::CodeWithScope.new(javascript, scope)
443
+ end
444
+ js_query(code)
439
445
  end
440
446
 
441
447
  private
@@ -72,7 +72,8 @@ module Mongoid
72
72
  # @since 5.1.0
73
73
  def create_with(attrs = {})
74
74
  tap do
75
- (@create_attrs ||= {}).merge!(attrs)
75
+ @create_attrs ||= {}
76
+ @create_attrs.update(attrs)
76
77
  end
77
78
  end
78
79
 
@@ -58,7 +58,7 @@ module Mongoid
58
58
  #
59
59
  # @since 1.0.0
60
60
  def __numeric__(object)
61
- object.to_s =~ /(^[-+]?[0-9]+$)|(\.0+$)|(\.$)/ ? object.to_i : Float(object)
61
+ object.to_s =~ /(\A[-+]?[0-9]+\z)|(\.0+\z)|(\.\z)/ ? object.to_i : Float(object)
62
62
  end
63
63
 
64
64
  # Evolve the object to an integer.
@@ -10,7 +10,7 @@ module Mongoid
10
10
  # Is the object a regexp?
11
11
  #
12
12
  # @example Is the object a regex?
13
- # /^[123]/.regexp?
13
+ # /\A[123]/.regexp?
14
14
  #
15
15
  # @return [ true ] Always true.
16
16
  #
@@ -22,7 +22,7 @@ module Mongoid
22
22
  # Evolve the object into a regex.
23
23
  #
24
24
  # @example Evolve the object to a regex.
25
- # Regexp.evolve("^[123]")
25
+ # Regexp.evolve("\A[123]")
26
26
  #
27
27
  # @param [ Regexp, String ] object The object to evolve.
28
28
  #
@@ -53,7 +53,7 @@ module Mongoid
53
53
  # Evolve the object into a raw bson regex.
54
54
  #
55
55
  # @example Evolve the object to a regex.
56
- # BSON::Regexp::Raw.evolve("^[123]")
56
+ # BSON::Regexp::Raw.evolve("\\A[123]")
57
57
  #
58
58
  # @param [ BSON::Regexp::Raw, String ] object The object to evolve.
59
59
  #
@@ -28,7 +28,7 @@ module Mongoid
28
28
  #
29
29
  # @since 1.0.0
30
30
  def __evolve_time__
31
- utc
31
+ getutc
32
32
  end
33
33
 
34
34
  module ClassMethods
@@ -7,6 +7,18 @@ module Mongoid
7
7
  # This module contains additional time with zone behaviour.
8
8
  module TimeWithZone
9
9
 
10
+ # Evolve the time as a date, UTC midnight.
11
+ #
12
+ # @example Evolve the time to a date query format.
13
+ # time.__evolve_date__
14
+ #
15
+ # @return [ Time ] The date at midnight UTC.
16
+ #
17
+ # @since 1.0.0
18
+ def __evolve_date__
19
+ ::Time.utc(year, month, day, 0, 0, 0, 0)
20
+ end
21
+
10
22
  # Evolve the time into a utc time.
11
23
  #
12
24
  # @example Evolve the time.
@@ -227,8 +227,9 @@ module Mongoid
227
227
  became = klass.new(clone_document)
228
228
  became._id = _id
229
229
  became.instance_variable_set(:@changed_attributes, changed_attributes)
230
- became.instance_variable_set(:@errors, ActiveModel::Errors.new(became))
231
- became.errors.instance_variable_set(:@messages, errors.instance_variable_get(:@messages))
230
+ new_errors = ActiveModel::Errors.new(became)
231
+ new_errors.copy!(errors)
232
+ became.instance_variable_set(:@errors, new_errors)
232
233
  became.instance_variable_set(:@new_record, new_record?)
233
234
  became.instance_variable_set(:@destroyed, destroyed?)
234
235
  became.changed_attributes["_type"] = self.class.to_s
@@ -46,9 +46,11 @@ module Mongoid
46
46
  value.each_pair do |_key, _value|
47
47
  value[_key] = (key == "$rename") ? _value.to_s : mongoize_for(key, klass, _key, _value)
48
48
  end
49
- (consolidated[key] ||= {}).merge!(value)
49
+ consolidated[key] ||= {}
50
+ consolidated[key].update(value)
50
51
  else
51
- (consolidated["$set"] ||= {}).merge!(key => mongoize_for(key, klass, key, value))
52
+ consolidated["$set"] ||= {}
53
+ consolidated["$set"].update(key => mongoize_for(key, klass, key, value))
52
54
  end
53
55
  end
54
56
  consolidated
@@ -9,7 +9,7 @@ module Mongoid
9
9
  # type.
10
10
  #
11
11
  # @example Mongoize the object.
12
- # Regexp.mongoize(/^[abc]/)
12
+ # Regexp.mongoize(/\A[abc]/)
13
13
  #
14
14
  # @param [ Regexp, String ] object The object to mongoize.
15
15
  #