mongoid 2.4.1 → 2.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,44 @@
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.1 \[ In Development \] \[ Branch: 2.4.0-stable \]
6
+ ## 2.4.2 \[ In Development \] \[ Branch: 2.4.0-stable \]
7
+
8
+ ### Resolved Issues
9
+
10
+ * \#1627 Validating format now works properly with localized fields.
11
+ (Douwe Maan)
12
+
13
+ * \#1617 Relation proxy methods now show up in Mongoid's list of
14
+ prohibited fields.
15
+
16
+ * \#1615 Allow a single configuration of host and port for all spec runs,
17
+ overridden by setting MONGOID_SPEC_HOST and MONGOID_SPEC_PORT env vars.
18
+
19
+ * \#1610 When versioning paranoid documents and max version is set, hard
20
+ delete old versions from the embedded relation.
21
+
22
+ * \#1609 Allow connection retry during cursor iteration as well as all other
23
+ operations.
24
+
25
+ * \#1608 Guard against no method errors when passing ids in nested attributes
26
+ and the documents do not exist.
27
+
28
+ * \#1605 Remove deprecation warning on rescue responses, Rails 3.2
29
+
30
+ * \#1602 Preserve structure of $and and $or queries when typecasting.
31
+
32
+ * \#1600 Uniqueness validation no longer errors when provided a relation.
33
+
34
+ * \#1599 Make sure enumerable targets yield to what is in memory first when
35
+ performing #each, not always the unloaded first.
36
+
37
+ * \#1597 Fix the ability to change the order of array fields with the same
38
+ elements.
39
+
40
+ * \#1590 Allow proper serialization of boolean values in criteria where the
41
+ field is nested inside an array.
42
+
43
+ ## 2.4.1
7
44
 
8
45
  ### Resolved Issues
9
46
 
@@ -66,6 +66,7 @@ module Mongoid #:nodoc
66
66
  Mongoid::NestedAttributes,
67
67
  Mongoid::Persistence,
68
68
  Mongoid::Relations,
69
+ Mongoid::Relations::Proxy,
69
70
  Mongoid::Safety,
70
71
  Mongoid::Serialization,
71
72
  Mongoid::Sharding,
@@ -23,6 +23,7 @@ module Mongoid #:nodoc
23
23
  option :autocreate_indexes, :default => false
24
24
  option :identity_map_enabled, :default => false
25
25
  option :include_root_in_json, :default => false
26
+ option :include_type_for_serialization, :default => false
26
27
  option :max_retries_on_connection_failure, :default => 0
27
28
  option :parameterize_keys, :default => true
28
29
  option :scope_overwrite_exception, :default => false
@@ -102,11 +102,9 @@ module Mongoid #:nodoc:
102
102
 
103
103
  def handle_and_or_value(values)
104
104
  [].tap do |result|
105
- values.map do |value|
106
- value.each do |key, value|
107
- result.push key => try_to_typecast(key, value)
108
- end
109
- end
105
+ result.push(*values.map do |value|
106
+ Hash[value.map{ |key, value| [key, try_to_typecast(key, value)] }]
107
+ end)
110
108
  end
111
109
  end
112
110
 
@@ -45,8 +45,10 @@ module Mongoid #:nodoc
45
45
  # @example Iterate over the cursor.
46
46
  # cursor.each { |doc| p doc.title }
47
47
  def each
48
- cursor.each do |document|
49
- yield Mongoid::Factory.from_db(klass, document)
48
+ retry_on_connection_failure do
49
+ while document = cursor.next_document
50
+ yield Factory.from_db(klass, document)
51
+ end
50
52
  end
51
53
  end
52
54
 
@@ -8,6 +8,7 @@ require "mongoid/fields/internal/binary"
8
8
  require "mongoid/fields/internal/boolean"
9
9
  require "mongoid/fields/internal/date"
10
10
  require "mongoid/fields/internal/date_time"
11
+ require "mongoid/fields/internal/false_class"
11
12
  require "mongoid/fields/internal/float"
12
13
  require "mongoid/fields/internal/hash"
13
14
  require "mongoid/fields/internal/integer"
@@ -23,6 +24,7 @@ require "mongoid/fields/internal/string"
23
24
  require "mongoid/fields/internal/symbol"
24
25
  require "mongoid/fields/internal/time"
25
26
  require "mongoid/fields/internal/time_with_zone"
27
+ require "mongoid/fields/internal/true_class"
26
28
  require "mongoid/fields/internal/foreign_keys/array"
27
29
  require "mongoid/fields/internal/foreign_keys/object"
28
30
 
@@ -21,17 +21,7 @@ module Mongoid #:nodoc:
21
21
  #
22
22
  # @since 2.4.0
23
23
  def add_atomic_changes(document, name, key, mods, new, old)
24
- pushes = (new || []) - (old || [])
25
- pulls = (old || []) - (new || [])
26
- if old.nil?
27
- mods[key] = pushes
28
- elsif !pushes.empty? && !pulls.empty?
29
- mods[key] = document.attributes[name]
30
- elsif !pushes.empty?
31
- document.atomic_array_pushes[key] = pushes
32
- elsif !pulls.empty?
33
- document.atomic_array_pulls[key] = pulls
34
- end
24
+ mods[key] = new
35
25
  end
36
26
 
37
27
  # Array fields are resizable.
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+ module Mongoid #:nodoc:
3
+ module Fields #:nodoc:
4
+ module Internal #:nodoc:
5
+ # Defines the behaviour for false values.
6
+ class FalseClass < Boolean
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+ module Mongoid #:nodoc:
3
+ module Fields #:nodoc:
4
+ module Internal #:nodoc:
5
+ # Defines the behaviour for true values.
6
+ class TrueClass < Boolean
7
+ end
8
+ end
9
+ end
10
+ end
@@ -81,10 +81,15 @@ module Rails #:nodoc:
81
81
  # 404s and not 500s, validation errors are 422s.
82
82
  initializer "load http errors" do |app|
83
83
  config.after_initialize do
84
- ActionDispatch::ShowExceptions.rescue_responses.update({
84
+ responses = {
85
85
  "Mongoid::Errors::DocumentNotFound" => :not_found,
86
86
  "Mongoid::Errors::Validations" => 422
87
- })
87
+ }
88
+ if rescue_responses = config.action_dispatch.rescue_responses
89
+ rescue_responses.update(responses)
90
+ else
91
+ ActionDispatch::ShowExceptions.rescue_responses.update(responses)
92
+ end
88
93
  end
89
94
  end
90
95
 
@@ -92,7 +92,9 @@ module Mongoid # :nodoc:
92
92
  def process(parent, attrs)
93
93
  return if reject?(parent, attrs)
94
94
  if id = attrs.extract_id
95
- doc = existing.find(convert_id(existing.first.class, id))
95
+ first = existing.first
96
+ converted = first ? convert_id(first.class, id) : id
97
+ doc = existing.find(converted)
96
98
  if destroyable?(attrs)
97
99
  existing.delete(doc)
98
100
  doc.destroy unless doc.embedded?
@@ -151,8 +151,9 @@ module Mongoid #:nodoc:
151
151
  end
152
152
  else
153
153
  unloaded.each do |doc|
154
- yield(doc)
155
- loaded.push(added.delete_one(doc) || loaded.delete_one(doc) || doc)
154
+ document = added.delete_one(doc) || loaded.delete_one(doc) || doc
155
+ yield(document)
156
+ loaded.push(document)
156
157
  end
157
158
  end
158
159
  added.each do |doc|
@@ -31,7 +31,7 @@ module Mongoid # :nodoc:
31
31
  only = Array.wrap(options[:only]).map(&:to_s)
32
32
  except = Array.wrap(options[:except]).map(&:to_s)
33
33
 
34
- except |= ['_type']
34
+ except |= ['_type'] unless Mongoid.include_type_for_serialization
35
35
 
36
36
  field_names = fields.keys.map { |field| field.to_s }
37
37
  attribute_names = (attributes.keys + field_names).sort
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require "mongoid/validations/associated"
3
+ require "mongoid/validations/format"
3
4
  require "mongoid/validations/uniqueness"
4
5
  require "mongoid/validations/presence"
5
6
 
@@ -88,6 +89,21 @@ module Mongoid #:nodoc:
88
89
 
89
90
  module ClassMethods #:nodoc:
90
91
 
92
+ # Validates whether or not a field matches a certain regular expression.
93
+ #
94
+ # @example
95
+ # class Person
96
+ # include Mongoid::Document
97
+ # field :website
98
+ #
99
+ # validates_format_of :website, :with => URI.regexp
100
+ # end
101
+ #
102
+ # @param [ Array ] *args The arguments to pass to the validator.
103
+ def validates_format_of(*args)
104
+ validates_with(FormatValidator, _merge_attributes(args))
105
+ end
106
+
91
107
  # Validates whether or not an association is valid or not. Will correctly
92
108
  # handle has one and has many associations.
93
109
  #
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ module Mongoid #:nodoc:
3
+ module Validations #:nodoc:
4
+
5
+ # Validates that the specified attributes do or do not match a certain
6
+ # regular expression.
7
+ #
8
+ # @example Set up the format validator.
9
+ #
10
+ # class Person
11
+ # include Mongoid::Document
12
+ # field :website
13
+ #
14
+ # validates_format_of :website, :with => URI.regexp
15
+ # end
16
+ class FormatValidator < ActiveModel::Validations::FormatValidator
17
+
18
+ # Validates each for format.
19
+ #
20
+ # @example Validate format.
21
+ # validator.validate_each(model, :name, "value")
22
+ #
23
+ # @param [ Document ] document The document.
24
+ # @param [ Symbol, String ] attribute The attribute to validate.
25
+ # @param [ Object ] value The attribute value.
26
+ #
27
+ # @since 2.4.2
28
+ def validate_each(document, attribute, value)
29
+ field = document.fields[attribute.to_s]
30
+ if field && field.localized? && !value.blank?
31
+ value.each_pair do |_locale, _value|
32
+ super(document, attribute, _value)
33
+ end
34
+ else
35
+ super
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -41,7 +41,7 @@ module Mongoid #:nodoc:
41
41
  #
42
42
  # @since 1.0.0
43
43
  def validate_each(document, attribute, value)
44
- return unless document.send("#{attribute}_changed?")
44
+ return unless document.send("attribute_changed?", attribute.to_s)
45
45
  if document.embedded?
46
46
  return if skip_validation?(document)
47
47
  relation = document._parent.send(document.metadata.name)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.4.1"
3
+ VERSION = "2.4.2"
4
4
  end
@@ -40,7 +40,16 @@ module Mongoid #:nodoc:
40
40
  previous.versioned_attributes, :without_protection => true
41
41
  ).attributes.delete("_id")
42
42
  if version_max.present? && versions.length > version_max
43
- versions.delete(versions.first)
43
+ deleted = versions.first
44
+ if deleted.paranoid?
45
+ versions.delete_one(deleted)
46
+ collection.update(
47
+ atomic_selector,
48
+ { "$pull" => { "versions" => { "version" => deleted.version }}}
49
+ )
50
+ else
51
+ versions.delete(deleted)
52
+ end
44
53
  end
45
54
  self.version = (version || 1 ) + 1
46
55
  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.1
4
+ version: 2.4.2
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-01-15 00:00:00.000000000 Z
12
+ date: 2012-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
- requirement: &70092776306560 !ruby/object:Gem::Requirement
16
+ requirement: &70314945130600 !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: *70092776306560
24
+ version_requirements: *70314945130600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tzinfo
27
- requirement: &70092776305140 !ruby/object:Gem::Requirement
27
+ requirement: &70314945129660 !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: *70092776305140
35
+ version_requirements: *70314945129660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mongo
38
- requirement: &70092776302420 !ruby/object:Gem::Requirement
38
+ requirement: &70314945129040 !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: *70092776302420
46
+ version_requirements: *70314945129040
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &70092776301540 !ruby/object:Gem::Requirement
49
+ requirement: &70314945128260 !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: *70092776301540
57
+ version_requirements: *70314945128260
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bson_ext
60
- requirement: &70092776300860 !ruby/object:Gem::Requirement
60
+ requirement: &70314945127340 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,21 +65,21 @@ dependencies:
65
65
  version: '1.3'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70092776300860
68
+ version_requirements: *70314945127340
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
- requirement: &70092776296740 !ruby/object:Gem::Requirement
71
+ requirement: &70314945126120 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
75
75
  - !ruby/object:Gem::Version
76
- version: 0.9.12
76
+ version: '0.10'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70092776296740
79
+ version_requirements: *70314945126120
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &70092776295300 !ruby/object:Gem::Requirement
82
+ requirement: &70314945106580 !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: *70092776295300
90
+ version_requirements: *70314945106580
91
91
  - !ruby/object:Gem::Dependency
92
- name: watchr
93
- requirement: &70092776293380 !ruby/object:Gem::Requirement
92
+ name: guard-rspec
93
+ requirement: &70314945098020 !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: *70092776293380
101
+ version_requirements: *70314945098020
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: ammeter
104
- requirement: &70092776292500 !ruby/object:Gem::Requirement
104
+ requirement: &70314945048580 !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: *70092776292500
112
+ version_requirements: *70314945048580
113
113
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
114
114
  in Ruby.
115
115
  email:
@@ -229,6 +229,7 @@ files:
229
229
  - lib/mongoid/fields/internal/boolean.rb
230
230
  - lib/mongoid/fields/internal/date.rb
231
231
  - lib/mongoid/fields/internal/date_time.rb
232
+ - lib/mongoid/fields/internal/false_class.rb
232
233
  - lib/mongoid/fields/internal/fixnum.rb
233
234
  - lib/mongoid/fields/internal/float.rb
234
235
  - lib/mongoid/fields/internal/foreign_keys/array.rb
@@ -246,6 +247,7 @@ files:
246
247
  - lib/mongoid/fields/internal/time.rb
247
248
  - lib/mongoid/fields/internal/time_with_zone.rb
248
249
  - lib/mongoid/fields/internal/timekeeping.rb
250
+ - lib/mongoid/fields/internal/true_class.rb
249
251
  - lib/mongoid/fields/mappings.rb
250
252
  - lib/mongoid/fields/serializable.rb
251
253
  - lib/mongoid/fields.rb
@@ -377,6 +379,7 @@ files:
377
379
  - lib/mongoid/timestamps/updated.rb
378
380
  - lib/mongoid/timestamps.rb
379
381
  - lib/mongoid/validations/associated.rb
382
+ - lib/mongoid/validations/format.rb
380
383
  - lib/mongoid/validations/presence.rb
381
384
  - lib/mongoid/validations/uniqueness.rb
382
385
  - lib/mongoid/validations.rb
@@ -411,7 +414,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
411
414
  version: '0'
412
415
  segments:
413
416
  - 0
414
- hash: 1067878638816238851
417
+ hash: 4438000233284558311
415
418
  required_rubygems_version: !ruby/object:Gem::Requirement
416
419
  none: false
417
420
  requirements: