mongoid 6.0.3 → 6.1.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +3 -2
  4. data/lib/config/locales/en.yml +15 -0
  5. data/lib/mongoid.rb +5 -0
  6. data/lib/mongoid/clients.rb +10 -2
  7. data/lib/mongoid/clients/factory.rb +2 -0
  8. data/lib/mongoid/config.rb +1 -0
  9. data/lib/mongoid/contextual/map_reduce.rb +20 -115
  10. data/lib/mongoid/contextual/memory.rb +1 -0
  11. data/lib/mongoid/contextual/mongo.rb +16 -13
  12. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
  13. data/lib/mongoid/criteria/queryable/optional.rb +14 -0
  14. data/lib/mongoid/errors.rb +1 -0
  15. data/lib/mongoid/errors/in_memory_collation_not_supported.rb +20 -0
  16. data/lib/mongoid/errors/mongoid_error.rb +1 -1
  17. data/lib/mongoid/extensions.rb +1 -0
  18. data/lib/mongoid/extensions/decimal128.rb +39 -0
  19. data/lib/mongoid/indexable/validators/options.rb +2 -1
  20. data/lib/mongoid/persistable/deletable.rb +3 -7
  21. data/lib/mongoid/query_cache.rb +2 -2
  22. data/lib/mongoid/relations/metadata.rb +3 -3
  23. data/lib/mongoid/relations/referenced/many.rb +2 -2
  24. data/lib/mongoid/version.rb +1 -1
  25. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +4 -0
  26. data/spec/app/models/band.rb +1 -0
  27. data/spec/config/mongoid.yml +19 -0
  28. data/spec/mongoid/clients/factory_spec.rb +8 -0
  29. data/spec/mongoid/clients_spec.rb +69 -0
  30. data/spec/mongoid/config_spec.rb +34 -2
  31. data/spec/mongoid/contextual/atomic_spec.rb +342 -76
  32. data/spec/mongoid/contextual/map_reduce_spec.rb +102 -135
  33. data/spec/mongoid/contextual/memory_spec.rb +316 -56
  34. data/spec/mongoid/contextual/mongo_spec.rb +366 -4
  35. data/spec/mongoid/criteria/queryable/optional_spec.rb +13 -0
  36. data/spec/mongoid/criteria_spec.rb +19 -0
  37. data/spec/mongoid/extensions/boolean_spec.rb +14 -0
  38. data/spec/mongoid/extensions/decimal128_spec.rb +44 -0
  39. data/spec/mongoid/indexable_spec.rb +43 -0
  40. data/spec/mongoid/query_cache_spec.rb +34 -0
  41. data/spec/mongoid/relations/metadata_spec.rb +0 -1
  42. data/spec/mongoid/relations/referenced/many_spec.rb +11 -0
  43. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +11 -0
  44. data/spec/mongoid/scopable_spec.rb +12 -0
  45. data/spec/spec_helper.rb +9 -0
  46. metadata +17 -7
  47. metadata.gz.sig +0 -0
@@ -3477,6 +3477,25 @@ describe Mongoid::Criteria do
3477
3477
  end
3478
3478
  end
3479
3479
 
3480
+ context "when querying on a BSON::Decimal128", if: decimal128_supported? do
3481
+
3482
+ let(:decimal) do
3483
+ BSON::Decimal128.new("0.0005")
3484
+ end
3485
+
3486
+ let!(:band) do
3487
+ Band.create(name: "Boards of Canada", decimal: decimal)
3488
+ end
3489
+
3490
+ let(:from_db) do
3491
+ Band.where(decimal: decimal).first
3492
+ end
3493
+
3494
+ it "finds the document by the big decimal value" do
3495
+ expect(from_db).to eq(band)
3496
+ end
3497
+ end
3498
+
3480
3499
  context 'when querying on a polymorphic relation' do
3481
3500
 
3482
3501
  let(:movie) do
@@ -82,6 +82,13 @@ describe Mongoid::Boolean do
82
82
  end
83
83
  end
84
84
 
85
+ context "when provided on" do
86
+
87
+ it "returns true" do
88
+ expect(described_class.mongoize("on")).to eq(true)
89
+ end
90
+ end
91
+
85
92
  context "when provided false" do
86
93
 
87
94
  it "returns false" do
@@ -123,6 +130,13 @@ describe Mongoid::Boolean do
123
130
  expect(described_class.mongoize("n")).to eq(false)
124
131
  end
125
132
  end
133
+
134
+ context "when provided off" do
135
+
136
+ it "returns true" do
137
+ expect(described_class.mongoize("off")).to eq(false)
138
+ end
139
+ end
126
140
  end
127
141
  end
128
142
 
@@ -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
@@ -122,6 +122,34 @@ describe Mongoid::Indexable do
122
122
  expect(indexes.get(_type: 1)).to_not be_nil
123
123
  end
124
124
  end
125
+
126
+ context "when a collation option is specified", if: collation_supported? do
127
+
128
+ let(:klass) do
129
+ Class.new do
130
+ include Mongoid::Document
131
+ store_in collection: "test_db_indexes"
132
+ index({ name: 1 }, { collation: { locale: 'en_US', strength: 2 }})
133
+ end
134
+ end
135
+
136
+ before do
137
+ klass.create_indexes
138
+ end
139
+
140
+ after do
141
+ klass.remove_indexes
142
+ end
143
+
144
+ let(:indexes) do
145
+ klass.collection.indexes
146
+ end
147
+
148
+ it "creates the indexes" do
149
+ expect(indexes.get("name_1")["collation"]).to_not be_nil
150
+ expect(indexes.get("name_1")["collation"]["locale"]).to eq('en_US')
151
+ end
152
+ end
125
153
  end
126
154
 
127
155
  describe ".add_indexes" do
@@ -270,6 +298,21 @@ describe Mongoid::Indexable do
270
298
  end
271
299
  end
272
300
 
301
+ context "when providing a collation option", if: collation_supported? do
302
+
303
+ before do
304
+ klass.index({ name: 1 }, collation: { locale: 'en_US', strength: 2 })
305
+ end
306
+
307
+ let(:options) do
308
+ klass.index_specification(name: 1).options
309
+ end
310
+
311
+ it "sets the index with a collation option" do
312
+ expect(options).to eq(collation: { locale: 'en_US', strength: 2 })
313
+ end
314
+ end
315
+
273
316
  context "when providing a compound index" do
274
317
 
275
318
  before do
@@ -164,6 +164,40 @@ describe Mongoid::QueryCache do
164
164
  end
165
165
  end
166
166
 
167
+ context 'when the first query has a collation', if: collation_supported? do
168
+
169
+ before do
170
+ Band.where(name: 'DEPECHE MODE').collation(locale: 'en_US', strength: 2).to_a
171
+ end
172
+
173
+ context "when the next query has the same collation" do
174
+
175
+ it "uses the cache" do
176
+ expect_no_queries do
177
+ Band.where(name: 'DEPECHE MODE').collation(locale: 'en_US', strength: 2).to_a
178
+ end
179
+ end
180
+ end
181
+
182
+ context "when the next query does not have the same collation" do
183
+
184
+ it "queries again" do
185
+ expect_query(1) do
186
+ Band.where(name: 'DEPECHE MODE').collation(locale: 'fr', strength: 2).to_a
187
+ end
188
+ end
189
+ end
190
+
191
+ context "when the next query does not have a collation" do
192
+
193
+ it "queries again" do
194
+ expect_query(1) do
195
+ Band.where(name: 'DEPECHE MODE').to_a
196
+ end
197
+ end
198
+ end
199
+ end
200
+
167
201
  context "when the first query has no limit" do
168
202
 
169
203
  let(:game) do
@@ -1982,5 +1982,4 @@ describe Mongoid::Relations::Metadata do
1982
1982
  end
1983
1983
  end
1984
1984
  end
1985
-
1986
1985
  end
@@ -2934,6 +2934,17 @@ describe Mongoid::Relations::Referenced::Many do
2934
2934
  it "applies the criteria to the documents" do
2935
2935
  expect(posts).to eq([ post_one ])
2936
2936
  end
2937
+
2938
+ context 'when providing a collation', if: collation_supported? do
2939
+
2940
+ let(:posts) do
2941
+ person.posts.where(title: "FIRST").collation(locale: 'en_US', strength: 2)
2942
+ end
2943
+
2944
+ it "applies the collation option to the query" do
2945
+ expect(posts).to eq([ post_one ])
2946
+ end
2947
+ end
2937
2948
  end
2938
2949
 
2939
2950
  context "when providing a criteria class method" do
@@ -2640,6 +2640,17 @@ describe Mongoid::Relations::Referenced::ManyToMany do
2640
2640
  it "applies the criteria to the documents" do
2641
2641
  expect(preferences).to eq([ preference_one ])
2642
2642
  end
2643
+
2644
+ context 'when providing a collation', if: collation_supported? do
2645
+
2646
+ let(:preferences) do
2647
+ person.preferences.where(name: "FIRST").collation(locale: 'en_US', strength: 2).to_a
2648
+ end
2649
+
2650
+ it "applies the collation option to the query" do
2651
+ expect(preferences).to eq([ preference_one ])
2652
+ end
2653
+ end
2643
2654
  end
2644
2655
 
2645
2656
  context "when providing a criteria on id" 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
@@ -74,6 +74,15 @@ def non_legacy_server?
74
74
  Mongoid::Clients.default.cluster.servers.first.features.write_command_enabled?
75
75
  end
76
76
 
77
+ def testing_replica_set?
78
+ Mongoid::Clients.default.cluster.replica_set?
79
+ end
80
+
81
+ def collation_supported?
82
+ Mongoid::Clients.default.cluster.next_primary.features.collation_enabled?
83
+ end
84
+ alias :decimal128_supported? :collation_supported?
85
+
77
86
  def testing_locally?
78
87
  !(ENV['CI'] == 'travis')
79
88
  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: 6.0.3
4
+ version: 6.1.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-02 00:00:00.000000000 Z
33
+ date: 2016-12-22 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: activemodel
@@ -50,16 +50,22 @@ dependencies:
50
50
  name: mongo
51
51
  requirement: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.4.1
56
+ - - "<"
54
57
  - !ruby/object:Gem::Version
55
- version: '2.3'
58
+ version: 3.0.0
56
59
  type: :runtime
57
60
  prerelease: false
58
61
  version_requirements: !ruby/object:Gem::Requirement
59
62
  requirements:
60
- - - "~>"
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.4.1
66
+ - - "<"
61
67
  - !ruby/object:Gem::Version
62
- version: '2.3'
68
+ version: 3.0.0
63
69
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
64
70
  in Ruby.
65
71
  email:
@@ -160,6 +166,7 @@ files:
160
166
  - lib/mongoid/errors/document_not_destroyed.rb
161
167
  - lib/mongoid/errors/document_not_found.rb
162
168
  - lib/mongoid/errors/eager_load.rb
169
+ - lib/mongoid/errors/in_memory_collation_not_supported.rb
163
170
  - lib/mongoid/errors/invalid_collection.rb
164
171
  - lib/mongoid/errors/invalid_config_option.rb
165
172
  - lib/mongoid/errors/invalid_field.rb
@@ -206,6 +213,7 @@ files:
206
213
  - lib/mongoid/extensions/boolean.rb
207
214
  - lib/mongoid/extensions/date.rb
208
215
  - lib/mongoid/extensions/date_time.rb
216
+ - lib/mongoid/extensions/decimal128.rb
209
217
  - lib/mongoid/extensions/false_class.rb
210
218
  - lib/mongoid/extensions/float.rb
211
219
  - lib/mongoid/extensions/hash.rb
@@ -690,6 +698,7 @@ files:
690
698
  - spec/mongoid/extensions/boolean_spec.rb
691
699
  - spec/mongoid/extensions/date_spec.rb
692
700
  - spec/mongoid/extensions/date_time_spec.rb
701
+ - spec/mongoid/extensions/decimal128_spec.rb
693
702
  - spec/mongoid/extensions/false_class_spec.rb
694
703
  - spec/mongoid/extensions/float_spec.rb
695
704
  - spec/mongoid/extensions/hash_spec.rb
@@ -853,7 +862,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
853
862
  version: 1.3.6
854
863
  requirements: []
855
864
  rubyforge_project: mongoid
856
- rubygems_version: 2.5.2
865
+ rubygems_version: 2.6.8
857
866
  signing_key:
858
867
  specification_version: 4
859
868
  summary: Elegant Persistence in Ruby for MongoDB.
@@ -1181,6 +1190,7 @@ test_files:
1181
1190
  - spec/mongoid/extensions/boolean_spec.rb
1182
1191
  - spec/mongoid/extensions/date_spec.rb
1183
1192
  - spec/mongoid/extensions/date_time_spec.rb
1193
+ - spec/mongoid/extensions/decimal128_spec.rb
1184
1194
  - spec/mongoid/extensions/false_class_spec.rb
1185
1195
  - spec/mongoid/extensions/float_spec.rb
1186
1196
  - spec/mongoid/extensions/hash_spec.rb
metadata.gz.sig CHANGED
Binary file