mongoid 7.1.10 → 7.1.11
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/lib/config/locales/en.yml +13 -0
- data/lib/mongoid/config/environment.rb +9 -1
- data/lib/mongoid/contextual/atomic.rb +7 -2
- data/lib/mongoid/contextual/none.rb +3 -0
- data/lib/mongoid/criteria/queryable/selectable.rb +2 -2
- data/lib/mongoid/criteria/queryable/storable.rb +4 -4
- data/lib/mongoid/document.rb +3 -2
- data/lib/mongoid/errors/empty_config_file.rb +26 -0
- data/lib/mongoid/errors/invalid_config_file.rb +26 -0
- data/lib/mongoid/errors.rb +2 -0
- data/lib/mongoid/persistence_context.rb +3 -1
- data/lib/mongoid/tasks/database.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/spec/app/models/mop.rb +26 -0
- data/spec/integration/contextual/empty_spec.rb +142 -0
- data/spec/mongoid/clients/factory_spec.rb +11 -0
- data/spec/mongoid/clients/options_spec.rb +11 -5
- data/spec/mongoid/config/environment_spec.rb +86 -8
- data/spec/mongoid/contextual/atomic_spec.rb +64 -25
- data/spec/mongoid/contextual/geo_near_spec.rb +1 -1
- data/spec/mongoid/document_spec.rb +21 -1
- data/spec/mongoid/errors/invalid_config_file_spec.rb +32 -0
- data/spec/mongoid/persistable/updatable_spec.rb +2 -0
- data/spec/shared/lib/mrss/constraints.rb +21 -4
- data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +17 -12
- data/spec/shared/share/Dockerfile.erb +5 -4
- data/spec/shared/shlib/server.sh +71 -21
- data.tar.gz.sig +0 -0
- metadata +542 -532
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17a1a3273952d5a0d0eb20c5a9864eaccec98bcb9b07647450a8fc86795a46c9
|
4
|
+
data.tar.gz: a992b0cea4ac0ddc46e622b405dae7e0d1eab46ff800655d4fa21b39a7b88561
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ac4c55216f2ee6e351afcadab0800c42fc39306b9d7e60dc31ddbeb3bc3a314e7b79961fa785b34ee267bf7d07343a4cb0ac787a9457ad9498783b6baaa5fa5
|
7
|
+
data.tar.gz: 0c4f99da1d7845b4736fe7cfb5000067462c7c91c20fb5af1ac351f4eb8562212d3a21e958e1f239b59f1bfde5a57f9f621bf18e260560622a388f5f6f657a25
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/config/locales/en.yml
CHANGED
@@ -77,6 +77,12 @@ en:
|
|
77
77
|
different collections so a simple id lookup is not sufficient enough."
|
78
78
|
resolution: "Don't attempt to perform this action and have patience,
|
79
79
|
maybe this will be supported in the future."
|
80
|
+
empty_config_file:
|
81
|
+
message: "Empty configuration file: %{path}."
|
82
|
+
summary: "Your mongoid.yml configuration file appears to be empty."
|
83
|
+
resolution: "Ensure your configuration file contains the correct contents.
|
84
|
+
Please consult the following page with respect to Mongoid's configuration:
|
85
|
+
https://docs.mongodb.com/mongoid/current/reference/configuration/"
|
80
86
|
invalid_collection:
|
81
87
|
message: "Access to the collection for %{klass} is not allowed."
|
82
88
|
summary: "%{klass}.collection was called, and %{klass} is an embedded
|
@@ -91,6 +97,13 @@ en:
|
|
91
97
|
A collation option is only supported if the query is executed on a MongoDB server
|
92
98
|
with version >= 3.4."
|
93
99
|
resolution: "Remove the collation option from the query."
|
100
|
+
invalid_config_file:
|
101
|
+
message: "Invalid configuration file: %{path}."
|
102
|
+
summary: "Your mongoid.yml configuration file does not contain the
|
103
|
+
correct file structure."
|
104
|
+
resolution: "Ensure your configuration file contains the correct contents.
|
105
|
+
Please consult the following page with respect to Mongoid's configuration:
|
106
|
+
https://docs.mongodb.com/mongoid/current/reference/configuration/"
|
94
107
|
invalid_config_option:
|
95
108
|
message: "Invalid configuration option: %{name}."
|
96
109
|
summary: "A invalid configuration option was provided in your
|
@@ -52,7 +52,15 @@ module Mongoid
|
|
52
52
|
# @api private
|
53
53
|
def load_yaml(path, environment = nil)
|
54
54
|
env = environment ? environment.to_s : env_name
|
55
|
-
|
55
|
+
contents = File.new(path).read
|
56
|
+
if contents.empty?
|
57
|
+
raise Mongoid::Errors::EmptyConfigFile.new(path)
|
58
|
+
end
|
59
|
+
data = YAML.load(ERB.new(contents).result)
|
60
|
+
unless data.is_a?(Hash)
|
61
|
+
raise Mongoid::Errors::InvalidConfigFile.new(path)
|
62
|
+
end
|
63
|
+
data[env]
|
56
64
|
end
|
57
65
|
end
|
58
66
|
end
|
@@ -173,13 +173,18 @@ module Mongoid
|
|
173
173
|
# @example Unset the field on the matches.
|
174
174
|
# context.unset(:name)
|
175
175
|
#
|
176
|
-
# @param [ String
|
176
|
+
# @param [ String | Symbol | Array<String|Symbol> | Hash ] args
|
177
|
+
# The name(s) of the field(s) to unset.
|
178
|
+
# If a Hash is specified, its keys will be used irrespective of what
|
179
|
+
# each key's value is, even if the value is nil or false.
|
177
180
|
#
|
178
181
|
# @return [ nil ] Nil.
|
179
182
|
#
|
180
183
|
# @since 3.0.0
|
181
184
|
def unset(*args)
|
182
|
-
fields = args.
|
185
|
+
fields = args.map { |a| a.is_a?(Hash) ? a.keys : a }
|
186
|
+
.__find_args__
|
187
|
+
.map { |f| [database_field_name(f), true] }
|
183
188
|
view.update_many("$unset" => Hash[fields])
|
184
189
|
end
|
185
190
|
|
@@ -585,7 +585,7 @@ module Mongoid
|
|
585
585
|
end
|
586
586
|
_mongoid_expand_keys(new_s).each do |k, v|
|
587
587
|
k = k.to_s
|
588
|
-
if c.selector[k] || k
|
588
|
+
if c.selector[k] || k.start_with?('$')
|
589
589
|
c = c.send(:__multi__, [{'$nor' => [{k => v}]}], '$and')
|
590
590
|
else
|
591
591
|
if v.is_a?(Hash)
|
@@ -874,7 +874,7 @@ module Mongoid
|
|
874
874
|
clone.tap do |query|
|
875
875
|
criterion.each do |field, value|
|
876
876
|
field_s = field.to_s
|
877
|
-
if field_s
|
877
|
+
if field_s.start_with?('$')
|
878
878
|
# Query expression-level operator, like $and or $where
|
879
879
|
query.add_operator_expression(field_s, value)
|
880
880
|
else
|
@@ -38,7 +38,7 @@ module Mongoid
|
|
38
38
|
raise ArgumentError, "Field must be a string: #{field}"
|
39
39
|
end
|
40
40
|
|
41
|
-
if field
|
41
|
+
if field.start_with?('$')
|
42
42
|
raise ArgumentError, "Field cannot be an operator (i.e. begin with $): #{field}"
|
43
43
|
end
|
44
44
|
|
@@ -48,7 +48,7 @@ module Mongoid
|
|
48
48
|
if value.is_a?(Hash) && selector[field].is_a?(Hash) &&
|
49
49
|
value.keys.all? { |key|
|
50
50
|
key_s = key.to_s
|
51
|
-
key_s
|
51
|
+
key_s.start_with?('$') && !selector[field].key?(key_s)
|
52
52
|
}
|
53
53
|
then
|
54
54
|
# Multiple operators can be combined on the same field by
|
@@ -185,7 +185,7 @@ module Mongoid
|
|
185
185
|
raise ArgumentError, "Operator must be a string: #{operator}"
|
186
186
|
end
|
187
187
|
|
188
|
-
unless operator
|
188
|
+
unless operator.start_with?('$')
|
189
189
|
raise ArgumentError, "Operator must begin with $: #{operator}"
|
190
190
|
end
|
191
191
|
|
@@ -220,7 +220,7 @@ module Mongoid
|
|
220
220
|
raise ArgumentError, "Field must be a string: #{field}"
|
221
221
|
end
|
222
222
|
|
223
|
-
if field
|
223
|
+
if field.start_with?('$')
|
224
224
|
add_operator_expression(field, value)
|
225
225
|
else
|
226
226
|
add_field_expression(field, value)
|
data/lib/mongoid/document.rb
CHANGED
@@ -194,8 +194,8 @@ module Mongoid
|
|
194
194
|
#
|
195
195
|
# @param [ Hash ] options The options.
|
196
196
|
#
|
197
|
-
# @option options [ true, false ] :compact Whether to include fields
|
198
|
-
# nil values in the json document.
|
197
|
+
# @option options [ true, false ] :compact (Deprecated) Whether to include fields
|
198
|
+
# with nil values in the json document.
|
199
199
|
#
|
200
200
|
# @return [ Hash ] The document as json.
|
201
201
|
#
|
@@ -203,6 +203,7 @@ module Mongoid
|
|
203
203
|
def as_json(options = nil)
|
204
204
|
rv = super
|
205
205
|
if options && options[:compact]
|
206
|
+
Mongoid.logger.warn('#as_json :compact option is deprecated. Please call #compact on the returned Hash object instead.')
|
206
207
|
rv = rv.compact
|
207
208
|
end
|
208
209
|
rv
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Mongoid
|
5
|
+
module Errors
|
6
|
+
|
7
|
+
# This error is raised when an empty configuration file is attempted to be
|
8
|
+
# loaded.
|
9
|
+
class EmptyConfigFile < MongoidError
|
10
|
+
|
11
|
+
# Create the new error.
|
12
|
+
#
|
13
|
+
# @param [ String ] path The path of the config file used.
|
14
|
+
#
|
15
|
+
# @api private
|
16
|
+
def initialize(path)
|
17
|
+
super(
|
18
|
+
compose_message(
|
19
|
+
"empty_config_file",
|
20
|
+
{ path: path }
|
21
|
+
)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Mongoid
|
5
|
+
module Errors
|
6
|
+
|
7
|
+
# This error is raised when a bad configuration file is attempted to be
|
8
|
+
# loaded.
|
9
|
+
class InvalidConfigFile < MongoidError
|
10
|
+
|
11
|
+
# Create the new error.
|
12
|
+
#
|
13
|
+
# @param [ String ] path The path of the config file used.
|
14
|
+
#
|
15
|
+
# @api private
|
16
|
+
def initialize(path)
|
17
|
+
super(
|
18
|
+
compose_message(
|
19
|
+
"invalid_config_file",
|
20
|
+
{ path: path }
|
21
|
+
)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/mongoid/errors.rb
CHANGED
@@ -8,8 +8,10 @@ require "mongoid/errors/criteria_argument_required"
|
|
8
8
|
require "mongoid/errors/document_not_destroyed"
|
9
9
|
require "mongoid/errors/document_not_found"
|
10
10
|
require "mongoid/errors/eager_load"
|
11
|
+
require "mongoid/errors/empty_config_file"
|
11
12
|
require "mongoid/errors/in_memory_collation_not_supported"
|
12
13
|
require "mongoid/errors/invalid_collection"
|
14
|
+
require "mongoid/errors/invalid_config_file"
|
13
15
|
require "mongoid/errors/invalid_config_option"
|
14
16
|
require "mongoid/errors/invalid_dependent_strategy"
|
15
17
|
require "mongoid/errors/invalid_field"
|
@@ -237,7 +237,9 @@ module Mongoid
|
|
237
237
|
# @since 6.0.0
|
238
238
|
def clear(object, cluster = nil, original_context = nil)
|
239
239
|
if context = get(object)
|
240
|
-
|
240
|
+
unless cluster.nil? || context.cluster.equal?(cluster)
|
241
|
+
context.client.close
|
242
|
+
end
|
241
243
|
end
|
242
244
|
ensure
|
243
245
|
Thread.current["[mongoid][#{object.object_id}]:context"] = original_context
|
@@ -123,7 +123,7 @@ module Mongoid
|
|
123
123
|
next if model.shard_config.nil?
|
124
124
|
|
125
125
|
if model.embedded? && !model.cyclic?
|
126
|
-
logger.warn("MONGOID: #{model} has shard config but is
|
126
|
+
logger.warn("MONGOID: #{model} has shard config but is embedded")
|
127
127
|
next
|
128
128
|
end
|
129
129
|
|
data/lib/mongoid/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
# This class is used for embedded matcher testing.
|
5
|
+
class Mop
|
6
|
+
include Mongoid::Document
|
7
|
+
|
8
|
+
# The dynamic attributes are used so that the tests can use various
|
9
|
+
# field names as makes sense for the particular operator.
|
10
|
+
include Mongoid::Attributes::Dynamic
|
11
|
+
|
12
|
+
# We need some fields of specific types because the query conditions are
|
13
|
+
# transformed differently based on the type of field being queried.
|
14
|
+
field :int_field, type: Integer
|
15
|
+
field :array_field, type: Array
|
16
|
+
field :date_field, type: Date
|
17
|
+
field :time_field, type: Time
|
18
|
+
field :datetime_field, type: DateTime
|
19
|
+
field :big_decimal_field, type: BigDecimal
|
20
|
+
field :decimal128_field, type: BSON::Decimal128
|
21
|
+
field :symbol_field, type: Symbol
|
22
|
+
field :bson_symbol_field, type: BSON::Symbol::Raw
|
23
|
+
field :regexp_field, type: Regexp
|
24
|
+
field :bson_regexp_field, type: BSON::Regexp::Raw
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe 'Contextual classes when dealing with empty result set' do
|
7
|
+
shared_examples 'behave as expected' do
|
8
|
+
context '#exists?' do
|
9
|
+
it 'is false' do
|
10
|
+
context.exists?.should be false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context '#count' do
|
15
|
+
it 'is 0' do
|
16
|
+
context.count.should == 0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context '#length' do
|
21
|
+
it 'is 0' do
|
22
|
+
context.length.should == 0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# #estimated_count only exists for Mongo
|
27
|
+
|
28
|
+
context '#distinct' do
|
29
|
+
it 'is empty array' do
|
30
|
+
context.distinct(:foo).should == []
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context '#each' do
|
35
|
+
context 'with block' do
|
36
|
+
it 'does not invoke the block' do
|
37
|
+
called = false
|
38
|
+
context.each do
|
39
|
+
called = true
|
40
|
+
end
|
41
|
+
called.should be false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'without block' do
|
46
|
+
it 'returns Enumerable' do
|
47
|
+
context.each.should be_a(Enumerable)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns empty Enumerable' do
|
51
|
+
context.each.to_a.should == []
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context '#map' do
|
57
|
+
context 'with block' do
|
58
|
+
it 'does not invoke the block' do
|
59
|
+
called = false
|
60
|
+
context.map do
|
61
|
+
called = true
|
62
|
+
end
|
63
|
+
called.should be false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'without block' do
|
68
|
+
it 'returns empty array' do
|
69
|
+
skip 'MONGOID-5148'
|
70
|
+
|
71
|
+
context.map(:field).should == []
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context '#first' do
|
77
|
+
it 'is nil' do
|
78
|
+
context.first.should be nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context '#find_first' do
|
83
|
+
it 'is nil' do
|
84
|
+
context.find_first.should be nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context '#one' do
|
89
|
+
it 'is nil' do
|
90
|
+
context.one.should be nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context '#last' do
|
95
|
+
it 'is nil' do
|
96
|
+
context.last.should be nil
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
let(:context) do
|
102
|
+
context_cls.new(criteria)
|
103
|
+
end
|
104
|
+
|
105
|
+
before do
|
106
|
+
# Create an object of the same class used in the Criteria instance
|
107
|
+
# to verify we are using the Contextual classes.
|
108
|
+
Mop.create!
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'Mongo' do
|
112
|
+
let(:context_cls) { Mongoid::Contextual::Mongo }
|
113
|
+
|
114
|
+
let(:criteria) do
|
115
|
+
Mop.and(Mop.where(a: 1), Mop.where(a: 2))
|
116
|
+
end
|
117
|
+
|
118
|
+
include_examples 'behave as expected'
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'Memory' do
|
122
|
+
let(:context_cls) { Mongoid::Contextual::Memory }
|
123
|
+
|
124
|
+
let(:criteria) do
|
125
|
+
Mop.all.tap do |criteria|
|
126
|
+
criteria.documents = []
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
include_examples 'behave as expected'
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'None' do
|
134
|
+
let(:context_cls) { Mongoid::Contextual::None }
|
135
|
+
|
136
|
+
let(:criteria) do
|
137
|
+
Mop.none
|
138
|
+
end
|
139
|
+
|
140
|
+
include_examples 'behave as expected'
|
141
|
+
end
|
142
|
+
end
|
@@ -65,6 +65,17 @@ describe Mongoid::Clients::Factory do
|
|
65
65
|
expect(client).to be_a(Mongo::Client)
|
66
66
|
end
|
67
67
|
|
68
|
+
context 'not JRuby' do
|
69
|
+
# Run this test on JRuby when driver 2.16.0 is released -
|
70
|
+
# see RUBY-2771.
|
71
|
+
fails_on_jruby
|
72
|
+
|
73
|
+
it 'does not produce driver warnings' do
|
74
|
+
Mongo::Logger.logger.should_not receive(:warn)
|
75
|
+
client
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
68
79
|
let(:cluster_addresses) do
|
69
80
|
cluster.addresses.map(&:to_s)
|
70
81
|
end
|