mongoid 4.0.0.alpha1 → 4.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/README.md +1 -1
  4. data/lib/config/locales/en.yml +4 -6
  5. data/lib/mongoid/attributes/processing.rb +1 -1
  6. data/lib/mongoid/contextual.rb +2 -0
  7. data/lib/mongoid/contextual/map_reduce.rb +3 -1
  8. data/lib/mongoid/contextual/none.rb +90 -0
  9. data/lib/mongoid/criteria.rb +25 -0
  10. data/lib/mongoid/extensions/array.rb +1 -1
  11. data/lib/mongoid/extensions/big_decimal.rb +1 -1
  12. data/lib/mongoid/extensions/date.rb +1 -1
  13. data/lib/mongoid/extensions/date_time.rb +3 -3
  14. data/lib/mongoid/extensions/float.rb +1 -1
  15. data/lib/mongoid/extensions/hash.rb +1 -1
  16. data/lib/mongoid/extensions/integer.rb +1 -1
  17. data/lib/mongoid/extensions/object.rb +3 -3
  18. data/lib/mongoid/extensions/object_id.rb +1 -1
  19. data/lib/mongoid/extensions/range.rb +1 -1
  20. data/lib/mongoid/extensions/regexp.rb +1 -1
  21. data/lib/mongoid/extensions/set.rb +1 -1
  22. data/lib/mongoid/extensions/string.rb +1 -1
  23. data/lib/mongoid/extensions/symbol.rb +1 -1
  24. data/lib/mongoid/extensions/time.rb +1 -1
  25. data/lib/mongoid/extensions/time_with_zone.rb +1 -1
  26. data/lib/mongoid/findable.rb +1 -0
  27. data/lib/mongoid/interceptable.rb +4 -2
  28. data/lib/mongoid/persistable.rb +4 -3
  29. data/lib/mongoid/relations/embedded/many.rb +1 -1
  30. data/lib/mongoid/relations/metadata.rb +8 -4
  31. data/lib/mongoid/relations/referenced/many.rb +1 -1
  32. data/lib/mongoid/relations/touchable.rb +1 -1
  33. data/lib/mongoid/scopable.rb +2 -26
  34. data/lib/mongoid/validatable/uniqueness.rb +13 -0
  35. data/lib/mongoid/version.rb +1 -1
  36. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +0 -4
  37. data/spec/app/models/acolyte.rb +1 -1
  38. data/spec/app/models/address.rb +2 -2
  39. data/spec/app/models/appointment.rb +1 -1
  40. data/spec/app/models/audio.rb +1 -1
  41. data/spec/app/models/dog.rb +1 -1
  42. data/spec/app/models/event.rb +1 -1
  43. data/spec/app/models/house.rb +1 -1
  44. data/spec/app/models/message.rb +8 -0
  45. data/spec/app/models/person.rb +3 -2
  46. data/spec/app/models/player.rb +2 -2
  47. data/spec/app/models/post.rb +3 -2
  48. data/spec/app/models/preference.rb +1 -1
  49. data/spec/app/models/sound.rb +1 -1
  50. data/spec/app/models/symptom.rb +1 -1
  51. data/spec/app/models/tree.rb +2 -2
  52. data/spec/app/models/video.rb +1 -1
  53. data/spec/mongoid/attributes_spec.rb +3 -3
  54. data/spec/mongoid/changeable_spec.rb +3 -3
  55. data/spec/mongoid/contextual/mongo_spec.rb +14 -14
  56. data/spec/mongoid/contextual/none_spec.rb +127 -0
  57. data/spec/mongoid/criteria/scopable_spec.rb +6 -6
  58. data/spec/mongoid/criteria_spec.rb +52 -96
  59. data/spec/mongoid/errors/invalid_scope_spec.rb +2 -2
  60. data/spec/mongoid/errors/mongoid_error_spec.rb +1 -1
  61. data/spec/mongoid/extensions/date_time_spec.rb +1 -1
  62. data/spec/mongoid/fields_spec.rb +6 -7
  63. data/spec/mongoid/findable_spec.rb +65 -0
  64. data/spec/mongoid/interceptable_spec.rb +11 -11
  65. data/spec/mongoid/persistable_spec.rb +4 -4
  66. data/spec/mongoid/relations/auto_save_spec.rb +1 -1
  67. data/spec/mongoid/relations/bindings/embedded/in_spec.rb +5 -5
  68. data/spec/mongoid/relations/bindings/embedded/many_spec.rb +1 -1
  69. data/spec/mongoid/relations/bindings/embedded/one_spec.rb +2 -2
  70. data/spec/mongoid/relations/bindings/referenced/in_spec.rb +14 -14
  71. data/spec/mongoid/relations/bindings/referenced/many_spec.rb +4 -4
  72. data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +10 -10
  73. data/spec/mongoid/relations/bindings/referenced/one_spec.rb +6 -6
  74. data/spec/mongoid/relations/builders/referenced/in_spec.rb +2 -2
  75. data/spec/mongoid/relations/builders/referenced/one_spec.rb +1 -1
  76. data/spec/mongoid/relations/cascading/delete_spec.rb +2 -2
  77. data/spec/mongoid/relations/cascading/destroy_spec.rb +4 -4
  78. data/spec/mongoid/relations/cascading/nullify_spec.rb +2 -2
  79. data/spec/mongoid/relations/cascading/restrict_spec.rb +4 -4
  80. data/spec/mongoid/relations/eager_spec.rb +6 -6
  81. data/spec/mongoid/relations/embedded/many_spec.rb +36 -5
  82. data/spec/mongoid/relations/metadata_spec.rb +34 -15
  83. data/spec/mongoid/relations/referenced/many_spec.rb +19 -4
  84. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +7 -7
  85. data/spec/mongoid/relations/referenced/one_spec.rb +1 -1
  86. data/spec/mongoid/relations/targets/enumerable_spec.rb +2 -2
  87. data/spec/mongoid/relations/touchable_spec.rb +17 -0
  88. data/spec/mongoid/scopable_spec.rb +17 -40
  89. data/spec/mongoid/sessions/options_spec.rb +1 -1
  90. data/spec/mongoid/timestamps/timeless_spec.rb +6 -6
  91. data/spec/mongoid/timestamps/updated/short_spec.rb +1 -1
  92. data/spec/mongoid/timestamps/updated_spec.rb +1 -1
  93. data/spec/mongoid/timestamps_spec.rb +2 -2
  94. data/spec/mongoid/validatable/associated_spec.rb +4 -4
  95. data/spec/mongoid/validatable/length_spec.rb +7 -7
  96. data/spec/mongoid/validatable/presence_spec.rb +6 -6
  97. data/spec/mongoid/validatable/uniqueness_spec.rb +44 -3
  98. data/spec/rails/mongoid_spec.rb +20 -20
  99. data/spec/spec_helper.rb +1 -0
  100. metadata +55 -50
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e868be748277deddf1b1ef5bc060551904de8ed
4
- data.tar.gz: a285380f00b0d3f7dcb9d06f1d669e6b4262a980
3
+ metadata.gz: 4a19035d46ca8c08250b25f7351b5b74a1fffd1f
4
+ data.tar.gz: 5d21abf409d5f12902c313678f5ced482ef5bf9f
5
5
  SHA512:
6
- metadata.gz: c7f1bc5844c340f5a8335e7c74d80a78082402de62e75d025cf510409f14842a785bb70644655f93ccf38e33e0859dfb1c4237ef961d377a3838586c92c15878
7
- data.tar.gz: 52d507c0df35681fd4f7afb28f3d23ea5b6ff1c455e96bde67c44ef3ae4039a6c195aa957453ff95d437bb8de67f583d6422cf1fe84648a984e8787e95fcba60
6
+ metadata.gz: d9a2567b69ffd592e74a45b345a52e2c15f1e0a049360313c847dc1b08e6ac081973d1cfb88dbae44db72f3eb3c1e4a68855916c0b70f1cae99fcc6cf8a60490
7
+ data.tar.gz: 93da6b0c3d2539ea4fd3126ac238019e16d5b6060de1bf81309ecaa40ab8cb5a023f7f558f2c4fbe5db65bf7f3f98b9fdb5da541dd5502f73d4d462333c6af37
@@ -7,6 +7,10 @@ For instructions on upgrading to newer versions, visit
7
7
 
8
8
  ### Major Changes (Backwards Incompatible)
9
9
 
10
+ * Scopes and default scopes must now all be defined within lambdas or procs.
11
+
12
+ * `skip_version_check` config option was removed.
13
+
10
14
  * IdentityMap removed. (Arthur Neves)
11
15
 
12
16
  * Eager load rework. Eager load now doesnt need the identity map to load
@@ -255,6 +259,15 @@ For instructions on upgrading to newer versions, visit
255
259
  ..
256
260
  end
257
261
 
262
+ * \#3479 Map/reduce now respects criteria no timeout options if output is not
263
+ inline.
264
+
265
+ * \#3478 Criteria objects now have a #none method that will cause the criteria to
266
+ never hit the database and always have zero documents.
267
+
268
+ Band.none
269
+ Band.none.where(name: "Tool") # Always has zero documents.
270
+
258
271
  * \#3319 Counters can now be reset from a document instance:
259
272
 
260
273
  document.reset_counters(:relation)
@@ -291,8 +304,14 @@ For instructions on upgrading to newer versions, visit
291
304
 
292
305
  ### Resolved Issues
293
306
 
307
+ * \#3449 Touch needs to work for create and update. (Greggory Rothmeier)
308
+
309
+ * \#3432 Fixed mongoization of DateTime losing precision.
310
+
294
311
  * \#3397 Fixed $ne matcher for embedded documents to match server behaviour.
295
312
 
313
+ * \#3352 Allow named scopes named "open" to work through 1-n relations.
314
+
296
315
  * \#3348 Fixing compounded indexes having the same keys with
297
316
  different directions. (Arthur Neves)
298
317
 
@@ -319,8 +338,19 @@ For instructions on upgrading to newer versions, visit
319
338
  * \#3063 `Document#becomes` now properly sets base object on errors.
320
339
  (Adam Ross Cohen)
321
340
 
341
+ * \#3019 Atomic operations will no longer attempt to persist if the document
342
+ is not persisted.
343
+
322
344
  * \#2903 Removed unused string `to_a` extension.
323
345
 
346
+ ## 3.1.7
347
+
348
+ ### Resolved Issues
349
+
350
+ * \#3465 Fixed ambigous relation errors where inverse_of is set to nil.
351
+
352
+ * \#3414 Backkport skip and limit options on aggregation. (Wojciech Piekutowski)
353
+
324
354
  ## 3.1.6
325
355
 
326
356
  ### Resolved Issues
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Mongoid [![Build Status](https://secure.travis-ci.org/mongoid/mongoid.png?branch=master)](http://travis-ci.org/mongoid/mongoid) [![Code Climate](https://codeclimate.com/github/mongoid/mongoid.png)](https://codeclimate.com/github/mongoid/mongoid) [![Coverage Status](https://coveralls.io/repos/mongoid/mongoid/badge.png?branch=master)](https://coveralls.io/r/mongoid/mongoid?branch=master)
1
+ Mongoid [![Build Status](https://secure.travis-ci.org/mongoid/mongoid.png?branch=master)](http://travis-ci.org/mongoid/mongoid) [![Code Climate](https://codeclimate.com/github/mongoid/mongoid.png)](https://codeclimate.com/github/mongoid/mongoid) [![Coverage Status](https://coveralls.io/repos/mongoid/mongoid/badge.png?branch=master)](https://coveralls.io/r/mongoid/mongoid?branch=master) [![Gem Version](https://badge.fury.io/rb/mongoid.png)](http://badge.fury.io/rb/mongoid)
2
2
  ========
3
3
 
4
4
  Mongoid is an ODM (Object-Document-Mapper) framework for MongoDB in Ruby.
@@ -119,6 +119,7 @@ en:
119
119
  has the correct options.\n\n
120
120
  Valid options are:\n
121
121
  \_\_background: true|false\n
122
+ \_\_database: 'database_name'\n
122
123
  \_\_drop_dups: true|false\n
123
124
  \_\_name: 'index_name'\n
124
125
  \_\_sparse: true|false\n
@@ -128,6 +129,7 @@ en:
128
129
  \_\_bits: 26\n
129
130
  \_\_bucket_size : 1\n
130
131
  \_\_weights: { content: 1, title: 2 }\n
132
+ \_\_expire_after_seconds: number_of_seconds\n
131
133
  Valid types are: 1, -1, '2d', '2dsphere', 'geoHaystack', 'text', 'hashed'\n\n
132
134
  Example:\n
133
135
  \_\_class Band\n
@@ -156,15 +158,11 @@ en:
156
158
  invalid_scope:
157
159
  message: "Defining a scope of value %{value} on %{klass} is not
158
160
  allowed."
159
- summary: "Scopes in Mongoid must be either criteria objects or procs
160
- that wrap criteria objects."
161
- resolution: "Change the scope to be a criteria or proc wrapped
162
- critera.\n\n
161
+ summary: "Scopes in Mongoid must be procs that wrap criteria objects."
162
+ resolution: "Change the scope to be a proc wrapped critera.\n\n
163
163
  Example:\n
164
164
  \_\_class Band\n
165
165
  \_\_\_\_include Mongoid::Document\n
166
- \_\_\_\_field :active, type: Boolean, default: true\n
167
- \_\_\_\_scope :active, where(active: true)\n
168
166
  \_\_\_\_scope :inactive, ->{ where(active: false) }\n
169
167
  \_\_end\n\n"
170
168
  invalid_storage_options:
@@ -19,7 +19,7 @@ module Mongoid
19
19
  def process_attributes(attrs = nil)
20
20
  attrs ||= {}
21
21
  if !attrs.empty?
22
- attrs = sanitize_for_mass_assignment(attrs)
22
+ attrs = sanitize_for_mass_assignment(attrs.to_hash)
23
23
  attrs.each_pair do |key, value|
24
24
  next if pending_attribute?(key, value)
25
25
  process_attribute(key, value)
@@ -2,6 +2,7 @@
2
2
  require "mongoid/contextual/queryable"
3
3
  require "mongoid/contextual/mongo"
4
4
  require "mongoid/contextual/memory"
5
+ require "mongoid/contextual/none"
5
6
 
6
7
  module Mongoid
7
8
  module Contextual
@@ -48,6 +49,7 @@ module Mongoid
48
49
  #
49
50
  # @since 3.0.0
50
51
  def create_context
52
+ return None.new(self) if empty_and_chainable?
51
53
  embedded ? Memory.new(self) : Mongo.new(self)
52
54
  end
53
55
  end
@@ -268,7 +268,9 @@ module Mongoid
268
268
  # @since 3.0.0
269
269
  def documents
270
270
  return results["results"] if results.has_key?("results")
271
- session[output_collection].find
271
+ query = session[output_collection].find
272
+ query.no_timeout if criteria.options[:timeout] == false
273
+ query
272
274
  end
273
275
 
274
276
  # Get the collection that the map/reduce results were stored in.
@@ -0,0 +1,90 @@
1
+ # encoding: utf-8
2
+ module Mongoid
3
+ module Contextual
4
+ class None
5
+ include Enumerable
6
+ include Queryable
7
+
8
+ attr_reader :criteria, :klass
9
+
10
+ # Check if the context is equal to the other object.
11
+ #
12
+ # @example Check equality.
13
+ # context == []
14
+ #
15
+ # @param [ Array ] other The other array.
16
+ #
17
+ # @return [ true, false ] If the objects are equal.
18
+ #
19
+ # @since 4.0.0
20
+ def ==(other)
21
+ other.is_a?(None)
22
+ end
23
+
24
+ # Iterate over the null context. There are no documents to iterate over
25
+ # in this case.
26
+ #
27
+ # @example Iterate over the context.
28
+ # context.each do |doc|
29
+ # puts doc.name
30
+ # end
31
+ #
32
+ # @return [ Enumerator ] The enumerator.
33
+ #
34
+ # @since 4.0.0
35
+ def each
36
+ if block_given?
37
+ [].each { |doc| yield(doc) }
38
+ self
39
+ else
40
+ to_enum
41
+ end
42
+ end
43
+
44
+ # Do any documents exist for the context.
45
+ #
46
+ # @example Do any documents exist for the context.
47
+ # context.exists?
48
+ #
49
+ # @return [ true, false ] If the count is more than zero.
50
+ #
51
+ # @since 4.0.0
52
+ def exists?; false; end
53
+
54
+ # Create the new null context.
55
+ #
56
+ # @example Create the new context.
57
+ # Null.new(criteria)
58
+ #
59
+ # @param [ Criteria ] The criteria.
60
+ #
61
+ # @since 4.0.0
62
+ def initialize(criteria)
63
+ @criteria, @klass = criteria, criteria.klass
64
+ end
65
+
66
+ # Always returns nil.
67
+ #
68
+ # @example Get the last document.
69
+ # context.last
70
+ #
71
+ # @return [ nil ] Always nil.
72
+ #
73
+ # @since 4.0.0
74
+ def last; nil; end
75
+
76
+ # Always returns zero.
77
+ #
78
+ # @example Get the length of matching documents.
79
+ # context.length
80
+ #
81
+ # @return [ Integer ] Always zero.
82
+ #
83
+ # @since 4.0.0
84
+ def length
85
+ entries.length
86
+ end
87
+ alias :size :length
88
+ end
89
+ end
90
+ end
@@ -297,6 +297,31 @@ module Mongoid
297
297
  self
298
298
  end
299
299
 
300
+ # Returns a criteria that will always contain zero results and never hits
301
+ # the database.
302
+ #
303
+ # @example Return a none criteria.
304
+ # criteria.none
305
+ #
306
+ # @return [ Criteria ] The none criteria.
307
+ #
308
+ # @since 4.0.0
309
+ def none
310
+ @none = true and self
311
+ end
312
+
313
+ # Is the criteria an empty but chainable criteria?
314
+ #
315
+ # @example Is the criteria a none criteria?
316
+ # criteria.empty_and_chainable?
317
+ #
318
+ # @return [ true, false ] If the criteria is a none.
319
+ #
320
+ # @since 4.0.0
321
+ def empty_and_chainable?
322
+ !!@none
323
+ end
324
+
300
325
  # Overriden to include _type in the fields.
301
326
  #
302
327
  # @example Limit the fields returned from the database.
@@ -177,4 +177,4 @@ module Mongoid
177
177
  end
178
178
 
179
179
  ::Array.__send__(:include, Mongoid::Extensions::Array)
180
- ::Array.__send__(:extend, Mongoid::Extensions::Array::ClassMethods)
180
+ ::Array.extend(Mongoid::Extensions::Array::ClassMethods)
@@ -66,4 +66,4 @@ module Mongoid
66
66
  end
67
67
 
68
68
  ::BigDecimal.__send__(:include, Mongoid::Extensions::BigDecimal)
69
- ::BigDecimal.__send__(:extend, Mongoid::Extensions::BigDecimal::ClassMethods)
69
+ ::BigDecimal.extend(Mongoid::Extensions::BigDecimal::ClassMethods)
@@ -74,4 +74,4 @@ module Mongoid
74
74
  end
75
75
 
76
76
  ::Date.__send__(:include, Mongoid::Extensions::Date)
77
- ::Date.__send__(:extend, Mongoid::Extensions::Date::ClassMethods)
77
+ ::Date.extend(Mongoid::Extensions::Date::ClassMethods)
@@ -12,9 +12,9 @@ module Mongoid
12
12
  #
13
13
  # @since 3.0.0
14
14
  def __mongoize_time__
15
- return self if utc? && Mongoid.use_utc?
15
+ return to_time if utc? && Mongoid.use_utc?
16
16
  if Mongoid.use_activesupport_time_zone?
17
- in_time_zone(::Time.zone)
17
+ in_time_zone(::Time.zone).to_time
18
18
  else
19
19
  time = to_time
20
20
  time.respond_to?(:getlocal) ? time.getlocal : time
@@ -70,4 +70,4 @@ module Mongoid
70
70
  end
71
71
 
72
72
  ::DateTime.__send__(:include, Mongoid::Extensions::DateTime)
73
- ::DateTime.__send__(:extend, Mongoid::Extensions::DateTime::ClassMethods)
73
+ ::DateTime.extend(Mongoid::Extensions::DateTime::ClassMethods)
@@ -54,4 +54,4 @@ module Mongoid
54
54
  end
55
55
 
56
56
  ::Float.__send__(:include, Mongoid::Extensions::Float)
57
- ::Float.__send__(:extend, Mongoid::Extensions::Float::ClassMethods)
57
+ ::Float.extend(Mongoid::Extensions::Float::ClassMethods)
@@ -214,4 +214,4 @@ module Mongoid
214
214
  end
215
215
 
216
216
  ::Hash.__send__(:include, Mongoid::Extensions::Hash)
217
- ::Hash.__send__(:extend, Mongoid::Extensions::Hash::ClassMethods)
217
+ ::Hash.extend(Mongoid::Extensions::Hash::ClassMethods)
@@ -64,4 +64,4 @@ module Mongoid
64
64
  end
65
65
 
66
66
  ::Integer.__send__(:include, Mongoid::Extensions::Integer)
67
- ::Integer.__send__(:extend, Mongoid::Extensions::Integer::ClassMethods)
67
+ ::Integer.extend(Mongoid::Extensions::Integer::ClassMethods)
@@ -104,14 +104,14 @@ module Mongoid
104
104
  send(name, *args) if name && respond_to?(name)
105
105
  end
106
106
 
107
- # Get the value for an instance variable or nil if it doesn't exist.
107
+ # Get the value for an instance variable or false if it doesn't exist.
108
108
  #
109
109
  # @example Get the value for an instance var.
110
110
  # document.ivar("person")
111
111
  #
112
112
  # @param [ String ] name The name of the variable.
113
113
  #
114
- # @return [ Object, nil ] The value or nil.
114
+ # @return [ Object, false ] The value or false.
115
115
  #
116
116
  # @since 2.0.0.rc.1
117
117
  def ivar(name)
@@ -271,4 +271,4 @@ module Mongoid
271
271
  end
272
272
 
273
273
  ::Object.__send__(:include, Mongoid::Extensions::Object)
274
- ::Object.__send__(:extend, Mongoid::Extensions::Object::ClassMethods)
274
+ ::Object.extend(Mongoid::Extensions::Object::ClassMethods)
@@ -51,4 +51,4 @@ module Mongoid
51
51
  end
52
52
 
53
53
  BSON::ObjectId.__send__(:include, Mongoid::Extensions::ObjectId)
54
- BSON::ObjectId.__send__(:extend, Mongoid::Extensions::ObjectId::ClassMethods)
54
+ BSON::ObjectId.extend(Mongoid::Extensions::ObjectId::ClassMethods)
@@ -82,4 +82,4 @@ module Mongoid
82
82
  end
83
83
 
84
84
  ::Range.__send__(:include, Mongoid::Extensions::Range)
85
- ::Range.__send__(:extend, Mongoid::Extensions::Range::ClassMethods)
85
+ ::Range.extend(Mongoid::Extensions::Range::ClassMethods)
@@ -24,4 +24,4 @@ module Mongoid
24
24
  end
25
25
  end
26
26
 
27
- ::Regexp.__send__(:extend, Mongoid::Extensions::Regexp::ClassMethods)
27
+ ::Regexp.extend(Mongoid::Extensions::Regexp::ClassMethods)
@@ -52,4 +52,4 @@ module Mongoid
52
52
  end
53
53
 
54
54
  ::Set.__send__(:include, Mongoid::Extensions::Set)
55
- ::Set.__send__(:extend, Mongoid::Extensions::Set::ClassMethods)
55
+ ::Set.extend(Mongoid::Extensions::Set::ClassMethods)
@@ -196,4 +196,4 @@ module Mongoid
196
196
  end
197
197
 
198
198
  ::String.__send__(:include, Mongoid::Extensions::String)
199
- ::String.__send__(:extend, Mongoid::Extensions::String::ClassMethods)
199
+ ::String.extend(Mongoid::Extensions::String::ClassMethods)
@@ -51,4 +51,4 @@ module Mongoid
51
51
  end
52
52
 
53
53
  ::Symbol.__send__(:include, Mongoid::Extensions::Symbol)
54
- ::Symbol.__send__(:extend, Mongoid::Extensions::Symbol::ClassMethods)
54
+ ::Symbol.extend(Mongoid::Extensions::Symbol::ClassMethods)
@@ -85,4 +85,4 @@ module Mongoid
85
85
  end
86
86
 
87
87
  ::Time.__send__(:include, Mongoid::Extensions::Time)
88
- ::Time.__send__(:extend, Mongoid::Extensions::Time::ClassMethods)
88
+ ::Time.extend(Mongoid::Extensions::Time::ClassMethods)
@@ -53,4 +53,4 @@ module Mongoid
53
53
  end
54
54
 
55
55
  ::ActiveSupport::TimeWithZone.__send__(:include, Mongoid::Extensions::TimeWithZone)
56
- ::ActiveSupport::TimeWithZone.__send__(:extend, Mongoid::Extensions::TimeWithZone::ClassMethods)
56
+ ::ActiveSupport::TimeWithZone.extend(Mongoid::Extensions::TimeWithZone::ClassMethods)
@@ -31,6 +31,7 @@ module Mongoid
31
31
  :map_reduce,
32
32
  :max,
33
33
  :min,
34
+ :none,
34
35
  :pluck,
35
36
  :sum,
36
37
  :text_search,
@@ -252,10 +252,12 @@ module Mongoid
252
252
  unless respond_to?(name)
253
253
  chain = ActiveSupport::Callbacks::CallbackChain.new(name, {})
254
254
  send("_#{kind}_callbacks").each do |callback|
255
- chain.push(callback) if callback.kind == place
255
+ chain.append(callback) if callback.kind == place
256
256
  end
257
257
  class_eval <<-EOM
258
- def #{name}() #{chain.compile} end
258
+ def #{name}()
259
+ #{chain.compile}
260
+ end
259
261
  protected :#{name}
260
262
  EOM
261
263
  end
@@ -142,7 +142,6 @@ module Mongoid
142
142
  #
143
143
  # @since 4.0.0
144
144
  def prepare_atomic_operation
145
- # @todo: Check if the document is persisted here.
146
145
  operations = yield({})
147
146
  persist_or_delay_atomic_operation(operations)
148
147
  self
@@ -205,8 +204,10 @@ module Mongoid
205
204
  #
206
205
  # @since 4.0.0
207
206
  def persist_atomic_operations(operations)
208
- selector = atomic_selector
209
- _root.collection.find(selector).update(positionally(selector, operations))
207
+ if persisted?
208
+ selector = atomic_selector
209
+ _root.collection.find(selector).update(positionally(selector, operations))
210
+ end
210
211
  end
211
212
  end
212
213
  end