mongoid 5.1.0 → 5.1.1
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/config.rb +1 -1
- data/lib/mongoid/matchable/and.rb +1 -1
- data/lib/mongoid/matchable/or.rb +1 -1
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +33 -8
- data/lib/mongoid/reloadable.rb +1 -0
- data/lib/mongoid/stateful.rb +6 -0
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +6 -1
- data/spec/mongoid/attributes/nested_spec.rb +21 -0
- data/spec/mongoid/config_spec.rb +34 -0
- data/spec/mongoid/matchable/and_spec.rb +25 -0
- data/spec/mongoid/matchable/or_spec.rb +25 -0
- data/spec/mongoid/reloadable_spec.rb +15 -0
- 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: ca6e4c501995a1483885dd73ee311c6f1ef818db
|
4
|
+
data.tar.gz: 7637900bde88e2c32c0b40e4f6ad09b82f1fd409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a471975f86db1e3f63fca5267f86722946ca19352445e22003b2181b279dfce7510d141037da8f14ccd4f81b8477dcecc07772ea61fbfe424f412ba637aabf0d
|
7
|
+
data.tar.gz: 42232d489eb95693bc6e0fcc49fa84b19e7b1ce5365b3a16fb2c3e676019208b50b3791139463a3d7d60089c1d7ae5ca1554046427a4f177c7feb06b861ec80c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mongoid/config.rb
CHANGED
data/lib/mongoid/matchable/or.rb
CHANGED
@@ -97,14 +97,7 @@ module Mongoid
|
|
97
97
|
def process_attributes(parent, attrs)
|
98
98
|
return if reject?(parent, attrs)
|
99
99
|
if id = attrs.extract_id
|
100
|
-
|
101
|
-
converted = first ? convert_id(first.class, id) : id
|
102
|
-
doc = existing.find(converted)
|
103
|
-
if destroyable?(attrs)
|
104
|
-
destroy(parent, existing, doc)
|
105
|
-
else
|
106
|
-
update_document(doc, attrs)
|
107
|
-
end
|
100
|
+
update_nested_relation(parent, id, attrs)
|
108
101
|
else
|
109
102
|
existing.push(Factory.build(metadata.klass, attrs)) unless destroyable?(attrs)
|
110
103
|
end
|
@@ -167,6 +160,38 @@ module Mongoid
|
|
167
160
|
doc.update_attributes(attrs)
|
168
161
|
end
|
169
162
|
end
|
163
|
+
|
164
|
+
# Update nested relation.
|
165
|
+
#
|
166
|
+
# @api private
|
167
|
+
#
|
168
|
+
# @example Update nested relation.
|
169
|
+
# builder.update_nested_relation(parent, id, attrs)
|
170
|
+
#
|
171
|
+
# @param [ Document ] parent The parent document.
|
172
|
+
# @param [ String, BSON::ObjectId ] id of the related document.
|
173
|
+
# @param [ Hash ] attrs The single document attributes to process.
|
174
|
+
#
|
175
|
+
# @since 6.0.0
|
176
|
+
def update_nested_relation(parent, id, attrs)
|
177
|
+
first = existing.first
|
178
|
+
converted = first ? convert_id(first.class, id) : id
|
179
|
+
|
180
|
+
if existing.where(id: converted).exists?
|
181
|
+
# document exists in relation
|
182
|
+
doc = existing.find(converted)
|
183
|
+
if destroyable?(attrs)
|
184
|
+
destroy(parent, existing, doc)
|
185
|
+
else
|
186
|
+
update_document(doc, attrs)
|
187
|
+
end
|
188
|
+
else
|
189
|
+
# push existing document to relation
|
190
|
+
doc = existing.unscoped.find(converted)
|
191
|
+
update_document(doc, attrs)
|
192
|
+
existing.push(doc) unless destroyable?(attrs)
|
193
|
+
end
|
194
|
+
end
|
170
195
|
end
|
171
196
|
end
|
172
197
|
end
|
data/lib/mongoid/reloadable.rb
CHANGED
data/lib/mongoid/stateful.rb
CHANGED
data/lib/mongoid/version.rb
CHANGED
@@ -92,7 +92,7 @@ development:
|
|
92
92
|
# A passphrase for the private key.
|
93
93
|
# ssl_key_pass_phrase: password
|
94
94
|
|
95
|
-
# Whether or not to do peer certification validation. (default:
|
95
|
+
# Whether or not to do peer certification validation. (default: true)
|
96
96
|
# ssl_verify: true
|
97
97
|
|
98
98
|
# The file containing a set of concatenated certification authority certifications
|
@@ -125,6 +125,11 @@ development:
|
|
125
125
|
|
126
126
|
# Ensure all times are UTC in the app side. (default: false)
|
127
127
|
# use_utc: false
|
128
|
+
|
129
|
+
# Set the Mongoid and Ruby driver log levels when not in a Rails
|
130
|
+
# environment. The Mongoid logger will be set to the Rails logger
|
131
|
+
# otherwise.(default: :info)
|
132
|
+
# log_level: :info
|
128
133
|
test:
|
129
134
|
clients:
|
130
135
|
default:
|
@@ -176,6 +176,27 @@ describe Mongoid::Attributes::Nested do
|
|
176
176
|
it "sets the nested attributes" do
|
177
177
|
expect(person.preferences.first.name).to eq("First")
|
178
178
|
end
|
179
|
+
|
180
|
+
context "when adding existing document to a relation" do
|
181
|
+
let(:preference) { Preference.create(name: 'sample preference') }
|
182
|
+
let(:person) do
|
183
|
+
Person.new(
|
184
|
+
preferences_attributes: { 0 => { id: preference.id, name: preference.name } }
|
185
|
+
)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "sets the nested attributes" do
|
189
|
+
expect(person.preferences.map(&:name)).to eq([preference.name])
|
190
|
+
end
|
191
|
+
|
192
|
+
it "updates attributes of existing document which is added to relation" do
|
193
|
+
preference_name = 'updated preference'
|
194
|
+
person = Person.new(
|
195
|
+
preferences_attributes: { 0 => { id: preference.id, name: preference_name } }
|
196
|
+
)
|
197
|
+
expect(person.preferences.map(&:name)).to eq([preference_name])
|
198
|
+
end
|
199
|
+
end
|
179
200
|
end
|
180
201
|
|
181
202
|
context "when the relation is a referenced in" do
|
data/spec/mongoid/config_spec.rb
CHANGED
@@ -63,6 +63,11 @@ describe Mongoid::Config do
|
|
63
63
|
context "when the log level is not set in the configuration" do
|
64
64
|
|
65
65
|
before do
|
66
|
+
if defined?(Rails)
|
67
|
+
RailsTemp = Rails
|
68
|
+
Object.send(:remove_const, :Rails)
|
69
|
+
end
|
70
|
+
|
66
71
|
Mongoid.configure do |config|
|
67
72
|
config.load_configuration(CONFIG)
|
68
73
|
end
|
@@ -125,6 +130,35 @@ describe Mongoid::Config do
|
|
125
130
|
it "sets the Mongo driver logger level" do
|
126
131
|
expect(Mongo::Logger.logger.level).to eq(Logger::WARN)
|
127
132
|
end
|
133
|
+
|
134
|
+
context "when in a Rails environment" do
|
135
|
+
|
136
|
+
before do
|
137
|
+
module Rails
|
138
|
+
def self.logger
|
139
|
+
::Logger.new($stdout)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
Mongoid.logger = Rails.logger
|
143
|
+
described_class.load!(file, :test)
|
144
|
+
end
|
145
|
+
|
146
|
+
after do
|
147
|
+
if defined?(Rails)
|
148
|
+
RailsTemp = Rails
|
149
|
+
Object.send(:remove_const, :Rails)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
it "keeps the Mongoid logger level the same as the Rails logger" do
|
154
|
+
expect(Mongoid.logger.level).to eq(Rails.logger.level)
|
155
|
+
expect(Mongoid.logger.level).not_to eq(Mongoid::Config.log_level)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "sets the Mongo driver logger level to Mongoid's logger level" do
|
159
|
+
expect(Mongo::Logger.logger.level).to eq(Mongoid.logger.level)
|
160
|
+
end
|
161
|
+
end
|
128
162
|
end
|
129
163
|
|
130
164
|
context "when provided an environment" do
|
@@ -31,6 +31,31 @@ describe Mongoid::Matchable::And do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
context "when the expression is a $not" do
|
35
|
+
|
36
|
+
let(:matches) do
|
37
|
+
matcher.matches?([ { title: {:$not => /Foobar/ } }])
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when the value matches" do
|
41
|
+
|
42
|
+
it "returns true" do
|
43
|
+
expect(matches).to be true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the value does not match" do
|
48
|
+
|
49
|
+
before do
|
50
|
+
person.title = "Foobar baz"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns false" do
|
54
|
+
expect(matches).to be false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
34
59
|
context "when the value does not match" do
|
35
60
|
|
36
61
|
let(:matches) do
|
@@ -37,6 +37,31 @@ describe Mongoid::Matchable::Or do
|
|
37
37
|
expect(matcher.matches?([])).to be false
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
context "when the expression is a $not" do
|
42
|
+
|
43
|
+
let(:matches) do
|
44
|
+
matcher.matches?([ { title: {:$not => /Foobar/ } }])
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the value matches" do
|
48
|
+
|
49
|
+
it "returns true" do
|
50
|
+
expect(matches).to be true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when the value does not match" do
|
55
|
+
|
56
|
+
before do
|
57
|
+
person.title = "Foobar baz"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns false" do
|
61
|
+
expect(matches).to be false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
40
65
|
end
|
41
66
|
|
42
67
|
context "when provided a complex expression" do
|
@@ -284,5 +284,20 @@ describe Mongoid::Reloadable do
|
|
284
284
|
expect(object.reload).to eq(from_db)
|
285
285
|
end
|
286
286
|
end
|
287
|
+
|
288
|
+
context 'when the document is readonly' do
|
289
|
+
|
290
|
+
before do
|
291
|
+
Person.create
|
292
|
+
end
|
293
|
+
|
294
|
+
let(:reloaded) do
|
295
|
+
Person.only(:name).first.reload
|
296
|
+
end
|
297
|
+
|
298
|
+
it 'resets the readonly state after reloading' do
|
299
|
+
expect(reloaded.readonly?).to be(false)
|
300
|
+
end
|
301
|
+
end
|
287
302
|
end
|
288
303
|
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: 5.1.
|
4
|
+
version: 5.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
ZIvvwAhgCjVW5QCi2I1noxXLmtZ3XDawWu8kaGtu8giHXcwL3941m8hvFZ/Wr9Yi
|
31
31
|
JvcXJt2a4/JvwnIs2hmKuyfhZmB9HEE5wQQaCMnnC14=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2016-
|
33
|
+
date: 2016-02-18 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: activemodel
|
@@ -811,7 +811,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
811
811
|
version: 1.3.6
|
812
812
|
requirements: []
|
813
813
|
rubyforge_project: mongoid
|
814
|
-
rubygems_version: 2.
|
814
|
+
rubygems_version: 2.4.6
|
815
815
|
signing_key:
|
816
816
|
specification_version: 4
|
817
817
|
summary: Elegant Persistence in Ruby for MongoDB.
|
metadata.gz.sig
CHANGED
Binary file
|