mongoid 2.4.7 → 2.4.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,32 @@
3
3
  For instructions on upgrading to newer versions, visit
4
4
  [mongoid.org](http://mongoid.org/docs/upgrading.html).
5
5
 
6
+ ## 2.4.8
7
+
8
+ ### Resolved Issues
9
+
10
+ * \#1892 When getting not master operation error, Mongoid should reconnect
11
+ before retrying the operation.
12
+
13
+ * \#1887 Don't cascade callbacks to children that don't have the callback
14
+ defined.
15
+
16
+ * \#1882 Don't expand duplicate id criterion into an $and with duplicate
17
+ selections.
18
+
19
+ * \#1878 Fixed default application values not to apply in certain `only`
20
+ or `without` selection on iteration, not just `first` and `last`.
21
+
22
+ * \#1874 Fixed the reject all blank proc constant to handle values
23
+ properly with a destroy non blank value. (Stefan Daschek)
24
+
25
+ * \#1869/\#1868 Delayed atomic sets now uses the atomic path instead of
26
+ the metadata name to fix multiple level embedding issues.
27
+ (Chris Micacchi provided specs)
28
+
29
+ * \#1866 Post processed defaults (procs) should be applied post binding
30
+ of the child in a relation.build.
31
+
6
32
  ## 2.4.7
7
33
 
8
34
  ### Resolved Issues
@@ -73,6 +73,7 @@ require "mongoid/sharding"
73
73
  require "mongoid/state"
74
74
  require "mongoid/timestamps"
75
75
  require "mongoid/validations"
76
+ require "mongoid/version"
76
77
  require "mongoid/versioning"
77
78
  require "mongoid/components"
78
79
  require "mongoid/paranoia"
@@ -105,7 +105,7 @@ module Mongoid #:nodoc:
105
105
  #
106
106
  # @since 2.3.0
107
107
  def cascadable_child?(kind, child)
108
- return false if kind == :initialize
108
+ return false if kind == :initialize || !child.respond_to?("_#{kind}_callbacks")
109
109
  [ :create, :destroy ].include?(kind) || child.changed? || child.new_record?
110
110
  end
111
111
 
@@ -32,6 +32,7 @@ module Mongoid #:nodoc:
32
32
  retry
33
33
  rescue Mongo::OperationFailure => ex
34
34
  if ex.message =~ /not master/
35
+ Mongoid.reconnect!
35
36
  retries = increase_retry_attempts(retries, ex)
36
37
  retry
37
38
  else
@@ -54,7 +54,9 @@ module Mongoid #:nodoc
54
54
  end
55
55
 
56
56
  # keys to remove from self to not pass through to Mongo::Connection
57
- PRIVATE_OPTIONS = %w(uri host hosts port database databases username password logger)
57
+ PRIVATE_OPTIONS =
58
+ %w(uri host hosts port database databases username
59
+ password logger use_activesupport_time_zone)
58
60
 
59
61
  # Get the blacklisted options from passing through to the driver.
60
62
  #
@@ -166,14 +166,12 @@ module Mongoid #:nodoc:
166
166
  # @return [ Cursor ] An enumerable +Cursor+ of results.
167
167
  def execute
168
168
  collection, options = klass.collection, process_options
169
- selecting do
170
- if criteria.inclusions.any?
171
- collection.find(selector, options).entries.tap do |docs|
172
- eager_load(docs)
173
- end
174
- else
175
- collection.find(selector, options)
169
+ if criteria.inclusions.any?
170
+ collection.find(selector, options).entries.tap do |docs|
171
+ eager_load(docs)
176
172
  end
173
+ else
174
+ collection.find(selector, options)
177
175
  end
178
176
  end
179
177
 
@@ -256,9 +254,11 @@ module Mongoid #:nodoc:
256
254
  # @example Iterate over the results.
257
255
  # context.iterate { |doc| p doc }
258
256
  def iterate(&block)
259
- return caching(&block) if cached?
260
- if block_given?
261
- execute.each { |doc| yield doc }
257
+ selecting do
258
+ return caching(&block) if cached?
259
+ if block_given?
260
+ execute.each { |doc| yield doc }
261
+ end
262
262
  end
263
263
  end
264
264
 
@@ -268,7 +268,7 @@ module Mongoid #:nodoc:
268
268
  if key.mongoid_id?
269
269
  if crit.selector.has_key?("$and")
270
270
  crit.selector["$and"] << { key => value }
271
- else
271
+ elsif crit.selector[key] != value
272
272
  crit.selector["$and"] = [{ key => crit.selector.delete(key) }, { key => value }]
273
273
  end
274
274
  elsif crit.selector[key].respond_to?(:merge) && value.respond_to?(:merge)
@@ -92,8 +92,10 @@ module Mongoid #:nodoc
92
92
  unless attributes.has_key?(name)
93
93
  if field = fields[name]
94
94
  default = field.eval_default(self)
95
- attribute_will_change!(name)
96
- attributes[name] = default
95
+ unless default.nil?
96
+ attribute_will_change!(name)
97
+ attributes[name] = default
98
+ end
97
99
  end
98
100
  end
99
101
  end
@@ -56,7 +56,8 @@ module Mongoid #:nodoc:
56
56
  (class << self; self; end).class_eval <<-EOT
57
57
  def #{name}(*args)
58
58
  scope = scopes[:#{name}]
59
- scope.extend(criteria.fuse(scope.conditions.as_conditions(*args)))
59
+ conditions = scope.conditions.as_conditions(*args)
60
+ scope.extend(criteria.fuse(conditions))
60
61
  end
61
62
  EOT
62
63
  end
@@ -12,7 +12,7 @@ module Mongoid #:nodoc:
12
12
 
13
13
  module ClassMethods #:nodoc:
14
14
 
15
- REJECT_ALL_BLANK_PROC = proc { |attributes| attributes.all? { |_, value| value.blank? } }
15
+ REJECT_ALL_BLANK_PROC = proc { |attributes| attributes.all? { |key, value| key == '_destroy' || value.blank? } }
16
16
 
17
17
  # Used when needing to update related models from a parent relation. Can
18
18
  # be used on embedded or referenced relations.
@@ -94,6 +94,7 @@ module Mongoid # :nodoc:
94
94
  Factory.build(type || metadata.klass, attributes, options).tap do |doc|
95
95
  doc.identify
96
96
  append(doc)
97
+ doc.apply_proc_defaults
97
98
  yield(doc) if block_given?
98
99
  doc.run_callbacks(:build) { doc }
99
100
  end
@@ -311,14 +312,15 @@ module Mongoid # :nodoc:
311
312
  docs = replacement.compact
312
313
  proxy.target = docs
313
314
  self._unscoped = docs.dup
314
- if _assigning?
315
- base.delayed_atomic_sets[metadata.name.to_s] = proxy.as_document
316
- end
317
315
  proxy.target.each_with_index do |doc, index|
318
316
  integrate(doc)
319
317
  doc._index = index
320
318
  doc.save if base.persisted? && !_assigning?
321
319
  end
320
+ if _assigning?
321
+ name = proxy.first.atomic_path
322
+ base.delayed_atomic_sets[name] = proxy.as_document
323
+ end
322
324
  end
323
325
  end
324
326
  end
@@ -89,6 +89,7 @@ module Mongoid #:nodoc:
89
89
 
90
90
  Factory.build(type || klass, attributes, options).tap do |doc|
91
91
  append(doc)
92
+ doc.apply_proc_defaults
92
93
  yield(doc) if block_given?
93
94
  doc.run_callbacks(:build) { doc }
94
95
  end
@@ -75,6 +75,7 @@ module Mongoid # :nodoc:
75
75
  Factory.build(type || klass, attributes, options).tap do |doc|
76
76
  base.send(metadata.foreign_key).push(doc.id)
77
77
  append(doc)
78
+ doc.apply_proc_defaults
78
79
  doc.synced[metadata.inverse_foreign_key] = false
79
80
  yield(doc) if block_given?
80
81
  end
@@ -67,7 +67,7 @@ module Mongoid #:nodoc:
67
67
  new? &&
68
68
  embedded_many? &&
69
69
  _parent.persisted? &&
70
- !_parent.delayed_atomic_sets[metadata.name.to_s]
70
+ !_parent.delayed_atomic_sets[atomic_path]
71
71
  end
72
72
 
73
73
  # Determine if the document can be set.
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.4.7"
3
+ VERSION = "2.4.8"
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: 2.4.7
4
+ version: 2.4.8
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: 2012-03-21 00:00:00.000000000 Z
12
+ date: 2012-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -459,7 +459,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
459
459
  version: '0'
460
460
  segments:
461
461
  - 0
462
- hash: -4230484003984922722
462
+ hash: 2935457969941610047
463
463
  required_rubygems_version: !ruby/object:Gem::Requirement
464
464
  none: false
465
465
  requirements: