mongoid 2.4.5 → 2.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,25 @@
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.5 (branch: 2.4.0-stable)
6
+ ## 2.4.6
7
+
8
+ ### Resolved Issues
9
+
10
+ * \#1772 Allow skip and limit to convert strings to integers. (Jean Boussier)
11
+
12
+ * \#1767 Model#update_attributes accepts mass assignment options again.
13
+ (Hans Hasselberg)
14
+
15
+ * \#1762 Criteria#any_of now properly handles localized fields.
16
+
17
+ * \#1758 Metadata now returns self on options for external library support.
18
+
19
+ * \#1757 Ensure serialization converts any attribute types to the type
20
+ defined by the field.
21
+
22
+ * \#1756 Serializable hash options should pass through to embedded docs.
23
+
24
+ ## 2.4.5
7
25
 
8
26
  ### Resolved Issues
9
27
 
@@ -109,7 +109,7 @@ module Mongoid #:nodoc:
109
109
  #
110
110
  # @return [ Criteria ] The cloned criteria.
111
111
  def limit(value = 20)
112
- clone.tap { |crit| crit.options[:limit] = value }
112
+ clone.tap { |crit| crit.options[:limit] = value.to_i }
113
113
  end
114
114
 
115
115
  # Returns the offset option. If a per_page option is in the list then it
@@ -163,7 +163,7 @@ module Mongoid #:nodoc:
163
163
  #
164
164
  # @return [ Criteria ] The cloned criteria.
165
165
  def skip(value = 0)
166
- clone.tap { |crit| crit.options[:skip] = value }
166
+ clone.tap { |crit| crit.options[:skip] = value.to_i }
167
167
  end
168
168
 
169
169
  # Adds a criterion to the +Criteria+ that specifies a type or an Array of
@@ -103,7 +103,12 @@ module Mongoid #:nodoc:
103
103
  def handle_and_or_value(values)
104
104
  [].tap do |result|
105
105
  result.push(*values.map do |value|
106
- Hash[value.map{ |key, value| [key, try_to_typecast(key, value)] }]
106
+ Hash[value.map do |_key, _value|
107
+ if klass.fields[_key.to_s].try(:localized?)
108
+ _key = "#{_key}.#{::I18n.locale}"
109
+ end
110
+ [_key, try_to_typecast(_key, _value)]
111
+ end]
107
112
  end)
108
113
  end
109
114
  end
@@ -116,8 +116,8 @@ module Mongoid #:nodoc:
116
116
  # @param [ Hash ] attributes The attributes to update.
117
117
  #
118
118
  # @return [ true, false ] True if validation passed, false if not.
119
- def update_attributes(attributes = {})
120
- write_attributes(attributes); save
119
+ def update_attributes(attributes = {}, options = {})
120
+ assign_attributes(attributes, options); save
121
121
  end
122
122
 
123
123
  # Update the document attributes in the database and raise an error if
@@ -131,8 +131,8 @@ module Mongoid #:nodoc:
131
131
  # @raise [ Errors::Validations ] If validation failed.
132
132
  #
133
133
  # @return [ true, false ] True if validation passed.
134
- def update_attributes!(attributes = {})
135
- update_attributes(attributes).tap do |result|
134
+ def update_attributes!(attributes = {}, options = {})
135
+ update_attributes(attributes, options).tap do |result|
136
136
  unless result
137
137
  self.class.fail_validate!(self) if errors.any?
138
138
  self.class.fail_callback!(self, :update_attributes!)
@@ -717,6 +717,19 @@ module Mongoid # :nodoc:
717
717
  !!self[:versioned]
718
718
  end
719
719
 
720
+ # Returns the metadata itself. Here for compatibility with Rails
721
+ # association metadata.
722
+ #
723
+ # @example Get the options.
724
+ # metadata.options
725
+ #
726
+ # @return [ Metadata ] self.
727
+ #
728
+ # @since 2.4.6
729
+ def options
730
+ self
731
+ end
732
+
720
733
  # Returns default order for this association.
721
734
  #
722
735
  # @example Get default order
@@ -46,11 +46,13 @@ module Mongoid # :nodoc:
46
46
  end.compact
47
47
 
48
48
  {}.tap do |attrs|
49
- attribute_names.each do |name|
50
- attrs[name] = attributes[name]
51
- end
52
- method_names.each do |name|
53
- attrs[name] = send(name)
49
+ (attribute_names + method_names).each do |name|
50
+ value = send(name)
51
+ if relations.has_key?(name)
52
+ attrs[name] = value.serializable_hash(options)
53
+ else
54
+ attrs[name] = value
55
+ end
54
56
  end
55
57
  serialize_relations(attrs, options) if options[:include]
56
58
  end
@@ -97,8 +99,7 @@ module Mongoid # :nodoc:
97
99
  inclusions = options[:include]
98
100
  relation_names(inclusions).each do |name|
99
101
  metadata = relations[name.to_s]
100
- relation = send(metadata.name)
101
- if relation
102
+ if metadata && relation = send(metadata.name)
102
103
  attributes[metadata.name.to_s] =
103
104
  relation.serializable_hash(relation_options(inclusions, options, name))
104
105
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.4.5"
3
+ VERSION = "2.4.6"
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.5
4
+ version: 2.4.6
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: 2012-02-22 00:00:00.000000000 Z
12
+ date: 2012-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
- requirement: &70356497238660 !ruby/object:Gem::Requirement
16
+ requirement: &70290122566500 !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: *70356497238660
24
+ version_requirements: *70290122566500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tzinfo
27
- requirement: &70356497237480 !ruby/object:Gem::Requirement
27
+ requirement: &70290122563300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.3.22
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70356497237480
35
+ version_requirements: *70290122563300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mongo
38
- requirement: &70356497236500 !ruby/object:Gem::Requirement
38
+ requirement: &70290122575540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.3'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70356497236500
46
+ version_requirements: *70290122575540
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &70356497234880 !ruby/object:Gem::Requirement
49
+ requirement: &70290122572600 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 3.5.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70356497234880
57
+ version_requirements: *70290122572600
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bson_ext
60
- requirement: &70356497233800 !ruby/object:Gem::Requirement
60
+ requirement: &70290122570780 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '1.3'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70356497233800
68
+ version_requirements: *70290122570780
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
- requirement: &70356497083440 !ruby/object:Gem::Requirement
71
+ requirement: &70290122594580 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0.10'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70356497083440
79
+ version_requirements: *70290122594580
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &70356497082860 !ruby/object:Gem::Requirement
82
+ requirement: &70290122606300 !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: *70356497082860
90
+ version_requirements: *70290122606300
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: guard-rspec
93
- requirement: &70356497081920 !ruby/object:Gem::Requirement
93
+ requirement: &70290122604280 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0.6'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70356497081920
101
+ version_requirements: *70290122604280
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: ammeter
104
- requirement: &70356497081280 !ruby/object:Gem::Requirement
104
+ requirement: &70290122602380 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: 0.1.3
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70356497081280
112
+ version_requirements: *70290122602380
113
113
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
114
114
  in Ruby.
115
115
  email:
@@ -414,7 +414,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
414
414
  version: '0'
415
415
  segments:
416
416
  - 0
417
- hash: 2742246905926364196
417
+ hash: 2263773657060838243
418
418
  required_rubygems_version: !ruby/object:Gem::Requirement
419
419
  none: false
420
420
  requirements: