mongoid 2.4.4 → 2.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,35 @@
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.4 (branch: 2.4.0-stable)
6
+ ## 2.4.5 (branch: 2.4.0-stable)
7
+
8
+ ### Resolved Issues
9
+
10
+ * \#1751 Mongoid's logger now responds to level for Ruby logging API
11
+ compatibility.
12
+
13
+ * \#1744/#1750 Sorting works now for localized fields in embedded documents
14
+ using the criteria API. (Hans Hasselberg)
15
+
16
+ * \#1746 Presence validation now shows which locales were empty for
17
+ localized fields. (Cyril Mougel)
18
+
19
+ * \#1727 Allow dot notation in embedded criteria to work on both embeds one
20
+ and embeds many. (Lyle Underwood)
21
+
22
+ * \#1723 Initialize callbacks should cascade through children without needing
23
+ to determine if the child is changed.
24
+
25
+ * \#1715 Serializable hashes are now consistent on inclusion of embedded
26
+ documents per or post save.
27
+
28
+ * \#1713 Fixing === checks when comparing a class with an instance of a
29
+ subclass.
30
+
31
+ * \#1495 Callbacks no longer get the 'super called outside of method` errors on
32
+ busted 1.8.7 rubies.
33
+
34
+ ## 2.4.4
7
35
 
8
36
  ### Resolved Issues
9
37
 
@@ -58,3 +58,4 @@ bg:
58
58
  scope_overwrite:
59
59
  "Cannot create scope :%{scope_name}, because of existing method
60
60
  %{model_name}.%{scope_name}."
61
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -58,3 +58,4 @@ de:
58
58
  scope_overwrite:
59
59
  "Scope :%{scope_name} kann nicht erzeugt werden, da bereits eine Methode
60
60
  %{model_name}.%{scope_name} existiert."
61
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -61,3 +61,4 @@ en-GB:
61
61
  scope_overwrite:
62
62
  "Cannot create scope :%{scope_name}, because of existing method
63
63
  %{model_name}.%{scope_name}."
64
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -61,3 +61,4 @@ en:
61
61
  scope_overwrite:
62
62
  "Cannot create scope :%{scope_name}, because of existing method
63
63
  %{model_name}.%{scope_name}."
64
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -56,3 +56,4 @@ es:
56
56
  scope_overwrite:
57
57
  "Cannot create scope :%{scope_name}, because of existing method
58
58
  %{model_name}.%{scope_name}."
59
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -59,3 +59,4 @@ fr:
59
59
  scope_overwrite:
60
60
  "Cannot create scope :%{scope_name}, because of existing method
61
61
  %{model_name}.%{scope_name}."
62
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -50,3 +50,4 @@ en:
50
50
  scope_overwrite:
51
51
  "Cannot create scope :%{scope_name}, because of existing method
52
52
  %{model_name}.%{scope_name}."
53
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -61,3 +61,4 @@ hu:
61
61
  scope_overwrite:
62
62
  "Cannot create scope :%{scope_name}, because of existing method
63
63
  %{model_name}.%{scope_name}."
64
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -59,3 +59,4 @@ id:
59
59
  scope_overwrite:
60
60
  "Cannot create scope :%{scope_name}, because of existing method
61
61
  %{model_name}.%{scope_name}."
62
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -56,3 +56,4 @@ it:
56
56
  scope_overwrite:
57
57
  "Cannot create scope :%{scope_name}, because of existing method
58
58
  %{model_name}.%{scope_name}."
59
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -54,3 +54,4 @@ ja:
54
54
  scope_overwrite:
55
55
  "Cannot create scope :%{scope_name}, because of existing method
56
56
  %{model_name}.%{scope_name}."
57
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -51,3 +51,4 @@ kr:
51
51
  scope_overwrite:
52
52
  "Cannot create scope :%{scope_name}, because of existing method
53
53
  %{model_name}.%{scope_name}."
54
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -58,3 +58,4 @@ nl:
58
58
  scope_overwrite:
59
59
  "Cannot create scope :%{scope_name}, because of existing method
60
60
  %{model_name}.%{scope_name}."
61
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -56,3 +56,4 @@ pl:
56
56
  scope_overwrite:
57
57
  "Cannot create scope :%{scope_name}, because of existing method
58
58
  %{model_name}.%{scope_name}."
59
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -57,3 +57,4 @@ pt-BR:
57
57
  scope_overwrite:
58
58
  "Cannot create scope :%{scope_name}, because of existing method
59
59
  %{model_name}.%{scope_name}."
60
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -57,3 +57,4 @@ pt:
57
57
  scope_overwrite:
58
58
  "Cannot create scope :%{scope_name}, because of existing method
59
59
  %{model_name}.%{scope_name}."
60
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -63,3 +63,4 @@ ro:
63
63
  scope_overwrite:
64
64
  "Cannot create scope :%{scope_name}, because of existing method
65
65
  %{model_name}.%{scope_name}."
66
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -58,3 +58,4 @@ ru:
58
58
  scope_overwrite:
59
59
  "Cannot create scope :%{scope_name}, because of existing method
60
60
  %{model_name}.%{scope_name}."
61
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -57,3 +57,4 @@ sv:
57
57
  scope_overwrite:
58
58
  "Cannot create scope :%{scope_name}, because of existing method
59
59
  %{model_name}.%{scope_name}."
60
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -59,3 +59,4 @@ vi:
59
59
  scope_overwrite:
60
60
  "Cannot create scope :%{scope_name}, because of existing method
61
61
  %{model_name}.%{scope_name}."
62
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -50,3 +50,4 @@ zh-CN:
50
50
  scope_overwrite:
51
51
  "Cannot create scope :%{scope_name}, because of existing method
52
52
  %{model_name}.%{scope_name}."
53
+ blank_on_locale: "can't be blank in %{in_locale}"
@@ -39,9 +39,8 @@ module Mongoid #:nodoc:
39
39
  #
40
40
  # @since 2.3.0
41
41
  def run_callbacks(kind, *args, &block)
42
- run_cascading_callbacks(cascadable_children(kind), kind, *args) do
43
- super(kind, *args, &block)
44
- end
42
+ run_cascading_callbacks(cascadable_children(kind), kind, *args) {}
43
+ super(kind, *args, &block)
45
44
  end
46
45
 
47
46
  private
@@ -106,7 +105,7 @@ module Mongoid #:nodoc:
106
105
  #
107
106
  # @since 2.3.0
108
107
  def cascadable_child?(kind, child)
109
- [ :create, :destroy ].include?(kind) || child.changed? || child.new_record?
108
+ [ :create, :destroy, :initialize ].include?(kind) || child.changed? || child.new_record?
110
109
  end
111
110
 
112
111
  # Get the name of the callback that the child should fire. This changes
@@ -303,7 +303,8 @@ module Mongoid #:nodoc:
303
303
  return documents if options[:sort].blank?
304
304
  documents.sort_by do |document|
305
305
  options[:sort].map do |key, direction|
306
- Sort.new(document.read_attribute(key), direction)
306
+ key = key.to_s.gsub(/(.*)\.#{I18n.locale}$/, '\1')
307
+ Sort.new(document.send(key), direction)
307
308
  end
308
309
  end
309
310
  end
@@ -276,7 +276,7 @@ module Mongoid #:nodoc:
276
276
  #
277
277
  # @since 2.0.0.rc.4
278
278
  def ===(other)
279
- self == (other.is_a?(Class) ? other : other.class)
279
+ other.is_a?(Class) ? self == other : other.is_a?(self)
280
280
  end
281
281
 
282
282
  # Instantiate a new object, only when loaded from the database or when
@@ -23,17 +23,22 @@ module Mongoid #:nodoc:
23
23
  # @param [ Array ] old The old elements getting removed.
24
24
  #
25
25
  # @since 2.4.0
26
- def add_atomic_changes(document, name, key, mods, new, old)
27
- pushes = (new || []) - (old || [])
28
- pulls = (old || []) - (new || [])
29
- if old.nil?
30
- mods[key] = pushes
31
- elsif !pushes.empty? && !pulls.empty?
32
- mods[key] = document.attributes[name]
33
- elsif !pushes.empty?
34
- document.atomic_array_add_to_sets[key] = pushes
35
- elsif !pulls.empty?
36
- document.atomic_array_pulls[key] = pulls
26
+ def add_atomic_changes(document, name, key, mods, new_elements, old_elements)
27
+ old = (old_elements || [])
28
+ new = (new_elements || [])
29
+ if new.length > old.length
30
+ if new.first(old.length) == old
31
+ document.atomic_array_add_to_sets[key] = new.drop(old.length)
32
+ else
33
+ mods[key] = document.attributes[name]
34
+ end
35
+ elsif new.length < old.length
36
+ pulls = old - new
37
+ if new == old - pulls
38
+ document.atomic_array_pulls[key] = pulls
39
+ else
40
+ mods[key] = document.attributes[name]
41
+ end
37
42
  elsif new != old
38
43
  mods[key] = document.attributes[name]
39
44
  end
@@ -4,7 +4,13 @@ module Mongoid #:nodoc:
4
4
  # The Mongoid logger which wraps some other ruby compliant logger class.
5
5
  class Logger
6
6
 
7
- delegate :info, :debug, :error, :fatal, :unknown, :to => :logger, :allow_nil => true
7
+ delegate \
8
+ :info,
9
+ :debug,
10
+ :error,
11
+ :fatal,
12
+ :level,
13
+ :unknown, :to => :logger, :allow_nil => true
8
14
 
9
15
  # Emit a warning log message.
10
16
  #
@@ -81,8 +81,12 @@ module Mongoid #:nodoc:
81
81
  # @since 2.2.1
82
82
  def extract_attribute(document, key)
83
83
  if (key_string = key.to_s) =~ /.+\..+/
84
- key_string.split('.').inject(document.attributes) do |attribs, key|
85
- attribs.try(:[], key)
84
+ key_string.split('.').inject(document.attributes) do |_attribs, _key|
85
+ if _attribs.is_a?(::Array)
86
+ _attribs.map { |doc| doc.try(:[], _key) }
87
+ else
88
+ _attribs.try(:[], _key)
89
+ end
86
90
  end
87
91
  else
88
92
  document.attributes[key_string]
@@ -34,15 +34,24 @@ module Mongoid # :nodoc:
34
34
  except |= ['_type'] unless Mongoid.include_type_for_serialization
35
35
 
36
36
  field_names = fields.keys.map { |field| field.to_s }
37
- attribute_names = (attributes.keys + field_names).sort
37
+ attribute_names = (as_document.keys + field_names).sort
38
38
  if only.any?
39
39
  attribute_names &= only
40
40
  elsif except.any?
41
41
  attribute_names -= except
42
42
  end
43
43
 
44
- method_names = Array.wrap(options[:methods]).map { |n| n.to_s if respond_to?(n.to_s) }.compact
45
- Hash[(attribute_names + method_names).map { |n| [n, send(n)] }].tap do |attrs|
44
+ method_names = Array.wrap(options[:methods]).map do |name|
45
+ name.to_s if respond_to?(name)
46
+ end.compact
47
+
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)
54
+ end
46
55
  serialize_relations(attrs, options) if options[:include]
47
56
  end
48
57
  end
@@ -29,7 +29,7 @@ module Mongoid #:nodoc:
29
29
  field = document.fields[attribute.to_s]
30
30
  if field && field.localized? && !value.blank?
31
31
  value.each_pair do |locale, value|
32
- document.errors.add(attribute, :blank, options) if value.blank?
32
+ document.errors.add(attribute, :blank_on_locale, options.merge(:in_locale => locale)) if value.blank?
33
33
  end
34
34
  else
35
35
  document.errors.add(attribute, :blank, options) if value.blank?
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.4.4"
3
+ VERSION = "2.4.5"
4
4
  end
@@ -90,7 +90,7 @@ module Rails #:nodoc:
90
90
  parts = model_path.map { |path| path.camelize }
91
91
  name = parts.join("::")
92
92
  klass = name.constantize
93
- rescue NameError => e
93
+ rescue NameError, LoadError => e
94
94
  logger.info("Attempted to constantize #{name}, trying without namespacing.")
95
95
  klass = parts.last.constantize
96
96
  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.4
4
+ version: 2.4.5
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-13 00:00:00.000000000 Z
12
+ date: 2012-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
- requirement: &70339260281720 !ruby/object:Gem::Requirement
16
+ requirement: &70356497238660 !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: *70339260281720
24
+ version_requirements: *70356497238660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tzinfo
27
- requirement: &70339260281240 !ruby/object:Gem::Requirement
27
+ requirement: &70356497237480 !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: *70339260281240
35
+ version_requirements: *70356497237480
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mongo
38
- requirement: &70339260280760 !ruby/object:Gem::Requirement
38
+ requirement: &70356497236500 !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: *70339260280760
46
+ version_requirements: *70356497236500
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &70339260280280 !ruby/object:Gem::Requirement
49
+ requirement: &70356497234880 !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: *70339260280280
57
+ version_requirements: *70356497234880
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bson_ext
60
- requirement: &70339260279800 !ruby/object:Gem::Requirement
60
+ requirement: &70356497233800 !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: *70339260279800
68
+ version_requirements: *70356497233800
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
- requirement: &70339260279320 !ruby/object:Gem::Requirement
71
+ requirement: &70356497083440 !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: *70339260279320
79
+ version_requirements: *70356497083440
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &70339260278840 !ruby/object:Gem::Requirement
82
+ requirement: &70356497082860 !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: *70339260278840
90
+ version_requirements: *70356497082860
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: guard-rspec
93
- requirement: &70339260278360 !ruby/object:Gem::Requirement
93
+ requirement: &70356497081920 !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: *70339260278360
101
+ version_requirements: *70356497081920
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: ammeter
104
- requirement: &70339260277880 !ruby/object:Gem::Requirement
104
+ requirement: &70356497081280 !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: *70339260277880
112
+ version_requirements: *70356497081280
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: -632008619262652936
417
+ hash: 2742246905926364196
418
418
  required_rubygems_version: !ruby/object:Gem::Requirement
419
419
  none: false
420
420
  requirements: