mongoid 3.0.0 → 3.0.1

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,21 @@
3
3
  For instructions on upgrading to newer versions, visit
4
4
  [mongoid.org](http://mongoid.org/docs/upgrading.html).
5
5
 
6
+ ## 3.0.1
7
+
8
+ ### Resolved Issues
9
+
10
+ * \#2191 Ensure proper visibility (private) for error message generation
11
+ methods.
12
+
13
+ * \#2187 Ensure all levels of nested documents are serialized in json.
14
+
15
+ * \#2184 Allow names of relations that conflict with ruby core kernel
16
+ methods to pass existence checks.
17
+
18
+ * \#2181 Ensure `.first` criteria sort by ascending ids, if no other
19
+ sorting criteria was provided.
20
+
6
21
  ## 3.0.0
7
22
 
8
23
  ### New Features
@@ -916,6 +931,12 @@ For instructions on upgrading to newer versions, visit
916
931
 
917
932
  ### Resolved Issues
918
933
 
934
+ * \#2178 Ensure destroy callbacks are run post replacement of an embeds one
935
+ relation.
936
+
937
+ * \#2169 Allow saves to pass when documents are destroyed after the save
938
+ in a callback.
939
+
919
940
  * \#2144 Uniqueness validation on paranoid documents now properly scopes.
920
941
 
921
942
  * \#2127 Don't unbind parents of embedded documents mid nested
@@ -196,6 +196,7 @@ module Mongoid
196
196
  #
197
197
  # @since 3.0.0
198
198
  def first
199
+ apply_id_sorting
199
200
  with_eager_loading(query.first)
200
201
  end
201
202
  alias :one :first
@@ -403,6 +404,21 @@ module Mongoid
403
404
  end
404
405
  end
405
406
 
407
+ # Apply an ascending id sort for use with #first queries, only if no
408
+ # other sorting is provided.
409
+ #
410
+ # @api private
411
+ #
412
+ # @example Apply the id sorting params.
413
+ # context.apply_dd_sorting
414
+ #
415
+ # @since 3.0.0
416
+ def apply_id_sorting
417
+ unless criteria.options.has_key?(:sort)
418
+ query.sort(_id: 1)
419
+ end
420
+ end
421
+
406
422
  # Map the inverse sort symbols to the correct MongoDB values.
407
423
  #
408
424
  # @example Apply the inverse sorting params.
@@ -413,7 +429,7 @@ module Mongoid
413
429
  if spec = criteria.options[:sort]
414
430
  query.sort(Hash[spec.map{|k, v| [k, -1*v]}])
415
431
  else
416
- query.sort({_id: -1})
432
+ query.sort(_id: -1)
417
433
  end
418
434
  end
419
435
 
@@ -23,6 +23,8 @@ module Mongoid
23
23
  "\nResolution:\n #{resolution(key, attributes)}"
24
24
  end
25
25
 
26
+ private
27
+
26
28
  # Given the key of the specific error and the options hash, translate the
27
29
  # message.
28
30
  #
@@ -40,7 +42,10 @@ module Mongoid
40
42
  # Create the problem.
41
43
  #
42
44
  # @example Create the problem.
43
- # error.problem
45
+ # error.problem("error", {})
46
+ #
47
+ # @param [ String, Symbol ] key The error key.
48
+ # @param [ Hash ] attributes The attributes to interpolate.
44
49
  #
45
50
  # @return [ String ] The problem.
46
51
  #
@@ -52,7 +57,10 @@ module Mongoid
52
57
  # Create the summary.
53
58
  #
54
59
  # @example Create the summary.
55
- # error.summary
60
+ # error.summary("error", {})
61
+ #
62
+ # @param [ String, Symbol ] key The error key.
63
+ # @param [ Hash ] attributes The attributes to interpolate.
56
64
  #
57
65
  # @return [ String ] The summary.
58
66
  #
@@ -64,7 +72,10 @@ module Mongoid
64
72
  # Create the resolution.
65
73
  #
66
74
  # @example Create the resolution.
67
- # error.resolution
75
+ # error.resolution("error", {})
76
+ #
77
+ # @param [ String, Symbol ] key The error key.
78
+ # @param [ Hash ] attributes The attributes to interpolate.
68
79
  #
69
80
  # @return [ String ] The resolution.
70
81
  #
@@ -76,7 +76,7 @@ module Mongoid
76
76
  # @since 1.0.0
77
77
  def save(options = {})
78
78
  if new_record?
79
- insert(options).persisted?
79
+ !insert(options).new_record?
80
80
  else
81
81
  update(options)
82
82
  end
@@ -126,7 +126,7 @@ module Mongoid
126
126
  def existence_check(name, metadata)
127
127
  module_eval <<-END
128
128
  def #{name}?
129
- without_autobuild { !#{name}.blank? }
129
+ without_autobuild { !__send__(:#{name}).blank? }
130
130
  end
131
131
  alias :has_#{name}? :#{name}?
132
132
  END
@@ -38,7 +38,7 @@ module Mongoid
38
38
  if _assigning?
39
39
  base.add_atomic_unset(target)
40
40
  else
41
- delete if persistable?
41
+ destroy if persistable?
42
42
  end
43
43
  unbind_one
44
44
  return nil unless replacement
@@ -31,56 +31,21 @@ module Mongoid
31
31
 
32
32
  names = field_names(options)
33
33
 
34
- _serializing do
35
- method_names = Array.wrap(options[:methods]).map do |name|
36
- name.to_s if respond_to?(name)
37
- end.compact
34
+ method_names = Array.wrap(options[:methods]).map do |name|
35
+ name.to_s if respond_to?(name)
36
+ end.compact
38
37
 
39
- (names + method_names).each do |name|
40
- without_autobuild do
41
- serialize_attribute(attrs, name, names, options)
42
- end
38
+ (names + method_names).each do |name|
39
+ without_autobuild do
40
+ serialize_attribute(attrs, name, names, options)
43
41
  end
44
- serialize_relations(attrs, options) if options[:include]
45
42
  end
43
+ serialize_relations(attrs, options) if options[:include]
46
44
  attrs
47
45
  end
48
46
 
49
47
  private
50
48
 
51
- # Enter the serialization block.
52
- #
53
- # @api private
54
- #
55
- # @example Begin serialization.
56
- # document._serializing do
57
- # end
58
- #
59
- # @return [ Object ] The result of the yield.
60
- #
61
- # @since 3.0.0
62
- def _serializing
63
- Threaded.begin("serialization")
64
- yield
65
- ensure
66
- Threaded.exit("serialization")
67
- end
68
-
69
- # Are we in a serialization block? We use this to protect multiple
70
- # unnecessary calls to #as_document.
71
- #
72
- # @api private
73
- #
74
- # @example Are we in serialization?
75
- # document._serializing?
76
- #
77
- # @return [ true, false ] If we are serializing.
78
- #
79
- # @since 3.0.0
80
- def _serializing?
81
- Threaded.executing?("serialization")
82
- end
83
-
84
49
  # Get the names of all fields that will be serialized.
85
50
  #
86
51
  # @api private
@@ -92,7 +57,7 @@ module Mongoid
92
57
  #
93
58
  # @since 3.0.0
94
59
  def field_names(options)
95
- names = (_serializing? ? attribute_names : as_document.keys + attribute_names).uniq.sort
60
+ names = (as_document.keys + attribute_names).uniq.sort
96
61
 
97
62
  only = Array.wrap(options[:only]).map(&:to_s)
98
63
  except = Array.wrap(options[:except]).map(&:to_s)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
- VERSION = "3.0.0"
3
+ VERSION = "3.0.1"
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.0
4
+ version: 3.0.1
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-07-08 00:00:00.000000000 Z
12
+ date: 2012-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -75,70 +75,6 @@ dependencies:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: 1.0.3
78
- - !ruby/object:Gem::Dependency
79
- name: mocha
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - '='
84
- - !ruby/object:Gem::Version
85
- version: '0.11'
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - '='
92
- - !ruby/object:Gem::Version
93
- version: '0.11'
94
- - !ruby/object:Gem::Dependency
95
- name: rspec
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- version: '2.10'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- version: '2.10'
110
- - !ruby/object:Gem::Dependency
111
- name: guard
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - '='
116
- - !ruby/object:Gem::Version
117
- version: 1.2.1
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - '='
124
- - !ruby/object:Gem::Version
125
- version: 1.2.1
126
- - !ruby/object:Gem::Dependency
127
- name: guard-rspec
128
- requirement: !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ~>
132
- - !ruby/object:Gem::Version
133
- version: '0.7'
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ~>
140
- - !ruby/object:Gem::Version
141
- version: '0.7'
142
78
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
143
79
  in Ruby.
144
80
  email:
@@ -416,7 +352,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
416
352
  version: '0'
417
353
  segments:
418
354
  - 0
419
- hash: 1324901210162009503
355
+ hash: 842230721201432915
420
356
  required_rubygems_version: !ruby/object:Gem::Requirement
421
357
  none: false
422
358
  requirements: