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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongoid/attributes/dynamic.rb +3 -3
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/criteria.rb +2 -0
- data/lib/mongoid/document.rb +1 -0
- data/lib/mongoid/persistable/settable.rb +3 -1
- data/lib/mongoid/relations/accessors.rb +1 -1
- data/lib/mongoid/relations/builders.rb +2 -2
- data/lib/mongoid/relations/eager.rb +2 -2
- data/lib/mongoid/relations/reflections.rb +5 -3
- data/lib/mongoid/relations/touchable.rb +1 -1
- data/lib/mongoid/scopable.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +2 -2
- data/spec/mongoid/persistable/settable_spec.rb +44 -0
- data/spec/mongoid/relations/cyclic_spec.rb +22 -0
- data/spec/mongoid/relations/reflections_spec.rb +9 -9
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c45686b0e53c4e404c5f52563b399c2ae3909dce
|
4
|
+
data.tar.gz: aea6ea222ae4e97af3ec984a7cb185cce8de966a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 033d87560a04cdcae0e2353117eccaa5f14ab4ea273e9bc491cd4cef659ae3488008f17894161375d6910c7be9533d249722eda57a556b8d388419761863366e
|
7
|
+
data.tar.gz: df6a8a161d146fd07a8ddc9867b0105c8f5285273770b169cd280b47c211d54ae31b7bb1ca96f27c35cc43a5e7ccf9e12485592722522efae0541f43d5ac42cf
|
checksums.yaml.gz.sig
CHANGED
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
|
data/lib/mongoid/criteria.rb
CHANGED
data/lib/mongoid/document.rb
CHANGED
@@ -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
|
-
|
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
|
@@ -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,
|
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,
|
92
|
+
attributes, _options = parse_args(*args)
|
93
93
|
document = Factory.build(metadata.klass, attributes)
|
94
94
|
doc = _assigning do
|
95
95
|
send("#{name}=", document)
|
@@ -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<
|
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<
|
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
|
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})
|
data/lib/mongoid/scopable.rb
CHANGED
@@ -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
|
|
data/lib/mongoid/version.rb
CHANGED
@@ -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:
|
54
|
-
# local_threshold:
|
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
|
-
|
78
|
+
context "when no argument supplied" do
|
80
79
|
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
let(:relations) do
|
81
|
+
klass.reflect_on_all_associations
|
82
|
+
end
|
84
83
|
|
85
|
-
|
86
|
-
|
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
|
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
|
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:
|
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.
|
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
|