mongoid 6.3.0 → 6.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/config/locales/en.yml +21 -0
  5. data/lib/mongoid.rb +1 -1
  6. data/lib/mongoid/clients.rb +2 -0
  7. data/lib/mongoid/clients/sessions.rb +113 -0
  8. data/lib/mongoid/clients/storage_options.rb +1 -0
  9. data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
  10. data/lib/mongoid/contextual/map_reduce.rb +6 -2
  11. data/lib/mongoid/contextual/memory.rb +7 -2
  12. data/lib/mongoid/contextual/mongo.rb +11 -2
  13. data/lib/mongoid/criteria.rb +1 -0
  14. data/lib/mongoid/criteria/queryable/mergeable.rb +3 -1
  15. data/lib/mongoid/errors.rb +1 -0
  16. data/lib/mongoid/errors/invalid_session_use.rb +24 -0
  17. data/lib/mongoid/indexable.rb +4 -4
  18. data/lib/mongoid/persistable.rb +1 -1
  19. data/lib/mongoid/persistable/creatable.rb +4 -2
  20. data/lib/mongoid/persistable/deletable.rb +4 -2
  21. data/lib/mongoid/persistable/destroyable.rb +1 -5
  22. data/lib/mongoid/persistable/updatable.rb +2 -2
  23. data/lib/mongoid/persistable/upsertable.rb +2 -1
  24. data/lib/mongoid/relations/embedded/batchable.rb +10 -4
  25. data/lib/mongoid/relations/many.rb +4 -0
  26. data/lib/mongoid/relations/referenced/many.rb +1 -1
  27. data/lib/mongoid/relations/touchable.rb +1 -1
  28. data/lib/mongoid/reloadable.rb +1 -1
  29. data/lib/mongoid/tasks/database.rb +3 -2
  30. data/lib/mongoid/threaded.rb +38 -0
  31. data/lib/mongoid/version.rb +1 -1
  32. data/spec/mongoid/attributes/nested_spec.rb +4 -0
  33. data/spec/mongoid/clients/sessions_spec.rb +325 -0
  34. data/spec/mongoid/contextual/mongo_spec.rb +38 -0
  35. data/spec/mongoid/criteria/queryable/selectable_spec.rb +32 -3
  36. data/spec/mongoid/interceptable_spec.rb +1 -1
  37. data/spec/mongoid/persistable/deletable_spec.rb +19 -0
  38. data/spec/mongoid/persistable/destroyable_spec.rb +19 -0
  39. data/spec/mongoid/persistable_spec.rb +16 -16
  40. data/spec/spec_helper.rb +70 -0
  41. metadata +17 -7
  42. metadata.gz.sig +0 -0
@@ -275,6 +275,23 @@ describe Mongoid::Contextual::Mongo do
275
275
  expect(Band.count).to eq(0)
276
276
  end
277
277
  end
278
+
279
+ context 'when the write concern is unacknowledged' do
280
+
281
+ let(:criteria) do
282
+ Band.all
283
+ end
284
+
285
+ let!(:deleted) do
286
+ criteria.with(write: { w: 0 }) do |crit|
287
+ crit.send(method)
288
+ end
289
+ end
290
+
291
+ it 'returns 0' do
292
+ expect(deleted).to eq(0)
293
+ end
294
+ end
278
295
  end
279
296
  end
280
297
 
@@ -363,6 +380,27 @@ describe Mongoid::Contextual::Mongo do
363
380
  end
364
381
  end
365
382
  end
383
+
384
+ context 'when the write concern is unacknowledged' do
385
+
386
+ before do
387
+ 2.times { Band.create }
388
+ end
389
+
390
+ let(:criteria) do
391
+ Band.all
392
+ end
393
+
394
+ let!(:deleted) do
395
+ criteria.with(write: { w: 0 }) do |crit|
396
+ crit.send(method)
397
+ end
398
+ end
399
+
400
+ it 'returns 0' do
401
+ expect(deleted).to eq(0)
402
+ end
403
+ end
366
404
  end
367
405
 
368
406
  describe "#distinct" do
@@ -1449,7 +1449,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
1449
1449
 
1450
1450
  context "when the criterion are on the same field" do
1451
1451
 
1452
- context "when the stretegy is the default (intersection)" do
1452
+ context "when the strategy is the default (intersection)" do
1453
1453
 
1454
1454
  let(:selection) do
1455
1455
  query.in(first: [ 1, 2 ].freeze).in(first: [ 2, 3 ])
@@ -1466,6 +1466,35 @@ describe Mongoid::Criteria::Queryable::Selectable do
1466
1466
  end
1467
1467
  end
1468
1468
 
1469
+ context 'when the field is aliased' do
1470
+
1471
+ before(:all) do
1472
+ class TestModel
1473
+ include Mongoid::Document
1474
+ end
1475
+ end
1476
+
1477
+ after(:all) do
1478
+ Object.send(:remove_const, :TestModel)
1479
+ end
1480
+
1481
+ let(:bson_object_id) do
1482
+ BSON::ObjectId.new
1483
+ end
1484
+
1485
+ let(:selection) do
1486
+ TestModel.in(id: [bson_object_id.to_s]).in(id: [bson_object_id.to_s])
1487
+ end
1488
+
1489
+ it "intersects the $in selectors" do
1490
+ expect(selection.selector).to eq("_id" => { "$in" => [ bson_object_id ] })
1491
+ end
1492
+
1493
+ it "returns a cloned query" do
1494
+ expect(selection).to_not equal(query)
1495
+ end
1496
+ end
1497
+
1469
1498
  context "when the stretegy is intersect" do
1470
1499
 
1471
1500
  let(:selection) do
@@ -1483,7 +1512,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
1483
1512
  end
1484
1513
  end
1485
1514
 
1486
- context "when the stretegy is override" do
1515
+ context "when the strategy is override" do
1487
1516
 
1488
1517
  let(:selection) do
1489
1518
  query.in(first: [ 1, 2 ]).override.in(first: [ 3, 4 ])
@@ -1500,7 +1529,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
1500
1529
  end
1501
1530
  end
1502
1531
 
1503
- context "when the stretegy is union" do
1532
+ context "when the strategy is union" do
1504
1533
 
1505
1534
  let(:selection) do
1506
1535
  query.in(first: [ 1, 2 ]).union.in(first: [ 3, 4 ])
@@ -526,7 +526,7 @@ describe Mongoid::Interceptable do
526
526
  end
527
527
 
528
528
  after(:all) do
529
- Band.reset_callbacks(:rearrange)
529
+ begin; Band.reset_callbacks(:rearrange); rescue; end
530
530
  end
531
531
 
532
532
  let(:attributes) do
@@ -228,6 +228,25 @@ describe Mongoid::Persistable::Deletable do
228
228
  expect(removed).to eq(1)
229
229
  end
230
230
  end
231
+
232
+ context 'when the write concern is unacknowledged' do
233
+
234
+ before do
235
+ Person.create(title: 'miss')
236
+ end
237
+
238
+ let!(:deleted) do
239
+ Person.with(write: { w: 0 }) { |klass| klass.delete_all(title: "sir") }
240
+ end
241
+
242
+ it "removes the matching documents" do
243
+ expect(Person.where(title: 'miss').count).to eq(1)
244
+ end
245
+
246
+ it "returns 0" do
247
+ expect(deleted).to eq(0)
248
+ end
249
+ end
231
250
  end
232
251
  end
233
252
  end
@@ -222,6 +222,25 @@ describe Mongoid::Persistable::Destroyable do
222
222
  end
223
223
  end
224
224
 
225
+ context 'when the write concern is unacknowledged' do
226
+
227
+ before do
228
+ Person.create(title: 'miss')
229
+ end
230
+
231
+ let!(:removed) do
232
+ Person.with(write: { w: 0 }) { |klass| klass.destroy_all(title: "sir") }
233
+ end
234
+
235
+ it "removes the matching documents" do
236
+ expect(Person.where(title: 'miss').count).to eq(1)
237
+ end
238
+
239
+ it "returns 0" do
240
+ expect(removed).to eq(0)
241
+ end
242
+ end
243
+
225
244
  context 'when removing a list of embedded documents' do
226
245
 
227
246
  context 'when the embedded documents list is reversed in memory' do
@@ -52,16 +52,16 @@ describe Mongoid::Persistable do
52
52
  context "when not chaining the operations" do
53
53
 
54
54
  let(:operations) do
55
- {
55
+ [{
56
56
  "$inc" => { "member_count" => 10 },
57
57
  "$bit" => { "likes" => { :and => 13 }},
58
58
  "$set" => { "name" => "Placebo" },
59
- "$unset" => { "origin" => true }
60
- }
59
+ "$unset" => { "origin" => true }},
60
+ { session: nil }]
61
61
  end
62
62
 
63
63
  before do
64
- expect_any_instance_of(Mongo::Collection::View).to receive(:update_one).with(operations).and_call_original
64
+ expect_any_instance_of(Mongo::Collection::View).to receive(:update_one).with(*operations).and_call_original
65
65
  end
66
66
 
67
67
  let!(:update) do
@@ -79,16 +79,16 @@ describe Mongoid::Persistable do
79
79
  context "when chaining the operations" do
80
80
 
81
81
  let(:operations) do
82
- {
82
+ [{
83
83
  "$inc" => { "member_count" => 10 },
84
84
  "$bit" => { "likes" => { :and => 13 }},
85
85
  "$set" => { "name" => "Placebo" },
86
- "$unset" => { "origin" => true }
87
- }
86
+ "$unset" => { "origin" => true }},
87
+ { :session => nil } ]
88
88
  end
89
89
 
90
90
  before do
91
- expect_any_instance_of(Mongo::Collection::View).to receive(:update_one).with(operations).and_call_original
91
+ expect_any_instance_of(Mongo::Collection::View).to receive(:update_one).with(*operations).and_call_original
92
92
  end
93
93
 
94
94
  let!(:update) do
@@ -107,16 +107,16 @@ describe Mongoid::Persistable do
107
107
  context "when given multiple operations of the same type" do
108
108
 
109
109
  let(:operations) do
110
- {
110
+ [{
111
111
  "$inc" => { "member_count" => 10, "other_count" => 10 },
112
112
  "$bit" => { "likes" => { :and => 13 }},
113
113
  "$set" => { "name" => "Placebo" },
114
- "$unset" => { "origin" => true }
115
- }
114
+ "$unset" => { "origin" => true }},
115
+ { session: nil }]
116
116
  end
117
117
 
118
118
  before do
119
- expect_any_instance_of(Mongo::Collection::View).to receive(:update_one).with(operations).and_call_original
119
+ expect_any_instance_of(Mongo::Collection::View).to receive(:update_one).with(*operations).and_call_original
120
120
  end
121
121
 
122
122
  let!(:update) do
@@ -144,16 +144,16 @@ describe Mongoid::Persistable do
144
144
  context "when expecting the document to be yielded" do
145
145
 
146
146
  let(:operations) do
147
- {
147
+ [{
148
148
  "$inc" => { "member_count" => 10 },
149
149
  "$bit" => { "likes" => { :and => 13 }},
150
150
  "$set" => { "name" => "Placebo" },
151
- "$unset" => { "origin" => true }
152
- }
151
+ "$unset" => { "origin" => true }},
152
+ { session: nil }]
153
153
  end
154
154
 
155
155
  before do
156
- expect_any_instance_of(Mongo::Collection::View).to receive(:update_one).with(operations).and_call_original
156
+ expect_any_instance_of(Mongo::Collection::View).to receive(:update_one).with(*operations).and_call_original
157
157
  end
158
158
 
159
159
  let!(:update) do
@@ -90,6 +90,7 @@ end
90
90
  def array_filters_supported?
91
91
  Mongoid::Clients.default.cluster.next_primary.features.array_filters_enabled?
92
92
  end
93
+ alias :sessions_supported? :array_filters_supported?
93
94
 
94
95
  # Set the database that the spec suite connects to.
95
96
  Mongoid.configure do |config|
@@ -145,3 +146,72 @@ RSpec.configure do |config|
145
146
  Mongoid.purge!
146
147
  end
147
148
  end
149
+
150
+ # A subscriber to be used with the Ruby driver for testing.
151
+ #
152
+ # @since 6.4.0
153
+ class EventSubscriber
154
+
155
+ # The started events.
156
+ #
157
+ # @since 6.4.0
158
+ attr_reader :started_events
159
+
160
+ # The succeeded events.
161
+ #
162
+ # @since 6.4.0
163
+ attr_reader :succeeded_events
164
+
165
+ # The failed events.
166
+ #
167
+ # @since 6.4.0
168
+ attr_reader :failed_events
169
+
170
+ # Create the test event subscriber.
171
+ #
172
+ # @example Create the subscriber
173
+ # EventSubscriber.new
174
+ #
175
+ # @since 6.4.0
176
+ def initialize
177
+ @started_events = []
178
+ @succeeded_events = []
179
+ @failed_events = []
180
+ end
181
+
182
+ # Cache the succeeded event.
183
+ #
184
+ # @param [ Event ] event The event.
185
+ #
186
+ # @since 6.4.0
187
+ def succeeded(event)
188
+ @succeeded_events.push(event)
189
+ end
190
+
191
+ # Cache the started event.
192
+ #
193
+ # @param [ Event ] event The event.
194
+ #
195
+ # @since 6.4.0
196
+ def started(event)
197
+ @started_events.push(event)
198
+ end
199
+
200
+ # Cache the failed event.
201
+ #
202
+ # @param [ Event ] event The event.
203
+ #
204
+ # @since 6.4.0
205
+ def failed(event)
206
+ @failed_events.push(event)
207
+ end
208
+
209
+ # Clear all cached events.
210
+ #
211
+ # @since 6.4.0
212
+ def clear_events!
213
+ @started_events = []
214
+ @succeeded_events = []
215
+ @failed_events = []
216
+ end
217
+ 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.3.0
4
+ version: 6.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -30,29 +30,35 @@ cert_chain:
30
30
  fxN/GvhskJEgmdQToxEBRLOu5/udtPpVe/hb3gk5hzsxcWuKN/VTi4SbtFQdz9cq
31
31
  fqd6ctFDOqcJmOYdlSRgb9g8zm4BiNgFWPBSk8NsP7c=
32
32
  -----END CERTIFICATE-----
33
- date: 2018-01-24 00:00:00.000000000 Z
33
+ date: 2018-03-12 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: activemodel
37
37
  requirement: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '5.1'
42
+ - - "<"
43
+ - !ruby/object:Gem::Version
44
+ version: 6.0.0
42
45
  type: :runtime
43
46
  prerelease: false
44
47
  version_requirements: !ruby/object:Gem::Requirement
45
48
  requirements:
46
- - - "~>"
49
+ - - ">="
47
50
  - !ruby/object:Gem::Version
48
51
  version: '5.1'
52
+ - - "<"
53
+ - !ruby/object:Gem::Version
54
+ version: 6.0.0
49
55
  - !ruby/object:Gem::Dependency
50
56
  name: mongo
51
57
  requirement: !ruby/object:Gem::Requirement
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
55
- version: 2.5.0
61
+ version: 2.5.1
56
62
  - - "<"
57
63
  - !ruby/object:Gem::Version
58
64
  version: 3.0.0
@@ -62,7 +68,7 @@ dependencies:
62
68
  requirements:
63
69
  - - ">="
64
70
  - !ruby/object:Gem::Version
65
- version: 2.5.0
71
+ version: 2.5.1
66
72
  - - "<"
67
73
  - !ruby/object:Gem::Version
68
74
  version: 3.0.0
@@ -97,6 +103,7 @@ files:
97
103
  - lib/mongoid/clients.rb
98
104
  - lib/mongoid/clients/factory.rb
99
105
  - lib/mongoid/clients/options.rb
106
+ - lib/mongoid/clients/sessions.rb
100
107
  - lib/mongoid/clients/storage_options.rb
101
108
  - lib/mongoid/clients/validators.rb
102
109
  - lib/mongoid/clients/validators/storage.rb
@@ -179,6 +186,7 @@ files:
179
186
  - lib/mongoid/errors/invalid_persistence_option.rb
180
187
  - lib/mongoid/errors/invalid_relation.rb
181
188
  - lib/mongoid/errors/invalid_scope.rb
189
+ - lib/mongoid/errors/invalid_session_use.rb
182
190
  - lib/mongoid/errors/invalid_set_polymorphic_relation.rb
183
191
  - lib/mongoid/errors/invalid_storage_options.rb
184
192
  - lib/mongoid/errors/invalid_storage_parent.rb
@@ -598,6 +606,7 @@ files:
598
606
  - spec/mongoid/changeable_spec.rb
599
607
  - spec/mongoid/clients/factory_spec.rb
600
608
  - spec/mongoid/clients/options_spec.rb
609
+ - spec/mongoid/clients/sessions_spec.rb
601
610
  - spec/mongoid/clients_spec.rb
602
611
  - spec/mongoid/composable_spec.rb
603
612
  - spec/mongoid/config/environment_spec.rb
@@ -863,7 +872,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
863
872
  version: 1.3.6
864
873
  requirements: []
865
874
  rubyforge_project: mongoid
866
- rubygems_version: 2.6.14
875
+ rubygems_version: 2.7.3
867
876
  signing_key:
868
877
  specification_version: 4
869
878
  summary: Elegant Persistence in Ruby for MongoDB.
@@ -872,6 +881,7 @@ test_files:
872
881
  - spec/mongoid/scopable_spec.rb
873
882
  - spec/mongoid/clients/factory_spec.rb
874
883
  - spec/mongoid/clients/options_spec.rb
884
+ - spec/mongoid/clients/sessions_spec.rb
875
885
  - spec/mongoid/matchable_spec.rb
876
886
  - spec/mongoid/copyable_spec.rb
877
887
  - spec/mongoid/changeable_spec.rb
metadata.gz.sig CHANGED
Binary file