mongoid 8.1.7 → 8.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/mongoid/attributes/readonly.rb +8 -3
- data/lib/mongoid/criteria/queryable/selectable.rb +1 -1
- data/lib/mongoid/document.rb +8 -1
- data/lib/mongoid/equality.rb +1 -0
- data/lib/mongoid/traversable.rb +24 -5
- data/lib/mongoid/version.rb +1 -1
- data/spec/mongoid/attributes/readonly_spec.rb +19 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +29 -0
- data/spec/mongoid/document_spec.rb +27 -0
- data/spec/mongoid/equality_spec.rb +6 -0
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f349e627130f8eacea25a6242dbcb2d3c48e8c75c7740368afeb62e5939f7c3
|
4
|
+
data.tar.gz: 1acc6e8d45a07d5d6a140228804eb6f9cdb6b89ac8deeb39283c89338dbbf256
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 418c4bf1aac91a436d7d149b5961273c4f704b122d554f76dbe42ff6a29a777e5a3c7dc97c80900c3341cdaabc4e1536e883c00c283fd040cea05b352b2a0a5a
|
7
|
+
data.tar.gz: 65371b0d3a22ecbeeecae3a9091bc9540921155debff4b556419280bd5c76a3205125e9bb3bb781490031564f7a532dbebe68f72c5ba3c7542690ef3f5308173
|
data/Rakefile
CHANGED
@@ -22,7 +22,7 @@ module Mongoid
|
|
22
22
|
# @return [ true | false ] If the document is new, or if the field is not
|
23
23
|
# readonly.
|
24
24
|
def attribute_writable?(name)
|
25
|
-
new_record? || (!readonly_attributes.include?(name) && _loaded?(name))
|
25
|
+
new_record? || (!self.class.readonly_attributes.include?(name) && _loaded?(name))
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
@@ -62,12 +62,17 @@ module Mongoid
|
|
62
62
|
# end
|
63
63
|
#
|
64
64
|
# @param [ Symbol... ] *names The names of the fields.
|
65
|
+
# @note When a parent class contains readonly attributes and is then
|
66
|
+
# inherited by a child class, the child class will inherit the
|
67
|
+
# parent's readonly attributes at the time of its creation.
|
68
|
+
# Updating the parent does not propagate down to child classes after wards.
|
65
69
|
def attr_readonly(*names)
|
70
|
+
self.readonly_attributes = self.readonly_attributes.dup
|
66
71
|
names.each do |name|
|
67
|
-
readonly_attributes << database_field_name(name)
|
72
|
+
self.readonly_attributes << database_field_name(name)
|
68
73
|
end
|
69
74
|
end
|
70
75
|
end
|
71
76
|
end
|
72
77
|
end
|
73
|
-
end
|
78
|
+
end
|
@@ -552,7 +552,7 @@ module Mongoid
|
|
552
552
|
# @return [ Selectable ] The new selectable.
|
553
553
|
def not(*criteria)
|
554
554
|
if criteria.empty?
|
555
|
-
dup.tap { |query| query.negating =
|
555
|
+
dup.tap { |query| query.negating = !query.negating }
|
556
556
|
else
|
557
557
|
criteria.compact.inject(self.clone) do |c, new_s|
|
558
558
|
if new_s.is_a?(Selectable)
|
data/lib/mongoid/document.rb
CHANGED
@@ -133,7 +133,14 @@ module Mongoid
|
|
133
133
|
#
|
134
134
|
# @return [ Hash ] A hash of all attributes in the hierarchy.
|
135
135
|
def as_document
|
136
|
-
|
136
|
+
attrs = as_attributes
|
137
|
+
|
138
|
+
# legacy attributes have a tendency to leak internal state via
|
139
|
+
# `as_document`; we have to deep_dup the attributes here to prevent
|
140
|
+
# that.
|
141
|
+
attrs = attrs.deep_dup if Mongoid.legacy_attributes
|
142
|
+
|
143
|
+
BSON::Document.new(attrs)
|
137
144
|
end
|
138
145
|
|
139
146
|
# Calls #as_json on the document with additional, Mongoid-specific options.
|
data/lib/mongoid/equality.rb
CHANGED
data/lib/mongoid/traversable.rb
CHANGED
@@ -7,6 +7,29 @@ module Mongoid
|
|
7
7
|
# Provides behavior around traversing the document graph.
|
8
8
|
module Traversable
|
9
9
|
extend ActiveSupport::Concern
|
10
|
+
# This code is extracted from ActiveSupport so that we do not depend on
|
11
|
+
# their private API that may change at any time.
|
12
|
+
# This code should be reviewed and maybe removed when implementing
|
13
|
+
# https://jira.mongodb.org/browse/MONGOID-5832
|
14
|
+
class << self
|
15
|
+
# @api private
|
16
|
+
def __redefine(owner, name, value)
|
17
|
+
if owner.singleton_class?
|
18
|
+
owner.redefine_method(name) { value }
|
19
|
+
owner.send(:public, name)
|
20
|
+
end
|
21
|
+
owner.redefine_singleton_method(name) { value }
|
22
|
+
owner.singleton_class.send(:public, name)
|
23
|
+
owner.redefine_singleton_method("#{name}=") do |new_value|
|
24
|
+
if owner.equal?(self)
|
25
|
+
value = new_value
|
26
|
+
else
|
27
|
+
::Mongoid::Traversable.redefine(self, name, new_value)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
owner.singleton_class.send(:public, "#{name}=")
|
31
|
+
end
|
32
|
+
end
|
10
33
|
|
11
34
|
def _parent
|
12
35
|
@__parent ||= nil
|
@@ -30,11 +53,7 @@ module Mongoid
|
|
30
53
|
if value
|
31
54
|
Mongoid::Fields::Validators::Macro.validate_field_name(self, value)
|
32
55
|
value = value.to_s
|
33
|
-
|
34
|
-
::ActiveSupport::ClassAttribute.redefine(self, 'discriminator_key', value)
|
35
|
-
else
|
36
|
-
super
|
37
|
-
end
|
56
|
+
::Mongoid::Traversable.__redefine(self, 'discriminator_key', value)
|
38
57
|
else
|
39
58
|
# When discriminator key is set to nil, replace the class's definition
|
40
59
|
# of the discriminator key reader (provided by class_attribute earlier)
|
data/lib/mongoid/version.rb
CHANGED
@@ -265,7 +265,26 @@ describe Mongoid::Attributes::Readonly do
|
|
265
265
|
expect(child.mother).to be_nil
|
266
266
|
end
|
267
267
|
end
|
268
|
+
end
|
269
|
+
|
270
|
+
context "when a subclass inherits readonly fields" do
|
271
|
+
let(:attributes) do
|
272
|
+
[:title, :terms]
|
273
|
+
end
|
274
|
+
|
275
|
+
before do
|
276
|
+
class OldPerson < Person
|
277
|
+
attr_readonly :age
|
278
|
+
end
|
279
|
+
end
|
268
280
|
|
281
|
+
it "ensures subclass inherits the readonly attributes from parent" do
|
282
|
+
expect(OldPerson.readonly_attributes.to_a).to include("title","terms")
|
283
|
+
end
|
284
|
+
|
285
|
+
it "ensures subclass does not modify parent's readonly attributes" do
|
286
|
+
expect(Person.readonly_attributes.to_a).not_to include("age")
|
287
|
+
end
|
269
288
|
end
|
270
289
|
end
|
271
290
|
end
|
@@ -2059,6 +2059,35 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
2059
2059
|
end
|
2060
2060
|
end
|
2061
2061
|
|
2062
|
+
describe "#not" do
|
2063
|
+
context "when negating a criterion" do
|
2064
|
+
let(:selection) do
|
2065
|
+
query.not(field: /value/)
|
2066
|
+
end
|
2067
|
+
|
2068
|
+
it "adds the $not selector" do
|
2069
|
+
expect(selection.selector).to eq({
|
2070
|
+
"field" => { "$not" => /value/ }
|
2071
|
+
})
|
2072
|
+
end
|
2073
|
+
|
2074
|
+
it "returns a cloned query" do
|
2075
|
+
expect(selection).to_not equal(query)
|
2076
|
+
end
|
2077
|
+
|
2078
|
+
context "when toggling negation state" do
|
2079
|
+
it "negates the negating value" do
|
2080
|
+
expect(query.negating).to be_nil
|
2081
|
+
negated_query = query.not
|
2082
|
+
expect(negated_query.negating).to be true
|
2083
|
+
double_negated_query = negated_query.not
|
2084
|
+
expect(double_negated_query.negating).to be false
|
2085
|
+
end
|
2086
|
+
end
|
2087
|
+
end
|
2088
|
+
end
|
2089
|
+
|
2090
|
+
|
2062
2091
|
describe Symbol do
|
2063
2092
|
|
2064
2093
|
describe "#all" do
|
@@ -591,6 +591,33 @@ describe Mongoid::Document do
|
|
591
591
|
expect(person.as_document["addresses"].first).to have_key(:locations)
|
592
592
|
end
|
593
593
|
|
594
|
+
context 'when modifying the returned object' do
|
595
|
+
let(:record) do
|
596
|
+
RootCategory.create(categories: [{ name: 'tests' }]).reload
|
597
|
+
end
|
598
|
+
|
599
|
+
shared_examples_for 'an object with protected internal state' do
|
600
|
+
it 'does not expose internal state' do
|
601
|
+
before_change = record.as_document.dup
|
602
|
+
record.categories.first.name = 'things'
|
603
|
+
after_change = record.as_document
|
604
|
+
expect(before_change['categories'].first['name']).not_to eq('things')
|
605
|
+
end
|
606
|
+
end
|
607
|
+
|
608
|
+
context 'when legacy_attributes is true' do
|
609
|
+
config_override :legacy_attributes, true
|
610
|
+
|
611
|
+
it_behaves_like 'an object with protected internal state'
|
612
|
+
end
|
613
|
+
|
614
|
+
context 'when legacy_attributes is false' do
|
615
|
+
config_override :legacy_attributes, false
|
616
|
+
|
617
|
+
it_behaves_like 'an object with protected internal state'
|
618
|
+
end
|
619
|
+
end
|
620
|
+
|
594
621
|
context "with relation define store_as option in embeded_many" do
|
595
622
|
|
596
623
|
let!(:phone) do
|
@@ -291,6 +291,12 @@ describe Mongoid::Equality do
|
|
291
291
|
it "compares based on the document id" do
|
292
292
|
expect(first <=> second).to eq(-1)
|
293
293
|
end
|
294
|
+
|
295
|
+
it "doesn't break if one isn't a document" do
|
296
|
+
expect do
|
297
|
+
first <=> "Foo"
|
298
|
+
end.to_not raise_error
|
299
|
+
end
|
294
300
|
end
|
295
301
|
|
296
302
|
describe "#eql?" do
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.1.
|
4
|
+
version: 8.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The MongoDB Ruby Team
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-07 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activemodel
|
@@ -1146,7 +1145,6 @@ metadata:
|
|
1146
1145
|
documentation_uri: https://www.mongodb.com/docs/mongoid/
|
1147
1146
|
homepage_uri: https://mongoid.org/
|
1148
1147
|
source_code_uri: https://github.com/mongodb/mongoid
|
1149
|
-
post_install_message:
|
1150
1148
|
rdoc_options: []
|
1151
1149
|
require_paths:
|
1152
1150
|
- lib
|
@@ -1161,8 +1159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1161
1159
|
- !ruby/object:Gem::Version
|
1162
1160
|
version: 1.3.6
|
1163
1161
|
requirements: []
|
1164
|
-
rubygems_version: 3.
|
1165
|
-
signing_key:
|
1162
|
+
rubygems_version: 3.6.2
|
1166
1163
|
specification_version: 4
|
1167
1164
|
summary: Elegant Persistence in Ruby for MongoDB.
|
1168
1165
|
test_files:
|