mongoid 2.3.2 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -8,7 +8,39 @@ For instructions on upgrading to newer versions, visit
8
8
  * Ranges can now be passed to #where criteria to create a $gte/$lte query under the
9
9
  covers. `Person.where(dob: start_date...end_date)`
10
10
 
11
- ## 2.3.2 \[ In Development \] \[ Branch: 2.3.0-stable \]
11
+ ## 2.3.3 \[ In Development \] \[ Branch: 2.3.0-stable \]
12
+
13
+ ### Resolved Issues
14
+
15
+ * \#1386 Lowered mongo/bson dependency to 1.3
16
+
17
+ * \#1377 Fix aggregation functions to properly handle nil or indefined values.
18
+ (Maxime Garcia)
19
+
20
+ * \#1373 Warn if a scope overrides another scope.
21
+
22
+ * \#1372 Never persist when binding inside of a read attribute for validation.
23
+
24
+ * \#1364 Fixed reloading of documents with non bson object id ids.
25
+
26
+ * \#1360 Fixed performance of Mongoid's observer instantiation by hooking into
27
+ Active Support's load hooks, a la AR.
28
+
29
+ * \#1358 Fixed type error on many to many synchronization when inverse_of is
30
+ set to nil.
31
+
32
+ * \#1356 $in criteria can now be chained to non-complex criteria on the same
33
+ key without error.
34
+
35
+ * \#1350, \#1351 Fixed errors in the string conversions of double quotes and
36
+ tilde when paramterizing keys.
37
+
38
+ * \#1349 Mongoid documents should not blow up when including Enumerable.
39
+ (Jonas Nicklas)
40
+
41
+ ## 2.3.2
42
+
43
+ ### Resolved Issues
12
44
 
13
45
  * \#1347 Fix embedded matchers when provided a hash value that does not have a
14
46
  modifier as a key.
@@ -39,8 +71,6 @@ For instructions on upgrading to newer versions, visit
39
71
 
40
72
  * \#736 Calling #reload on embedded documents now works properly.
41
73
 
42
- ### Resolved Issues
43
-
44
74
  ## 2.3.1
45
75
 
46
76
  ### Resolved Issues
data/lib/mongoid.rb CHANGED
@@ -25,6 +25,7 @@ require "time"
25
25
  require "active_support/core_ext"
26
26
  require 'active_support/json'
27
27
  require "active_support/inflector"
28
+ require "active_support/lazy_load_hooks"
28
29
  require "active_support/time_with_zone"
29
30
  require "active_model"
30
31
  require "mongo"
@@ -396,14 +396,19 @@ module Mongoid #:nodoc:
396
396
  clone.tap do |crit|
397
397
  converted = BSON::ObjectId.convert(klass, attributes || {})
398
398
  converted.each_pair do |key, value|
399
- unless crit.selector[key]
399
+ existing = crit.selector[key]
400
+ unless existing
400
401
  crit.selector[key] = { operator => value }
401
402
  else
402
- if crit.selector[key].has_key?(operator)
403
- new_value = crit.selector[key].values.first.send(combine, value)
404
- crit.selector[key] = { operator => new_value }
403
+ if existing.respond_to?(:merge)
404
+ if existing.has_key?(operator)
405
+ new_value = existing.values.first.send(combine, value)
406
+ crit.selector[key] = { operator => new_value }
407
+ else
408
+ crit.selector[key][operator] = value
409
+ end
405
410
  else
406
- crit.selector[key][operator] = value
411
+ crit.selector[key] = { operator => value }
407
412
  end
408
413
  end
409
414
  end
@@ -14,9 +14,6 @@ module Mongoid #:nodoc:
14
14
  # @example Is the array vacant?
15
15
  # [].vacant?
16
16
  #
17
- # @example Is the hash vacant?
18
- # {}.vacant?
19
- #
20
17
  # @example Is the object vacant?
21
18
  # nil.vacant?
22
19
  #
@@ -24,7 +21,7 @@ module Mongoid #:nodoc:
24
21
  #
25
22
  # @since 2.0.2
26
23
  def _vacant?
27
- is_a?(::Enumerable) || is_a?(::String) ? empty? : !self
24
+ is_a?(::Array) || is_a?(::String) ? empty? : !self
28
25
  end
29
26
  end
30
27
  end
@@ -18,7 +18,7 @@ module Mongoid #:nodoc:
18
18
  CHAR_CONV = {
19
19
  " " => "-",
20
20
  "!" => "-excl-",
21
- "\"" => "-bckslsh-",
21
+ "\"" => "-dblquo-",
22
22
  "#" => "-hash-",
23
23
  "$" => "-dol-",
24
24
  "%" => "-perc-",
@@ -48,7 +48,7 @@ module Mongoid #:nodoc:
48
48
  "{" => "-ocurly-",
49
49
  "|" => "-pipe-",
50
50
  "}" => "-clcurly-",
51
- "~" => "-tilda-"
51
+ "~" => "-tilde-"
52
52
  }
53
53
 
54
54
  REVERSALS = {
@@ -10,20 +10,20 @@ group:
10
10
 
11
11
  max:
12
12
  "function(obj, prev) {
13
- if (prev.max == 'start') {
13
+ if (obj.[field] && prev.max == 'start') {
14
14
  prev.max = obj.[field];
15
15
  }
16
- if (prev.max < obj.[field]) {
16
+ if (obj.[field] && prev.max < obj.[field]) {
17
17
  prev.max = obj.[field];
18
18
  }
19
19
  }"
20
20
 
21
21
  min:
22
22
  "function(obj, prev) {
23
- if (prev.min == 'start') {
23
+ if (obj.[field] && prev.min == 'start') {
24
24
  prev.min = obj.[field];
25
25
  }
26
- if (prev.min > obj.[field]) {
26
+ if (obj.[field] && prev.min > obj.[field]) {
27
27
  prev.min = obj.[field];
28
28
  }
29
29
  }"
@@ -33,5 +33,7 @@ sum:
33
33
  if (prev.sum == 'start') {
34
34
  prev.sum = 0;
35
35
  }
36
- prev.sum += obj.[field];
36
+ if (obj.[field]) {
37
+ prev.sum += obj.[field];
38
+ }
37
39
  }"
@@ -125,8 +125,14 @@ module Mongoid #:nodoc:
125
125
 
126
126
  protected
127
127
 
128
+ # Warns if overriding another scope or method.
129
+ #
130
+ # @example Warn if name exists.
131
+ # Model.valid_scope_name?("test")
132
+ #
133
+ # @param [ String, Symbol ] name The name of the scope.
128
134
  def valid_scope_name?(name)
129
- if !scopes[name] && respond_to?(name, true)
135
+ if scopes[name] || respond_to?(name, true)
130
136
  if Mongoid.logger
131
137
  Mongoid.logger.warn(
132
138
  "Creating scope :#{name}. " +
@@ -115,9 +115,8 @@ module Rails #:nodoc:
115
115
  # instantiate them after being reloaded in the development environment
116
116
  initializer "instantiate observers" do
117
117
  config.after_initialize do
118
- ::Mongoid.instantiate_observers
119
-
120
- ActionDispatch::Callbacks.to_prepare do
118
+ ::Mongoid::instantiate_observers
119
+ ActionDispatch::Reloader.to_prepare do
121
120
  ::Mongoid.instantiate_observers
122
121
  end
123
122
  end
@@ -243,6 +243,19 @@ module Mongoid # :nodoc:
243
243
  !!extension
244
244
  end
245
245
 
246
+ # Does this metadata have a forced nil inverse_of defined. (Used in many
247
+ # to manies)
248
+ #
249
+ # @example Is this a forced nil inverse?
250
+ # metadata.forced_nil_inverse?
251
+ #
252
+ # @return [ true, false ] If inverse_of has been explicitly set to nil.
253
+ #
254
+ # @since 2.3.3
255
+ def forced_nil_inverse?
256
+ has_key?(:inverse_of) && inverse_of.nil?
257
+ end
258
+
246
259
  # Handles all the logic for figuring out what the foreign_key is for each
247
260
  # relations query. The logic is as follows:
248
261
  #
@@ -33,7 +33,7 @@ module Mongoid #:nodoc:
33
33
  args.flatten.each do |doc|
34
34
  next unless doc
35
35
  append(doc)
36
- doc.save if persistable?
36
+ doc.save if persistable? && !doc.validated?
37
37
  end
38
38
  end
39
39
  end
@@ -153,7 +153,9 @@ module Mongoid # :nodoc:
153
153
  #
154
154
  # @since 2.0.0.rc.1
155
155
  def nullify
156
- criteria.pull(metadata.inverse_foreign_key, base.id)
156
+ unless metadata.forced_nil_inverse?
157
+ criteria.pull(metadata.inverse_foreign_key, base.id)
158
+ end
157
159
  if persistable?
158
160
  base.set(
159
161
  metadata.foreign_key,
@@ -93,8 +93,10 @@ module Mongoid # :nodoc:
93
93
  #
94
94
  # @since 2.1.0
95
95
  def synced(metadata)
96
- synced_save(metadata)
97
- synced_destroy(metadata)
96
+ unless metadata.forced_nil_inverse?
97
+ synced_save(metadata)
98
+ synced_destroy(metadata)
99
+ end
98
100
  end
99
101
 
100
102
  private
@@ -54,7 +54,7 @@ module Mongoid #:nodoc:
54
54
  #
55
55
  # @since 2.3.2
56
56
  def reload_root_document
57
- {}.merge(collection.find_one(id) || {})
57
+ {}.merge(collection.find_one(:_id => id) || {})
58
58
  end
59
59
 
60
60
  # Reload the embedded document.
@@ -67,7 +67,7 @@ module Mongoid #:nodoc:
67
67
  # @since 2.3.2
68
68
  def reload_embedded_document
69
69
  extract_embedded_attributes({}.merge(
70
- _root.collection.find_one(_root.id)
70
+ _root.collection.find_one(:_id => _root.id)
71
71
  ))
72
72
  end
73
73
 
@@ -44,7 +44,9 @@ module Mongoid #:nodoc:
44
44
  # @since 2.0.0.rc.1
45
45
  def read_attribute_for_validation(attr)
46
46
  if relations[attr.to_s]
47
+ begin_validate
47
48
  relation = send(attr)
49
+ exit_validate
48
50
  relation.do_or_do_not(:in_memory) || relation
49
51
  else
50
52
  send(attr)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.3.2"
3
+ VERSION = "2.3.3"
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.3.2
4
+ version: 2.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-16 00:00:00.000000000Z
12
+ date: 2011-10-31 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
- requirement: &70271939701520 !ruby/object:Gem::Requirement
16
+ requirement: &70239778174840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70271939701520
24
+ version_requirements: *70239778174840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tzinfo
27
- requirement: &70271939726340 !ruby/object:Gem::Requirement
27
+ requirement: &70239778174200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,21 +32,21 @@ dependencies:
32
32
  version: 0.3.22
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70271939726340
35
+ version_requirements: *70239778174200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mongo
38
- requirement: &70271939739080 !ruby/object:Gem::Requirement
38
+ requirement: &70239778173520 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
42
42
  - !ruby/object:Gem::Version
43
- version: '1.4'
43
+ version: '1.3'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70271939739080
46
+ version_requirements: *70239778173520
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &70271939765740 !ruby/object:Gem::Requirement
49
+ requirement: &70239778172400 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,21 +54,21 @@ dependencies:
54
54
  version: 3.5.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70271939765740
57
+ version_requirements: *70239778172400
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bson_ext
60
- requirement: &70271939772120 !ruby/object:Gem::Requirement
60
+ requirement: &70239778171440 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
64
64
  - !ruby/object:Gem::Version
65
- version: '1.4'
65
+ version: '1.3'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70271939772120
68
+ version_requirements: *70239778171440
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
- requirement: &70271939777600 !ruby/object:Gem::Requirement
71
+ requirement: &70239778170600 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.9.12
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70271939777600
79
+ version_requirements: *70239778170600
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &70271939921440 !ruby/object:Gem::Requirement
82
+ requirement: &70239778169700 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '2.6'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70271939921440
90
+ version_requirements: *70239778169700
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: watchr
93
- requirement: &70271940131480 !ruby/object:Gem::Requirement
93
+ requirement: &70239778168680 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0.6'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70271940131480
101
+ version_requirements: *70239778168680
102
102
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
103
103
  in Ruby.
104
104
  email:
@@ -393,7 +393,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
393
393
  version: '0'
394
394
  segments:
395
395
  - 0
396
- hash: 4419494650639076055
396
+ hash: 1966370546899582904
397
397
  required_rubygems_version: !ruby/object:Gem::Requirement
398
398
  none: false
399
399
  requirements: