mongoid 5.1.6 → 5.2.0.rc0
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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/config/locales/en.yml +15 -0
- data/lib/mongoid.rb +5 -0
- data/lib/mongoid/clients/factory.rb +2 -0
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/map_reduce.rb +20 -97
- data/lib/mongoid/contextual/memory.rb +1 -0
- data/lib/mongoid/contextual/mongo.rb +15 -13
- data/lib/mongoid/errors.rb +1 -0
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +20 -0
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/extensions.rb +1 -0
- data/lib/mongoid/extensions/decimal128.rb +39 -0
- data/lib/mongoid/indexable/validators/options.rb +2 -1
- data/lib/mongoid/persistable/deletable.rb +3 -7
- data/lib/mongoid/query_cache.rb +2 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +4 -0
- data/spec/app/models/band.rb +1 -0
- data/spec/config/mongoid.yml +5 -0
- data/spec/mongoid/clients/factory_spec.rb +8 -0
- data/spec/mongoid/clients_spec.rb +78 -1
- data/spec/mongoid/config_spec.rb +31 -0
- data/spec/mongoid/contextual/atomic_spec.rb +342 -76
- data/spec/mongoid/contextual/map_reduce_spec.rb +102 -135
- data/spec/mongoid/contextual/memory_spec.rb +316 -56
- data/spec/mongoid/contextual/mongo_spec.rb +367 -5
- data/spec/mongoid/criteria_spec.rb +19 -0
- data/spec/mongoid/extensions/decimal128_spec.rb +44 -0
- data/spec/mongoid/indexable_spec.rb +43 -0
- data/spec/mongoid/query_cache_spec.rb +34 -0
- data/spec/mongoid/relations/referenced/many_spec.rb +11 -0
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +11 -0
- data/spec/mongoid/scopable_spec.rb +12 -0
- data/spec/spec_helper.rb +9 -0
- metadata +19 -9
- metadata.gz.sig +0 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Extensions::Decimal128 do
|
4
|
+
|
5
|
+
let(:decimal128) do
|
6
|
+
BSON::Decimal128.new("0.0005")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#__evolve_decimal128__" do
|
10
|
+
|
11
|
+
it "returns the same instance" do
|
12
|
+
expect(decimal128.__evolve_decimal128__).to be(decimal128)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".evolve" do
|
17
|
+
|
18
|
+
context "when provided a single decimal128" do
|
19
|
+
|
20
|
+
let(:evolved) do
|
21
|
+
BSON::Decimal128.evolve(decimal128)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns the decimal128" do
|
25
|
+
expect(evolved).to be(decimal128)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when provided an array of decimal128s" do
|
30
|
+
|
31
|
+
let(:other_decimal128) do
|
32
|
+
BSON::Decimal128.new("3.14")
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:evolved) do
|
36
|
+
BSON::ObjectId.evolve([decimal128, other_decimal128])
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns the array of decimal128s" do
|
40
|
+
expect(evolved).to eq([decimal128, other_decimal128])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -114,6 +114,34 @@ describe Mongoid::Indexable do
|
|
114
114
|
expect(indexes.get(_type: 1)).to_not be_nil
|
115
115
|
end
|
116
116
|
end
|
117
|
+
|
118
|
+
context "when a collation option is specified", if: collation_supported? do
|
119
|
+
|
120
|
+
let(:klass) do
|
121
|
+
Class.new do
|
122
|
+
include Mongoid::Document
|
123
|
+
store_in collection: "test_db_indexes"
|
124
|
+
index({name: 1}, {collation: {locale: 'en_US', strength: 2}})
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
before do
|
129
|
+
klass.create_indexes
|
130
|
+
end
|
131
|
+
|
132
|
+
after do
|
133
|
+
klass.remove_indexes
|
134
|
+
end
|
135
|
+
|
136
|
+
let(:indexes) do
|
137
|
+
klass.collection.indexes
|
138
|
+
end
|
139
|
+
|
140
|
+
it "creates the indexes" do
|
141
|
+
expect(indexes.get("name_1")["collation"]).to_not be_nil
|
142
|
+
expect(indexes.get("name_1")["collation"]["locale"]).to eq('en_US')
|
143
|
+
end
|
144
|
+
end
|
117
145
|
end
|
118
146
|
|
119
147
|
describe ".add_indexes" do
|
@@ -258,6 +286,21 @@ describe Mongoid::Indexable do
|
|
258
286
|
end
|
259
287
|
end
|
260
288
|
|
289
|
+
context "when providing a collation option", if: collation_supported? do
|
290
|
+
|
291
|
+
before do
|
292
|
+
klass.index({ name: 1 }, collation: { locale: 'en_US', strength: 2 })
|
293
|
+
end
|
294
|
+
|
295
|
+
let(:options) do
|
296
|
+
klass.index_specification(name: 1).options
|
297
|
+
end
|
298
|
+
|
299
|
+
it "sets the index with a collation option" do
|
300
|
+
expect(options).to eq(collation: { locale: 'en_US', strength: 2 })
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
261
304
|
context "when providing a compound index" do
|
262
305
|
|
263
306
|
before do
|
@@ -75,6 +75,40 @@ describe Mongoid::QueryCache do
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
context 'when the first query has a collation', if: collation_supported? do
|
79
|
+
|
80
|
+
before do
|
81
|
+
Band.where(name: 'DEPECHE MODE').collation(locale: 'en_US', strength: 2).to_a
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when the next query has the same collation" do
|
85
|
+
|
86
|
+
it "uses the cache" do
|
87
|
+
expect_no_queries do
|
88
|
+
Band.where(name: 'DEPECHE MODE').collation(locale: 'en_US', strength: 2).to_a
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "when the next query does not have the same collation" do
|
94
|
+
|
95
|
+
it "queries again" do
|
96
|
+
expect_query(1) do
|
97
|
+
Band.where(name: 'DEPECHE MODE').collation(locale: 'fr', strength: 2).to_a
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "when the next query does not have a collation" do
|
103
|
+
|
104
|
+
it "queries again" do
|
105
|
+
expect_query(1) do
|
106
|
+
Band.where(name: 'DEPECHE MODE').to_a
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
78
112
|
context "when the first query has no limit" do
|
79
113
|
|
80
114
|
let(:game) do
|
@@ -2936,6 +2936,17 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2936
2936
|
end
|
2937
2937
|
end
|
2938
2938
|
|
2939
|
+
context 'when providing a collation', if: collation_supported? do
|
2940
|
+
|
2941
|
+
let(:posts) do
|
2942
|
+
person.posts.where(title: "FIRST").collation(locale: 'en_US', strength: 2)
|
2943
|
+
end
|
2944
|
+
|
2945
|
+
it "applies the collation option to the query" do
|
2946
|
+
expect(posts).to eq([ post_one ])
|
2947
|
+
end
|
2948
|
+
end
|
2949
|
+
|
2939
2950
|
context "when providing a criteria class method" do
|
2940
2951
|
|
2941
2952
|
let(:posts) do
|
@@ -2654,6 +2654,17 @@ describe Mongoid::Relations::Referenced::ManyToMany do
|
|
2654
2654
|
end
|
2655
2655
|
end
|
2656
2656
|
|
2657
|
+
context 'when providing a collation', if: collation_supported? do
|
2658
|
+
|
2659
|
+
let(:preferences) do
|
2660
|
+
person.preferences.where(name: "FIRST").collation(locale: 'en_US', strength: 2).to_a
|
2661
|
+
end
|
2662
|
+
|
2663
|
+
it "applies the collation option to the query" do
|
2664
|
+
expect(preferences).to eq([ preference_one ])
|
2665
|
+
end
|
2666
|
+
end
|
2667
|
+
|
2657
2668
|
context "when providing a criteria on id" do
|
2658
2669
|
|
2659
2670
|
let(:preferences) do
|
@@ -227,6 +227,18 @@ describe Mongoid::Scopable do
|
|
227
227
|
|
228
228
|
context "when provided a criteria" do
|
229
229
|
|
230
|
+
context 'when a collation is defined on the criteria', if: collation_supported? do
|
231
|
+
|
232
|
+
before do
|
233
|
+
Band.scope(:tests, ->{ Band.where(name: 'TESTING').collation(locale: 'en_US', strength: 2) })
|
234
|
+
Band.create(name: 'testing')
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'applies the collation' do
|
238
|
+
expect(Band.tests.first['name']).to eq('testing')
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
230
242
|
context "when the lambda includes a geo_near query" do
|
231
243
|
|
232
244
|
before do
|
data/spec/spec_helper.rb
CHANGED
@@ -75,11 +75,20 @@ def testing_locally?
|
|
75
75
|
!(ENV['CI'] == 'travis')
|
76
76
|
end
|
77
77
|
|
78
|
+
def testing_replica_set?
|
79
|
+
Mongoid::Clients.default.cluster.replica_set?
|
80
|
+
end
|
81
|
+
|
78
82
|
# Set the database that the spec suite connects to.
|
79
83
|
Mongoid.configure do |config|
|
80
84
|
config.load_configuration(CONFIG)
|
81
85
|
end
|
82
86
|
|
87
|
+
def collation_supported?
|
88
|
+
Mongoid::Clients.default.cluster.next_primary.features.collation_enabled?
|
89
|
+
end
|
90
|
+
alias :decimal128_supported? :collation_supported?
|
91
|
+
|
83
92
|
# Autoload every model for the test suite that sits in spec/app/models.
|
84
93
|
Dir[ File.join(MODELS, "*.rb") ].sort.each do |file|
|
85
94
|
name = File.basename(file, ".rb")
|
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.
|
4
|
+
version: 5.2.0.rc0
|
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-
|
33
|
+
date: 2016-12-22 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: activemodel
|
@@ -64,30 +64,36 @@ dependencies:
|
|
64
64
|
name: mongo
|
65
65
|
requirement: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - "
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.4.1
|
70
|
+
- - "<"
|
68
71
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
72
|
+
version: 3.0.0
|
70
73
|
type: :runtime
|
71
74
|
prerelease: false
|
72
75
|
version_requirements: !ruby/object:Gem::Requirement
|
73
76
|
requirements:
|
74
|
-
- - "
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 2.4.1
|
80
|
+
- - "<"
|
75
81
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
82
|
+
version: 3.0.0
|
77
83
|
- !ruby/object:Gem::Dependency
|
78
84
|
name: origin
|
79
85
|
requirement: !ruby/object:Gem::Requirement
|
80
86
|
requirements:
|
81
87
|
- - "~>"
|
82
88
|
- !ruby/object:Gem::Version
|
83
|
-
version: '2.
|
89
|
+
version: '2.3'
|
84
90
|
type: :runtime
|
85
91
|
prerelease: false
|
86
92
|
version_requirements: !ruby/object:Gem::Requirement
|
87
93
|
requirements:
|
88
94
|
- - "~>"
|
89
95
|
- !ruby/object:Gem::Version
|
90
|
-
version: '2.
|
96
|
+
version: '2.3'
|
91
97
|
description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
|
92
98
|
in Ruby.
|
93
99
|
email:
|
@@ -158,6 +164,7 @@ files:
|
|
158
164
|
- lib/mongoid/errors/document_not_destroyed.rb
|
159
165
|
- lib/mongoid/errors/document_not_found.rb
|
160
166
|
- lib/mongoid/errors/eager_load.rb
|
167
|
+
- lib/mongoid/errors/in_memory_collation_not_supported.rb
|
161
168
|
- lib/mongoid/errors/invalid_collection.rb
|
162
169
|
- lib/mongoid/errors/invalid_config_option.rb
|
163
170
|
- lib/mongoid/errors/invalid_field.rb
|
@@ -202,6 +209,7 @@ files:
|
|
202
209
|
- lib/mongoid/extensions/boolean.rb
|
203
210
|
- lib/mongoid/extensions/date.rb
|
204
211
|
- lib/mongoid/extensions/date_time.rb
|
212
|
+
- lib/mongoid/extensions/decimal128.rb
|
205
213
|
- lib/mongoid/extensions/false_class.rb
|
206
214
|
- lib/mongoid/extensions/float.rb
|
207
215
|
- lib/mongoid/extensions/hash.rb
|
@@ -651,6 +659,7 @@ files:
|
|
651
659
|
- spec/mongoid/extensions/boolean_spec.rb
|
652
660
|
- spec/mongoid/extensions/date_spec.rb
|
653
661
|
- spec/mongoid/extensions/date_time_spec.rb
|
662
|
+
- spec/mongoid/extensions/decimal128_spec.rb
|
654
663
|
- spec/mongoid/extensions/false_class_spec.rb
|
655
664
|
- spec/mongoid/extensions/float_spec.rb
|
656
665
|
- spec/mongoid/extensions/hash_spec.rb
|
@@ -812,7 +821,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
812
821
|
version: 1.3.6
|
813
822
|
requirements: []
|
814
823
|
rubyforge_project: mongoid
|
815
|
-
rubygems_version: 2.
|
824
|
+
rubygems_version: 2.6.8
|
816
825
|
signing_key:
|
817
826
|
specification_version: 4
|
818
827
|
summary: Elegant Persistence in Ruby for MongoDB.
|
@@ -1107,6 +1116,7 @@ test_files:
|
|
1107
1116
|
- spec/mongoid/extensions/boolean_spec.rb
|
1108
1117
|
- spec/mongoid/extensions/date_spec.rb
|
1109
1118
|
- spec/mongoid/extensions/date_time_spec.rb
|
1119
|
+
- spec/mongoid/extensions/decimal128_spec.rb
|
1110
1120
|
- spec/mongoid/extensions/false_class_spec.rb
|
1111
1121
|
- spec/mongoid/extensions/float_spec.rb
|
1112
1122
|
- spec/mongoid/extensions/hash_spec.rb
|
metadata.gz.sig
CHANGED
Binary file
|