mongoid 3.0.21 → 3.0.22

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.
@@ -3,6 +3,30 @@
3
3
  For instructions on upgrading to newer versions, visit
4
4
  [mongoid.org](http://mongoid.org/en/mongoid/docs/upgrading.html).
5
5
 
6
+ ## 3.0.22
7
+
8
+ ### Resolved Issues
9
+
10
+ * \#2812 Fixed criteria on many to many relations when the base document is
11
+ destroyed and the foreign key has not yet been lazy evaluated.
12
+
13
+ * \#2796 Don't cascade changes on has_many relations when assigning with
14
+ a delete.
15
+
16
+ * \#2795 Fix precision on time conversions. (Tom de Bruijn)
17
+
18
+ * \#2794 Don't autobuild when reading a relation for validation.
19
+
20
+ * \#2790 `becomes` now copies embedded documents even if they were protected
21
+ by mass assignment.
22
+
23
+ * \#2787 Allow `becomes` to replace the document in the identity map.
24
+
25
+ * \#2786 Fixed regressed cascading callbacks on destroy not firing.
26
+
27
+ * \#2784 Fixed uniqueness validation properly getting added to subclasses.
28
+ (Takeshi Akima)
29
+
6
30
  ## 3.0.21
7
31
 
8
32
  ### Resolved Issues
@@ -52,6 +52,21 @@ module Mongoid
52
52
  respond_to?("_#{kind}_callbacks")
53
53
  end
54
54
 
55
+ # Is the document currently in a state that could potentially require
56
+ # callbacks to be executed?
57
+ #
58
+ # @example Is the document in a callback state?
59
+ # document.in_callback_state?(:update)
60
+ #
61
+ # @param [ Symbol ] kind The callback kind.
62
+ #
63
+ # @return [ true, false ] If the document is in a callback state.
64
+ #
65
+ # @since 3.1.0
66
+ def in_callback_state?(kind)
67
+ [ :create, :destroy ].include?(kind) || new_record? || flagged_for_destroy? || changed?
68
+ end
69
+
55
70
  # Run only the after callbacks for the specific event.
56
71
  #
57
72
  # @note ActiveSupport does not allow this type of behaviour by default, so
@@ -172,8 +187,8 @@ module Mongoid
172
187
  #
173
188
  # @since 2.3.0
174
189
  def cascadable_child?(kind, child)
175
- return false if kind == :initialize || !child.callback_executable?(kind)
176
- child.changed? || child.new_record? || child.flagged_for_destroy?
190
+ return false if kind == :initialize
191
+ child.callback_executable?(kind) ? child.in_callback_state?(kind) : false
177
192
  end
178
193
 
179
194
  # Get the name of the callback that the child should fire. This changes
@@ -18,17 +18,30 @@ module Mongoid
18
18
  #
19
19
  # @return [ Document ] The new document.
20
20
  def clone
21
- attrs = as_document.except("_id")
22
- if attrs.delete("versions")
23
- attrs["version"] = 1
24
- end
25
- process_localized_attributes(attrs)
21
+ attrs = clone_document.except("_id")
26
22
  self.class.new(attrs, without_protection: true)
27
23
  end
28
24
  alias :dup :clone
29
25
 
30
26
  private
31
27
 
28
+ # Clone the document attributes
29
+ #
30
+ # @api private
31
+ #
32
+ # @example clone document
33
+ # model.clone_document
34
+ #
35
+ # @param [ Hash ] dcoument The document with hash format
36
+ #
37
+ # @since 3.0.22
38
+ def clone_document
39
+ attrs = as_document.__deep_copy__
40
+ attrs["version"] = 1 if attrs.delete("versions")
41
+ process_localized_attributes(attrs)
42
+ attrs
43
+ end
44
+
32
45
  # When cloning, if the document has localized fields we need to ensure they
33
46
  # are properly processed in the clone.
34
47
  #
@@ -234,7 +234,7 @@ module Mongoid
234
234
  raise ArgumentError, "A class which includes Mongoid::Document is expected"
235
235
  end
236
236
 
237
- became = klass.new(as_document.__deep_copy__)
237
+ became = klass.new(clone_document, without_protection: true)
238
238
  became.id = id
239
239
  became.instance_variable_set(:@changed_attributes, changed_attributes)
240
240
  became.instance_variable_set(:@errors, errors)
@@ -242,6 +242,7 @@ module Mongoid
242
242
  became.instance_variable_set(:@destroyed, destroyed?)
243
243
  became.changed_attributes["_type"] = self.class.to_s
244
244
  became._type = klass.to_s
245
+ IdentityMap.set(became) unless became.new_record?
245
246
  became
246
247
  end
247
248
 
@@ -67,6 +67,8 @@ module Mongoid
67
67
  time = object.__mongoize_time__
68
68
  if time.respond_to?(:sec_fraction)
69
69
  ::Time.at(time.to_i, time.sec_fraction * 10**6).utc
70
+ elsif time.respond_to?(:subsec)
71
+ ::Time.at(time.to_i, time.subsec * 10**6).utc
70
72
  else
71
73
  ::Time.at(time.to_i, time.usec).utc
72
74
  end
@@ -108,7 +108,7 @@ module Mongoid
108
108
  target.delete(document) do |doc|
109
109
  if doc
110
110
  unbind_one(doc)
111
- cascade!(doc)
111
+ cascade!(doc) if !_assigning?
112
112
  end
113
113
  end
114
114
  end
@@ -300,7 +300,7 @@ module Mongoid
300
300
  #
301
301
  # @since 2.1.0
302
302
  def criteria(metadata, object, type = nil)
303
- apply_ordering(metadata.klass.all_of(_id: { "$in" => object }), metadata)
303
+ apply_ordering(metadata.klass.all_of(_id: { "$in" => object || [] }), metadata)
304
304
  end
305
305
 
306
306
  # Get the criteria that is used to eager load a relation of this
@@ -57,7 +57,7 @@ module Mongoid
57
57
  attribute = attr.to_s
58
58
  if relations.has_key?(attribute)
59
59
  begin_validate
60
- relation = send(attr)
60
+ relation = without_autobuild { send(attr) }
61
61
  exit_validate
62
62
  relation.do_or_do_not(:in_memory) || relation
63
63
  elsif fields[attribute].try(:localized?)
@@ -16,6 +16,20 @@ module Mongoid
16
16
  class UniquenessValidator < ActiveModel::EachValidator
17
17
  include Queryable
18
18
 
19
+ attr_reader :klass
20
+
21
+ # Unfortunately, we have to tie Uniqueness validators to a class.
22
+ #
23
+ # @example Setup the validator.
24
+ # UniquenessValidator.new.setup(Person)
25
+ #
26
+ # @param [ Class ] klass The class getting validated.
27
+ #
28
+ # @since 1.0.0
29
+ def setup(klass)
30
+ @klass = klass
31
+ end
32
+
19
33
  # Validate the document for uniqueness violations.
20
34
  #
21
35
  # @example Validate the document.
@@ -252,7 +266,7 @@ module Mongoid
252
266
  #
253
267
  # @since 2.4.10
254
268
  def validate_root(document, attribute, value)
255
- criteria = create_criteria(document.class, document, attribute, value)
269
+ criteria = create_criteria(klass, document, attribute, value)
256
270
  if criteria.with(consistency: :strong).exists?
257
271
  add_error(document, attribute, value)
258
272
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
- VERSION = "3.0.21"
3
+ VERSION = "3.0.22"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.21
4
+ version: 3.0.22
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-04 00:00:00.000000000 Z
12
+ date: 2013-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -344,7 +344,8 @@ files:
344
344
  - README.md
345
345
  - Rakefile
346
346
  homepage: http://mongoid.org
347
- licenses: []
347
+ licenses:
348
+ - MIT
348
349
  post_install_message:
349
350
  rdoc_options: []
350
351
  require_paths: