mongoid 2.4.10 → 2.4.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,23 @@ For instructions on upgrading to newer versions, visit
7
7
 
8
8
  ### Resolved Issues
9
9
 
10
+ * This release forces a cap on the mongo driver version at 1.6.2 due to
11
+ changes in the `Mongo::Connection.from_uri` API not allowing valid
12
+ connection options anymore.
13
+
14
+ * \#2040 Fixed bad interpolation for locale presence validation.
15
+
16
+ * \#2038 Allow inverse relations to be determined by foreign keys alone
17
+ if defined on both sides, not just an inverse_of declaration.
18
+
19
+ * \#2023 Allow serilialization of dynamic types that conflict with core
20
+ Ruby methods to still be serialized.
21
+
22
+ * \#2008 Presence validation should hit the db to check validity if the
23
+ relation in memory is blank.
24
+
25
+ * \#2006 Allow excluding only the _id field post execution of an #only call.
26
+
10
27
  ## 2.4.10
11
28
 
12
29
  ### Resolved Issues
data/Rakefile CHANGED
@@ -2,7 +2,6 @@ require "bundler"
2
2
  Bundler.setup
3
3
 
4
4
  require "rake"
5
- require "rdoc/task"
6
5
  require "rspec"
7
6
  require "rspec/core/rake_task"
8
7
 
@@ -37,13 +36,5 @@ RSpec::Core::RakeTask.new('spec:progress') do |spec|
37
36
  spec.pattern = "spec/**/*_spec.rb"
38
37
  end
39
38
 
40
- RDoc::Task.new do |rdoc|
41
- rdoc.rdoc_dir = "rdoc"
42
- rdoc.title = "mongoid #{Mongoid::VERSION}"
43
- rdoc.rdoc_files.include("README*")
44
- rdoc.rdoc_files.include("CHANGELOG*")
45
- rdoc.rdoc_files.include("lib/**/*.rb")
46
- end
47
-
48
39
  task :spec => [ "spec:functional", "spec:unit" ]
49
40
  task :default => :spec
@@ -58,4 +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}"
61
+ blank_on_locale: "can't be blank in %{location}"
@@ -58,4 +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
+ blank_on_locale: "can't be blank in %{location}"
@@ -61,4 +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}"
64
+ blank_on_locale: "can't be blank in %{location}"
@@ -56,4 +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
+ blank_on_locale: "can't be blank in %{location}"
@@ -59,4 +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}"
62
+ blank_on_locale: "can't be blank in %{location}"
@@ -50,4 +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}"
53
+ blank_on_locale: "can't be blank in %{location}"
@@ -61,4 +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}"
64
+ blank_on_locale: "can't be blank in %{location}"
@@ -59,4 +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}"
62
+ blank_on_locale: "can't be blank in %{location}"
@@ -56,4 +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}"
59
+ blank_on_locale: "can't be blank in %{location}"
@@ -54,4 +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}"
57
+ blank_on_locale: "can't be blank in %{location}"
@@ -51,4 +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}"
54
+ blank_on_locale: "can't be blank in %{location}"
@@ -58,4 +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}"
61
+ blank_on_locale: "can't be blank in %{location}"
@@ -56,4 +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}"
59
+ blank_on_locale: "can't be blank in %{location}"
@@ -57,4 +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}"
60
+ blank_on_locale: "can't be blank in %{location}"
@@ -57,4 +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}"
60
+ blank_on_locale: "can't be blank in %{location}"
@@ -63,4 +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}"
66
+ blank_on_locale: "can't be blank in %{location}"
@@ -58,4 +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}"
61
+ blank_on_locale: "can't be blank in %{location}"
@@ -57,4 +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}"
60
+ blank_on_locale: "can't be blank in %{location}"
@@ -59,4 +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}"
62
+ blank_on_locale: "can't be blank in %{location}"
@@ -50,4 +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}"
53
+ blank_on_locale: "can't be blank in %{location}"
@@ -22,7 +22,6 @@ module Mongoid #:nodoc
22
22
  include Mongoid::Dirty
23
23
  include Mongoid::Attributes
24
24
  include Mongoid::Collections
25
- include Mongoid::Copyable
26
25
  include Mongoid::DefaultScope
27
26
  include Mongoid::Extras
28
27
  include Mongoid::Fields
@@ -45,6 +44,7 @@ module Mongoid #:nodoc
45
44
  include Mongoid::Timestamps::Timeless
46
45
  include Mongoid::Validations
47
46
  include Mongoid::Callbacks
47
+ include Mongoid::Copyable
48
48
  include Mongoid::MultiDatabase
49
49
 
50
50
  MODULES = [
@@ -8,11 +8,13 @@ module Mongoid #:nodoc
8
8
 
9
9
  # Get the name of the environment that we are running under. This first
10
10
  # looks for Rails, then Sinatra, then a RACK_ENV environment variable,
11
- # and if none of those are found returns "development".
11
+ # and if none of those are found raises an error.
12
12
  #
13
13
  # @example Get the env name.
14
14
  # Environment.env_name
15
15
  #
16
+ # @raise [ Errors::NoEnvironment ] If no environment was set.
17
+ #
16
18
  # @return [ String ] The name of the current environment.
17
19
  #
18
20
  # @since 2.3.0
@@ -23,13 +23,44 @@ module Mongoid #:nodoc:
23
23
  # @example Clone the document.
24
24
  # document.clone
25
25
  #
26
+ # @param [ Document ] other The document getting cloned.
27
+ #
28
+ # @return [ Document ] The new document.
29
+ def initialize_copy(other)
30
+ __copy__(other)
31
+ end
32
+
33
+ # Clone or dup the current +Document+. This will return all attributes with
34
+ # the exception of the document's id and versions, and will reset all the
35
+ # instance variables.
36
+ #
37
+ # This clone also includes embedded documents.
38
+ #
26
39
  # @example Dup the document.
27
40
  # document.dup
28
41
  #
29
42
  # @param [ Document ] other The document getting cloned.
30
43
  #
31
44
  # @return [ Document ] The new document.
32
- def initialize_copy(other)
45
+ def initialize_dup(other)
46
+ __copy__(other)
47
+ end
48
+
49
+ private
50
+
51
+ # Handle the copy of the object.
52
+ #
53
+ # @api private
54
+ #
55
+ # @example Copy the object.
56
+ # document.__copy__(other)
57
+ #
58
+ # @param [ Document ] other The other document.
59
+ #
60
+ # @return [ Document ] self.
61
+ #
62
+ # @since 3.0.0
63
+ def __copy__(other)
33
64
  other.as_document
34
65
  instance_variables.each { |name| remove_instance_variable(name) }
35
66
  COPYABLES.each do |name|
@@ -96,7 +96,9 @@ module Mongoid #:nodoc:
96
96
  def without(*args)
97
97
  clone.tap do |crit|
98
98
  if args.any?
99
- crit.options[:fields] = {}
99
+ unless args == [ :id ] || args == [ :_id ]
100
+ crit.options[:fields] = {}
101
+ end
100
102
  args.flatten.each do |f|
101
103
  crit.options[:fields][f] = 0
102
104
  end
@@ -861,7 +861,7 @@ module Mongoid # :nodoc:
861
861
  #
862
862
  # @since 2.0.0.rc.1
863
863
  def determine_inverse_relation
864
- default = klass.relations[inverse_klass.name.underscore]
864
+ default = foreign_key_match || klass.relations[inverse_klass.name.underscore]
865
865
  return default.name if default
866
866
  klass.relations.each_pair do |key, meta|
867
867
  next if meta.versioned? || meta.name == name
@@ -872,6 +872,25 @@ module Mongoid # :nodoc:
872
872
  return nil
873
873
  end
874
874
 
875
+ # Return metadata where the foreign key matches the foreign key on this
876
+ # relation.
877
+ #
878
+ # @api private
879
+ #
880
+ # @example Return a foreign key match.
881
+ # meta.foreign_key_match
882
+ #
883
+ # @return [ Metadata ] A match, if any.
884
+ #
885
+ # @since 2.4.11
886
+ def foreign_key_match
887
+ if fk = self[:foreign_key]
888
+ klass.relations.values.detect do |meta|
889
+ fk == meta.foreign_key if meta.stores_foreign_key?
890
+ end
891
+ end
892
+ end
893
+
875
894
  # Determine the key for the relation in the attributes.
876
895
  #
877
896
  # @example Get the key.
@@ -47,11 +47,13 @@ module Mongoid # :nodoc:
47
47
 
48
48
  {}.tap do |attrs|
49
49
  (attribute_names + method_names).each do |name|
50
- value = send(name)
51
50
  if relations.has_key?(name)
52
- attrs[name] = value.serializable_hash(options)
51
+ value = send(name)
52
+ attrs[name] = value ? value.serializable_hash(options) : nil
53
+ elsif attribute_names.include?(name) && !fields.has_key?(name)
54
+ attrs[name] = read_attribute(name)
53
55
  else
54
- attrs[name] = value
56
+ attrs[name] = send(name)
55
57
  end
56
58
  end
57
59
  serialize_relations(attrs, options) if options[:include]
@@ -48,7 +48,7 @@ module Mongoid #:nodoc:
48
48
  # @since 2.0.0.rc.1
49
49
  def read_attribute_for_validation(attr)
50
50
  attribute = attr.to_s
51
- if relations[attribute]
51
+ if relations.has_key?(attribute)
52
52
  begin_validate
53
53
  relation = send(attr)
54
54
  exit_validate
@@ -31,6 +31,10 @@ module Mongoid #:nodoc:
31
31
  value.each_pair do |locale, value|
32
32
  document.errors.add(attribute, :blank_on_locale, options.merge(:location => locale)) if value.blank?
33
33
  end
34
+ elsif document.relations.has_key?(attribute.to_s)
35
+ if value.blank? && document.send(attribute).blank?
36
+ document.errors.add(attribute, :blank, options)
37
+ end
34
38
  else
35
39
  document.errors.add(attribute, :blank, options) if value.blank?
36
40
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.4.10"
3
+ VERSION = "2.4.11"
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.10
4
+ version: 2.4.11
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-05-12 00:00:00.000000000 Z
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -48,33 +48,17 @@ dependencies:
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ~>
51
+ - - <=
52
52
  - !ruby/object:Gem::Version
53
- version: '1.3'
53
+ version: 1.6.2
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '1.3'
62
- - !ruby/object:Gem::Dependency
63
- name: rdoc
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: 3.5.0
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
59
+ - - <=
76
60
  - !ruby/object:Gem::Version
77
- version: 3.5.0
61
+ version: 1.6.2
78
62
  - !ruby/object:Gem::Dependency
79
63
  name: bson_ext
80
64
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +98,7 @@ dependencies:
114
98
  requirements:
115
99
  - - ~>
116
100
  - !ruby/object:Gem::Version
117
- version: '2.6'
101
+ version: '2.10'
118
102
  type: :development
119
103
  prerelease: false
120
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +106,7 @@ dependencies:
122
106
  requirements:
123
107
  - - ~>
124
108
  - !ruby/object:Gem::Version
125
- version: '2.6'
109
+ version: '2.10'
126
110
  - !ruby/object:Gem::Dependency
127
111
  name: guard-rspec
128
112
  requirement: !ruby/object:Gem::Requirement
@@ -130,23 +114,7 @@ dependencies:
130
114
  requirements:
131
115
  - - ~>
132
116
  - !ruby/object:Gem::Version
133
- version: '0.6'
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.6'
142
- - !ruby/object:Gem::Dependency
143
- name: ammeter
144
- requirement: !ruby/object:Gem::Requirement
145
- none: false
146
- requirements:
147
- - - ~>
148
- - !ruby/object:Gem::Version
149
- version: 0.1.3
117
+ version: '0.7'
150
118
  type: :development
151
119
  prerelease: false
152
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -154,7 +122,7 @@ dependencies:
154
122
  requirements:
155
123
  - - ~>
156
124
  - !ruby/object:Gem::Version
157
- version: 0.1.3
125
+ version: '0.7'
158
126
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
159
127
  in Ruby.
160
128
  email:
@@ -461,7 +429,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
461
429
  version: '0'
462
430
  segments:
463
431
  - 0
464
- hash: 2758014138080710719
432
+ hash: 4531209101708295137
465
433
  required_rubygems_version: !ruby/object:Gem::Requirement
466
434
  none: false
467
435
  requirements: