mongoid 5.2.0.rc0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe14c770935c2292f42dcab9a0198ecf778e2a0d
4
- data.tar.gz: e5af1a0ceb58047b47420f3374d86f29a1243a51
3
+ metadata.gz: c45686b0e53c4e404c5f52563b399c2ae3909dce
4
+ data.tar.gz: aea6ea222ae4e97af3ec984a7cb185cce8de966a
5
5
  SHA512:
6
- metadata.gz: f3c567925e7f39d74f08294de83e4e33a67973655cecf39184675c5b72dc80fb565c736d1e43c43012c2be5adcdf709bffe9bec543826a2491ffbb7fd635cd0b
7
- data.tar.gz: 8e7c1b6d23eed2225b768b77c1025ab70f78e2581c70d55af31b063a44961577c9d4a0ff103553f98ab8fe97b78e7482db85fca998434343768cd59ab67d02d1
6
+ metadata.gz: 033d87560a04cdcae0e2353117eccaa5f14ab4ea273e9bc491cd4cef659ae3488008f17894161375d6910c7be9533d249722eda57a556b8d388419761863366e
7
+ data.tar.gz: df6a8a161d146fd07a8ddc9867b0105c8f5285273770b169cd280b47c211d54ae31b7bb1ca96f27c35cc43a5e7ccf9e12485592722522efae0541f43d5ac42cf
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -37,7 +37,7 @@ module Mongoid
37
37
  # @since 4.0.0
38
38
  def define_dynamic_reader(name)
39
39
  return unless name.valid_method_name?
40
- class_eval <<-READER
40
+ class_eval <<-READER, __FILE__, __LINE__ + 1
41
41
  def #{name}
42
42
  attribute_will_change!(#{name.inspect})
43
43
  read_attribute(#{name.inspect})
@@ -56,7 +56,7 @@ module Mongoid
56
56
  #
57
57
  # @since 4.0.0
58
58
  def define_dynamic_before_type_cast_reader(name)
59
- class_eval <<-READER
59
+ class_eval <<-READER, __FILE__, __LINE__ + 1
60
60
  def #{name}_before_type_cast
61
61
  attribute_will_change!(#{name.inspect})
62
62
  read_attribute_before_type_cast(#{name.inspect})
@@ -77,7 +77,7 @@ module Mongoid
77
77
  def define_dynamic_writer(name)
78
78
  return unless name.valid_method_name?
79
79
 
80
- class_eval <<-WRITER
80
+ class_eval <<-WRITER, __FILE__, __LINE__ + 1
81
81
  def #{name}=(value)
82
82
  write_attribute(#{name.inspect}, value)
83
83
  end
@@ -31,7 +31,7 @@ module Mongoid
31
31
  def option(name, options = {})
32
32
  defaults[name] = settings[name] = options[:default]
33
33
 
34
- class_eval <<-RUBY
34
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
35
35
  def #{name}
36
36
  settings[#{name.inspect}]
37
37
  end
@@ -193,6 +193,8 @@ module Mongoid
193
193
  # @since 1.0.0
194
194
  def initialize(klass)
195
195
  @klass = klass
196
+ @embedded = nil
197
+ @none = nil
196
198
  klass ? super(klass.aliased_fields, klass.fields) : super({}, {})
197
199
  end
198
200
 
@@ -101,6 +101,7 @@ module Mongoid
101
101
  #
102
102
  # @since 1.0.0
103
103
  def initialize(attrs = nil)
104
+ @__parent = nil
104
105
  _building do
105
106
  @new_record = true
106
107
  @attributes ||= {}
@@ -27,7 +27,9 @@ module Mongoid
27
27
  field = field_and_value_hash.keys.first.to_s
28
28
 
29
29
  if fields[field] && fields[field].type == Hash && attributes.key?(field)
30
- process_attribute(field.to_s, attributes[field].merge(field_and_value_hash[field]))
30
+ merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
31
+ value = attributes[field].merge(field_and_value_hash[field], &merger)
32
+ process_attribute(field.to_s, value)
31
33
  else
32
34
  process_attribute(field.to_s, field_and_value_hash[field])
33
35
  end
@@ -160,7 +160,7 @@ module Mongoid
160
160
  #
161
161
  # @since 3.0.0
162
162
  def existence_check(name)
163
- module_eval <<-END
163
+ module_eval <<-END, __FILE__, __LINE__ + 1
164
164
  def #{name}?
165
165
  without_autobuild { !__send__(:#{name}).blank? }
166
166
  end
@@ -64,7 +64,7 @@ module Mongoid
64
64
  # @since 2.0.0.rc.1
65
65
  def builder(name, metadata)
66
66
  re_define_method("build_#{name}") do |*args|
67
- attributes, options = parse_args(*args)
67
+ attributes, _options = parse_args(*args)
68
68
  document = Factory.build(metadata.klass, attributes)
69
69
  _building do
70
70
  child = send("#{name}=", document)
@@ -89,7 +89,7 @@ module Mongoid
89
89
  # @since 2.0.0.rc.1
90
90
  def creator(name, metadata)
91
91
  re_define_method("create_#{name}") do |*args|
92
- attributes, options = parse_args(*args)
92
+ attributes, _options = parse_args(*args)
93
93
  document = Factory.build(metadata.klass, attributes)
94
94
  doc = _assigning do
95
95
  send("#{name}=", document)
@@ -14,9 +14,9 @@ module Mongoid
14
14
  end
15
15
 
16
16
  def eager_load(docs)
17
- docs.tap do |docs|
17
+ docs.tap do |d|
18
18
  if eager_loadable?
19
- preload(criteria.inclusions, docs)
19
+ preload(criteria.inclusions, d)
20
20
  end
21
21
  end
22
22
  end
@@ -24,7 +24,7 @@ module Mongoid
24
24
  # @example Find multiple relation metadata by macro.
25
25
  # person.reflect_on_all_associations(:embeds_many)
26
26
  #
27
- # @param [ Array<String, Symbol> ] *macros The relation macros.
27
+ # @param [ Array<Symbol> ] *macros The relation macros.
28
28
  #
29
29
  # @return [ Array<Metadata> ] The matching relation metadata.
30
30
  def reflect_on_all_associations(*macros)
@@ -50,11 +50,13 @@ module Mongoid
50
50
  # @example Find multiple relation metadata by macro.
51
51
  # Person.reflect_on_all_associations(:embeds_many)
52
52
  #
53
- # @param [ Array<String, Symbol> ] *macros The relation macros.
53
+ # @param [ Array<Symbol> ] *macros The relation macros.
54
54
  #
55
55
  # @return [ Array<Metadata> ] The matching relation metadata.
56
56
  def reflect_on_all_associations(*macros)
57
- relations.values.select { |meta| macros.include?(meta.macro) }
57
+ association_reflections = relations.values
58
+ association_reflections.select! { |reflection| macros.include?(reflection.macro) } unless macros.empty?
59
+ association_reflections
58
60
  end
59
61
  end
60
62
  end
@@ -78,7 +78,7 @@ module Mongoid
78
78
  # @return [ Symbol ] The method name.
79
79
  def define_relation_touch_method(name)
80
80
  method_name = "touch_#{name}_after_create_or_destroy"
81
- class_eval <<-TOUCH
81
+ class_eval <<-TOUCH, __FILE__, __LINE__ + 1
82
82
  def #{method_name}
83
83
  without_autobuild do
84
84
  relation = __send__(:#{name})
@@ -117,7 +117,7 @@ module Mongoid
117
117
  # @since 3.0.0
118
118
  def queryable
119
119
  crit = Threaded.current_scope(self) || Criteria.new(self)
120
- crit.embedded = true if crit.klass.embedded?
120
+ crit.embedded = true if (crit.klass.embedded? && !crit.klass.cyclic?)
121
121
  crit
122
122
  end
123
123
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
- VERSION = "5.2.0.rc0"
3
+ VERSION = "5.2.0"
4
4
  end
@@ -50,8 +50,8 @@ development:
50
50
  # via ismaster commands. (default: 10)
51
51
  # heartbeat_frequency: 10
52
52
 
53
- # The time in seconds for selecting servers for a near read preference. (default: 5)
54
- # local_threshold: 5
53
+ # The time in seconds for selecting servers for a near read preference. (default: 0.015)
54
+ # local_threshold: 0.015
55
55
 
56
56
  # The timeout in seconds for selecting a server for an operation. (default: 30)
57
57
  # server_selection_timeout: 30
@@ -263,6 +263,50 @@ describe Mongoid::Persistable::Settable do
263
263
  end
264
264
  end
265
265
 
266
+ context 'when the field is a nested hash' do
267
+
268
+ context 'when a leaf value in the nested hash is updated' do
269
+
270
+ let(:church) do
271
+ Church.new.tap do |a|
272
+ a.location = {'address' => {'city' => 'Berlin', 'street' => 'Yorckstr'}}
273
+ a.name = 'Church1'
274
+ a.save
275
+ end
276
+ end
277
+
278
+ before do
279
+ church.set('location.address.city' => 'Munich')
280
+ end
281
+
282
+ it 'does not reset the nested hash' do
283
+ expect(church.name).to eq('Church1')
284
+ expect(church.location).to eql({'address' => {'city' => 'Munich', 'street' => 'Yorckstr'}})
285
+ end
286
+ end
287
+
288
+
289
+ context 'when the nested hash is many levels deep' do
290
+
291
+ let(:church) do
292
+ Church.new.tap do |a|
293
+ a.location = {'address' => {'state' => {'address' => {'city' => 'Berlin', 'street' => 'Yorckstr'}}}}
294
+ a.name = 'Church1'
295
+ a.save
296
+ end
297
+ end
298
+
299
+ before do
300
+ church.set('location.address.state.address.city' => 'Munich')
301
+ end
302
+
303
+ it 'does not reset the nested hash' do
304
+ expect(church.name).to eq('Church1')
305
+ expect(church.location).to eql({'address' => {'state' => {'address' => {'city' => 'Munich', 'street' => 'Yorckstr'}}}})
306
+ end
307
+ end
308
+ end
309
+
266
310
  context 'when the field is not already set locally' do
267
311
 
268
312
  let(:church) do
@@ -21,6 +21,17 @@ describe Mongoid::Relations::Cyclic do
21
21
  it "sets cyclic to true" do
22
22
  expect(document.cyclic).to be true
23
23
  end
24
+
25
+ context "when a query is executed" do
26
+
27
+ before do
28
+ document.save
29
+ end
30
+
31
+ it "queries the database, not memory" do
32
+ expect(Role.first).to be_a(Role)
33
+ end
34
+ end
24
35
  end
25
36
 
26
37
  context "when the name is not inflected easily" do
@@ -133,6 +144,17 @@ describe Mongoid::Relations::Cyclic do
133
144
  expect(document.class.relations['child_mango']).to be_cascading_callbacks
134
145
  end
135
146
  end
147
+
148
+ context "when a query is executed" do
149
+
150
+ before do
151
+ document.save
152
+ end
153
+
154
+ it "queries the database, not memory" do
155
+ expect(Shelf.first).to be_a(Shelf)
156
+ end
157
+ end
136
158
  end
137
159
 
138
160
  context "when building a namespaced hierarchy" do
@@ -74,23 +74,23 @@ describe Mongoid::Relations::Reflections do
74
74
  expect(relations.size).to eq(1)
75
75
  end
76
76
  end
77
- end
78
77
 
79
- context "when no relations exist for the macros" do
78
+ context "when no argument supplied" do
80
79
 
81
- let(:relations) do
82
- klass.reflect_on_all_associations(:embeds_one)
83
- end
80
+ let(:relations) do
81
+ klass.reflect_on_all_associations
82
+ end
84
83
 
85
- it "returns an empty array" do
86
- expect(relations).to be_empty
84
+ it "returns an array of all relations" do
85
+ expect(relations.size).to eq(3)
86
+ end
87
87
  end
88
88
  end
89
89
 
90
- context "when no argument supplied" do
90
+ context "when no relations exist for the macros" do
91
91
 
92
92
  let(:relations) do
93
- klass.reflect_on_all_associations
93
+ klass.reflect_on_all_associations(:embeds_one)
94
94
  end
95
95
 
96
96
  it "returns an empty array" do
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: 5.2.0.rc0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -30,7 +30,7 @@ cert_chain:
30
30
  cGiNQIiHBj/9/xHfOyOthBPUevTiVnuffarDr434z/LGLwYzgaG5EcJFvZqpvUpP
31
31
  fGcAPtAZUMGLXwcOB1BJEFkDxUQIJiEpSmf4YzzZhEM=
32
32
  -----END CERTIFICATE-----
33
- date: 2016-12-22 00:00:00.000000000 Z
33
+ date: 2017-01-26 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: activemodel
@@ -821,7 +821,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
821
821
  version: 1.3.6
822
822
  requirements: []
823
823
  rubyforge_project: mongoid
824
- rubygems_version: 2.6.8
824
+ rubygems_version: 2.4.5.1
825
825
  signing_key:
826
826
  specification_version: 4
827
827
  summary: Elegant Persistence in Ruby for MongoDB.
metadata.gz.sig CHANGED
Binary file